/* neuronDB-admin — a modern, data-dense operator console.
 *
 * Dark-first. A manual theme toggle sets [data-theme] on <html> (persisted,
 * seeded from prefers-color-scheme). Depth is built from subtle lightness
 * shifts and low-opacity borders; the background is a space, not a void. */

:root {
  --bg:        #0a0d14;
  --bg-glow:   #122034;
  --surface-0: #0e121b;
  --surface-1: #141926;
  --surface-2: #1b2130;
  --border:    rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.14);
  --text:      #e7ebf4;
  --text-dim:  #8b93a7;
  --text-faint:#5b6478;

  --accent:      #3fb9ff;  /* neuron cyan — primary */
  --accent-dim:  rgba(63,185,255,0.14);
  --violet:      #a78bfa;
  --violet-dim:  rgba(167,139,250,0.14);
  --ok:          #34d399;
  --ok-dim:      rgba(52,211,153,0.14);
  --warn:        #fbbf24;
  --warn-dim:    rgba(251,191,36,0.14);
  --danger:      #fb7185;
  --danger-dim:  rgba(251,113,133,0.14);

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.28);
  --shadow-lg: 0 2px 4px rgba(0,0,0,0.5), 0 20px 50px rgba(0,0,0,0.4);

  --font-display: "Space Grotesk", "Segoe UI", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-body: "Inter var", "Segoe UI", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
}

:root[data-theme="light"] {
  --bg:        #f4f6fb;
  --bg-glow:   #e3ecf9;
  --surface-0: #ffffff;
  --surface-1: #ffffff;
  --surface-2: #f1f4fa;
  --border:    rgba(15,23,42,0.10);
  --border-strong: rgba(15,23,42,0.18);
  --text:      #0f172a;
  --text-dim:  #52607a;
  --text-faint:#8c96ac;

  --accent:     #0f8fe0;
  --accent-dim: rgba(15,143,224,0.12);
  --violet:     #7c5cf0;
  --violet-dim: rgba(124,92,240,0.12);
  --ok:         #0f9d6b;
  --ok-dim:     rgba(15,157,107,0.12);
  --warn:       #b7791f;
  --warn-dim:   rgba(183,121,31,0.14);
  --danger:     #e11d48;
  --danger-dim: rgba(225,29,72,0.12);
  --shadow: 0 1px 2px rgba(15,23,42,0.06), 0 8px 24px rgba(15,23,42,0.08);
  --shadow-lg: 0 2px 4px rgba(15,23,42,0.08), 0 20px 50px rgba(15,23,42,0.12);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  background-image:
    radial-gradient(900px 500px at 82% -8%, var(--bg-glow), transparent 60%),
    radial-gradient(700px 500px at 0% 0%, var(--accent-dim), transparent 55%);
  background-attachment: fixed;
}

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

h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
code, .mono { font-family: var(--font-mono); font-size: 0.86em; }

/* ---- App shell ---------------------------------------------------------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

.sidebar {
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface-0), transparent);
  padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 9px;
  background: conic-gradient(from 210deg, var(--accent), var(--violet), var(--accent));
  box-shadow: 0 0 18px var(--accent-dim);
  display: grid; place-items: center; color: #041018; font-weight: 800;
  font-family: var(--font-display);
}
.brand .name { font-family: var(--font-display); font-weight: 700; font-size: 1.02rem; }
.brand .name small { display: block; color: var(--text-faint); font-size: 0.68rem; font-weight: 500; letter-spacing: 0.04em; }

.nav-group { color: var(--text-faint); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.1em; padding: 14px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-weight: 500; cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}
.nav-item:hover { background: var(--surface-1); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-item .ic { width: 18px; text-align: center; opacity: 0.9; }
.sidebar .spacer { flex: 1; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 16px 28px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
}
.topbar .title { min-width: 0; }
.topbar .title p { margin: 2px 0 0; color: var(--text-dim); font-size: 0.82rem; }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.content { padding: 24px 28px 64px; max-width: 1280px; width: 100%; }

/* ---- Badges / pills ----------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px; font-size: 0.72rem; font-weight: 600;
  border: 1px solid var(--border-strong); color: var(--text-dim);
  white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-dim); border-color: transparent; }
.badge.warn { color: var(--warn); background: var(--warn-dim); border-color: transparent; }
.badge.danger { color: var(--danger); background: var(--danger-dim); border-color: transparent; }
.badge.accent { color: var(--accent); background: var(--accent-dim); border-color: transparent; }
.badge.violet { color: var(--violet); background: var(--violet-dim); border-color: transparent; }
.badge.mute { color: var(--text-faint); }

.mock-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; margin: 0;
  background: var(--warn-dim); color: var(--warn);
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem; font-weight: 600;
}

/* ---- Cards -------------------------------------------------------------- */
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1080px) { .cols-3, .cols-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px) { .cols-2, .cols-3, .cols-4 { grid-template-columns: 1fr; } }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}
.card.hero { background: linear-gradient(145deg, var(--surface-2), var(--surface-1)); box-shadow: var(--shadow-lg); }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h2 { flex: 1; min-width: 0; }
.card-head .sub { color: var(--text-dim); font-size: 0.8rem; }

.kpi .label { color: var(--text-dim); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.08em; }
.kpi .value { font-family: var(--font-display); font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; margin-top: 6px; }
.kpi .value.mono { font-family: var(--font-mono); font-size: 1.5rem; }
.kpi .foot { color: var(--text-faint); font-size: 0.76rem; margin-top: 6px; }
.kpi .value .unit { font-size: 0.9rem; color: var(--text-dim); font-weight: 500; }

/* ---- Tables ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
thead th {
  position: sticky; top: 0;
  background: var(--surface-2); color: var(--text-dim);
  text-align: left; font-weight: 600; font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.06em;
  padding: 11px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s ease; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
td small { color: var(--text-faint); }

/* ---- Forms / buttons ---------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2);
  color: var(--text); font-weight: 600; font-size: 0.82rem; cursor: pointer;
  font-family: var(--font-body);
  transition: filter 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}
.btn:hover { filter: brightness(1.12); text-decoration: none; }
.btn.primary { background: var(--accent); color: #041018; border-color: transparent; }
.btn.danger { background: var(--danger-dim); color: var(--danger); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 0.76rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-dim); cursor: pointer;
}
.icon-btn:hover { color: var(--text); }

label { display: block; color: var(--text-dim); font-size: 0.78rem; margin-bottom: 5px; font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-0);
  color: var(--text); font-family: var(--font-body); font-size: 0.86rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-dim); border-color: var(--accent); }
.field { margin-bottom: 14px; }
.field.inline { display: flex; gap: 10px; align-items: flex-end; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.muted { color: var(--text-dim); }
.hint { color: var(--text-faint); font-size: 0.76rem; margin-top: 4px; }

.flash {
  padding: 11px 15px; border-radius: var(--radius-sm); margin-bottom: 18px;
  font-size: 0.86rem; font-weight: 500; border: 1px solid transparent;
}
.flash.ok { background: var(--ok-dim); color: var(--ok); }
.flash.err { background: var(--danger-dim); color: var(--danger); }

details.disclosure { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0; margin-top: 10px; }
details.disclosure > summary { cursor: pointer; padding: 10px 14px; font-weight: 600; color: var(--text-dim); list-style: none; }
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure[open] > summary { border-bottom: 1px solid var(--border); color: var(--text); }
details.disclosure .body { padding: 14px; }

/* ---- Login -------------------------------------------------------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { justify-content: center; padding-top: 0; }

/* ---- Gap callouts ------------------------------------------------------- */
.gap-note {
  border-left: 3px solid var(--warn); background: var(--warn-dim);
  padding: 10px 14px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text); font-size: 0.8rem; margin-top: 12px;
}
.gap-note b { color: var(--warn); }

.meter { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.meter > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--violet)); }

/* ---- Motion ------------------------------------------------------------- */
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.animate > * { animation: fadeUp 0.4s ease both; }
.animate > *:nth-child(2) { animation-delay: 0.04s; }
.animate > *:nth-child(3) { animation-delay: 0.08s; }
.animate > *:nth-child(4) { animation-delay: 0.12s; }
.animate > *:nth-child(5) { animation-delay: 0.16s; }
.animate > *:nth-child(6) { animation-delay: 0.20s; }
@media (prefers-reduced-motion: reduce) { .animate > * { animation: none; } }

.section-title { margin: 26px 0 12px; color: var(--text-dim); font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.1em; }
.section-title:first-child { margin-top: 0; }

/* ---- Modern chat feed --------------------------------------------------- */
.room-wrap { display: flex; flex-direction: column; gap: 16px; height: calc(100vh - 150px); }
.feed-card { padding: 0; overflow: hidden; flex: 1; display: flex; flex-direction: column; min-height: 0; }
.feed-card .card-head { padding: 14px 18px; margin: 0; border-bottom: 1px solid var(--border); display: flex; align-items: baseline; gap: 10px; flex: none; }
.feed {
  display: flex; flex-direction: column; gap: 1px;
  flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px; scroll-behavior: auto;
}
.feed-loading { text-align: center; color: var(--text-faint); font-size: 0.78rem; padding: 8px; }

/* A chat row: avatar + bubble. Consecutive same-sender rows are "grouped". */
.chat { display: flex; gap: 10px; padding: 2px 0; align-items: flex-start; }
.chat:not(.grouped) { margin-top: 12px; }
.chat:first-child { margin-top: 0; }
.chat-avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 0.82rem;
  font-family: var(--font-display); color: #fff;
  background: hsl(var(--hue), 55%, 45%);
  box-shadow: 0 0 0 2px color-mix(in srgb, hsl(var(--hue),55%,45%) 25%, transparent);
}
.chat.grouped .chat-avatar { visibility: hidden; height: 0; }
.chat-body { min-width: 0; flex: 1; }
.chat-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.chat.grouped .chat-head { display: none; }
.chat-who { font-weight: 700; font-family: var(--font-display); color: hsl(var(--hue), 65%, 62%); font-size: 0.86rem; }
:root[data-theme="light"] .chat-who { color: hsl(var(--hue), 55%, 42%); }
.chat-time { color: var(--text-faint); font-size: 0.7rem; font-family: var(--font-mono); margin-left: auto; }
.chat-text {
  white-space: pre-wrap; word-break: break-word; line-height: 1.5;
  border-radius: 4px 12px 12px 12px;
  padding: 8px 12px; display: inline-block; max-width: 100%;
  /* Each bubble is tied to its agent: a coloured left edge + a faint tint of
     the agent's colour, so alternating speakers read as a real conversation. */
  border: 1px solid var(--border);
  border-left: 3px solid hsl(var(--hue), 60%, 55%);
  background: color-mix(in srgb, hsl(var(--hue), 60%, 50%) 9%, var(--surface-1));
}
.chat.grouped .chat-text { border-radius: 4px 12px 12px 12px; }
.chat:hover .chat-time { color: var(--text-dim); }
/* Questions / answers keep the per-agent colour; the badge marks the kind. */
.chat.answer .chat-text { border-left-style: double; border-left-width: 4px; }

.composer { display: flex; gap: 10px; flex: none; }
.composer input { flex: 1; }

/* ---- Structured questions ----------------------------------------------- */
.question-card { border-left: 3px solid var(--violet); }
.q-asker { margin-bottom: 8px; }
.q-text { font-weight: 600; margin-bottom: 10px; white-space: pre-wrap; }
.q-options { display: flex; flex-wrap: wrap; gap: 8px; }
.opt-btn.selected { background: var(--accent); color: #041018; border-color: transparent; }
.q-free { flex: 1; }

/* ---- Docked "Awaiting you" panel (persistent while decisions are open) --- */
.awaiting {
  position: fixed; right: 20px; bottom: 20px; z-index: 100;
  width: 400px; max-width: calc(100vw - 40px);
  display: flex; flex-direction: column;
  background: var(--surface-1); border: 1px solid var(--danger);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  overflow: hidden; transition: transform 0.18s ease;
}
/* Hidden entirely when nothing is open. */
.awaiting.empty { display: none; }
.awaiting-head {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  padding: 11px 14px; background: var(--danger-dim); color: var(--text);
  font-family: var(--font-display); font-weight: 700; font-size: 0.9rem;
  user-select: none;
}
.awaiting-head .ic { display: flex; color: var(--danger); }
.awaiting-title { flex: 1; }
.awaiting-caret { color: var(--text-dim); transition: transform 0.18s ease; }
.awaiting.collapsed .awaiting-caret { transform: rotate(0deg); }
.awaiting:not(.collapsed) .awaiting-caret { transform: rotate(90deg); }
.awaiting-list {
  overflow-y: auto; max-height: 60vh; padding: 10px;
  display: flex; flex-direction: column; gap: 10px;
}
.awaiting.collapsed .awaiting-list { display: none; }
.await-item { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; background: var(--surface-0); }
.await-item .meta { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; font-size: 0.74rem; flex-wrap: wrap; }
.await-avatar {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 0.68rem; color: #fff; font-family: var(--font-display);
  background: hsl(var(--hue), 55%, 45%);
}
.await-item .chat-who { font-size: 0.8rem; }
.await-item .q { font-weight: 600; margin-bottom: 8px; white-space: pre-wrap; word-break: break-word; }
.await-item .opts { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.await-item .free-row { display: flex; gap: 6px; }
.await-item .free-row input { flex: 1; }
.badge.pulse { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.45; } }

/* ---- Firehose (cross-room) chips ---------------------------------------- */
.room-chip {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600;
  color: var(--accent); background: var(--accent-dim);
  padding: 1px 7px; border-radius: 999px; text-decoration: none;
}
.room-chip:hover { text-decoration: none; filter: brightness(1.15); }
.firehose .msg-meta { flex-wrap: wrap; }
