/* ============================================================
   HQ Dashboard (/admin/dashboard) — KPI cards, chart panels and
   the charts themselves (Components/Charts). Chrome uses the AVEUM
   tokens from aveum.css; the data colours are defined once here.
   ============================================================ */
.dash {
  /* Activity by status — the reference's green / grey / orange, given a meaning. */
  --viz-approved: #0d8f63;
  --viz-pending: #8d8aa3;
  --viz-problem: #eb6834;
  /* Emphasis pairs: the story in orange, its context in grey. */
  --viz-accent: #eb6834;
  --viz-accent-soft: #f5b594;
  --viz-context: #8d8aa3;
  --viz-context-dark: #5d5a70;
  /* Recessive chrome */
  --viz-track: #f3f2f8;
  --viz-grid: #eeecf5;
  --viz-axis: #9a96ad;
}

/* ---------- Sample (no data yet) ---------- */
.dash-sample { display: flex; flex-direction: column; gap: 14px; }
.dash-sample-note { align-items: center; justify-content: space-between; flex-wrap: wrap; }
.dash-sample-img { display: block; width: 100%; height: auto; border-radius: var(--r-lg);
  border: 1px solid var(--line-portal); box-shadow: var(--sh-1); background: #fff; }

/* ---------- Top bar ---------- */
.dash-topbar { gap: 20px; padding-top: 14px; padding-bottom: 14px; }
.dash-crumb { font-size: 18px; font-weight: 500; color: var(--muted-3); white-space: nowrap; letter-spacing: -.01em; }
.dash-crumb b { color: var(--ink); font-weight: 700; }
.dash-search { position: relative; flex: 1; max-width: 420px; display: flex; align-items: center; }
.dash-search input { width: 100%; background: var(--surface-3); border: 1px solid transparent; border-radius: var(--r-pill);
  padding: 10px 40px 10px 18px; font-family: inherit; font-size: 13px; color: var(--ink); outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s; }
.dash-search input::placeholder { color: var(--muted-4); }
.dash-search input:focus { background: #fff; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(47,107,255,.10); }
.dash-search button { position: absolute; right: 6px; width: 30px; height: 30px; border: none; background: none;
  color: var(--muted-2); cursor: pointer; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.dash-search button:hover { background: var(--line-2); color: var(--ink); }
.dash-actions { display: flex; align-items: center; gap: 14px; }
.dash-icon-btn { position: relative; width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; color: var(--graphite); transition: background .12s; }
.dash-icon-btn:hover { background: var(--primary-soft); color: var(--ink); }
.dash-bell-badge { position: absolute; top: 1px; right: 0; min-width: 17px; height: 17px; padding: 0 4px; border-radius: var(--r-pill);
  background: var(--error-2); color: #fff; font-size: 10px; font-weight: 700; display: flex; align-items: center;
  justify-content: center; box-shadow: 0 0 0 2px #fff; }
.dash-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 13px; text-transform: uppercase;
  user-select: none; }

/* Popovers (add menu, date range) — opened by a button, closed by a click outside. */
.dash-pop-anchor { position: relative; }
.dash-pop-shield { position: fixed; inset: 0; z-index: 40; }
.dash-pop-shield.is-page { z-index: 19; }   /* below the sticky topbar (20), above the page */
.dash-pop { position: absolute; top: calc(100% + 8px); right: 0; z-index: 41; min-width: 230px; background: #fff;
  border: 1px solid var(--line-portal); border-radius: var(--r-lg); box-shadow: var(--sh-portal); padding: 6px; }
.dash-pop-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: none; background: none;
  border-radius: 9px; font-family: inherit; font-size: 13px; color: var(--ink); text-align: left; cursor: pointer; }
.dash-pop-item:hover { background: var(--surface-2); }
.dash-pop-item .check { width: 16px; font-weight: 800; color: var(--primary); }
.dash-pop-item small { color: var(--muted-3); font-size: 11px; margin-left: auto; }
.dash-pop-foot { border-top: 1px solid var(--line-2); margin-top: 6px; padding: 10px 6px 4px; display: grid;
  grid-template-columns: 1fr 1fr; gap: 8px; }
.dash-pop-foot .input { padding: 8px 9px; font-size: 12px; }
.dash-pop-foot .btn { grid-column: 1 / -1; }

/* ---------- Filter row ---------- */
.dash-filterbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.dash-showing { font-size: 13px; font-weight: 600; color: var(--ink); }
.dash-control { display: inline-flex; align-items: center; gap: 8px; background: #fff; border: 1px solid var(--line-3);
  border-radius: 9px; padding: 8px 12px; font-family: inherit; font-size: 13px; font-weight: 600; color: var(--ink);
  cursor: pointer; white-space: nowrap; }
.dash-control:hover { border-color: #cfcbe0; }
select.dash-control { padding-right: 30px; appearance: none; -webkit-appearance: none;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%235b5b63' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center; }

/* Refetch keeps the frame: the previous render dims instead of flashing a spinner. */
.dash-body { transition: opacity .2s ease; }
.dash-body.is-loading { opacity: .55; pointer-events: none; }

/* ---------- KPI cards ---------- */
.dash-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.dash-kpi { background: #fff; border: 1px solid var(--line-portal); border-radius: var(--r-lg); box-shadow: var(--sh-1);
  padding: 16px 20px 14px; display: flex; flex-direction: column; min-width: 0; }
.dash-kpi-label { font-size: 13px; color: var(--muted-2); font-weight: 500; }
.dash-kpi-value { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin: 6px 0 12px; }
.dash-kpi-value strong { font-size: 26px; font-weight: 800; letter-spacing: -.03em; color: var(--ink); line-height: 1.15; }
.dash-kpi-value .unit { font-size: 13px; font-weight: 600; color: var(--muted-2); margin-left: -3px; }
.dash-delta { font-size: 12px; font-weight: 700; white-space: nowrap; }
.dash-delta.up { color: var(--success); }
.dash-delta.down { color: var(--error-2); }
.dash-delta.flat { color: var(--muted-3); }
.dash-link { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700;
  color: var(--primary); width: fit-content; }
.dash-link:hover { text-decoration: underline; }
.dash-kpi .dash-link { margin-top: auto; }

/* ---------- Panels ---------- */
.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.dash-panel { background: #fff; border: 1px solid var(--line-portal); border-radius: var(--r-lg); box-shadow: var(--sh-1);
  padding: 18px 20px 16px; min-width: 0; display: flex; flex-direction: column; }
.dash-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.dash-panel-title { font-size: 15px; font-weight: 800; color: var(--ink); letter-spacing: -.01em; }
.dash-panel-tools { display: flex; align-items: center; gap: 12px; }
.dash-toggle { border: none; background: none; padding: 0; font-family: inherit; font-size: 12px; font-weight: 600;
  color: var(--muted-2); cursor: pointer; }
.dash-toggle:hover { color: var(--ink); text-decoration: underline; }
.dash-empty { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; padding: 36px 12px;
  color: var(--muted-3); font-size: 13px; }

/* Recent leads */
.dash-leads { display: flex; flex-direction: column; margin: 0 -20px; }
.dash-lead { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto auto; align-items: center; gap: 12px;
  padding: 11px 20px; border-top: 1px solid #f2f0f8; cursor: pointer; transition: background .12s; }
.dash-lead:hover { background: #faf9ff; }
.dash-lead-avatar { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: #fff; }
.dash-lead-name { font-size: 14px; font-weight: 700; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-lead-sub { font-size: 12px; color: var(--muted-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-lead-date { font-size: 12px; color: var(--muted-3); white-space: nowrap; }

/* Leaderboard banner */
.dash-banner { display: flex; align-items: center; gap: 14px; background: #fff; border: 1px solid var(--line-portal);
  border-radius: var(--r-lg); box-shadow: var(--sh-1); padding: 12px 16px 12px 14px; }
.dash-banner-icon { width: 40px; height: 40px; border-radius: 50%; background: var(--primary-soft); color: var(--primary);
  flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.dash-banner-text { flex: 1; font-size: 14px; color: var(--ink); min-width: 0; }
.dash-banner-text b { font-weight: 800; }
.dash-pill-btn { border: 1px solid var(--line-3); background: #fff; border-radius: var(--r-pill); padding: 9px 18px;
  font-family: inherit; font-size: 13px; font-weight: 700; color: var(--ink); cursor: pointer; white-space: nowrap; }
.dash-pill-btn:hover { border-color: var(--primary); color: var(--primary); }

/* Device leaderboard (modal) — one series, one colour. */
.dash-rank { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 4px 10px; align-items: center; }
.dash-rank-no { font-family: var(--font-mono); font-size: 12px; color: var(--muted-3); text-align: right; }
.dash-rank-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.dash-rank-bar { grid-column: 2; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.dash-rank-bar span { height: 8px; border-radius: 0 4px 4px 0; background: var(--primary); min-width: 2px; }
.dash-rank-bar b { font-size: 12px; font-weight: 700; color: var(--graphite); }

/* ============================================================
   Charts (Components/Charts) — thin marks, 4px rounded data ends,
   hairline solid grid, tooltips that list every series.
   ============================================================ */
.viz { position: relative; display: flex; flex-direction: column; flex: 1; }
.viz-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted-2); margin-bottom: 12px; }
.viz-legend span { display: inline-flex; align-items: center; gap: 6px; }
.viz-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.viz-linekey { width: 14px; height: 2px; border-radius: 2px; display: inline-block; }
.viz-plot { position: relative; display: grid; grid-template-columns: 52px minmax(0, 1fr); }
.viz-yaxis { position: relative; }
.viz-ytick { position: absolute; right: 10px; transform: translateY(50%); font-size: 11px; color: var(--viz-axis);
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.viz-area { position: relative; }
.viz-gridline { position: absolute; left: 0; right: 0; height: 1px; background: var(--viz-grid); }
.viz-xaxis { display: grid; margin-left: 52px; margin-top: 8px; font-size: 11px; color: var(--viz-axis); }
/* A flex box centres a label wider than its column on the column, overflowing both sides —
   text-align stops centring once a nowrap line overflows and pushes it toward the next bar. */
.viz-xaxis span { display: flex; justify-content: center; white-space: nowrap; min-width: 0; }
.viz-note { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 13px;
  color: var(--muted-3); pointer-events: none; }
.viz-note span { background: rgba(255,255,255,.9); padding: 6px 12px; border-radius: 8px; }

/* Bar slots: the whole column is the hit target; the mark sits at its foot. */
.viz-bars { position: absolute; inset: 0; display: flex; }
.viz-slot { position: relative; flex: 1 1 0; min-width: 0; display: flex; align-items: flex-end; justify-content: center;
  gap: 2px; border: none; background: none; padding: 0; margin: 0; cursor: pointer; font: inherit; }
.viz-slot:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; border-radius: 6px; }
.viz-track { position: absolute; bottom: 0; top: 0; left: 50%; transform: translateX(-50%); width: min(24px, 64%);
  background: var(--viz-track); border-radius: 4px 4px 0 0; transition: background .12s; }
.viz-slot.is-hover .viz-track { background: #e9e7f2; }
/* Segments share the stack's height strictly by value (flex-grow on a zero basis), so the bar's
   total matches the axis and no segment is pushed out of a short bar. The 2px surface gap is a
   shadow drawn over the segment beneath rather than a gap, which would take height from the data. */
.viz-stack { position: relative; width: min(24px, 64%); display: flex; flex-direction: column-reverse;
  border-radius: 4px 4px 0 0; overflow: hidden; transition: filter .12s; }
.viz-stack > i { display: block; flex-basis: 0; min-height: 0; }
.viz-stack > i + i { box-shadow: 0 2px 0 #fff; }
.viz-slot.is-hover .viz-stack, .viz-slot.is-hover .viz-col { filter: brightness(1.1) saturate(1.1); }

/* Paired columns (two per month) inside one background track. */
.viz-group-track { position: absolute; top: 0; bottom: 0; left: 50%; transform: translateX(-50%); width: min(58px, 84%);
  background: var(--viz-track); border-radius: 6px 6px 0 0; }
.viz-slot.is-hover .viz-group-track { background: #e9e7f2; }
.viz-col { position: relative; width: min(22px, 34%); border-radius: 4px 4px 0 0; min-height: 0; transition: filter .12s; }
.viz-col-label { position: absolute; left: 50%; transform: translate(-50%, -100%); margin-top: -4px; font-size: 11px;
  font-weight: 700; color: var(--ink); white-space: nowrap; pointer-events: none; }

/* Lines */
.viz-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.viz-crosshair { position: absolute; top: 0; bottom: 0; width: 1px; background: #cfcbe0; pointer-events: none; }
.viz-dot { position: absolute; width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff;
  transform: translate(-50%, 50%); pointer-events: none; box-shadow: 0 0 0 .5px rgba(0,0,0,.04); }
.viz-hit { position: absolute; top: 0; bottom: 0; border: none; background: none; padding: 0; cursor: pointer; }
.viz-hit:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; border-radius: 6px; }

/* Tooltip: value first, label second, a line key per series. It sits beside the hovered
   column (right of it, or left in the chart's right half) so it never covers the mark. */
.viz-tip { position: absolute; top: 2px; z-index: 5; min-width: 150px; background: #fff; border: 1px solid var(--line-portal);
  border-radius: 10px; box-shadow: var(--sh-portal); padding: 9px 11px; pointer-events: none; font-size: 12px;
  color: var(--muted-2); white-space: nowrap; }
.viz-tip-title { font-weight: 700; color: var(--ink); margin-bottom: 6px; }
.viz-tip-row { display: flex; align-items: center; gap: 7px; line-height: 1.7; }
.viz-tip-row b { color: var(--ink); font-weight: 800; font-variant-numeric: tabular-nums; }
.viz-tip-total { border-top: 1px solid var(--line-2); margin-top: 5px; padding-top: 5px; }

/* Table view — every value readable without hovering. */
.viz-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.viz-table th { text-align: right; font-size: 10px; font-weight: 700; color: #a09bbb; text-transform: uppercase;
  letter-spacing: .06em; padding: 6px 8px; border-bottom: 1px solid var(--line-portal); }
.viz-table th:first-child, .viz-table td:first-child { text-align: left; }
.viz-table td { text-align: right; padding: 7px 8px; border-bottom: 1px solid #f4f2fb; color: var(--ink);
  font-variant-numeric: tabular-nums; }
.viz-table-wrap { max-height: 260px; overflow-y: auto; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .dash-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1020px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
  .dash-topbar { gap: 12px; }
  .dash-crumb span { display: none; }
}
@media (max-width: 640px) {
  .dash-search { display: none; }
  .dash-kpis { grid-template-columns: minmax(0, 1fr); }
  .dash-banner { flex-wrap: wrap; }
  .dash-crumb { font-size: 16px; }
}
