/* ─────────────────────────────────────────────────────────────────────────
   HelixGuard — read-only status console

   Dark by default and dark by intent: this is looked at in the small hours
   on a phone. Colours are taken from the mark (teal → cyan → violet), and
   posture is the only thing allowed to shout.
   ───────────────────────────────────────────────────────────────────────── */

:root {
  --bg:            #070d18;
  --bg-raised:     #0d1526;
  --bg-card:       #101b30;
  --bg-input:      #0a1220;
  --border:        #1d2d48;
  --border-strong: #2b4066;

  --text:          #e6edf7;
  --text-dim:      #9aabc4;
  --text-faint:    #677894;

  --accent:        #22d3ee;
  --accent-2:      #a78bfa;
  --accent-3:      #5eead4;

  --quiet:         #34d399;
  --elevated:      #fbbf24;
  --attack:        #f87171;
  --critical:      #fb7185;
  --high:          #fb923c;
  --medium:        #fbbf24;
  --low:           #60a5fa;
  --info:          #94a3b8;

  --radius:   14px;
  --radius-s: 9px;
  --gap:      16px;

  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 28px rgba(0,0,0,.35);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  min-height: 100dvh;
  /* A very faint field so the flat black does not look broken on OLED. */
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(34,211,238,.08), transparent 70%),
    radial-gradient(ellipse 60% 40% at 90% 10%, rgba(167,139,250,.06), transparent 70%);
  background-attachment: fixed;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .92em; }

/* ── Layout ──────────────────────────────────────────────────────────── */
.app { max-width: 1180px; margin: 0 auto; padding: 0 16px 96px; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  margin: 0 -16px 18px;
  background: rgba(7,13,24,.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 32px; height: 32px; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-name { font-weight: 650; letter-spacing: -.01em; }
.brand-sub { font-size: 11px; color: var(--text-faint); white-space: nowrap; }

.topbar-spacer { flex: 1; }

.icon-btn {
  position: relative;
  display: grid; place-items: center;
  width: 38px; height: 38px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text-dim);
  cursor: pointer; font-size: 17px;
  transition: border-color .15s, color .15s;
}
.icon-btn:hover { border-color: var(--border-strong); color: var(--text); }
.icon-btn .dot {
  position: absolute; top: 6px; right: 6px;
  min-width: 16px; height: 16px; padding: 0 4px;
  background: var(--attack); color: #2a0a0a;
  border-radius: 99px; font-size: 10px; font-weight: 700;
  display: grid; place-items: center;
}

/* ── Tabs ────────────────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 4px; overflow-x: auto;
  margin: 0 -16px 20px; padding: 0 16px 2px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  padding: 8px 14px; border-radius: 99px;
  background: transparent; border: 1px solid transparent;
  color: var(--text-dim); font-size: 14px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); background: var(--bg-raised); }
.tab.active {
  color: var(--bg); background: linear-gradient(135deg, var(--accent-3), var(--accent));
  font-weight: 600;
}

/* ── Posture banner ──────────────────────────────────────────────────── */
.posture {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 18px 20px; margin-bottom: 20px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.posture::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: var(--posture-colour, var(--quiet));
}
.posture[data-posture="quiet"]        { --posture-colour: var(--quiet); }
.posture[data-posture="elevated"]     { --posture-colour: var(--elevated); }
.posture[data-posture="under_attack"] { --posture-colour: var(--attack); }
.posture[data-posture="unknown"]      { --posture-colour: var(--text-faint); }

.posture-pulse {
  flex: none; width: 12px; height: 12px; margin-top: 6px;
  border-radius: 50%; background: var(--posture-colour);
  box-shadow: 0 0 0 0 var(--posture-colour);
}
.posture[data-posture="elevated"] .posture-pulse,
.posture[data-posture="under_attack"] .posture-pulse { animation: pulse 2s infinite; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--posture-colour) 70%, transparent); }
  70%  { box-shadow: 0 0 0 12px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) { .posture-pulse { animation: none !important; } }

.posture-body { min-width: 0; flex: 1; }
.posture-title {
  font-size: 19px; font-weight: 650; letter-spacing: -.015em;
  color: var(--posture-colour); text-transform: capitalize;
}
.posture-reason { color: var(--text-dim); font-size: 14px; margin-top: 2px; }
.posture-since { color: var(--text-faint); font-size: 12px; margin-top: 6px; }

/* ── Cards and grid ──────────────────────────────────────────────────── */
.grid { display: grid; gap: var(--gap); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; margin-bottom: 14px;
}
.card-title { font-size: 13px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-faint); }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-value { font-size: 30px; font-weight: 640; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .06em; }
.stat-note  { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.stat-value.good { color: var(--quiet); }
.stat-value.warn { color: var(--elevated); }
.stat-value.bad  { color: var(--attack); }

/* ── Pills and badges ────────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .01em;
  border: 1px solid transparent; white-space: nowrap;
}
.pill.critical { color: var(--critical); background: rgba(251,113,133,.12); border-color: rgba(251,113,133,.3); }
.pill.high     { color: var(--high);     background: rgba(251,146,60,.12);  border-color: rgba(251,146,60,.3); }
.pill.medium   { color: var(--medium);   background: rgba(251,191,36,.12);  border-color: rgba(251,191,36,.3); }
.pill.low      { color: var(--low);      background: rgba(96,165,250,.12);  border-color: rgba(96,165,250,.3); }
.pill.info     { color: var(--info);     background: rgba(148,163,184,.12); border-color: rgba(148,163,184,.3); }
.pill.ok       { color: var(--quiet);    background: rgba(52,211,153,.12);  border-color: rgba(52,211,153,.3); }
.pill.muted    { color: var(--text-faint); background: var(--bg-raised); border-color: var(--border); }

.score {
  font-family: var(--mono); font-weight: 700; font-size: 13px;
  padding: 2px 8px; border-radius: 7px;
  background: var(--bg-raised); border: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.score[data-band="critical"] { color: var(--critical); border-color: rgba(251,113,133,.35); }
.score[data-band="high"]     { color: var(--high);     border-color: rgba(251,146,60,.35); }
.score[data-band="medium"]   { color: var(--medium);   border-color: rgba(251,191,36,.35); }
.score[data-band="low"]      { color: var(--low);      border-color: rgba(96,165,250,.35); }

/* ── Lists ───────────────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  min-width: 0;
}
.row:last-child { border-bottom: none; }
.row:hover { background: rgba(34,211,238,.04); }
.row.static { cursor: default; }
.row.static:hover { background: none; }
.row-main { flex: 1; min-width: 0; }
.row-title {
  font-weight: 550; font-size: 14.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-sub {
  font-size: 12.5px; color: var(--text-dim); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.row-meta { flex: none; display: flex; align-items: center; gap: 8px; }

.unread { background: rgba(34,211,238,.05); }
.unread .row-title::before {
  content: ''; display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: var(--accent); margin-right: 7px; vertical-align: middle;
}

/* ── Firewall tiles ──────────────────────────────────────────────────── */
.fw {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; border-radius: var(--radius-s);
  background: var(--bg-raised); border: 1px solid var(--border);
}
.fw-light {
  flex: none; width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-faint);
}
.fw.up   .fw-light { background: var(--quiet);  box-shadow: 0 0 10px rgba(52,211,153,.6); }
.fw.down .fw-light { background: var(--attack); box-shadow: 0 0 10px rgba(248,113,113,.6); }
.fw.idle .fw-light { background: var(--text-faint); }
.fw-body { min-width: 0; flex: 1; }
.fw-name { font-weight: 600; font-size: 14px; }
.fw-sub  { font-size: 12px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fw-num  { font-family: var(--mono); font-size: 13px; color: var(--text-dim); text-align: right; flex: none; }

/* ── Timeline chart ──────────────────────────────────────────────────── */
.chart { width: 100%; height: 150px; display: block; overflow: visible; }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-faint); margin-top: 8px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 3px; border-radius: 2px; }

/* ── Detail panel ────────────────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(3,7,14,.72); backdrop-filter: blur(3px);
  display: flex; justify-content: flex-end;
}
.sheet {
  width: min(620px, 100%); height: 100%;
  background: var(--bg-raised); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 20px; padding-bottom: 60px;
  animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: .5; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
@media (max-width: 640px) {
  .sheet-backdrop { align-items: flex-end; }
  .sheet { height: 92dvh; border-left: none; border-top: 1px solid var(--border);
           border-radius: 18px 18px 0 0; }
}
.sheet-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.sheet-title { font-size: 19px; font-weight: 650; letter-spacing: -.015em; flex: 1; min-width: 0; }

.field { margin-bottom: 16px; }
.field-label {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-faint); font-weight: 600; margin-bottom: 4px;
}
.field-value { font-size: 14px; word-break: break-word; }

.evidence {
  font-family: var(--mono); font-size: 11.5px; line-height: 1.6;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-s); padding: 12px;
  max-height: 300px; overflow: auto; white-space: pre-wrap; word-break: break-all;
  color: var(--text-dim);
}

.reasons { display: flex; flex-direction: column; gap: 6px; }
.reason {
  display: flex; align-items: baseline; gap: 10px;
  font-size: 13px; padding: 7px 10px;
  background: var(--bg-input); border-radius: var(--radius-s);
  border-left: 3px solid var(--border-strong);
}
.reason .delta {
  font-family: var(--mono); font-weight: 700; flex: none; min-width: 38px;
  font-variant-numeric: tabular-nums;
}
.reason.pos { border-left-color: var(--high); }
.reason.pos .delta { color: var(--high); }
.reason.neg { border-left-color: var(--quiet); }
.reason.neg .delta { color: var(--quiet); }
.reason.base { border-left-color: var(--accent); }
.reason.base .delta { color: var(--accent); }
.reason .note { color: var(--text-dim); }

.refusal {
  padding: 12px 14px; border-radius: var(--radius-s);
  background: rgba(52,211,153,.07); border: 1px solid rgba(52,211,153,.24);
  font-size: 13.5px; color: var(--text);
}
.refusal strong { color: var(--quiet); }

/* ── Forms ───────────────────────────────────────────────────────────── */
input[type="text"], input[type="email"], input[type="password"], input[type="number"], select, textarea {
  width: 100%; padding: 11px 13px;
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-s);
  font-size: 15px; font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34,211,238,.14);
}
label { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; font-weight: 500; }

button.btn {
  padding: 11px 18px; border-radius: var(--radius-s);
  border: 1px solid var(--border-strong); background: var(--bg-card);
  color: var(--text); font-size: 14.5px; font-weight: 550; font-family: inherit;
  cursor: pointer; transition: border-color .15s, background .15s;
}
button.btn:hover:not(:disabled) { border-color: var(--accent); background: var(--bg-raised); }
button.btn:disabled { opacity: .5; cursor: not-allowed; }
button.btn.primary {
  background: linear-gradient(135deg, var(--accent-3), var(--accent));
  color: #04202a; border-color: transparent; font-weight: 650;
}
button.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
button.btn.ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }

/* ── Misc ────────────────────────────────────────────────────────────── */
.empty { padding: 36px 20px; text-align: center; color: var(--text-faint); font-size: 14px; }
.empty .big { font-size: 34px; display: block; margin-bottom: 10px; opacity: .55; }

.banner {
  padding: 12px 16px; border-radius: var(--radius-s);
  font-size: 13.5px; margin-bottom: 16px;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text-dim);
}
.banner.warn { border-color: rgba(251,191,36,.3); background: rgba(251,191,36,.08); color: #fde68a; }
.banner.info { border-color: rgba(34,211,238,.26); background: rgba(34,211,238,.07); }
.banner.bad  { border-color: rgba(248,113,113,.3); background: rgba(248,113,113,.08); color: #fecaca; }
.banner b { color: var(--text); }

.muted { color: var(--text-faint); }
.dim   { color: var(--text-dim); }
.nowrap{ white-space: nowrap; }
.hidden{ display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 200; padding: 12px 20px; border-radius: 99px;
  background: var(--bg-card); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow); font-size: 14px; max-width: calc(100vw - 32px);
}
.toast.bad { border-color: rgba(248,113,113,.4); color: #fecaca; }

/* ── Login ───────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
}
.login {
  width: min(400px, 100%);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 18px; padding: 32px 28px; box-shadow: var(--shadow);
}
.login-mark { display: grid; place-items: center; margin-bottom: 20px; }
.login-mark img { width: 72px; height: 72px; }
.login h1 { font-size: 22px; margin: 0 0 4px; text-align: center; letter-spacing: -.02em; }
.login .sub { text-align: center; color: var(--text-faint); font-size: 13px; margin-bottom: 24px; }
.login .field { margin-bottom: 14px; }
.login .error {
  padding: 10px 13px; border-radius: var(--radius-s); font-size: 13.5px; margin-bottom: 14px;
  background: rgba(248,113,113,.1); border: 1px solid rgba(248,113,113,.3); color: #fecaca;
}

.readonly-note {
  margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-faint); text-align: center;
}

/* ── Tables ──────────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; padding: 8px 10px; font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint);
  border-bottom: 1px solid var(--border);
}
.table td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: none; }
.table-scroll { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }

.report {
  font-size: 14px; line-height: 1.65; white-space: pre-wrap;
  font-family: var(--sans); color: var(--text-dim);
}
.report h1, .report h2 { font-family: var(--sans); color: var(--text); }

/* ── Chat with the operator session ───────────────────────────────────────── */
.chat-wrap { display: flex; flex-direction: column; height: calc(100dvh - 190px); min-height: 380px; }

.chat-scroll {
  flex: 1; overflow-y: auto; padding: 4px 2px 12px;
  display: flex; flex-direction: column; gap: 12px;
}

.msg { display: flex; flex-direction: column; max-width: min(640px, 88%); }
.msg.from-owner { align-self: flex-end; align-items: flex-end; }
.msg.from-guard { align-self: flex-start; align-items: flex-start; }

.msg-bubble {
  padding: 11px 14px; border-radius: 14px; font-size: 14.5px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; border: 1px solid var(--border);
}
.msg.from-owner .msg-bubble {
  background: linear-gradient(135deg, rgba(94,234,212,.16), rgba(34,211,238,.16));
  border-color: rgba(34,211,238,.34); border-bottom-right-radius: 5px;
}
.msg.from-guard .msg-bubble { background: var(--bg-card); border-bottom-left-radius: 5px; }

.msg.kind-question .msg-bubble { border-color: rgba(251,146,60,.45); background: rgba(251,146,60,.09); }
.msg.kind-alert    .msg-bubble { border-color: rgba(251,113,133,.45); background: rgba(251,113,133,.09); }
.msg.kind-reminder .msg-bubble { border-style: dashed; color: var(--text-dim); }

.msg-title { font-weight: 650; font-size: 14px; margin-bottom: 4px; }
.msg-meta {
  font-size: 11px; color: var(--text-faint); margin-top: 5px;
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
}

.msg-options { display: flex; gap: 7px; margin-top: 9px; flex-wrap: wrap; }
.msg-options button {
  padding: 7px 13px; border-radius: 99px; font-size: 13px; font-weight: 550;
  background: var(--bg-raised); border: 1px solid var(--border-strong);
  color: var(--text); cursor: pointer; font-family: inherit;
}
.msg-options button:hover { border-color: var(--accent); background: var(--bg-input); }

.chat-compose {
  display: flex; gap: 8px; align-items: flex-end;
  padding-top: 12px; border-top: 1px solid var(--border);
}
.chat-compose textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 160px;
  font-size: 15px; line-height: 1.45; padding: 11px 13px;
}
.chat-compose button { flex: none; height: 44px; }

.replying-to {
  font-size: 12.5px; color: var(--text-dim); padding: 8px 12px; margin-bottom: 8px;
  background: var(--bg-input); border-left: 3px solid var(--accent); border-radius: 0 8px 8px 0;
  display: flex; align-items: center; gap: 10px;
}
.replying-to button {
  margin-left: auto; background: none; border: none; color: var(--text-faint);
  cursor: pointer; font-size: 16px; padding: 0 4px;
}

.session-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.session-pill i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.session-pill.listening i { background: var(--quiet); box-shadow: 0 0 8px rgba(52,211,153,.6); }
.session-pill.stale i     { background: var(--elevated); }
.session-pill.offline i   { background: var(--attack); }

/* ── Upcoming reminders ───────────────────────────────────────────────────── */
.todo { display: flex; gap: 11px; align-items: flex-start; padding: 11px 4px;
        border-bottom: 1px solid var(--border); }
.todo:last-child { border-bottom: none; }
.todo-when {
  flex: none; min-width: 74px; font-family: var(--mono); font-size: 11.5px;
  color: var(--text-faint); padding-top: 2px; text-align: right;
}
.todo.overdue .todo-when { color: var(--elevated); font-weight: 600; }
.todo-body { flex: 1; font-size: 13.5px; line-height: 1.45; min-width: 0; }
.todo-sub { font-size: 11.5px; color: var(--text-faint); margin-top: 3px; }
.todo button {
  flex: none; background: none; border: none; color: var(--text-faint);
  cursor: pointer; font-size: 15px; padding: 0 5px;
}
.todo button:hover { color: var(--attack); }
