/* ── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink-50:  #f8f8f7;
  --ink-100: #eeeeec;
  --ink-200: #d9d9d5;
  --ink-400: #8a8a86;
  --ink-600: #4a4a46;
  --ink-800: #23231f;
  --ink-900: #131311;
  --accent:  #2f6feb;
  --green:   #2ecc71;
  --red:     #e74c3c;
  --amber:   #f39c12;
}

html {
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto,
               Helvetica, Arial, sans-serif;
  background: var(--ink-50);
  color: var(--ink-800);
  color-scheme: light;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html.dark {
  background: var(--ink-900);
  color: var(--ink-100);
  color-scheme: dark;
}

body { min-height: 100vh; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.01em; color: var(--ink-900); }
html.dark h1, html.dark h2, html.dark h3, html.dark h4 { color: var(--ink-50); }

h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 0.875rem; text-transform: uppercase; letter-spacing: 0.05em;
     color: var(--ink-400); }

code, pre, .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ── Container ────────────────────────────────────────────────────── */
.container { max-width: 896px; margin: 0 auto; padding: 0 1rem; }

/* ── Topbar ───────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  height: 52px; padding: 0 1.5rem;
  background: rgba(255,255,255,0.72);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--ink-100);
  transition: background 0.2s, border-color 0.2s;
}
html.dark .topbar {
  background: rgba(19,19,17,0.72);
  border-bottom-color: var(--ink-800);
}

.topbar-left { display: flex; align-items: center; gap: 0.5rem; }
.topbar-title { font-size: 0.9375rem; font-weight: 600; color: var(--ink-900); }
html.dark .topbar-title { color: var(--ink-50); }
.topbar-title a { color: inherit; text-decoration: none; }

.topbar-nav { display: flex; align-items: center; gap: 0.25rem; }
.topbar-nav a {
  padding: 0.375rem 0.75rem; border-radius: 6px;
  font-size: 0.8125rem; font-weight: 500; color: var(--ink-600);
  text-decoration: none; transition: background 0.15s, color 0.15s;
}
.topbar-nav a:hover { background: var(--ink-100); color: var(--ink-900); }
.topbar-nav a.active { background: var(--ink-200); color: var(--ink-900); }
html.dark .topbar-nav a { color: var(--ink-400); }
html.dark .topbar-nav a:hover { background: var(--ink-800); color: var(--ink-100); }
html.dark .topbar-nav a.active { background: var(--ink-800); color: var(--ink-50); }

.topbar-right { display: flex; align-items: center; gap: 0.75rem; }

/* Sign-out: only rendered when the dashboard password gate is on. */
.topbar-signout {
  font-size: 0.8125rem; font-weight: 500; color: var(--ink-600);
  text-decoration: none; transition: color 0.15s;
}
.topbar-signout:hover { color: var(--ink-900); text-decoration: none; }
html.dark .topbar-signout { color: var(--ink-400); }
html.dark .topbar-signout:hover { color: var(--ink-100); }

/* ── Theme toggle ─────────────────────────────────────────────────── */
.theme-toggle {
  width: 34px; height: 34px; border: 1px solid var(--ink-200);
  border-radius: 8px; background: transparent; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; line-height: 1; color: var(--ink-600);
  transition: background 0.15s, border-color 0.15s;
}
.theme-toggle:hover { background: var(--ink-100); }
html.dark .theme-toggle { border-color: var(--ink-800); color: var(--ink-400); }
html.dark .theme-toggle:hover { background: var(--ink-800); }

/* ── Connection badge ─────────────────────────────────────────────── */
.conn { display: none; align-items: center; gap: 6px; font-size: 0.75rem; }
.conn.visible { display: flex; }
.conn .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-400); }
.conn[data-state="live"] .dot { background: var(--green); }
.conn[data-state="reconnecting"] .dot { background: var(--amber); animation: pulse 1.2s ease-in-out infinite; }
.conn[data-state="disconnected"] .dot { background: var(--red); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Banner ───────────────────────────────────────────────────────── */
.banner {
  padding: 10px 1.5rem; font-size: 0.8125rem; text-align: center;
  background: #5b2222; color: #fff;
}
.banner.hidden { display: none; }

/* ── Main content ─────────────────────────────────────────────────── */
main { padding: 2rem 0; }

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
  background: #fff; border: 1px solid var(--ink-200);
  border-radius: 10px; padding: 1.25rem;
}
html.dark .card { background: var(--ink-900); border-color: var(--ink-800); }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 0.375rem;
  padding: 0.5rem 0.875rem; border: none; border-radius: 7px;
  font-size: 0.8125rem; font-weight: 500; cursor: pointer;
  background: var(--ink-900); color: #fff;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
}
.btn:hover { background: var(--ink-800); text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
html.dark .btn { background: var(--ink-50); color: var(--ink-900); }
html.dark .btn:hover { background: var(--ink-100); }

.btn-secondary {
  display: inline-flex; align-items: center; gap: 0.375rem;
  padding: 0.5rem 0.875rem; border: 1px solid var(--ink-200);
  border-radius: 7px; font-size: 0.8125rem; font-weight: 500;
  cursor: pointer; background: transparent; color: var(--ink-800);
  transition: background 0.15s, border-color 0.15s;
  text-decoration: none;
}
.btn-secondary:hover { background: var(--ink-100); text-decoration: none; }
html.dark .btn-secondary { border-color: var(--ink-800); color: var(--ink-100); }
html.dark .btn-secondary:hover { background: var(--ink-800); }

.btn-danger {
  display: inline-flex; align-items: center; gap: 0.375rem;
  padding: 0.5rem 0.875rem; border: 1px solid var(--red);
  border-radius: 7px; font-size: 0.8125rem; font-weight: 500;
  cursor: pointer; background: transparent; color: var(--red);
  transition: background 0.15s;
}
.btn-danger:hover { background: rgba(231,76,60,0.08); }

.btn-sm { padding: 0.25rem 0.625rem; font-size: 0.75rem; border-radius: 5px; }

/* ── Forms ────────────────────────────────────────────────────────── */
/* `.fld > span` catches the bare <span> labels the editor emits, so a field
   built as <label class="fld"><span>name</span><input></label> looks the same
   as one using an explicit .label. .hint is excluded — it sits in the same
   slot but is helper text, not a label. */
.label, .fld > span:not(.hint) {
  display: block; font-size: 0.6875rem; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-600); margin-bottom: 0.25rem;
}
html.dark .label, html.dark .fld > span:not(.hint) { color: var(--ink-200); }

/* Every text-ish control shares one look. `input`/`select`/`textarea` are
   styled by element too, so a control that forgets the .input class still
   matches the rest of the form instead of falling back to the UA default. */
.input, .textarea,
input[type="text"], input[type="number"], input[type="password"],
input[type="search"], input:not([type]), textarea, select {
  width: 100%; padding: 0.5rem 0.625rem;
  border: 1px solid var(--ink-200); border-radius: 7px;
  font-size: 0.8125rem; font-family: inherit; line-height: 1.4;
  background: #fff; color: var(--ink-900);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .textarea:focus,
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47,111,235,0.15);
}
html.dark .input, html.dark .textarea,
html.dark input[type="text"], html.dark input[type="number"],
html.dark input[type="password"], html.dark input[type="search"],
html.dark input:not([type]), html.dark textarea, html.dark select {
  background: var(--ink-900); border-color: var(--ink-800); color: var(--ink-100);
}
html.dark .input:focus, html.dark .textarea:focus,
html.dark input:focus, html.dark textarea:focus, html.dark select:focus {
  box-shadow: 0 0 0 3px rgba(47,111,235,0.25);
}
input::placeholder, textarea::placeholder { color: var(--ink-400); }

.textarea, textarea { min-height: 80px; resize: vertical; }

select { cursor: pointer; }
/* Checkboxes must keep their intrinsic size — the rules above would stretch
   them to the full field width. */
input[type="checkbox"], input[type="radio"] {
  width: auto; padding: 0; accent-color: var(--accent);
}

.fld { margin-bottom: 0.875rem; }
.fld-row { display: flex; gap: 0.75rem; align-items: flex-end; }
/* Per-field helper text explaining what a knob actually does. */
.fld-hint {
  display: block; margin-top: 0.25rem;
  font-size: 0.6875rem; line-height: 1.45; color: var(--ink-400);
}

/* ── Segmented control ────────────────────────────────────────────── */
.seg { display: inline-flex; border-radius: 7px; overflow: hidden;
       border: 1px solid var(--ink-200); }
.seg button {
  padding: 0.375rem 0.75rem; border: none; border-right: 1px solid var(--ink-200);
  font-size: 0.75rem; font-weight: 500; cursor: pointer;
  background: transparent; color: var(--ink-600);
  transition: background 0.15s, color 0.15s;
}
.seg button:last-child { border-right: none; }
.seg button.active { background: var(--ink-900); color: #fff; }
html.dark .seg { border-color: var(--ink-800); }
html.dark .seg button { border-color: var(--ink-800); color: var(--ink-400); }
html.dark .seg button.active { background: var(--ink-50); color: var(--ink-900); }

/* ── Tables ───────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; }
.table th {
  font-size: 0.6875rem; font-weight: 500; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--ink-400);
  padding: 0.5rem 0.75rem; text-align: left;
  border-bottom: 2px solid var(--ink-200);
}
html.dark .table th { border-bottom-color: var(--ink-800); }
.table td {
  padding: 0.625rem 0.75rem; font-size: 0.8125rem;
  border-bottom: 1px solid var(--ink-100);
}
html.dark .table td { border-bottom-color: var(--ink-800); }
.table tbody tr { cursor: pointer; transition: background 0.1s; }
.table tbody tr:hover { background: var(--ink-100); }
html.dark .table tbody tr:hover { background: var(--ink-800); }

/* ── Status dots ──────────────────────────────────────────────────── */
.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%;
              margin-right: 0.375rem; vertical-align: middle; }
.status-active    .status-dot { background: var(--green); }
.status-winddown  .status-dot { background: var(--amber); }
.status-paused    .status-dot { background: var(--ink-400); }
.status-completed .status-dot { background: var(--accent); }
.status-draft     .status-dot { background: var(--ink-400); }
.status-archived  .status-dot { background: var(--ink-200); }
html.dark .status-archived .status-dot { background: var(--ink-600); }

/* ── KPI grid ─────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
            gap: 0.75rem; margin: 1rem 0; }
.kpi .kpi-label { font-size: 0.6875rem; font-weight: 500; text-transform: uppercase;
                  letter-spacing: 0.05em; color: var(--ink-400); margin-bottom: 0.25rem; }
.kpi .kpi-value { font-size: 1.375rem; font-weight: 600; color: var(--ink-900); }
html.dark .kpi .kpi-value { color: var(--ink-50); }

/* ── Controls row ─────────────────────────────────────────────────── */
.controls { display: flex; gap: 1.5rem; align-items: flex-end;
            margin-bottom: 1rem; flex-wrap: wrap; }
/* A .toggle-label inside a control is a checkbox caption, not the control's
   own heading — it keeps its normal casing. */
.control > label:not(.toggle-label) {
  font-size: 0.6875rem; font-weight: 500; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--ink-400);
  display: block; margin-bottom: 0.25rem;
}
.control > .toggle-label { height: 34px; }

/* ── Chart ────────────────────────────────────────────────────────── */
.chart-wrap { height: 300px; }

/* ── Actions bar ──────────────────────────────────────────────────── */
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ── Row (2-col grid) ─────────────────────────────────────────────── */
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }

/* ── Page header (back link + title + actions) ────────────────────── */
.page-header { margin-bottom: 1.5rem; }
.page-header nav { margin-bottom: 0.5rem; }
/* Campaign controls sit beside the title so they're reachable without
   scrolling past the whole page. */
.page-header-bar {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
}
.page-header-bar .actions { padding-top: 0.25rem; }

/* Card header row: title on the left, a control on the right. */
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; margin-bottom: 0.75rem;
}
.card-head h3 { margin: 0; }

/* ── Editor ───────────────────────────────────────────────────────── */
/* The editor needs more room than the 896px reading column the rest of
   the dashboard uses — nav, form and live preview sit side by side. */
.container:has(.editor) { max-width: 1180px; }

.editor-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin: 0.5rem 0 0.25rem;
}
.editor-header h2 { margin-bottom: 0.15rem; }
.editor-header-actions {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
}
.editor-error { color: var(--red); font-size: 0.75rem; min-height: 1rem; }

.editor {
  display: grid; grid-template-columns: 164px minmax(0, 1fr) 288px;
  gap: 1.25rem; margin-top: 1rem; align-items: start;
}
@media (max-width: 1100px) {
  .editor { grid-template-columns: 164px minmax(0, 1fr); }
  .editor-preview { grid-column: 1 / -1; }
}
.editor-nav { display: flex; flex-direction: column; gap: 2px; }
.editor-nav button {
  padding: 0.5rem 0.75rem; border: none; border-radius: 6px;
  text-align: left; font-size: 0.8125rem; cursor: pointer;
  background: transparent; color: var(--ink-600);
  transition: background 0.15s, color 0.15s;
}
.editor-nav button:hover { background: var(--ink-100); }
.editor-nav button.active {
  background: var(--ink-200); color: var(--ink-900); font-weight: 500;
}
html.dark .editor-nav button { color: var(--ink-400); }
html.dark .editor-nav button:hover { background: var(--ink-800); }
html.dark .editor-nav button.active {
  background: var(--ink-800); color: var(--ink-50);
}

/* Editor form area */
.editor-form { min-height: 400px; }
.editor-form h3 { margin-bottom: 0.875rem; }
/* Grouped block of related fields, so the form reads as sections rather
   than one undifferentiated stack of inputs. */
.fld-group {
  border: 1px solid var(--ink-200); border-radius: 8px;
  padding: 0.875rem 1rem 0.25rem; margin-bottom: 0.875rem;
}
html.dark .fld-group { border-color: var(--ink-800); }
/* Extra breathing room so a field's hint reads as belonging to the field
   above it rather than to the label below. */
.fld-group .fld { margin-bottom: 1.25rem; }
.fld-group > .fld-group-title {
  font-size: 0.6875rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--ink-400); margin-bottom: 0.75rem;
}
.fld-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.875rem; }
@media (max-width: 640px) { .fld-grid { grid-template-columns: 1fr; } }

/* ── Editor live preview ──────────────────────────────────────────── */
.editor-preview {
  position: sticky; top: 72px;
  border: 1px solid var(--ink-200); border-radius: 10px;
  padding: 1rem; background: #fff;
}
html.dark .editor-preview { background: var(--ink-900); border-color: var(--ink-800); }
.editor-preview h4 {
  font-size: 0.6875rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--ink-400); margin-bottom: 0.75rem;
}
.preview-stat {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 0.5rem; padding: 0.3rem 0; font-size: 0.75rem;
}
.preview-stat + .preview-stat { border-top: 1px solid var(--ink-100); }
html.dark .preview-stat + .preview-stat { border-top-color: var(--ink-800); }
.preview-stat .k { color: var(--ink-400); }
.preview-stat .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.preview-section {
  margin-top: 0.875rem; padding-top: 0.875rem;
  border-top: 1px solid var(--ink-200);
}
html.dark .preview-section { border-top-color: var(--ink-800); }
.preview-note { font-size: 0.6875rem; color: var(--ink-400); line-height: 1.45; }

/* Sparkline of the projected daily visit count over the ramp. */
.preview-spark {
  display: flex; align-items: flex-end; gap: 1px; height: 52px;
  margin-bottom: 0.35rem;
}
.preview-spark div {
  flex: 1; min-height: 2px; border-radius: 1px 1px 0 0;
  background: var(--accent); opacity: 0.75;
}
.preview-spark div:last-child { opacity: 1; }
.preview-axis {
  display: flex; justify-content: space-between;
  font-size: 0.625rem; color: var(--ink-400);
}

/* 24-bar hour-of-day distribution. */
.preview-hours { display: flex; align-items: flex-end; gap: 1px; height: 48px; }
.preview-hours div {
  flex: 1; min-height: 2px; border-radius: 1px 1px 0 0;
  background: var(--accent); opacity: 0.45;
}

/* ── Curve editor (24 draggable hour bars) ────────────────────────── */
.curve-chart {
  display: flex; align-items: flex-end; gap: 2px;
  height: 140px; margin: 0.75rem 0 0.5rem;
  padding: 0.5rem 0.5rem 0; border: 1px solid var(--ink-200);
  border-radius: 8px; background: var(--ink-50);
}
html.dark .curve-chart { border-color: var(--ink-800); background: #0d0d0c; }
.curve-bar {
  flex: 1; min-height: 2px; border-radius: 2px 2px 0 0;
  background: var(--accent); opacity: 0.75;
  cursor: ns-resize; touch-action: none;
  transition: opacity 0.1s;
}
.curve-bar:hover { opacity: 1; }
.curve-axis {
  display: flex; justify-content: space-between;
  font-size: 0.625rem; color: var(--ink-400); margin-bottom: 0.5rem;
}

/* ── Prompt cards (editor) ────────────────────────────────────────── */
.prompt-card {
  border: 1px solid var(--ink-200); border-radius: 8px;
  padding: 1rem; margin-bottom: 0.75rem;
}
html.dark .prompt-card { border-color: var(--ink-800); }

.prompt-card-header {
  display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.625rem;
}
.prompt-card-header .fld { margin-bottom: 0; }
.prompt-card-header .fld input { width: 56px; }
.prompt-card-header .spacer { flex: 1; }

.prompt-card .prompt-url { margin-bottom: 0.625rem; }

.prompt-card-footer {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 0.5rem; margin-top: 0.5rem;
}

.prompt-test-result {
  margin-top: 0.625rem; padding: 0.75rem;
  background: var(--ink-50); border-radius: 6px;
  font-size: 0.75rem; display: none;
}
.prompt-test-result.open { display: block; }
html.dark .prompt-test-result { background: var(--ink-800); }

/* ── Modal ────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.4); display: flex;
  align-items: center; justify-content: center;
}
html.dark .modal-backdrop { background: rgba(0,0,0,0.6); }
.modal-backdrop.hidden { display: none; }
.modal {
  background: #fff; border-radius: 12px; padding: 1.5rem;
  max-width: 520px; width: 90%; max-height: 80vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
html.dark .modal { background: var(--ink-900); }
.modal h3 { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end;
                 margin-top: 1rem; }

/* ── Spinner ──────────────────────────────────────────────────────── */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--ink-200); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Badge ────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 0.125rem 0.5rem; border-radius: 999px;
  font-size: 0.6875rem; font-weight: 500; vertical-align: middle;
}
.badge-muted  { background: var(--ink-100); color: var(--ink-600); }
.badge-accent { background: rgba(47,111,235,0.1); color: var(--accent); }
html.dark .badge-muted  { background: var(--ink-800); color: var(--ink-400); }
html.dark .badge-accent { background: rgba(47,111,235,0.15); color: var(--accent); }

/* ── Settings page ────────────────────────────────────────────────── */
.settings-card { max-width: 480px; }
.settings-card .fld { margin-bottom: 1.25rem; }
.password-wrap { position: relative; }
.password-wrap .toggle-vis {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer;
  font-size: 0.75rem; color: var(--ink-400); padding: 4px;
}
.password-wrap .toggle-vis:hover { color: var(--ink-800); }

/* ── Reward ───────────────────────────────────────────────────────── */
/* The reward toggle hides these cells wholesale, header included. */
.hide-reward .col-reward { display: none; }
.reward-value { font-variant-numeric: tabular-nums; color: var(--green); font-weight: 500; }
.reward-value.zero { color: var(--ink-400); font-weight: 400; }

/* ── Misc ─────────────────────────────────────────────────────────── */
.hint { font-size: 0.6875rem; color: var(--ink-400); }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }
.hidden { display: none !important; }

/* ── Tabs ─────────────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 2px; margin-bottom: 1rem;
  border-bottom: 1px solid var(--ink-200);
}
html.dark .tabs { border-bottom-color: var(--ink-800); }
.tab {
  padding: 0.5rem 1.25rem; border: none; border-bottom: 2px solid transparent;
  background: none; font-size: 0.8125rem; font-weight: 500;
  cursor: pointer; color: var(--ink-400);
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--ink-900); }
.tab.active { color: var(--ink-900); border-bottom-color: var(--accent); }
html.dark .tab:hover { color: var(--ink-100); }
html.dark .tab.active { color: var(--ink-50); }

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

/* ── History timeline ─────────────────────────────────────────────── */
.history-item {
  border: 1px solid var(--ink-200);
  border-radius: 8px; margin-bottom: 0.75rem; overflow: hidden;
}
html.dark .history-item { border-color: var(--ink-700); }

.history-header {
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center;
  padding: 0.6rem 0.75rem; font-size: 0.75rem;
  background: var(--ink-50); cursor: pointer; user-select: none;
}
html.dark .history-header { background: var(--ink-800); }
.history-header:hover { background: var(--ink-100); }
html.dark .history-header:hover { background: var(--ink-700); }

.history-label { font-weight: 600; min-width: 50px; }
.history-time { color: var(--ink-400); font-size: 0.6875rem; }
.history-status { font-size: 0.625rem; padding: 1px 6px; border-radius: 4px; font-weight: 600; }
.history-status.status-succeeded { background: var(--green); color: #fff; }
.history-status.status-failed, .history-status.status-timeout { background: var(--red); color: #fff; }
.history-meta { color: var(--ink-400); font-size: 0.6875rem; }
.history-goal { flex: 1; min-width: 200px; color: var(--ink-600); font-size: 0.6875rem; }
html.dark .history-goal { color: var(--ink-300); }
.history-expand { font-size: 0.625rem; transition: transform 0.2s; color: var(--ink-400); }
.history-item.expanded .history-expand { transform: rotate(90deg); }

.history-events { display: none; padding: 0; }
.history-item.expanded .history-events { display: block; }

.ev-row {
  display: flex; gap: 0.5rem; align-items: baseline;
  padding: 0.3rem 0.75rem; font-size: 0.6875rem;
  border-bottom: 1px solid var(--ink-100);
  line-height: 1.5;
}
.ev-row:last-child { border-bottom: none; }
html.dark .ev-row { border-bottom-color: var(--ink-800); }
.ev-row:hover { background: var(--ink-50); }
html.dark .ev-row:hover { background: var(--ink-800); }

.ev-seq { flex-shrink: 0; width: 2rem; text-align: right; font-family: ui-monospace, monospace; color: var(--ink-400); font-size: 0.625rem; }
.ev-url { flex-shrink: 0; width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-400); }
.ev-type { flex-shrink: 0; }

.event-badge {
  display: inline-block; font-size: 0.5625rem; padding: 0 4px; border-radius: 3px;
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;
  background: var(--ink-200); color: var(--ink-700);
}
html.dark .event-badge { background: var(--ink-700); color: var(--ink-200); }
.event-badge-save_finding { background: #d4edda; color: #155724; }
html.dark .event-badge-save_finding { background: #1a3a2a; color: #8fdf8f; }
.event-badge-follow_links { background: #cce5ff; color: #004085; }
html.dark .event-badge-follow_links { background: #1a2d4a; color: #8fc8ff; }
.event-badge-finish_crawl { background: #fff3cd; color: #856404; }
html.dark .event-badge-finish_crawl { background: #3d3200; color: #ffd970; }
.event-badge-llm_call { background: #e8daef; color: #6c3483; }
html.dark .event-badge-llm_call { background: #2d1a3d; color: #d4a0f0; }
.event-badge-cache_replay { background: var(--ink-200); color: var(--ink-600); font-style: italic; }
.event-badge-llm_error, .event-badge-fetch_error { background: #f8d7da; color: #721c24; }
html.dark .event-badge-llm_error, html.dark .event-badge-fetch_error { background: #3d1a1d; color: #f09090; }

.ev-desc { flex: 1; min-width: 0; word-break: break-word; }

/* Inline trace screenshot thumbnail (rendered in the History timeline) */
.ev-shot {
  display: block;
  margin-top: 0.35rem;
  max-height: 120px;
  max-width: 100%;
  border: 1px solid var(--ink-300);
  border-radius: 4px;
  cursor: zoom-in;
  object-fit: cover;
  object-position: top left;
}
.ev-shot:hover { border-color: var(--accent, #6c3483); }
html.dark .ev-shot { border-color: var(--ink-700); }

/* Fullscreen lightbox opened on thumbnail click */
.shot-lightbox {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, 0.82);
  cursor: zoom-out;
  padding: 2rem;
}
.shot-lightbox.hidden { display: none; }
.shot-lightbox img {
  max-width: 100%; max-height: 100%;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

.toggle-label {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.75rem; color: var(--ink-600); cursor: pointer;
  user-select: none;
}
.toggle-label input[type="checkbox"] { cursor: pointer; }

/* ── Login ────────────────────────────────────────────────────────── */
/* Only the layout is new here — inputs, .btn and .theme-toggle already
   carry the app's look, so the sign-in page matches without restating it. */
.login-body {
  display: grid; place-items: center; min-height: 100vh; padding: 1.5rem;
  background: radial-gradient(48rem 30rem at 50% -8%,
              rgba(47,111,235,0.10), transparent 62%), var(--ink-50);
}
html.dark .login-body {
  background: radial-gradient(48rem 30rem at 50% -8%,
              rgba(47,111,235,0.15), transparent 62%), var(--ink-900);
}
.login-theme { position: fixed; top: 1rem; right: 1rem; }
.login-main { width: 100%; max-width: 21rem; }
.login-card {
  display: flex; flex-direction: column; gap: 0.75rem;
  padding: 1.5rem;
  border: 1px solid var(--ink-200); border-radius: 14px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 16px 40px -20px rgba(0,0,0,0.22);
}
html.dark .login-card {
  background: var(--ink-900); border-color: var(--ink-800);
  box-shadow: 0 1px 2px rgba(0,0,0,0.4), 0 16px 40px -20px rgba(0,0,0,0.7);
}
.login-head { display: flex; align-items: baseline; gap: 0.375rem; }
.login-mark { font-size: 1rem; font-weight: 600; letter-spacing: -0.01em; }
.login-mark-sub { font-size: 0.8125rem; color: var(--ink-400); }
.login-sub { font-size: 0.8125rem; color: var(--ink-400); margin-bottom: 0.125rem; }
.login-field { display: flex; flex-direction: column; gap: 0.375rem; }
.login-field > span {
  font-size: 0.6875rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-400);
}
.login-submit { width: 100%; justify-content: center; margin-top: 0.25rem; }
.login-error {
  padding: 0.5rem 0.625rem; border-radius: 7px;
  font-size: 0.8125rem; color: var(--red);
  background: rgba(231,76,60,0.08);
  border: 1px solid rgba(231,76,60,0.25);
}
