/* =====================================================================
   Qnaura web app — styles

   Colour roles come from the validated data-viz palette. Both themes are
   selected, not flipped: the dark steps were chosen for the dark surface.
   ===================================================================== */

:root {
  color-scheme: dark;

  /* surfaces & ink */
  --page:            #0d1014;
  --surface-1:       #12161c;
  --surface-2:       #171c24;
  --surface-3:       #1e242e;
  --border:          rgba(255,255,255,0.10);
  --border-strong:   rgba(255,255,255,0.18);
  --text-primary:    #ffffff;
  --text-secondary:  #c3c2b7;
  --text-muted:      #898781;
  --grid:            #2c2c2a;
  --axis:            #383835;

  /* categorical series (dark steps) */
  --series-1: #3987e5;   /* offered  */
  --series-2: #d95926;   /* abandoned */
  --series-3: #199e70;   /* answered */

  /* status — fixed, never themed */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;

  --accent:   #3987e5;
  --radius:   10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --page:            #f9f9f7;
  --surface-1:       #ffffff;
  --surface-2:       #f7f8fa;
  --surface-3:       #f2f3f5;
  --border:          rgba(11,11,11,0.10);
  --border-strong:   rgba(11,11,11,0.20);
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --grid:            #e1e0d9;
  --axis:            #c3c2b7;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;

  --accent:   #2a78d6;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
button, select, input { font-family: inherit; font-size: inherit; }

/* ---------------- Boot screen ---------------- */
.boot {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--page); z-index: 100;
}
/* `display:grid` above outranks the browser's [hidden]{display:none}, so the
   overlay stayed on top and swallowed every click after loading. Restore it. */
.boot[hidden], .toast[hidden], .empty-note[hidden] { display: none; }
.boot-card { text-align: center; max-width: 560px; padding: 32px; }
.boot-mark { width: 44px; height: 44px; color: var(--accent); }
.boot-name { font-size: 22px; font-weight: 700; letter-spacing: 0.18em; margin-top: 12px; }
.boot-msg { color: var(--text-secondary); margin-top: 10px; }
.boot-detail {
  margin-top: 18px; padding: 14px 16px; text-align: left;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-secondary);
  font-size: 13px; line-height: 1.6;
}
.boot-detail code {
  background: var(--surface-3); padding: 1px 5px; border-radius: 4px;
  font-size: 12px;
}

/* ---------------- Top bar ---------------- */
.topbar {
  height: 56px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 26px; height: 26px; color: var(--accent); flex: none; }
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: 0.16em; line-height: 1.1; }
.brand-sub { font-size: 11px; color: var(--text-muted); letter-spacing: 0.04em; }

.topbar-right { display: flex; align-items: center; gap: 14px; }

.badge {
  font-size: 10px; font-weight: 700; letter-spacing: 0.09em;
  padding: 4px 8px; border-radius: 999px; border: 1px solid;
}
.badge-demo { color: var(--warning); border-color: var(--warning); }
.badge-live { color: var(--good); border-color: var(--good); }

.clock { text-align: right; line-height: 1.15; }
.clock span:first-child {
  display: block; font-size: 16px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.clock-zone { font-size: 10px; color: var(--text-muted); letter-spacing: 0.05em; }

.refresh-state {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-muted); letter-spacing: 0.05em;
}
.pulse-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--good);
  box-shadow: 0 0 0 0 rgba(12,163,12,0.6); animation: pulse 2.4s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(12,163,12,0.5); }
  70%  { box-shadow: 0 0 0 7px rgba(12,163,12,0); }
  100% { box-shadow: 0 0 0 0 rgba(12,163,12,0); }
}
@media (prefers-reduced-motion: reduce) { .pulse-dot { animation: none; } }

.icon-btn {
  width: 32px; height: 32px; display: grid; place-items: center;
  background: var(--surface-3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-secondary); cursor: pointer;
}
.icon-btn:hover { border-color: var(--border-strong); color: var(--text-primary); }
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
:root[data-theme="dark"] .ico-sun { display: none; }
:root[data-theme="light"] .ico-moon { display: none; }

/* ---------------- Shell / nav ---------------- */
.shell { display: flex; min-height: calc(100vh - 56px); }

.sidenav {
  width: 176px; flex: none; background: var(--surface-1);
  border-right: 1px solid var(--border);
  padding: 12px 10px; display: flex; flex-direction: column; gap: 3px;
  position: sticky; top: 56px; height: calc(100vh - 56px);
}
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 11px; background: none; border: 0; border-radius: var(--radius-sm);
  color: var(--text-secondary); cursor: pointer; text-align: left; font-size: 13px;
}
.nav-item svg { width: 17px; height: 17px; fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-item:hover { background: var(--surface-3); color: var(--text-primary); }
.nav-item.is-active {
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--text-primary); font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
}
.nav-spacer { flex: 1; }
.nav-foot { padding: 10px 11px; border-top: 1px solid var(--border); }
.dq-ok, .dq-bad { display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--text-muted); }
.dq-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); flex: none; }
.dq-bad .dq-dot { background: var(--critical); }
.dq-bad { color: var(--critical); }

.content { flex: 1; padding: 20px 22px 40px; min-width: 0; }

.view { display: none; }
.view.is-active { display: block; }
.view-head { margin-bottom: 16px; }
.view-head h1 { font-size: 19px; letter-spacing: -0.01em; }
.view-sub { margin: 3px 0 0; color: var(--text-muted); font-size: 12.5px; }

/* ---------------- KPI tiles ---------------- */
.kpi-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.kpi {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px 14px;
  position: relative; overflow: hidden;
}
.kpi::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--kpi-accent, transparent);
}
.kpi-label {
  font-size: 10.5px; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 600;
}
.kpi-value {
  font-size: 27px; font-weight: 650; line-height: 1.15; margin-top: 6px;
  letter-spacing: -0.02em;
}
.kpi-value .unit { font-size: 14px; font-weight: 500; color: var(--text-secondary); margin-left: 2px; }
.kpi-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; display: flex; align-items: center; gap: 5px; }
.kpi-meta svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; }
.kpi.s-good    { --kpi-accent: var(--good); }
.kpi.s-warning { --kpi-accent: var(--warning); }
.kpi.s-serious { --kpi-accent: var(--serious); }
.kpi.s-critical{ --kpi-accent: var(--critical); }
.kpi.s-neutral { --kpi-accent: var(--accent); }
.kpi-row-compact .kpi-value { font-size: 22px; }

/* ---------------- Panels ---------------- */
.panel {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 16px; overflow: hidden;
}
.panel-head {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.panel-head h2 { font-size: 13.5px; }
.panel-note { font-size: 11.5px; color: var(--text-muted); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
#view-wallboard .grid-2 > .panel { min-height: 340px; }
@media (max-width: 1080px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; }
.table-scroll { max-height: 480px; overflow-y: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th {
  position: sticky; top: 0; background: var(--surface-2); z-index: 1;
  text-align: left; font-weight: 600; font-size: 10.5px; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--text-muted);
  padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td {
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  color: var(--text-secondary); white-space: nowrap;
}
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table td:first-child { color: var(--text-primary); font-weight: 500; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table td.num { color: var(--text-primary); }
.status-col { text-align: center; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.04em; border: 1px solid;
}
.pill svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 2.2;
  stroke-linecap: round; stroke-linejoin: round; }
.pill.good     { color: var(--good);     border-color: color-mix(in srgb, var(--good) 55%, transparent);     background: color-mix(in srgb, var(--good) 12%, transparent); }
.pill.warning  { color: var(--warning);  border-color: color-mix(in srgb, var(--warning) 55%, transparent);  background: color-mix(in srgb, var(--warning) 12%, transparent); }
.pill.serious  { color: var(--serious);  border-color: color-mix(in srgb, var(--serious) 55%, transparent);  background: color-mix(in srgb, var(--serious) 12%, transparent); }
.pill.critical { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 55%, transparent); background: color-mix(in srgb, var(--critical) 12%, transparent); }
.pill.neutral  { color: var(--text-secondary); border-color: var(--border-strong); }

.val-good     { color: var(--good) !important; }
.val-warning  { color: var(--warning) !important; }
.val-serious  { color: var(--serious) !important; }
.val-critical { color: var(--critical) !important; }

/* ---------------- Filters ---------------- */
.filters {
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span {
  font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 600;
}
.field select, .field input {
  background: var(--surface-3); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 7px 10px; min-width: 168px;
}
.field select:focus, .field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.filter-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface-3); color: var(--text-primary);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 8px 13px; cursor: pointer; font-size: 12.5px; font-weight: 500;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.9;
  stroke-linecap: round; stroke-linejoin: round; }
.count-pill {
  font-size: 12px; color: var(--text-muted);
  background: var(--surface-3); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 999px;
}

/* ---------------- Agent state bar ---------------- */
.state-bar { display: flex; gap: 2px; padding: 16px 16px 0; height: 60px; }
.state-seg { border-radius: 4px; min-width: 3px; position: relative; }
.state-legend {
  display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 14px 16px 6px;
}
.reason-list { padding: 4px 16px 16px; }
.reason-head { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 600; margin: 10px 0 8px;
  border-top: 1px solid var(--border); padding-top: 12px; }
.reason-row { display: grid; grid-template-columns: 118px 1fr 34px;
  align-items: center; gap: 10px; margin-bottom: 6px; font-size: 12px;
  color: var(--text-secondary); }
.reason-bar { height: 7px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.reason-bar > i { display: block; height: 100%; border-radius: 4px; background: var(--series-2); }
.reason-row b { text-align: right; color: var(--text-primary); font-variant-numeric: tabular-nums; font-weight: 600; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-secondary); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-count { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------------- Charts ---------------- */
.chart-host { padding: 14px 16px 16px; }
.chart-host svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-legend { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 10px; }
.chart-tip {
  position: fixed; pointer-events: none; z-index: 60;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 9px 11px; font-size: 12px;
  box-shadow: 0 6px 22px rgba(0,0,0,0.35); min-width: 132px;
}
.chart-tip .tip-head {
  font-weight: 600; color: var(--text-primary); margin-bottom: 6px;
  font-size: 11.5px;
}
.chart-tip .tip-row {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  color: var(--text-secondary); line-height: 1.7;
}
.chart-tip .tip-row b { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.tip-key { display: flex; align-items: center; gap: 6px; }

/* ---------------- Agent tiles ---------------- */
.agent-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(212px, 1fr)); gap: 11px;
}
.agent-card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-left: 3px solid var(--st, var(--text-muted));
  border-radius: var(--radius); padding: 11px 13px;
}
.agent-name {
  font-weight: 600; font-size: 13px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.agent-sub { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.agent-state {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-top: 9px; gap: 8px;
}
.agent-state-name {
  font-size: 11px; font-weight: 700; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--st, var(--text-secondary));
}
.agent-timer { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--text-primary); }
.agent-foot {
  display: flex; justify-content: space-between; margin-top: 9px;
  padding-top: 8px; border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text-muted);
}
.agent-foot b { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.empty-note { color: var(--text-muted); text-align: center; padding: 36px; }

/* ---------------- Tabs ---------------- */
.tabs { display: flex; gap: 3px; margin-bottom: 14px; flex-wrap: wrap; }
.tab {
  background: none; border: 1px solid transparent; border-radius: var(--radius-sm);
  color: var(--text-secondary); padding: 7px 13px; cursor: pointer; font-size: 12.5px;
}
.tab:hover { background: var(--surface-2); color: var(--text-primary); }
.tab.is-active {
  background: var(--surface-1); border-color: var(--border);
  color: var(--text-primary); font-weight: 600;
}

.note-card {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--surface-1); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 14px 16px;
  color: var(--text-secondary); font-size: 12.5px; line-height: 1.65;
}
.note-card svg { width: 17px; height: 17px; flex: none; margin-top: 1px;
  fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; }
.note-card strong { color: var(--text-primary); }
.note-card code {
  background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-size: 11.5px;
}

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--surface-3); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 11px 18px; font-size: 13px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.4); z-index: 80;
}

@media (max-width: 720px) {
  .sidenav { width: 56px; }
  .nav-item span, .nav-foot { display: none; }
  .content { padding: 14px; }
  .brand-sub { display: none; }
}
