/* Analytics page: KPIs, daily chart with a series toggle, hour / weekday columns, bar lists, top tables */
/* --ana-3 (avg % of ref) is palette slot 2 (dark), validated with --viz-1 / --viz-2 on --surface (dataviz validate_palette, all pairs);
   the moving average is a neutral line: same measure as the bars, not a new series */
.ana { --ana-3: #d95926; --ana-ma: #c4c8ce; transition: opacity .2s; }
.ana { position: relative; }
.ana.stale { opacity: .45; pointer-events: none; }
/* 2px indeterminate bar while a range loads */
.ana.stale::before {
  content: ""; position: absolute; top: -12px; left: 0; right: 0; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent) no-repeat; background-size: 35% 100%;
  animation: ana-load 1.1s ease-in-out infinite;
}
@keyframes ana-load { from { background-position: -60% 0; } to { background-position: 160% 0; } }
.ana-none { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; font-style: italic; color: var(--muted); }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.kpis .stat .value { font-size: 22px; font-variant-numeric: normal; }
.delta { display: inline; }
.grid.split { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
/* chart head: legend + series toggle */
.ana-chart-ctl { display: flex; align-items: center; gap: 10px 16px; flex-wrap: wrap; }
.ana-seg { background: var(--bg); }
.ana-seg button { min-width: 0; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 12.5px; }
.legend .key { display: inline-flex; align-items: center; gap: 7px; }
.legend .key::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--viz-1); }
.legend .key.line::before { width: 14px; height: 2px; border-radius: 2px; }
.legend .key.kma::before { background: var(--ana-ma); }

.chart { position: relative; margin: 6px 0 2px; min-height: 100px; }
.plot { display: block; overflow: visible; touch-action: pan-y; -webkit-tap-highlight-color: transparent; }
.plot:focus { outline: none; }
.plot:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.plot .grid { stroke: var(--viz-grid); stroke-width: 1; shape-rendering: crispEdges; }
.plot .base { stroke: var(--viz-base); stroke-width: 1; shape-rendering: crispEdges; }
.plot .tick { fill: var(--faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.plot .cap { fill: var(--muted); font-size: 12.5px; }
.plot .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.plot .ln.ma { stroke: var(--ana-ma); stroke-opacity: .85; }
.plot .ln.pct { stroke: var(--ana-3); }
.plot .ln.draw { stroke-dasharray: 1; animation: ana-draw .9s var(--ease) .25s both; }
.plot .dot.pct { fill: var(--ana-3); }
.plot .hot-dot { stroke: var(--surface); stroke-width: 2; pointer-events: none; }
.plot .hot-dot.ma { fill: var(--ana-ma); }
.plot .hot-dot.pct { fill: var(--ana-3); }
@keyframes ana-draw { from { stroke-dashoffset: 1; } }
.plot .hit { fill: transparent; cursor: crosshair; }
.plot .hover-col { fill: rgba(255, 255, 255, .035); }
.plot .bar { transition: fill .12s; }
.plot .b1 { fill: var(--viz-1); }
.plot .b2 { fill: var(--viz-2); }
.plot .b1.hot { fill: var(--viz-1-hi); }
.plot .b2.hot { fill: var(--viz-2-hi); }
.plot.grow .bar { transform-box: fill-box; transform-origin: 50% 100%; animation: bar-grow .55s var(--ease) both; }
.tip {
  position: absolute; top: 4px; left: 0; z-index: 3; pointer-events: none;
  min-width: 156px; padding: 9px 12px; border-radius: 10px;
  background: rgba(36, 40, 45, .96); border: 1px solid #343940; box-shadow: 0 10px 28px rgba(0, 0, 0, .45);
  font-size: 12.5px; white-space: nowrap;
  opacity: 0; visibility: hidden; transition: opacity .12s, visibility .12s;
}
.tip.on { opacity: 1; visibility: visible; }
.tip-head { color: var(--muted); margin-bottom: 5px; }
.tip-row { display: flex; align-items: center; gap: 7px; line-height: 1.6; }
.tip-row strong { font-weight: 600; font-variant-numeric: tabular-nums; }
.key-line { width: 10px; height: 2px; border-radius: 2px; flex: none; }
.key-line.k1 { background: var(--viz-1); }
.key-line.k2 { background: var(--viz-2); }
.key-line.k3 { background: var(--ana-3); }
.key-line.kma { background: var(--ana-ma); }
.tip-row strong.pos { color: var(--pos); }
.tip-row strong.neg { color: var(--neg); }

/* "Show as table" under the chart: scrolls inside itself, so its header sticks at 0 */
.twin { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 4px; }
.twin summary { display: inline-flex; align-items: center; min-height: 32px; color: var(--muted); font-size: 12.5px; cursor: pointer; list-style: none; transition: color .15s; }
.twin summary::-webkit-details-marker { display: none; }
.twin summary::before { content: "›"; display: inline-block; width: 14px; transition: transform .2s var(--ease); }
.twin[open] summary::before { transform: rotate(90deg); }
.twin summary:hover { color: var(--text); }
.twin .table-wrap { max-height: 420px; overflow-y: auto; margin: 0 -20px -18px; border-top: 1px solid var(--border); }
.twin .table-wrap th { top: 0; }

.bars { display: flex; flex-direction: column; gap: 14px; }
.bar-top { display: flex; justify-content: space-between; gap: 12px; }
.bar-label { min-width: 0; overflow-wrap: anywhere; }
.bar-label::first-letter { text-transform: uppercase; }
.bar-track { height: 8px; margin-top: 6px; border-radius: 0 4px 4px 0; background: var(--surface-2); overflow: hidden; }
.bar-track .fill { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--viz-1); transform-origin: 0 50%; animation: bar-x .6s var(--ease) both; }
.bar-row:hover .fill { background: var(--viz-1-hi); }
.bar-sub { color: var(--muted); font-size: 12px; margin-top: 4px; font-variant-numeric: tabular-nums; }

/* hour of day / weekday columns (buttons: hover, tap or focus for the tooltip) */
.ana-cols-wrap { position: relative; padding-top: 4px; }
.ana-cols { display: grid; grid-template-columns: repeat(var(--cols, 24), minmax(0, 1fr)); gap: 2px; height: 150px; }
.ana-col {
  display: flex; flex-direction: column; min-width: 0; padding: 0; border: 0; border-radius: 4px;
  background: transparent; color: inherit; font: inherit; cursor: default; -webkit-tap-highlight-color: transparent;
}
.ana-col-track { flex: 1; display: flex; align-items: flex-end; justify-content: center; border-radius: 4px; transition: background .12s; }
.ana-col-fill { display: block; width: min(100%, 24px); min-height: 0; border-radius: 4px 4px 0 0; background: var(--viz-2); transform-origin: 50% 100%; animation: bar-grow .55s var(--ease) both; transition: background .12s; }
.ana-col-tick { height: 20px; padding-top: 5px; color: var(--faint); font-size: 11px; line-height: 1; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ana-col:hover .ana-col-track, .ana-col:focus-visible .ana-col-track { background: rgba(255, 255, 255, .035); }
.ana-col:hover .ana-col-fill, .ana-col:focus-visible .ana-col-fill { background: var(--viz-2-hi); }
.ana-col:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ana-cols-wrap .ana-cols { border-bottom: 0; }
.ana-cols-wrap .ana-col-track { box-shadow: inset 0 -1px 0 var(--viz-base); }

/* item images: fixed square, soft rarity tint, neutral placeholder underneath */
.ana-thumb {
  --thumb: 40px; --rarity: #5d626a;
  position: relative; flex: none; display: grid; place-items: center; overflow: hidden;
  width: var(--thumb); height: var(--thumb); border-radius: 8px;
  background: radial-gradient(circle at 50% 65%, color-mix(in srgb, var(--rarity) 30%, transparent), transparent 70%), var(--surface-2);
  box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--rarity) 70%, transparent);
}
.ana-thumb::before { content: ""; width: 38%; height: 22%; border-radius: 3px; background: var(--surface-3); }
.ana-thumb img { position: absolute; inset: 6%; width: 88%; height: 88%; object-fit: contain; opacity: 0; transition: opacity .25s; }
.ana-thumb img.on { opacity: 1; }
.ana-thumb:has(img.on)::before { display: none; }
.ana-item { display: flex; align-items: center; gap: 12px; min-width: 0; }
.ana-item-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
/* top tables: same row height in both cards; rows past the top 5 sit behind "Show all" */
.ana-top { display: flex; flex-direction: column; }
@media (min-width: 721px) { .ana-top td { height: 49px; padding-top: 6px; padding-bottom: 6px; } }
.ana-top:not(.all) tbody tr:nth-child(n+6) { display: none; }
.ana-more {
  margin-top: auto; width: 100%; min-height: 40px; padding: 0 20px; border: 0; border-top: 1px solid var(--border);
  background: transparent; color: var(--muted); font: inherit; font-size: 12.5px; cursor: pointer; transition: color .15s, background .15s;
}
.ana-more:hover { color: var(--text); background: var(--surface-2); }
.ana-more:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding: 56px 20px; }
.empty-state .ico { width: 30px; height: 30px; color: var(--faint); margin-bottom: 6px; }
.empty-state p { margin: 0; }
.chart-skel { height: 420px; }

@media (max-width: 720px) {
  .ana-vs { display: none; }
  .ana-cols { height: 120px; gap: 1px; }
  .ana-chart-ctl { width: 100%; }
  .ana-seg { width: 100%; }
  .ana-seg button { padding: 6px 4px; min-height: 36px; }
  .chart-skel { height: 340px; }
  .ana-more { min-height: 44px; }
  .ana-chart-ctl .legend { order: 2; }
  /* top tables: name left, spent right on one line; the rest on tap */
  .ana-top .table-wrap td.item { flex: 1 1 0; min-width: 0; padding-right: 0; }
  .ana-top .table-wrap td.pri.num { padding-right: 26px; }
  .ana-top .table-wrap tr[aria-expanded] { align-items: center; }
  .ana-top .table-wrap tr[aria-expanded]::after { top: 50%; margin-top: -5px; }
  .ana-top .table-wrap tr[aria-expanded="true"]::after { top: 22px; margin-top: 0; }
  .table-wrap .ana-item-name { white-space: normal; }
  .grid.split { grid-template-columns: minmax(0, 1fr); }
  .grid.kpis > :last-child:nth-child(odd) { grid-column: 1 / -1; }
  .kpis .stat .value { font-size: 20px; }
  .twin summary { min-height: 44px; }
  .twin .table-wrap { margin: 0 -16px -15px; max-height: 60dvh; }
}
@media (max-width: 380px) {
  .grid.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
