:root {
  --bg: #f4efe7;
  --ink: #182126;
  --muted: #5d696f;
  --panel: rgba(255, 252, 247, 0.88);
  --line: rgba(24, 33, 38, 0.12);
  --brand: #0f766e;
  --brand-2: #d97706;
  --ok: #1d9a5b;
  --warn: #b45309;
  --shadow: 0 18px 48px rgba(24, 33, 38, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.18), transparent 34%),
    radial-gradient(circle at bottom right, rgba(217, 119, 6, 0.18), transparent 32%),
    radial-gradient(circle at center, rgba(255, 255, 255, 0.45), transparent 48%),
    linear-gradient(135deg, #f9f3ea 0%, #f4eee6 45%, #edf4f3 100%);
  font-family: Georgia, "Times New Roman", serif;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.16), transparent 24%),
    radial-gradient(circle at bottom right, rgba(217, 119, 6, 0.14), transparent 22%),
    radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.4), transparent 30%);
  filter: blur(38px);
  opacity: 0.95;
}

.app {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 56px;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(24, 33, 38, 0.48);
  backdrop-filter: blur(10px);
}

.auth-overlay.hidden {
  display: none;
}

.auth-card {
  width: min(860px, 100%);
  background: rgba(255, 252, 247, 0.96);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 26px;
}

.auth-card-inline {
  margin: 0 auto;
}

.auth-page {
  padding-top: 72px;
}

.auth-page .hero {
  text-align: center;
}

.auth-page .eyebrow,
.auth-page h1,
.auth-page .auth-status {
  margin-left: auto;
  margin-right: auto;
}

.auth-page .auth-status {
  max-width: 56ch;
}

.auth-status {
  margin: 0 0 18px;
  color: var(--muted);
}

.auth-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.auth-box {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.78);
}

.auth-box h3 {
  margin: 0;
}

.auth-session {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.auth-session-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.auth-session-info span {
  color: var(--muted);
  font-size: 0.95rem;
}

.invite-admin-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr 0.8fr auto;
  gap: 16px;
  align-items: end;
  margin-bottom: 12px;
}

.audit-toolbar {
  grid-template-columns: 1.2fr auto auto;
  margin: 12px 0;
}

.invite-list {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.7);
  font-family: "Courier New", monospace;
  font-size: 0.92rem;
  white-space: pre-wrap;
}

.invite-items {
  display: grid;
  gap: 10px;
}

.invite-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.invite-item:last-child {
  border-bottom: 0;
}

.invite-meta {
  display: grid;
  gap: 4px;
}

.invite-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.invite-actions button {
  padding: 8px 12px;
}

.hidden {
  display: none !important;
}

.hero { margin-bottom: 24px; }
.eyebrow {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--brand);
  font-size: 0.76rem;
  font-weight: 700;
}

h1, h2 { margin: 0 0 12px; }
h1 { font-size: clamp(2rem, 4vw, 3.2rem); line-height: 1; max-width: none; }
h2 { font-size: 1.2rem; }
.lead { max-width: 64ch; color: var(--muted); font-size: 1.05rem; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 20px;
  backdrop-filter: blur(16px);
}

.controls-top-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.top-shell {
  margin-bottom: 22px;
}

.top-tabs {
  margin-bottom: 18px;
}

.top-panel {
  display: none;
  gap: 18px;
}

.top-panel.active {
  display: grid;
}

.tabs-shell {
  margin-bottom: 22px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.tab-btn {
  background: rgba(255, 255, 255, 0.7);
  color: var(--ink);
}

.tab-btn.active {
  background: var(--brand);
  color: white;
}

.tab-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel-inner {
  background: rgba(255, 255, 255, 0.58);
  box-shadow: none;
}

.row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.row.hidden {
  display: none;
}

label {
  font-size: 0.95rem;
  color: var(--muted);
}

input, select, button {
  border-radius: 14px;
  border: 1px solid var(--line);
  font: inherit;
}

input, select {
  padding: 12px 14px;
  background: white;
}

textarea {
  border-radius: 14px;
  border: 1px solid var(--line);
  font: inherit;
  padding: 12px 14px;
  background: white;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 14px;
  color: var(--ink);
}

.log-toggle {
  margin-top: 0;
}

.toggle-row input {
  width: 18px;
  height: 18px;
}

.hex-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.hex-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.hex-legend-swatch {
  width: 18px;
  height: 12px;
  border-radius: 4px;
  border: 1px solid var(--line);
}

.hex-legend-data {
  background: rgba(217, 119, 6, 0.22);
}

.hex-legend-trailer {
  background: rgba(15, 118, 110, 0.22);
}

.hex-legend-blocked {
  background: rgba(185, 28, 28, 0.18);
}

button {
  padding: 12px 18px;
  background: var(--ink);
  color: white;
  cursor: pointer;
  transition: transform 160ms ease, opacity 160ms ease, background 160ms ease;
}

button:hover { transform: translateY(-1px); }
button.secondary { background: #6b7280; }
button.accent { background: var(--brand-2); }
button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #9ca3af;
  box-shadow: 0 0 0 6px rgba(156, 163, 175, 0.18);
}

.dot.connected {
  background: var(--ok);
  box-shadow: 0 0 0 6px rgba(29, 154, 91, 0.18);
}

.dot.busy {
  background: var(--warn);
  box-shadow: 0 0 0 6px rgba(180, 83, 9, 0.18);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  margin-bottom: 22px;
}

.recover-form {
  display: grid;
  gap: 18px;
  margin-bottom: 18px;
}

.recover-known-grid,
.recover-target-grid {
  display: grid;
  gap: 18px;
}

.recover-known-grid {
  grid-template-columns: 1fr 1fr 1fr 1.4fr;
}

.recover-target-grid {
  grid-template-columns: 1fr 1fr;
}

.facts {
  margin: 0;
  display: grid;
  gap: 14px;
}

.facts div {
  display: grid;
  gap: 4px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

dt {
  color: var(--muted);
  font-size: 0.92rem;
}

dd {
  margin: 0;
  font-family: "Courier New", monospace;
  font-size: 1rem;
}

pre {
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Courier New", monospace;
  font-size: 0.92rem;
  line-height: 1.45;
}

.ops-card {
  display: grid;
  gap: 16px;
}

.ops-head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.ops-head strong {
  font-size: 1.05rem;
}

.ops-head span,
.ops-detail {
  color: var(--muted);
  font-size: 0.94rem;
}

.ops-progress {
  display: grid;
  gap: 8px;
}

.ops-progress-bar {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: rgba(24, 33, 38, 0.08);
  overflow: hidden;
}

.ops-progress-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand) 0%, var(--brand-2) 100%);
  transition: width 220ms ease;
}

.ops-progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.ops-progress-meta strong {
  color: var(--ink);
  font-size: 0.95rem;
}

.ops-facts {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 18px;
}

.ops-facts div {
  display: grid;
  gap: 4px;
}

.ops-facts dd {
  font-family: inherit;
  font-weight: 700;
}

.ops-detail {
  margin: 0;
}

.hex-editor {
  width: 100%;
  min-height: 420px;
  resize: vertical;
  font-family: "Courier New", monospace;
  font-size: 0.92rem;
  line-height: 1.45;
  position: relative;
  color: transparent;
  caret-color: var(--ink);
  background: transparent;
  z-index: 2;
}

.hex-editor.dirty {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.12);
}

.hex-editor-shell {
  position: relative;
}

.hex-highlight {
  position: absolute;
  inset: 0;
  min-height: 420px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: white;
  overflow: auto;
  pointer-events: none;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Courier New", monospace;
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--ink);
  z-index: 1;
}

.hex-diff-block {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.hex-diff-block:last-child {
  border-bottom: 0;
}

.hex-diff-heading {
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 8px;
}

.hex-diff-title {
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 2px;
}

.hex-diff-key {
  color: var(--muted);
  margin: 0 0 2px;
}

.hex-diff-line {
  display: block;
  margin: 0;
  line-height: 1.15;
}

.hex-diff-label {
  display: inline-block;
  width: 10ch;
}

.hex-changed {
  background: rgba(217, 119, 6, 0.22);
  color: #8a4b00;
  border-radius: 4px;
}

.hex-changed-trailer {
  background: rgba(15, 118, 110, 0.22);
  color: #0f5c56;
  border-radius: 4px;
}

.hex-changed-blocked {
  background: rgba(185, 28, 28, 0.18);
  color: #991b1b;
  border-radius: 4px;
}

.hex-line-changed {
  display: inline-block;
  width: 100%;
  background: rgba(217, 119, 6, 0.08);
  border-radius: 6px;
}

.hex-diff-summary {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  font-family: "Courier New", monospace;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

#logOutput { min-height: 180px; max-height: 360px; }
#logOutput.hidden { display: none; }

@media (max-width: 820px) {
  .grid { grid-template-columns: 1fr; }
  .controls-top-grid { grid-template-columns: 1fr; }
  .recover-known-grid,
  .recover-target-grid { grid-template-columns: 1fr; }
  .ops-facts { grid-template-columns: 1fr; }
  .auth-grid,
  .invite-admin-grid { grid-template-columns: 1fr; }
  .auth-session { align-items: flex-start; flex-direction: column; }
  .app { width: min(100% - 20px, 1100px); padding-top: 24px; }
  h1 { max-width: none; font-size: clamp(1.7rem, 7vw, 2.4rem); }
}
