/* ═══════════════════════════════════════════════════════════════
   Godseye — Minaki AI operations console
   Dark, dense, professional. Built mobile-first and scaled up.
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg: #0a0e17;
  --bg-2: #0f1523;
  --panel: #131b2c;
  --panel-2: #182236;
  --line: #22304a;
  --line-soft: #1b2437;

  --text: #e8eefc;
  --muted: #8fa3c4;
  --dim: #64789b;

  --sky: #38bdf8;
  --indigo: #818cf8;
  --violet: #a78bfa;
  --pink: #f472b6;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;

  --r: 14px;
  --r-sm: 9px;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
  --glow: 0 0 0 1px rgba(56,189,248,.18), 0 8px 32px -12px rgba(56,189,248,.35);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* The `hidden` attribute is how the app hides the empty-state and the chat pane.
   It only works via the UA stylesheet's `display: none`, which ANY author rule
   setting `display` on the same element will beat — `.chat-empty { display: grid }`
   did exactly that, so the "Select a conversation…" panel stayed on screen after
   a conversation was opened and pushed the chat pane out of view. */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* Ambient background wash — subtle, fixed, GPU-friendly. */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(900px 600px at 12% -8%, rgba(56,189,248,.10), transparent 60%),
    radial-gradient(800px 500px at 88% 4%, rgba(167,139,250,.10), transparent 60%),
    radial-gradient(700px 500px at 50% 100%, rgba(244,114,182,.06), transparent 60%);
  pointer-events: none;
}

::selection { background: rgba(129,140,248,.35); }

/* Scrollbars */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #22304a; border-radius: 8px; border: 2px solid var(--bg); }
*::-webkit-scrollbar-thumb:hover { background: #2e3f5e; }

/* ── Animations ─────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes drawIn { from { stroke-dashoffset: var(--len, 2000); } to { stroke-dashoffset: 0; } }
@keyframes barGrow { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes shimmer { 0% { background-position: -300% 0; } 100% { background-position: 300% 0; } }
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.spin-slow { transform-origin: 60px 60px; animation: spin 22s linear infinite; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ── Gate ───────────────────────────────────────────────────────── */
.gate {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  background: var(--bg); z-index: 100;
}
.gate-card {
  width: min(400px, 100%); text-align: center;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line); border-radius: 20px;
  padding: 40px 28px 28px; box-shadow: var(--shadow);
  animation: rise .5s cubic-bezier(.2,.8,.2,1) both;
}
.gate-logo { width: 92px; height: 92px; margin-bottom: 8px; }
.gate-card h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.gate-sub { color: var(--muted); margin: 4px 0 26px; font-size: 13px; }
.gate-label { display: block; text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--dim); margin-bottom: 6px; }
.gate-input {
  width: 100%; padding: 12px 14px; border-radius: var(--r-sm);
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  font-family: var(--mono); font-size: 13px; outline: none; transition: border-color .2s, box-shadow .2s;
}
.gate-input:focus { border-color: var(--sky); box-shadow: var(--glow); }
.gate-btn {
  width: 100%; margin-top: 14px; padding: 12px; border: 0; border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--sky), var(--indigo));
  color: #04121f; font-weight: 700; font-size: 14px; cursor: pointer;
  transition: transform .15s, filter .2s;
}
.gate-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.gate-btn:active { transform: translateY(0); }
.gate-err { color: var(--red); font-size: 13px; min-height: 20px; margin: 10px 0 0; }
.gate-foot { color: var(--dim); font-size: 11.5px; margin: 14px 0 0; }

/* ── Shell ──────────────────────────────────────────────────────── */
#app { min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 18px;
  background: rgba(10,14,23,.82);
  backdrop-filter: blur(14px) saturate(160%);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-mark { width: 32px; height: 32px; }
.brand-name { font-weight: 700; letter-spacing: -.01em; }
.brand-sub { font-size: 11px; color: var(--dim); }

.tabs { display: flex; gap: 2px; padding: 3px; background: var(--panel); border: 1px solid var(--line-soft); border-radius: 11px; }
.tab {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  padding: 7px 13px; border-radius: 8px; font: inherit; font-size: 13.5px; font-weight: 600;
  cursor: pointer; transition: color .18s, background .18s; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.04) inset; }

.topbar-right { display: flex; align-items: center; gap: 8px; }
.live {
  display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted);
  padding: 5px 9px; border: 1px solid var(--line-soft); border-radius: 20px; background: var(--panel);
}
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); animation: pulse 2.2s ease-in-out infinite; }
.live.is-stale .live-dot { background: var(--amber); }

.icon-btn {
  display: grid; place-items: center; width: 34px; height: 34px;
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: 9px;
  color: var(--muted); cursor: pointer; transition: color .18s, border-color .18s, transform .18s;
}
.icon-btn:hover { color: var(--text); border-color: var(--line); transform: translateY(-1px); }
.icon-btn.is-busy svg { animation: spin .9s linear infinite; }

.wrap { padding: 20px; max-width: 1500px; margin: 0 auto; }
.view { display: none; }
.view.is-active { display: block; animation: fadeUp .3s ease both; }

/* ── KPI cards ──────────────────────────────────────────────────── */
.kpi-grid {
  display: grid; gap: 12px; margin-bottom: 18px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.kpi {
  position: relative; overflow: hidden;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--line-soft); border-radius: var(--r);
  padding: 16px 16px 14px; box-shadow: var(--shadow);
  animation: rise .45s cubic-bezier(.2,.8,.2,1) both;
}
.kpi::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 20%, rgba(255,255,255,.05) 50%, transparent 80%);
  transform: translateX(-100%); animation: sweep 5s ease-in-out infinite 1.5s;
  pointer-events: none;
}
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--dim); }
.kpi-value { font-size: clamp(22px, 4.4vw, 30px); font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi[data-accent="sky"]   .kpi-value { color: var(--sky); }
.kpi[data-accent="indigo"] .kpi-value { color: var(--indigo); }
.kpi[data-accent="green"]  .kpi-value { color: var(--green); }
.kpi[data-accent="pink"]   .kpi-value { color: var(--pink); }
.kpi[data-accent="amber"]  .kpi-value { color: var(--amber); }
.kpi[data-accent="red"]    .kpi-value { color: var(--red); }

/* ── Panels ─────────────────────────────────────────────────────── */
.panel {
  background: var(--panel); border: 1px solid var(--line-soft);
  border-radius: var(--r); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.panel-row { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .panel-row { grid-template-columns: 2fr 1fr; } .span-2 { grid-column: span 1; } }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.panel-head h2 { margin: 0; font-size: 14.5px; font-weight: 650; letter-spacing: -.01em; }
.hint { font-size: 12px; color: var(--dim); }
.hint.pad { margin: 8px 0 14px; }

.seg { display: flex; gap: 2px; padding: 2px; background: var(--bg); border: 1px solid var(--line-soft); border-radius: 9px; }
.seg button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 12.5px;
  padding: 5px 11px; border-radius: 7px; cursor: pointer; transition: all .18s;
}
.seg button.is-active { background: var(--panel-2); color: var(--text); }

/* ── Chart ──────────────────────────────────────────────────────── */
.chart-wrap { width: 100%; height: 260px; position: relative; }
@media (max-width: 640px) { .chart-wrap { height: 200px; } }
.chart { width: 100%; height: 100%; overflow: visible; }
.chart .grid-line { stroke: var(--line-soft); stroke-width: 1; }
.chart .axis-text { fill: var(--dim); font-size: 10px; font-family: var(--mono); }
.chart .area { opacity: .22; }
.chart .line { fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
  stroke-dasharray: var(--len, 3000); stroke-dashoffset: var(--len, 3000);
  animation: drawIn 1.1s cubic-bezier(.4,0,.2,1) forwards; }
.chart .dot { transition: r .15s; }
.chart .hover-line { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 3; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 10px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ── Bars ───────────────────────────────────────────────────────── */
.bars { display: flex; flex-direction: column; gap: 11px; }
.bar-row { display: grid; grid-template-columns: 116px 1fr 44px; align-items: center; gap: 10px; font-size: 12.5px; }
.bar-row .lbl { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 8px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; transform-origin: left; animation: barGrow .9s cubic-bezier(.2,.8,.2,1) both; }
.bar-row .val { text-align: right; font-family: var(--mono); font-size: 12px; color: var(--text); font-variant-numeric: tabular-nums; }
@media (max-width: 520px) { .bar-row { grid-template-columns: 92px 1fr 38px; } }

/* ── Heatmap ────────────────────────────────────────────────────── */
.heatmap { display: grid; grid-template-columns: repeat(24, 1fr); gap: 3px; }
@media (max-width: 760px) { .heatmap { grid-template-columns: repeat(12, 1fr); } }
.hm-cell {
  aspect-ratio: 1; border-radius: 4px; background: var(--bg);
  border: 1px solid var(--line-soft); cursor: default;
  transition: transform .15s, box-shadow .15s;
  animation: fadeUp .4s ease both;
}
.hm-cell:hover { transform: scale(1.16); box-shadow: 0 0 0 1px var(--sky); z-index: 2; }
.hm-legend { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--dim); margin-top: 10px; }
.hm-legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* ── Attention list ─────────────────────────────────────────────── */
.attn { display: flex; flex-direction: column; gap: 8px; }
.attn-row {
  display: flex; align-items: center; gap: 12px; padding: 11px 13px;
  background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: 11px;
  cursor: pointer; transition: border-color .18s, transform .18s, background .18s;
  animation: fadeUp .35s ease both;
}
.attn-row:hover { border-color: var(--line); transform: translateX(3px); background: var(--panel-2); }
.attn-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.attn-main { min-width: 0; flex: 1; }
.attn-name { font-weight: 600; font-size: 13.5px; }
.attn-meta { font-size: 11.5px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attn-tag { font-size: 11px; padding: 3px 8px; border-radius: 20px; background: var(--panel-2); border: 1px solid var(--line-soft); color: var(--muted); white-space: nowrap; }

/* ── Split / conversation viewer ────────────────────────────────── */
.split { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 900px) { .split { grid-template-columns: 320px 1fr; height: calc(100vh - 110px); } }

.users-pane {
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--r);
  display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--shadow);
}
@media (min-width: 900px) { .users-pane { height: 100%; } }
.users-head { padding: 12px; border-bottom: 1px solid var(--line-soft); }
.users-meta { font-size: 11px; color: var(--dim); margin-top: 7px; }

/* Sort toggle: Recent (default) / Busiest. */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 8px;
       background: var(--panel-2); border: 1px solid var(--line-soft); border-radius: 8px; padding: 3px; }
.seg-btn { border: 0; background: transparent; color: var(--dim); cursor: pointer;
           font: inherit; font-size: 11.5px; font-weight: 600; padding: 5px 4px; border-radius: 6px;
           transition: background .15s, color .15s; }
.seg-btn:hover { color: var(--text); }
.seg-btn.is-on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

/* Badge shows recency first (what you triage on) with the volume beneath. */
.user-badge { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.badge-when { font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.badge-count { font-size: 10px; color: var(--dim); font-family: var(--mono); white-space: nowrap; }
.user-list { overflow-y: auto; flex: 1; padding: 6px; }
@media (max-width: 899px) { .user-list { max-height: 44vh; } }

.user-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px;
  border-radius: 9px; cursor: pointer; transition: background .15s;
}
.user-row:hover { background: var(--panel-2); }
.user-row.is-active { background: var(--panel-2); box-shadow: inset 2px 0 0 var(--sky); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #04121f;
}
.user-main { min-width: 0; flex: 1; }
.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-phone { font-size: 11px; color: var(--dim); font-family: var(--mono); }
.user-badge { font-size: 10.5px; color: var(--muted); white-space: nowrap; }

.chat-pane {
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: var(--r);
  overflow: hidden; display: flex; flex-direction: column; box-shadow: var(--shadow);
}
@media (min-width: 900px) { .chat-pane { height: 100%; } }
.chat-empty { flex: 1; display: grid; place-items: center; gap: 12px; color: var(--dim); padding: 40px; text-align: center; }
.empty-art { width: 110px; height: 110px; }

/* The scroll container itself.
   #chat was previously unstyled, so .chat-body's `flex: 1` had no flex parent to
   fill: the pane grew to full content height and the user could never scroll. */
.chat {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  height: 100%; overflow: hidden;
}

.chat-body {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 16px;
  background:
    radial-gradient(circle at 20% 0%, rgba(56,189,248,.05), transparent 45%),
    radial-gradient(circle at 80% 100%, rgba(167,139,250,.05), transparent 45%),
    var(--bg);
  /* Anchor scroll height correctly when older messages are prepended. */
  overflow-anchor: none;
}
@media (max-width: 899px) { .chat-body { max-height: 62vh; } }

/* "Load older messages" affordance shown at the very top, like WhatsApp. */
.chat-top {
  display: grid; place-items: center; padding: 10px 0 16px;
  position: sticky; top: -18px; z-index: 3;
}
.chat-more {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--muted);
  font: inherit; font-size: 12.5px; padding: 7px 15px; border-radius: 20px;
  cursor: pointer; transition: color .18s, border-color .18s;
}
.chat-more:hover { color: var(--text); border-color: var(--sky); }
.chat-top-note { font-size: 11.5px; color: var(--dim); }

.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft); background: var(--bg-2); flex: none;
}
.chat-title { font-weight: 650; font-size: 14px; }
.chat-sub { font-size: 11.5px; color: var(--dim); font-family: var(--mono); }

.chat-body {
  flex: 1; overflow-y: auto; padding: 18px 16px;
  background:
    radial-gradient(circle at 20% 0%, rgba(56,189,248,.05), transparent 45%),
    radial-gradient(circle at 80% 100%, rgba(167,139,250,.05), transparent 45%),
    var(--bg);
}
@media (max-width: 899px) { .chat-body { max-height: 62vh; } }

.day-sep { text-align: center; margin: 18px 0 12px; }
.day-sep span { font-size: 11px; color: var(--dim); background: var(--panel-2); padding: 4px 12px; border-radius: 20px; border: 1px solid var(--line-soft); }

.msg { display: flex; margin-bottom: 8px; animation: fadeUp .3s ease both; }
.msg.out { justify-content: flex-end; }
.bubble {
  max-width: min(78%, 620px); padding: 9px 13px 7px; border-radius: 16px;
  font-size: 14px; line-height: 1.48; white-space: pre-wrap; word-break: break-word;
  position: relative; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.msg.out .bubble { background: linear-gradient(135deg, #1d4ed8, #2563eb); border-bottom-right-radius: 5px; }
.msg.in  .bubble { background: var(--panel-2); border: 1px solid var(--line-soft); border-bottom-left-radius: 5px; }
.bubble time { display: block; font-size: 10px; color: rgba(255,255,255,.55); margin-top: 3px; text-align: right; }
.msg.in .bubble time { color: var(--dim); }

/* ── Search ─────────────────────────────────────────────────────── */
.input {
  width: 100%; padding: 10px 13px; border-radius: 10px;
  background: var(--bg); border: 1px solid var(--line); color: var(--text);
  font: inherit; font-size: 13.5px; outline: none; transition: border-color .2s, box-shadow .2s;
}
.input:focus { border-color: var(--sky); box-shadow: var(--glow); }
.input.big { padding: 13px 16px; font-size: 15px; }
.search-row { display: flex; gap: 10px; }
.btn {
  padding: 0 22px; border: 0; border-radius: 10px; cursor: pointer;
  background: linear-gradient(135deg, var(--sky), var(--indigo)); color: #04121f;
  font: inherit; font-weight: 700; font-size: 14px; transition: filter .2s, transform .15s;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }

.results { display: flex; flex-direction: column; gap: 8px; }
.result {
  padding: 11px 13px; background: var(--bg-2); border: 1px solid var(--line-soft);
  border-radius: 10px; cursor: pointer; transition: border-color .18s, transform .18s;
  animation: fadeUp .3s ease both;
}
.result:hover { border-color: var(--line); transform: translateX(3px); }
.result-top { display: flex; align-items: center; gap: 10px; font-size: 11.5px; color: var(--dim); margin-bottom: 5px; font-family: var(--mono); }
.result-body { font-size: 13.5px; color: var(--text); }
.role-chip { font-size: 10px; padding: 2px 7px; border-radius: 20px; font-family: var(--sans); font-weight: 600; }
.role-chip.user { background: rgba(56,189,248,.16); color: var(--sky); }
.role-chip.assistant { background: rgba(167,139,250,.16); color: var(--violet); }

/* ── System view ────────────────────────────────────────────────── */
.prose { font-size: 13.5px; color: var(--muted); line-height: 1.65; }
.prose code { background: var(--bg); padding: 2px 6px; border-radius: 5px; font-family: var(--mono); font-size: 12px; color: var(--sky); }
.prose a { color: var(--sky); }
.prose strong { color: var(--text); }

.svc { display: flex; flex-direction: column; gap: 8px; }
.svc-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--bg-2); border: 1px solid var(--line-soft); border-radius: 10px; }
.svc-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.svc-name { font-size: 13px; font-weight: 600; }
.svc-meta { font-size: 11px; color: var(--dim); font-family: var(--mono); margin-left: auto; }

.reports { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }
.report-row { display: flex; gap: 10px; align-items: center; padding: 8px 10px; background: var(--bg-2); border-radius: 8px; }
.report-row .f { font-family: var(--mono); color: var(--dim); }

/* ── Utilities ──────────────────────────────────────────────────── */
.empty { color: var(--dim); font-size: 13px; padding: 26px; text-align: center; }
.muted { color: var(--dim); }
.skel { background: linear-gradient(90deg, var(--panel-2) 25%, #22304a 50%, var(--panel-2) 75%);
  background-size: 300% 100%; animation: shimmer 1.4s infinite; border-radius: 8px; }

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  .brand-sub { display: none; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .wrap { padding: 14px 12px; }
  .live { display: none; }
}