:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #f7f9fc;
  --ink: #1a2430;
  --muted: #5a6a7c;
  --line: #e3e8ee;
  --accent: #0e62ae;
  --on-accent: #ffffff;
  --wash: #dce8f6;
  --danger: #8d2f2f;
  --on-danger: #ffffff;
  --danger-bg: #f8ecec;
  --shadow: 0 16px 40px rgba(16, 40, 72, 0.10);
  --select: #d0e2f4;
  --ring: rgba(14, 98, 174, 0.32);
  --faint: #6d7e90;
  --scroll: #d0d7e0;
  --scroll-hover: #b7c1cd;
  --shade: #f2f5f9;
  --rail: #e6edf4;
  --ok: #1f6b45;
  --ok-bg: #e5f4eb;
  --warn: #8a5a12;
  --warn-bg: #f8f1e4;
}

/* Dark theme snapshot 2026-11-17. Restore by replacing the block below and setting
   the theme-color strings in theme.js and js/events.js back to #1b1e23.
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121417;
  --panel: #1b1e23;
  --ink: #ece8e2;
  --muted: #a3a9b2;
  --line: #2d3238;
  --accent: #8eb4dc;
  --on-accent: #121417;
  --wash: #262c34;
  --danger: #f0b4b4;
  --on-danger: #2a1414;
  --danger-bg: #3a2424;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  --select: #2c4158;
  --ring: rgba(142, 180, 220, 0.35);
  --faint: #8d959e;
  --scroll: #3c4450;
  --scroll-hover: #5c6674;
  --shade: #16191d;
  --rail: #07080a;
  --ok: #9dccb0;
  --ok-bg: #1d3328;
  --warn: #e6c48a;
  --warn-bg: #3a3120;
}
*/

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #212327;
  --panel: #2a2e34;
  --ink: #ece8e2;
  --muted: #a3a9b2;
  --line: #42474e;
  --accent: #8eb4dc;
  --on-accent: #121417;
  --wash: #363c46;
  --danger: #f0b4b4;
  --on-danger: #2a1414;
  --danger-bg: #3a2424;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  --select: #394d60;
  --ring: rgba(142, 180, 220, 0.35);
  --faint: #8d959e;
  --scroll: #4a5159;
  --scroll-hover: #6a727c;
  --shade: #25282d;
  --rail: #17191d;
  --ok: #9dccb0;
  --ok-bg: #1d3328;
  --warn: #e6c48a;
  --warn-bg: #3a3120;
}

* { box-sizing: border-box; scrollbar-width: thin; scrollbar-color: var(--scroll) transparent; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--scroll);
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--scroll-hover); background-clip: padding-box; }

html, body, #app { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; color: inherit; }

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  min-height: 36px;
  padding: 0 12px;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease, filter 120ms ease;
}

button:hover { background: var(--wash); }
button.primary { background: var(--accent); color: var(--on-accent); }
button.primary:hover { filter: brightness(1.06); background: var(--accent); }
button.danger { color: var(--danger); }
button.danger:hover { background: var(--danger-bg); }
button.primary.danger { background: var(--danger); color: var(--on-danger); }
button.primary.danger:hover { background: var(--danger); filter: brightness(1.08); }
button:disabled { opacity: 0.55; cursor: default; }
button:disabled:hover { background: transparent; filter: none; }
button.primary:disabled:hover { background: var(--accent); }

.icon { width: 18px; height: 18px; flex: none; display: block; }

input, select {
  width: 100%;
  min-height: 36px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}
::placeholder { color: var(--muted); opacity: 1; }
::selection { background: var(--select); }

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 480px at 50% -10%, var(--wash), transparent 60%),
    var(--bg);
}

.card, .dialog {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.gate-layout {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 440px);
  align-items: center;
  gap: clamp(32px, 6vw, 80px);
}
.gate-info { padding: 24px 0; }
.gate-brand { display: flex; align-items: center; gap: 18px; margin-bottom: 20px; }
.gate-info h1 { margin: 0; font-size: 1.4rem; }
.gate-info .app-brand-mark { width: 48px; height: 48px; margin: 0; background: transparent; }
.app-brand-mark img { display: block; width: 100%; height: 100%; object-fit: contain; border-radius: 25%; }
.gate-intro { font-size: clamp(32px, 4vw, 48px); line-height: 1.12; font-weight: 600; margin: 0 0 20px; letter-spacing: -0.03em; }
.gate-info .lead { max-width: 48ch; line-height: 1.65; margin: 0 0 18px; }
.gate-form { width: 100%; min-width: 0; }
.gate-form h2 { margin: 0 0 12px; font-size: 24px; }
.gate-form label { color: var(--ink); }
@media (max-width: 799px) {
  .gate-layout { max-width: 480px; grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .gate-info { padding: 8px 0; }
  .gate-brand { margin-bottom: 12px; }
  .gate-intro { margin-bottom: 12px; }
}

.dialog { width: min(520px, 100%); }

h1 { font-size: 1.35rem; font-weight: 650; line-height: 1.25; margin: 0; }
h2 { font-size: 1rem; font-weight: 650; margin: 0; }
.lead, .quiet { color: var(--muted); margin: 0; }
.lead { margin: 8px 0 0; }
.outbound-form { max-width: 600px; margin-top: 20px; }
.outbound-form .quiet { margin-top: 8px; font-size: 0.85rem; }

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--wash);
  color: var(--accent);
  flex: none;
}
.brand-mark .icon { width: 16px; height: 16px; }
.card .brand-mark { width: 44px; height: 44px; border-radius: 12px; margin-bottom: 14px; }
.card .brand-mark .icon { width: 22px; height: 22px; }

label { display: block; font-size: 0.82rem; margin: 12px 0 6px; color: var(--muted); }
label.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0 0;
  color: var(--ink);
  font-size: 0.92rem;
}
label.check input { width: auto; min-height: 0; }

.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.actions button.start { margin-right: auto; }
.copy-line { margin: 8px 0 0; }
.copy-line.copy-error { color: var(--danger); }
.actions button { border: 1px solid var(--line); background: var(--panel); }
.actions button.primary { border-color: transparent; background: var(--accent); color: var(--on-accent); }
.actions button.primary.danger { background: var(--danger); color: var(--on-danger); }

.banner {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 8px;
  border-left: 3px solid var(--danger);
  padding: 8px 12px;
  margin: 14px 0 12px;
}
.banner[hidden] { display: none; }

.shell { height: 100%; display: flex; flex-direction: column; min-height: 0; }

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  min-height: 60px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: inset 0 2px 0 var(--accent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  min-width: 0;
  padding-left: 16px;
}
.brand-sub { color: var(--muted); font-weight: 500; }

.tools {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-right: 16px;
}
.who { color: var(--muted); font-size: 0.92rem; padding: 0 8px; }

.tool {
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: var(--panel);
}
.tool:hover { background: var(--wash); }
.tool.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.tool.primary:hover { background: var(--accent); filter: brightness(1.06); }
.tool.icon-only { width: 36px; padding: 0; }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
}

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 6px;
  background: var(--rail);
  border-right: 1px solid var(--line);
}
.rail-btn {
  width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 0;
  color: var(--muted);
}
.rail-btn.active, .rail-btn.active:hover {
  background: var(--wash);
  color: var(--accent);
  box-shadow: inset 3px 0 var(--accent);
}

.stage { min-width: 0; min-height: 0; overflow: auto; }

.split { height: 100%; display: grid; grid-template-columns: 280px minmax(0, 1fr); }
.list-pane, .detail-pane { min-width: 0; min-height: 0; }
.list-pane {
  display: flex;
  flex-direction: column;
  background: var(--shade);
  border-right: 1px solid var(--line);
}
.list-scroll { overflow: auto; padding-bottom: 24px; }
.detail-pane, .page { padding: 20px 24px 40px; }

.pane-head, .section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.pane-head { padding: 16px 16px 12px; }
.detail-pane .pane-head, .page > .pane-head { padding: 0 0 16px; align-items: center; }
.section { margin-top: 22px; }
.section-head { margin-bottom: 10px; align-items: center; }

.domain-row {
  width: 100%;
  min-height: 52px;
  border-radius: 0;
  padding: 8px 16px;
  justify-content: flex-start;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
.domain-row.active, .domain-row.active:hover {
  background: var(--select);
  box-shadow: inset 3px 0 var(--accent);
}
.domain-name { font-weight: 650; }

.owner-form { display: flex; align-items: end; gap: 8px; margin: 0 0 16px; }
.owner-form label { margin: 0 0 6px; }
.owner-form select { width: 220px; }

.note {
  background: var(--wash);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.mx {
  margin: 0 0 6px;
  font-family: ui-monospace, "Cascadia Mono", monospace;
  user-select: all;
}
.mx span { color: var(--muted); font-family: system-ui, "Segoe UI", sans-serif; margin-right: 8px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-top: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 0.82rem; }
td.actions-cell { text-align: right; white-space: nowrap; }
td.actions-cell button { margin-left: 4px; }

.empty { color: var(--muted); padding: 8px 0; }
.empty.inset { padding: 0 16px 16px; }

.stats, .cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}
.cards { margin-top: 12px; }

.health-card, .stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat p, .health-card p { margin: 8px 0 0; }
meter { width: 100%; height: 10px; margin-top: 10px; }

.pill {
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.78rem;
  font-weight: 650;
  background: var(--shade);
  color: var(--muted);
}
.pill.running { background: var(--ok-bg); color: var(--ok); }
.pill.failed { background: var(--danger-bg); color: var(--danger); }
.pill.starting { background: var(--warn-bg); color: var(--warn); }

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}
.filters label { margin: 0 0 6px; }
.filters button { height: 36px; }

pre.log {
  overflow: auto;
  max-height: 38rem;
  padding: 12px;
  background: var(--shade);
  border: 1px solid var(--line);
  border-radius: 12px;
  font: 0.82rem/1.45 ui-monospace, "Cascadia Mono", monospace;
  white-space: pre-wrap;
}

.person { padding: 12px 0; border-top: 1px solid var(--line); }
.person h2 { margin-bottom: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--wash);
  color: var(--ink);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.82rem;
}
.chip:has(.chip-x) { padding: 3px 4px 3px 10px; }
.chip-x {
  width: 22px;
  height: 22px;
  min-height: 22px;
  padding: 0;
  border-radius: 999px;
  color: var(--muted);
}
.mailbox {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.mailbox .section-head { margin: 0; }
.mailbox h2 { word-break: break-all; }
.row-actions { display: flex; gap: 4px; flex: none; }
.alias-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, 0.52);
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
  z-index: 5;
}

.toasts {
  position: fixed;
  z-index: 8;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(340px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-left: 3px solid var(--ink);
  border-radius: 0;
  box-shadow: 0 10px 24px rgba(16, 20, 28, 0.16);
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 600;
}
.toast-info { border-left-color: var(--accent); }
.toast-error { color: var(--danger); border-left-color: var(--danger); }

@media (max-width: 800px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .rail {
    flex-direction: row;
    justify-content: flex-start;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 6px;
  }
  .rail-btn.active, .rail-btn.active:hover { box-shadow: inset 0 -3px 0 var(--accent); }
  .split { grid-template-columns: 1fr; height: auto; }
  .list-pane { border-right: 0; border-bottom: 1px solid var(--line); max-height: 240px; }
  .who { display: none; }
  .owner-form { flex-wrap: wrap; }
  .owner-form select { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  button { transition: none; }
}

.api-scopes { display: grid; gap: .6rem; margin: 1rem 0; }
.api-key-row { padding: .75rem 0; border-bottom: 1px solid var(--line, #8893); }
.dialog:has(.api-scopes) { max-height: 90vh; overflow-y: auto; }
.api-key-row button { margin-right: .5rem; }
.dialog textarea { width: 100%; box-sizing: border-box; }

.api-log-table { overflow-x: auto; }
.api-log-table table { min-width: 1080px; }
.api-log-table td, .api-log-table th { vertical-align: top; }
.api-log-table code { overflow-wrap: anywhere; }
.api-status-error { color: var(--danger, #b63131); font-weight: 700; }
.api-status-ok { color: var(--accent, #1d4e89); font-weight: 700; }
.api-key-row form { margin: .75rem 0; }
