/* Analytics: usage and charges for everyone, profit and the explorer for super
   admins. Uses the admin page's tokens (index.html :root); chart series colours
   are the validated categorical slots (dataviz reference palette, light). */
.an-root {
  --series-1: #2a78d6;  /* blue    */
  --series-2: #eb6834;  /* orange  */
  --series-3: #1baf7a;  /* aqua    */
  --series-4: #eda100;  /* yellow  */
  --series-5: #e87ba4;  /* magenta */
  --ink-line: #18181b;
  --grid: #ececef;
  display: flex; flex-direction: column; gap: 18px; margin-bottom: 26px;
}

/* ── filter row: one row, above everything it scopes ── */
.an-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.an-filters .an-spacer { flex: 1; }
.an-select, .an-date {
  padding: 7px 10px; font: inherit; font-size: .82rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); outline: none;
}
.an-select:focus-visible, .an-date:focus-visible { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(110,64,201,.12); }
.an-seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); background: var(--surface); }
.an-seg button {
  padding: 7px 12px; font: inherit; font-size: .8rem; color: var(--text-muted);
  background: none; border: none; cursor: pointer;
}
.an-seg button + button { border-left: 1px solid var(--border); }
.an-seg button[aria-pressed="true"] { background: var(--purple-light); color: var(--purple); font-weight: 600; }
.an-seg button:focus-visible { outline: 2px solid var(--purple); outline-offset: -2px; }
.an-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 12px; font: inherit; font-size: .8rem; font-weight: 500; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); cursor: pointer;
}
.an-btn:hover { border-color: #c4c4c8; }
.an-btn:disabled { opacity: .55; cursor: default; }
.an-btn svg { width: 14px; height: 14px; }
.an-note { font-size: .75rem; color: var(--text-subtle); }

/* ── stat tiles ── */
.an-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 820px) { .an-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.an-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm); min-width: 0;
}
.an-tile-value { font-size: 1.55rem; font-weight: 700; letter-spacing: -.02em; color: var(--text); font-variant-numeric: tabular-nums; line-height: 1.1; }
.an-tile-label { margin-top: 6px; font-size: .72rem; font-weight: 600; color: var(--text-subtle); text-transform: uppercase; letter-spacing: .05em; }
.an-tile-sub { margin-top: 4px; font-size: .75rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ── cards ── */
.an-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-sm); min-width: 0;
}
.an-card-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.an-card-title { font-size: .95rem; font-weight: 650; color: var(--text); }
.an-card-head .an-spacer { flex: 1; }
.an-section-title { font-size: 1.05rem; font-weight: 700; color: var(--text); margin: 8px 0 -4px; display: flex; align-items: center; gap: 10px; }
.an-badge { font-size: .66rem; font-weight: 700; padding: 3px 9px; border-radius: 20px; background: var(--purple-light); color: var(--purple); letter-spacing: .03em; text-transform: uppercase; }

/* ── legend ── */
.an-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-bottom: 8px; }
.an-legend-item { display: inline-flex; align-items: center; gap: 7px; font-size: .78rem; color: var(--text-muted); }
.an-legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.an-legend-line { width: 16px; height: 2px; border-radius: 1px; flex-shrink: 0; }

/* ── chart ── */
.an-chart { position: relative; width: 100%; }
.an-chart svg { display: block; width: 100%; overflow: visible; }
.an-chart .an-axis text { font-size: 11px; fill: var(--text-subtle); font-variant-numeric: tabular-nums; }
.an-chart .an-gridline { stroke: var(--grid); stroke-width: 1; }
.an-chart .an-baseline { stroke: #d4d4d8; stroke-width: 1; }
.an-chart .an-hit { fill: transparent; cursor: default; }
.an-chart .an-col-hover { fill: rgba(110,64,201,.06); }
.an-chart .an-seg-rect { transition: opacity .12s; }
.an-chart.dim .an-seg-rect { opacity: .72; }
.an-chart.dim .an-seg-rect.hot { opacity: 1; }
.an-tip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 170px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow-lg); padding: 9px 11px; font-size: .78rem;
}
.an-tip[hidden] { display: none; }
.an-tip-title { font-weight: 600; color: var(--text); margin-bottom: 6px; }
.an-tip-row { display: grid; grid-template-columns: 14px 1fr auto; align-items: center; gap: 7px; padding: 1px 0; }
.an-tip-row .k { height: 2px; border-radius: 1px; }
.an-tip-row .n { color: var(--text-muted); }
.an-tip-row .v { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.an-tip-total { border-top: 1px solid var(--border); margin-top: 5px; padding-top: 5px; }
.an-empty { padding: 34px 0; text-align: center; color: var(--text-subtle); font-size: .85rem; }
.an-loading { opacity: .5; transition: opacity .15s; }

/* ── tables ── */
.an-table-wrap { overflow-x: auto; }
.an-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.an-table th {
  text-align: left; font-size: .68rem; font-weight: 700; color: var(--text-subtle);
  text-transform: uppercase; letter-spacing: .05em; padding: 7px 8px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.an-table th.sortable { cursor: pointer; user-select: none; }
.an-table th.sortable:hover { color: var(--text-muted); }
.an-table th .dir { margin-left: 4px; color: var(--purple); }
.an-table td { padding: 7px 8px; border-bottom: 1px solid var(--surface-2, #f4f4f5); color: var(--text); white-space: nowrap; }
.an-table td.num, .an-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.an-table tr.total td { font-weight: 650; border-top: 1px solid var(--text); border-bottom: none; }
.an-table .swatch { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 8px; vertical-align: 0; }
.an-table td.neg { color: var(--red); }
.an-share { display: inline-block; height: 6px; border-radius: 3px; background: var(--purple); opacity: .35; vertical-align: middle; margin-right: 8px; }

/* ── explorer ── */
.an-explorer-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.an-explorer-controls label { font-size: .78rem; color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; }
.an-check { display: inline-flex; align-items: center; gap: 7px; font-size: .8rem; color: var(--text-muted); cursor: pointer; }
