/* Brand palette from ampirical.com's Elementor kit:
   primary #011e41 (navy), secondary #f5a800 (gold), accent #00aeef (cyan),
   typeface Manrope (vendored, OFL).

   Theming: dark is the base palette; system light preference applies the
   light palette unless the user forced dark (data-theme, persisted by the
   header picker); explicit data-theme wins in both directions. */
:root {
  --gold: #f5a800;
  --cyan: #00aeef;
  /* on-gold text: brand navy reads well on gold in BOTH themes (never use
     --bg for this — it goes near-white in light mode) */
  --on-gold: #011e41;
  /* "ink" variants: accent colors used as text on the theme's surfaces;
     the light palette darkens them for contrast */
  --gold-ink: #f5a800;
  --cyan-ink: #2fbdf2;
  --bg: #01152e;
  --bg-raised: #011e41;
  --bg-inset: #000d1f;
  --border: #14335c;
  --text: #e9eef5;
  --muted: #8fa3bf;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --gold-ink: #8f6200;
    --cyan-ink: #016d96;
    --bg: #f2f5f9;
    --bg-raised: #ffffff;
    --bg-inset: #e9edf3;
    --border: #d0d8e4;
    --text: #181b31;
    --muted: #54595f;
  }
  :root:not([data-theme="dark"]) .only-dark { display: none; }
  :root:not([data-theme="dark"]) .only-light { display: initial; }
}

:root[data-theme="light"] {
  --gold-ink: #8f6200;
  --cyan-ink: #016d96;
  --bg: #f2f5f9;
  --bg-raised: #ffffff;
  --bg-inset: #e9edf3;
  --border: #d0d8e4;
  --text: #181b31;
  --muted: #54595f;
}
:root[data-theme="light"] .only-dark { display: none; }
:root[data-theme="light"] .only-light { display: initial; }
:root[data-theme="dark"] .only-dark { display: initial; }
:root[data-theme="dark"] .only-light { display: none; }
.only-light { display: none; }

@font-face {
  font-family: "Manrope";
  src: url("/manrope.ttf") format("truetype-variations");
  font-weight: 200 800;
  font-display: swap;
}

* { box-sizing: border-box; }

/* Author display rules (flex/grid) on sections would otherwise beat the UA's
   [hidden] { display: none } — this keeps the hidden attribute authoritative. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 14px/1.45 "Manrope", system-ui, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  /* Brand bar: stays navy in both themes, so re-pin the palette vars its
     children (buttons, email, tabs, theme picker) resolve against. */
  --bg-raised: #011e41;
  --bg-inset: #001330;
  --border: #14335c;
  --text: #e9eef5;
  --muted: #8fa3bf;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: var(--bg-raised);
  border-bottom: 2px solid var(--gold);
  color: var(--text);
}
header .logo { height: 28px; }
header h1 { font-size: 17px; font-weight: 600; margin: 0; white-space: nowrap; }
#home-link { display: flex; align-items: center; gap: 12px; cursor: pointer; color: inherit; text-decoration: none; }
#theme-select { font-size: 12.5px; padding: 4px 6px; }
/* Always-present flex filler between the brand and the theme picker; the app
   injects its content (tabs, user, sign-out) INSIDE it, so the picker never
   shifts when the header gains or loses content. */
#header-app { flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0; }
.accent { color: var(--gold); }
.spacer { flex: 1; }
#user-email { color: var(--muted); font-size: 13px; }

#env-tabs { display: flex; gap: 4px; margin-left: 18px; }
#env-tabs button {
  background: none; border: 1px solid transparent; color: var(--muted);
  padding: 5px 12px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
#env-tabs button:hover { color: var(--text); }
#env-tabs button.active {
  color: var(--on-gold); background: var(--gold); font-weight: 600;
}

main { flex: 1; min-height: 0; display: flex; }
section { flex: 1; min-height: 0; }

#signin-view, #boot-view { display: flex; align-items: center; justify-content: center; }
.boot-box { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.card {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 12px; padding: 40px 48px; max-width: 420px;
}
.card.center { text-align: center; }
.logo-large { width: 260px; margin-bottom: 12px; }
#signin-theme-select { font-size: 12.5px; padding: 4px 6px; }

#home-view { display: flex; align-items: flex-start; justify-content: center; padding: 48px 24px; }
.cards { display: flex; flex-direction: row; flex-wrap: wrap; gap: 20px; justify-content: center; }
.cards .tool-card { width: 300px; }
button.gear { font-size: 17px; padding: 3px 9px; }
.tool-card {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 12px; padding: 22px 24px; cursor: pointer;
  transition: border-color 0.15s;
}
.tool-card:hover { border-color: var(--gold); }
.tool-card h2 { margin: 0 0 8px; font-size: 16px; color: var(--gold-ink); }
.tool-card p { margin: 0; color: var(--muted); font-size: 13px; }
.tool-card.disabled { cursor: default; opacity: 0.55; }
.tool-card.disabled:hover { border-color: var(--border); }

#logs-view { display: flex; min-height: 0; }

#group-pane {
  width: 320px; min-width: 240px; display: flex; flex-direction: column;
  border-right: 1px solid var(--border); background: var(--bg-raised);
}
.pane-head { padding: 10px; border-bottom: 1px solid var(--border); }
#group-filter { width: 100%; }
#group-list { list-style: none; margin: 0; padding: 4px; overflow-y: auto; flex: 1; }
#group-list li {
  padding: 6px 10px; border-radius: 6px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: ui-monospace, monospace; font-size: 12.5px;
}
#group-list li:hover { background: var(--bg-inset); }
#group-list li.selected { background: var(--gold); color: var(--on-gold); font-weight: 600; }
#group-list li .size { color: var(--muted); font-size: 11px; margin-left: 6px; }
#group-list li.selected .size { color: var(--on-gold); }

#detail-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#mode-tabs { display: flex; gap: 2px; padding: 8px 12px 0; }
button.mode {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 6px 14px; cursor: pointer; font-size: 13.5px;
}
button.mode.active { color: var(--gold-ink); border-bottom-color: var(--gold); }

#events-pane, #insights-pane {
  flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 10px 12px;
}
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.toolbar input[type="search"] { flex: 1; min-width: 160px; }
.tail-toggle { color: var(--muted); display: flex; align-items: center; gap: 4px; }

input, select, textarea {
  background: var(--bg-inset); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px;
  font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--gold); }
textarea { font-family: ui-monospace, monospace; font-size: 12.5px; margin-bottom: 8px; resize: vertical; }

button.primary {
  background: var(--gold); color: var(--on-gold); border: none; border-radius: 6px;
  padding: 7px 16px; font-weight: 600; cursor: pointer;
}
button.primary:hover { filter: brightness(1.08); }
button.ghost {
  background: none; border: 1px solid var(--border); color: var(--muted);
  border-radius: 6px; padding: 5px 12px; cursor: pointer;
}
button.ghost:hover { color: var(--text); border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: default; }
button.ghost:disabled:hover { color: var(--muted); border-color: var(--border); }
.menu.disabled summary { opacity: 0.45; pointer-events: none; }

#event-scroll, #insights-scroll { flex: 1; overflow: auto; background: var(--bg-inset); border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-family: ui-monospace, monospace; font-size: 12.5px; }
td, th { padding: 3px 10px; vertical-align: top; text-align: left; }
tr:hover td { background: rgba(244, 168, 29, 0.06); }
td.ts { color: var(--gold-ink); white-space: nowrap; }
td.stream { color: var(--cyan-ink); white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
td.msg { white-space: pre-wrap; word-break: break-word; }
th { position: sticky; top: 0; background: var(--bg-raised); color: var(--muted); font-weight: 600; }

button.icon, .menu summary.icon { font-size: 15px; padding: 4px 10px; line-height: 1.3; }
details.menu { position: relative; }
.menu summary {
  list-style: none; cursor: pointer;
  background: none; border: 1px solid var(--border); color: var(--muted); border-radius: 6px;
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover { color: var(--text); border-color: var(--muted); }
.menu-items {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 10;
  display: flex; flex-direction: column; min-width: 110px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.menu-items button {
  background: none; border: none; color: var(--text); cursor: pointer;
  text-align: left; padding: 7px 10px; border-radius: 5px; font: inherit; font-size: 13px;
}
.menu-items button:hover { background: var(--bg-inset); }
#user-menu summary { font-size: 13px; padding: 5px 12px; }
#user-menu summary::after { content: " \25BE"; color: var(--muted); }
#user-menu .menu-items { min-width: 200px; }
.menu-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 6px 10px; font-size: 13px; color: var(--text);
}
.menu-row select { font-size: 12.5px; padding: 3px 6px; }

.spinner-wrap { display: flex; justify-content: center; padding: 28px; }
.empty-note { color: var(--muted); text-align: center; padding: 28px 16px; margin: 0; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--gold);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#admin-view { display: flex; justify-content: center; padding: 24px; overflow-y: auto; }
#admin-inner { width: min(960px, 100%); display: flex; flex-direction: column; }
.pane-title { font-size: 15px; margin: 0 auto 0 0; color: var(--gold-ink); }
#admin-scroll { overflow: auto; background: var(--bg-inset); border: 1px solid var(--border); border-radius: 8px; }
#admin-table { font-family: inherit; }
#admin-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 999px; padding: 2px 6px 2px 10px; margin: 2px 4px 2px 0;
  font-size: 12px;
}
.chip.admin-chip { border-color: var(--gold); color: var(--gold-ink); }
.chip button {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 13px; padding: 0 2px; line-height: 1;
}
.chip button:hover { color: #e06c75; }
.add-group { display: flex; gap: 6px; align-items: center; }

.muted { color: var(--muted); }
.small { font-size: 12px; margin: 0 0 6px; }
.error-row td { color: #e06c75; }
