/* Theme tokens. Dark is the default (Rowads marketing style); the light theme
   overrides below follow the brand guidelines' docs palette. `data-theme` is
   set on <html> by a tiny head script before first paint (system preference,
   overridable via the ☀/☾ toggle → localStorage "extraweb_theme"). */
:root, html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --fg: #ffffff;
  --accent: #ed1165;
  --ok: #1fbf6c;
  --warn: #e0a11b;
  --frozen: #5cc8ff;
  --muted: rgba(255, 255, 255, 0.5);
  --muted-2: rgba(255, 255, 255, 0.35);
  --border: rgba(255, 255, 255, 0.1);
  --border-2: rgba(255, 255, 255, 0.16);
  --card-bg: rgba(255, 255, 255, 0.04);
  --card-bg-2: rgba(255, 255, 255, 0.06);
  --input-bg: rgba(0, 0, 0, 0.35);
  --topbar-bg: rgba(0, 0, 0, 0.85);
  --overlay-bg: rgba(0, 0, 0, 0.6);
  --surface: #0b0b0b;
  --surface-2: #141414;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --fg: #000000;
  --frozen: #0a7fbf;
  --muted: rgba(0, 0, 0, 0.45);
  --muted-2: rgba(0, 0, 0, 0.32);
  --border: rgba(0, 0, 0, 0.08);
  --border-2: rgba(0, 0, 0, 0.14);
  --card-bg: rgba(0, 0, 0, 0.03);
  --card-bg-2: rgba(0, 0, 0, 0.05);
  --input-bg: rgba(0, 0, 0, 0.04);
  --topbar-bg: rgba(255, 255, 255, 0.85);
  --overlay-bg: rgba(0, 0, 0, 0.35);
  --surface: #ffffff;
  --surface-2: #ffffff;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
}

* { box-sizing: border-box; }

/* The .gate/.viewer/.modal rules below set display:flex, which would otherwise
   beat the UA [hidden] rule (author class > UA attribute) and leave hidden
   overlays visible. Force hidden to win. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--muted); }
.accent { color: var(--accent); }
.error { color: var(--accent); }
.mono { font-family: var(--mono); }

button, input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--fg);
}

button { cursor: pointer; border: none; border-radius: var(--radius-sm); }

button.primary, .gate button {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 10px 16px;
}
button.primary:hover, .gate button:hover { filter: brightness(1.08); }

button.ghost, a.ghost {
  background: transparent;
  border: 1px solid var(--border-2);
  color: var(--fg);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
button.ghost:hover, a.ghost:hover { background: var(--card-bg); }

button.danger {
  background: transparent;
  border: 1px solid rgba(237, 17, 101, 0.4);
  color: var(--accent);
  padding: 8px 14px;
}
button.danger:hover { background: rgba(237, 17, 101, 0.1); }

.sm { padding: 6px 12px !important; font-size: 13px; }

input, select, textarea {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }

/* ── Gate ───────────────────────────────────────────────────────── */
.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.gate-card {
  width: 100%;
  max-width: 420px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
}
.gate-card h1 { font-size: 40px; font-weight: 800; letter-spacing: -0.04em; margin: 20px 0 8px; }
.gate-card p { margin: 0 0 24px; font-size: 14px; line-height: 1.5; }
.gate-form, #gate-form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.gate-details { margin-top: 18px; }
.gate-details summary { cursor: pointer; font-size: 13px; color: var(--muted); list-style: none; }
.gate-details summary::-webkit-details-marker { display: none; }
.gate-details summary:hover { color: var(--fg); }
.gate-details[open] summary { margin-bottom: 4px; }

/* ── Topbar ─────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-title { font-weight: 600; letter-spacing: -0.01em; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.pill {
  font-size: 12px;
  font-family: var(--mono);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
}

/* ── Layout ─────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 28px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px 28px 80px;
}
.col-head { display: flex; align-items: center; justify-content: space-between; }
.col-head h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.col-sub { margin: 6px 0 20px; font-size: 13px; line-height: 1.5; }
.empty { padding: 28px; border: 1px dashed var(--border-2); border-radius: var(--radius); text-align: center; font-size: 14px; }

/* ── Profile cards ──────────────────────────────────────────────── */
.cards { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
}
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-name { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.card-id { font-size: 11px; color: var(--muted-2); margin-top: 2px; }
.card-desc { margin: 6px 0 0; font-size: 13px; color: var(--muted); line-height: 1.4; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 0; }
.badge {
  font-size: 11px;
  font-family: var(--mono);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  color: var(--muted);
  display: inline-flex;
  gap: 5px;
  align-items: center;
}
.badge.on { color: var(--fg); border-color: var(--border-2); }
.badge.proxy { color: var(--accent); border-color: rgba(237,17,101,0.35); }
.badge.active { color: var(--ok); border-color: rgba(31,191,108,0.4); }
.badge.frozen { color: var(--frozen); border-color: color-mix(in srgb, var(--frozen) 35%, transparent); }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }

/* ── Sessions ───────────────────────────────────────────────────── */
.sessions { display: flex; flex-direction: column; gap: 12px; }
.session {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.session-meta { min-width: 0; }
.session-name { font-size: 14px; font-weight: 600; }
.session-sub { font-size: 12px; color: var(--muted); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-actions { display: flex; gap: 8px; flex-shrink: 0; }
.dot-live { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgba(31,191,108,0.2); display: inline-block; }

/* ── Sites list ─────────────────────────────────────────────────── */
.sites { display: flex; flex-direction: column; gap: 8px; max-height: 55vh; overflow-y: auto; }
.site-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--card-bg);
}
.site-host { font-weight: 600; font-size: 14px; }
.site-badges { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Session page (session.html — one session, full tab) ────────── */
/* The stage stays black in BOTH themes: it frames the remote browser's
   screen, not local UI. */
body.session-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
body.session-page .topbar { position: static; }
.session-stage { flex: 1; position: relative; background: #000; }
.session-stage iframe { width: 100%; height: 100%; border: 0; display: block; background: #000; }
.session-msg {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: var(--bg); text-align: center; padding: 24px;
}
.session-msg .spinner { width: 30px; height: 30px; border-width: 3px; }
.session-msg > div:not(.spinner) { max-width: 420px; font-size: 14px; line-height: 1.5; }
.session-msg-actions { display: flex; gap: 10px; }

/* ── Downloads drawer (session page) ────────────────────────────── */
.count-badge {
  display: inline-block; margin-left: 7px; min-width: 18px; padding: 1px 6px;
  border-radius: 9px; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 600; line-height: 16px; text-align: center;
}
.drawer {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 20;
  width: min(400px, 100%);
  display: flex; flex-direction: column; gap: 4px;
  padding: 20px;
  background: var(--surface); border-left: 1px solid var(--border-2);
  box-shadow: var(--shadow);
  overflow-y: auto;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-head h3 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.drawer-head-actions { display: flex; gap: 8px; }
.drawer-sub { margin: 6px 0 16px; font-size: 12px; line-height: 1.5; }
.dl-list { display: flex; flex-direction: column; gap: 8px; }
.dl-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: inherit; text-decoration: none;
}
.dl-row:hover { border-color: var(--accent); }
.dl-meta { min-width: 0; }
.dl-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-sub { font-size: 11px; color: var(--muted); font-family: var(--mono); margin-top: 3px; }
.dl-save { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.dl-row:hover .dl-save { color: var(--accent); }

/* ── Drag-and-drop upload overlay (session page) ────────────────── */
/* Hidden until a file drag enters the window (session.js toggles it); then it
   covers the stage above the iframe so the parent page catches the drop. */
.drop-overlay {
  position: absolute; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: color-mix(in srgb, var(--accent) 14%, rgba(0, 0, 0, 0.55));
  backdrop-filter: blur(2px);
}
.drop-card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  text-align: center; max-width: 380px;
  padding: 32px 40px;
  border: 2px dashed var(--accent); border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  pointer-events: none;
}
.drop-icon { font-size: 30px; line-height: 1; color: var(--accent); }
.drop-title { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.drop-sub { font-size: 13px; line-height: 1.5; }

/* ── Theme toggle (☀/☾) ─────────────────────────────────────────── */
.theme-toggle { font-size: 15px; line-height: 1; padding: 8px 11px !important; }

/* ── Modal ──────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: var(--overlay-bg); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal-card {
  width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-2); box-shadow: var(--shadow); border-radius: var(--radius); padding: 24px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h3 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
.field .hint { font-size: 11px; color: var(--muted-2); margin-top: 5px; line-height: 1.4; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.fieldset-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted-2); margin: 22px 0 12px; padding-top: 16px; border-top: 1px solid var(--border); }

/* Collapsible "Advanced options" block in dialogs. */
.adv-details { margin: 18px 0 4px; border-top: 1px solid var(--border); padding-top: 14px; }
.adv-details summary { cursor: pointer; font-size: 13px; font-weight: 500; list-style: none; }
.adv-details summary::-webkit-details-marker { display: none; }
.adv-details summary::before { content: "▸ "; color: var(--muted); }
.adv-details[open] summary::before { content: "▾ "; }
.adv-details summary:hover { color: var(--accent); }
.adv-body { margin-top: 14px; }

/* ── Toasts ─────────────────────────────────────────────────────── */
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 80; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--surface-2); border: 1px solid var(--border-2); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 12px 16px; font-size: 13px; max-width: 340px;
  box-shadow: var(--shadow);
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--accent); }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-2); border-top-color: var(--fg);
  animation: spin 0.8s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { display: flex; justify-content: center; padding: 40px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

/* ── Admin page (admin.html) ────────────────────────────────────────────── */
.admin { max-width: 1240px; margin: 0 auto; padding: 28px 28px 90px; display: flex; flex-direction: column; gap: 28px; }
.range-select { width: auto; padding: 7px 10px; font-size: 13px; }

/* Health strip: the first thing an operator reads. State is a dot AND words,
   never color alone. */
.health { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.health-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-bg);
}
.health-dot { width: 9px; height: 9px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; background: var(--muted-2); }
.health-item.ok .health-dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(31,191,108,0.18); }
.health-item.warn .health-dot { background: var(--warn); box-shadow: 0 0 0 3px rgba(224,161,27,0.18); }
.health-item.bad .health-dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(237,17,101,0.2); }
.health-item.bad { border-color: rgba(237,17,101,0.4); }
.health-label { font-size: 14px; font-weight: 600; }
.health-sub { font-size: 12px; margin-top: 2px; }

/* Headline numbers. */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.tile { padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-bg); }
.tile-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
.tile-value { font-size: 30px; font-weight: 700; letter-spacing: -0.03em; margin-top: 6px; line-height: 1.05; }
.tile-sub { font-size: 12px; margin-top: 4px; }

.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-bg); padding: 18px 20px 16px; }
.panel.wide { grid-column: 1 / -1; }
.panel-head h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.panel-sub { margin: 4px 0 14px; font-size: 12px; line-height: 1.5; }

/* Charts: recessive axes, thin marks, no value printed on every bar. */
.chart { width: 100%; }
.chart-empty { padding: 48px 12px; text-align: center; font-size: 13px; }
.grid-line { stroke: var(--border); stroke-width: 1; }
.axis-label { fill: var(--muted-2); font-size: 10px; font-family: var(--mono); }
/* The hit targets sit above the marks, so hovering is signalled from JS:
   the chart dims and the hovered column stays lit. */
.bar { transition: opacity 0.12s; }
.chart svg.dim .bar { opacity: 0.45; }
.chart svg .bar.bar-hi { opacity: 1; }
.chart-tip {
  position: fixed; z-index: 90; pointer-events: none;
  background: var(--surface-2); border: 1px solid var(--border-2); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); padding: 9px 12px; font-size: 12px; line-height: 1.5; max-width: 260px;
}
.chart-tip .tip-title { font-weight: 600; font-family: var(--mono); margin-bottom: 3px; }
.chart-tip .tip-line { color: var(--muted); }

.data-toggle { margin-top: 12px; }
.data-toggle summary { cursor: pointer; font-size: 12px; color: var(--muted); list-style: none; }
.data-toggle summary::-webkit-details-marker { display: none; }
.data-toggle summary::before { content: "▸ "; }
.data-toggle[open] summary::before { content: "▾ "; }
.data-toggle summary:hover { color: var(--fg); }

.table-wrap { overflow-x: auto; max-height: 420px; overflow-y: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left; font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted-2); padding: 8px 10px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface);
}
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.data-table td.num, .data-table th.num { text-align: right; font-family: var(--mono); }
.data-table tbody tr:hover td { background: var(--card-bg-2); }

/* Health feed + alerts. */
.feed { display: flex; flex-direction: column; gap: 8px; max-height: 460px; overflow-y: auto; }
.feed-row { padding: 10px 12px; border: 1px solid var(--border); border-left-width: 3px; border-radius: var(--radius-sm); }
.feed-row.bad { border-left-color: var(--accent); }
.feed-row.warn { border-left-color: var(--warn); }
.feed-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.feed-kind { font-size: 13px; font-weight: 600; }
.feed-time { font-size: 11px; flex-shrink: 0; }
.feed-sub { font-size: 11px; margin-top: 2px; }
.feed-detail { font-size: 11px; color: var(--muted); margin-top: 6px; white-space: pre-wrap; word-break: break-word; }
.feed-more summary { cursor: pointer; font-size: 11px; color: var(--muted); margin-top: 6px; }

/* Settings. */
.settings { display: flex; flex-direction: column; gap: 26px; }
.settings-block h3 { margin: 0 0 4px; font-size: 14px; font-weight: 700; }
.settings-block > p { margin: 0 0 12px; font-size: 12px; }
.settings-grid { display: grid; grid-template-columns: minmax(220px, 1.3fr) 1fr 1fr; gap: 14px 18px; align-items: start; }
.settings-grid .field { margin-bottom: 0; }
.check-row { display: flex; align-items: flex-start; gap: 10px; font-size: 13px; cursor: pointer; }
input.check { width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; accent-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border-2); border-radius: 999px; padding: 5px 8px 5px 12px; font-size: 13px;
}
.chip-x { background: transparent; color: var(--muted); font-size: 12px; padding: 0 4px; }
.chip-x:hover { color: var(--accent); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.cost-note { font-size: 12px; line-height: 1.6; margin: 0; }

@media (max-width: 980px) {
  .panels { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}

/* ── API keys panel ─────────────────────────────────────────────────────── */
/* Name field + Generate on one line: creating a key is a single decision, so
   it shouldn't look like a form to fill in. */
.form-row { display: flex; gap: 10px; align-items: center; margin: 18px 0 20px; }
.form-row input { flex: 1; min-width: 0; }

/* The one-time reveal. Deliberately loud: once this modal closes the key is
   gone for good, because only its hash is stored. */
.key-warn { color: var(--accent); font-size: 13px; line-height: 1.5; margin: 0 0 12px; }
.key-reveal {
  display: block;
  padding: 14px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  background: var(--input-bg);
  font-size: 13px;
  line-height: 1.5;
  word-break: break-all;
  user-select: all;
}
