/* ==========================================================================
   Unada client dashboard — futuristic analytics shell
   Builds on style.css tokens. Chart colours are role tokens (validated).
   ========================================================================== */

.dash-body {
  --chart-surface: #0c1a38;
  --grid: #182a4d;
  --axis: #2a3e66;
  --ink-1: #eef3fb;
  --ink-2: #b3c0d6;
  --ink-3: #8797b4;

  /* Categorical (fixed order — never cycled) */
  /* Logo hues stepped into the dark chart band; this order passes CVD + contrast checks on #0c1a38 */
  --series-1: #2f86dd;
  --series-2: #d9661a;
  --series-3: #8f63e0;
  --series-4: #4f9a2c;
  /* Single-series accent + comparison */
  --signal: #3aa8f0;
  --compare: #6b7a99;

  /* Status (reserved, always with icon + label) */
  --st-good: #0ca30c;
  --st-good-text: #3ddc5b;
  --st-warning: #fab219;
  --st-serious: #ec835a;
  --st-critical: #d03b3b;
  --st-critical-text: #f87171;

  background: var(--bg);
  min-height: 100vh;
}

.app { display: grid; min-height: 100vh; }
@media (min-width: 1024px) { .app { grid-template-columns: 248px 1fr; } }

/* Background ambience */
.dash-ambience { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.dash-ambience::before {
  content: ""; position: absolute; inset: 0;
  background-image: linear-gradient(rgba(58,168,240,.05) 1px, transparent 1px), linear-gradient(90deg, rgba(58,168,240,.05) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at 70% 0%, #000 10%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse at 70% 0%, #000 10%, transparent 70%);
}
.dash-ambience .orb-1 { opacity: .25; }

/* Sidebar ------------------------------------------------------------------ */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 280px; z-index: 120;
  display: flex; flex-direction: column; gap: 4px; padding: 20px 16px;
  background: rgba(7, 16, 36, 0.97); border-right: 1px solid var(--line);
  transform: translateX(-100%); transition: transform .35s var(--ease-out);
  overflow-y: auto;
}
.sidebar-open .sidebar { transform: none; }
.sidebar-scrim { position: fixed; inset: 0; z-index: 110; background: rgba(0,0,0,.55); opacity: 0; visibility: hidden; transition: opacity .3s, visibility 0s .3s; }
.sidebar-open .sidebar-scrim { opacity: 1; visibility: visible; transition-delay: 0s; }
@media (min-width: 1024px) {
  .sidebar { position: sticky; top: 0; height: 100vh; width: auto; transform: none; background: rgba(7,16,36,.75); backdrop-filter: blur(16px); }
  .sidebar-scrim { display: none; }
}
.sidebar .brand { padding: 4px 8px 20px; }
.side-label { font-family: var(--font-mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); padding: 16px 12px 8px; }
.side-link {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 10px;
  color: var(--ink-2); font-size: 15px; transition: background-color .2s, color .2s; position: relative;
}
.side-link:hover { background: rgba(255,255,255,.04); color: var(--ink-1); }
.side-link.is-active { background: rgba(58,168,240,.1); color: var(--ink-1); }
.side-link.is-active::before { content: ""; position: absolute; left: -16px; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--signal); box-shadow: 0 0 12px var(--signal); }
.side-card {
  margin-top: auto; padding: 16px; border-radius: 14px; border: 1px solid rgba(244,123,32,.3);
  background: linear-gradient(160deg, rgba(244,123,32,.12), rgba(12,26,56,.6));
}
.side-card strong { display: block; font-family: var(--font-display); font-stretch: var(--display-stretch); font-weight: 650; }
.side-card p { font-size: 13px; color: var(--ink-2); margin: 6px 0 12px; }

/* Topbar ------------------------------------------------------------------- */
.main { min-width: 0; padding: 0 16px 48px; }
@media (min-width: 768px) { .main { padding: 0 28px 64px; } }
.topbar {
  position: sticky; top: 0; z-index: 50; display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 14px 16px; margin: 0 -16px 8px;
  background: rgba(5, 13, 31, 0.82);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
@media (min-width: 768px) { .topbar { padding: 14px 28px; margin: 0 -28px 16px; } }
@media (max-width: 767px) { .topbar { position: relative; } }
.topbar .menu-toggle { flex-shrink: 0; }
@media (min-width: 1024px) { .topbar .menu-toggle { display: none; } }
.topbar-title { flex: 1; min-width: 180px; }
.topbar-title h1 { font-size: clamp(22px, 3vw, 30px); }
.topbar-title p { color: var(--ink-3); font-size: 14px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 2px; }
.demo-badge { font-family: var(--font-mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; padding: 3px 8px; border-radius: 6px; background: rgba(250,178,25,.12); color: #fcd34d; border: 1px solid rgba(250,178,25,.3); }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
@media (max-width: 639px) { .topbar-actions { width: 100%; } .topbar-actions .segmented { flex: 1; } }

.segmented { display: inline-flex; padding: 4px; border-radius: 12px; background: rgba(255,255,255,.03); border: 1px solid var(--line-strong); }
.segmented button {
  flex: 1; min-height: 38px; min-width: 52px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent;
  color: var(--ink-2); font-family: var(--font-mono); font-size: 13px; transition: background-color .2s, color .2s;
}
.segmented button:hover { color: var(--ink-1); }
.segmented button[aria-pressed="true"] { background: rgba(58,168,240,.16); color: var(--ink-1); box-shadow: inset 0 0 0 1px rgba(58,168,240,.45); }

/* Panels ------------------------------------------------------------------- */
.panel {
  position: relative; border-radius: 18px; padding: 20px; min-width: 0;
  background: linear-gradient(180deg, rgba(17,35,71,.72), rgba(12,26,56,.82));
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.panel::before {
  content: ""; position: absolute; top: -1px; left: 24px; right: 24px; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(58,168,240,.5), transparent); opacity: .6;
}
.panel-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-head h2 { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.panel-head p { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.panel-tools { display: flex; gap: 8px; align-items: center; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 9px;
  border: 1px solid var(--line-strong); background: rgba(255,255,255,.02); color: var(--ink-2); font-size: 13px;
  transition: border-color .2s, color .2s;
}
.tool-btn:hover { color: var(--ink-1); border-color: rgba(58,168,240,.5); }
@media (pointer: coarse) { .tool-btn { min-height: 44px; } }

.dash-grid { display: grid; gap: 16px; }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 768px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1280px) { .kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.row-a, .row-b, .row-c { display: grid; gap: 16px; }
@media (min-width: 1180px) {
  .row-a { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
  .row-b { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .row-c { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
}
@media (min-width: 768px) and (max-width: 1179px) {
  .row-b { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row-b > :last-child { grid-column: 1 / -1; }
}

/* KPI tile */
.kpi { padding: 16px; }
.kpi .k-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.kpi .k-label .icon { width: 16px; height: 16px; color: var(--ink-3); }
.kpi .k-value { font-family: var(--font-display); font-stretch: var(--display-stretch); font-size: clamp(24px, 2.4vw, 30px); font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; margin-top: 6px; line-height: 1.1; }
.kpi .k-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.delta { display: inline-flex; align-items: center; gap: 3px; font-size: 13px; font-weight: 600; }
.delta .icon { width: 14px; height: 14px; }
.delta.up { color: var(--st-good-text); }
.delta.down { color: var(--st-critical-text); }
.delta small { color: var(--ink-3); font-weight: 400; margin-left: 4px; }
.spark { width: 84px; height: 28px; flex-shrink: 0; }

/* Charts */
.chart { position: relative; width: 100%; outline: none; touch-action: pan-y; }
.chart:focus-visible { outline: 2px solid var(--signal); outline-offset: 4px; border-radius: 8px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { font-family: var(--font-body); }
.axis-text { fill: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 8px; }
.legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.dashed { background: repeating-linear-gradient(90deg, var(--compare) 0 4px, transparent 4px 7px) !important; }
.legend i.swatch { width: 10px; height: 10px; border-radius: 3px; }
.legend b { color: var(--ink-1); font-weight: 600; font-variant-numeric: tabular-nums; }

.tooltip {
  position: absolute; z-index: 10; pointer-events: none; min-width: 150px;
  padding: 10px 12px; border-radius: 10px; font-size: 13px;
  background: rgba(7,16,36,.96); border: 1px solid var(--line-strong);
  box-shadow: 0 16px 40px -12px rgba(0,0,0,.8);
  opacity: 0; transform: translateY(4px); transition: opacity .15s, transform .15s;
}
.tooltip.show { opacity: 1; transform: none; }
.tooltip .tt-title { color: var(--ink-3); font-size: 12px; margin-bottom: 6px; }
.tooltip .tt-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--ink-2); }
.tooltip .tt-row + .tt-row { margin-top: 4px; }
.tooltip .tt-row span { display: inline-flex; align-items: center; gap: 6px; }
.tooltip .tt-row i { width: 8px; height: 8px; border-radius: 50%; }
.tooltip .tt-row b { color: var(--ink-1); font-variant-numeric: tabular-nums; }

/* Data tables */
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--grid); }
.data-table th { font-weight: 500; color: var(--ink-3); font-size: 12px; font-family: var(--font-mono); letter-spacing: .06em; text-transform: uppercase; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr { transition: background-color .15s; }
.data-table tbody tr:hover { background: rgba(255,255,255,.02); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-height: 320px; }
.table-scroll .data-table { min-width: 420px; }
.kw-pos { font-family: var(--font-display); font-weight: 650; font-size: 16px; font-variant-numeric: tabular-nums; }
.kw-change { display: inline-flex; align-items: center; gap: 2px; font-size: 13px; font-weight: 600; }
.kw-change .icon { width: 13px; height: 13px; }
.kw-change.up { color: var(--st-good-text); }
.kw-change.down { color: var(--st-critical-text); }
.kw-change.flat { color: var(--ink-3); }

/* Live panel */
.recent-count { display: flex; align-items: baseline; gap: 10px; }
.recent-count .num { font-family: var(--font-display); font-stretch: var(--display-stretch); font-size: 46px; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; line-height: 1; }
.recent-count span { color: var(--ink-2); font-size: 14px; }
.feed { display: grid; gap: 8px; margin-top: 16px; }
.feed li {
  display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; grid-template-areas: "icon title time" "icon sub sub";
  column-gap: 10px; row-gap: 2px; align-items: center;
  padding: 10px; border-radius: 10px; background: rgba(255,255,255,.025); border: 1px solid var(--line);
  font-size: 13px;
}
.feed .f-icon { grid-area: icon; width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; }
.feed .f-icon .icon { width: 16px; height: 16px; }
.feed strong { grid-area: title; color: var(--ink-1); font-weight: 500; }
.feed small { grid-area: sub; font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed time { grid-area: time; font-family: var(--font-mono); font-size: 11px; color: var(--ink-3); white-space: nowrap; }

/* Bars (channel) */
.hbar-list { display: grid; gap: 14px; }
.hbar { display: grid; gap: 6px; }
.hbar-top { display: flex; justify-content: space-between; font-size: 14px; color: var(--ink-2); }
.hbar-top b { color: var(--ink-1); font-variant-numeric: tabular-nums; }
.hbar-track { position: relative; height: 10px; border-radius: 4px; background: rgba(255,255,255,.05); }
.hbar-fill { position: absolute; inset: 0 auto 0 0; border-radius: 0 4px 4px 0; transform-origin: left; transition: width .8s var(--ease-out); }
.hbar[data-tip] { cursor: default; }

/* Stacked share bar */
.share-bar { display: flex; gap: 2px; height: 16px; border-radius: 4px; overflow: hidden; margin: 8px 0 18px; }
.share-bar span { height: 100%; transition: flex-grow .8s var(--ease-out); min-width: 2px; }
.share-bar span:first-child { border-radius: 4px 0 0 4px; }
.share-bar span:last-child { border-radius: 0 4px 4px 0; }
.share-legend { display: grid; gap: 10px; }
.share-legend li { display: grid; grid-template-columns: 12px 1fr auto auto; gap: 10px; align-items: center; font-size: 14px; color: var(--ink-2); }
.share-legend i { width: 10px; height: 10px; border-radius: 3px; }
.share-legend b { color: var(--ink-1); font-variant-numeric: tabular-nums; }
.share-legend em { font-style: normal; color: var(--ink-3); font-variant-numeric: tabular-nums; min-width: 42px; text-align: right; }

/* Funnel */
.funnel { display: grid; gap: 10px; }
.funnel-step { display: grid; grid-template-columns: 1fr; gap: 6px; }
.funnel-top { display: flex; justify-content: space-between; font-size: 14px; color: var(--ink-2); }
.funnel-top b { color: var(--ink-1); font-variant-numeric: tabular-nums; }
.funnel-top em { font-style: normal; color: var(--ink-3); font-size: 12px; margin-left: 6px; }
.funnel-bar { height: 22px; border-radius: 0 4px 4px 0; background: var(--signal); transition: width .8s var(--ease-out); box-shadow: 0 0 20px -6px rgba(58,168,240,.6); }

/* Heatmap */
.heat-wrap { position: relative; }
.heat-scale { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-3); margin-top: 12px; }
.heat-scale .ramp { display: flex; gap: 2px; }
.heat-scale .ramp i { width: 18px; height: 10px; border-radius: 2px; }

/* Vitals bullet charts */
.vitals { display: grid; gap: 18px; }
@media (min-width: 768px) { .vitals { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.vital-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.vital-top strong { font-size: 14px; color: var(--ink-1); font-weight: 500; }
.vital-top .v { font-family: var(--font-display); font-stretch: var(--display-stretch); font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.vital-sub { font-size: 12px; color: var(--ink-3); }
.bullet { position: relative; height: 14px; margin: 10px 0 6px; display: flex; gap: 2px; }
.bullet .band { height: 100%; }
.bullet .band:first-child { border-radius: 4px 0 0 4px; }
.bullet .band:last-of-type { border-radius: 0 4px 4px 0; }
.bullet .marker { position: absolute; top: -4px; bottom: -4px; width: 3px; border-radius: 2px; background: var(--ink-1); box-shadow: 0 0 0 2px var(--chart-surface); transform: translateX(-50%); transition: left .8s var(--ease-out); }
.bullet-labels { position: relative; height: 16px; font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.bullet-labels span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.bullet-labels span:first-child { transform: none; }
.bullet-labels span:last-child { transform: translateX(-100%); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; margin-top: 8px; }
.status .icon { width: 15px; height: 15px; }
.status.good { color: var(--st-good-text); }
.status.warning { color: var(--st-warning); }
.status.critical { color: var(--st-critical-text); }

.dash-footer { margin-top: 32px; color: var(--ink-3); font-size: 13px; display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; }

@media (prefers-reduced-motion: reduce) {
  .hbar-fill, .funnel-bar, .bullet .marker, .share-bar span { transition: none; }
}
@media (forced-colors: active) {
  .hbar-fill, .funnel-bar, .share-bar span, .legend i, .share-legend i { forced-color-adjust: none; }
}
