/* Spend analytics: tabs, filters and the richer chart forms (flow, treemap, burn-up, calendar, matrices, bullets). */
:root {
    --spend-seq-0: #f1f3f6;
    --spend-seq-1: #d6e6f8;
    --spend-seq-2: #9fc4ee;
    --spend-seq-3: #2d6cc0;
    --spend-seq-4: #17488c;
}

.spend-page { display: grid; gap: 18px; }
.spend-tab { display: grid; gap: 16px; min-width: 0; }
.spend-panel { display: grid; gap: 16px; min-width: 0; }
.spend-panel[hidden] { display: none; }
.spend-grid-main { grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr); align-items: stretch; }
.spend-page .kpi-strip article { min-height: 0; padding: 14px 18px; }
.spend-basis { margin: 0; max-width: 1080px; color: var(--ops-muted); font-size: 13px; line-height: 1.5; }
.spend-basis .runtime-status { margin-right: 8px; }
.spend-basis a { color: var(--ops-accent-text); font-weight: 600; }

/* Tabs and filters */
.spend-tabbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding-inline-end: 6px; border: 1px solid var(--ops-border); border-radius: 12px; background: var(--ops-card); }
.spend-page .spend-tabbar > .admin-task-tabs { flex: 1 1 auto; width: auto; margin: 0; border: 0; }
.spend-tabs-tools { display: inline-flex; align-items: center; gap: 12px; margin-left: auto; padding-right: 4px; }

.spend-filters { position: sticky; top: 0; z-index: 4; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; padding: 10px 12px; border: 1px solid var(--ops-border); border-radius: 14px; background: var(--ops-card); box-shadow: 0 1px 0 rgba(0, 0, 0, .02); }
.spend-select { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.spend-select > span { color: var(--ops-muted); font-weight: 600; }
.spend-select select { max-width: 220px; min-height: 32px; padding: 0 28px 0 12px; border: 1px solid var(--ops-control-border); border-radius: 999px; color: var(--ops-text); background-color: var(--ops-card); font: inherit; font-size: 13px; cursor: pointer; }
.spend-select select:focus-visible { outline: 2px solid var(--ops-accent-strong); outline-offset: 1px; }
.spend-select.is-set select { border-color: #8fb6e8; background-color: #eef4fc; }
.spend-freshness { color: var(--ops-muted); font-size: 12px; }

.spend-coverage { margin: 0; padding: 10px 14px; border: 1px solid #f0d9a6; border-radius: 12px; color: #5c4300; background: #fff8e8; font-size: 12px; line-height: 1.5; }

/* Biggest changes */
.spend-changes { display: grid; margin: 0; padding: 0; list-style: none; }
.spend-changes li + li { border-top: 1px solid var(--ops-border); }
.spend-change { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; width: 100%; padding: 10px 18px; border: 0; color: inherit; background: transparent; font: inherit; text-align: left; cursor: pointer; }
.spend-change:hover { background: var(--viz-hover); }
.spend-change:focus-visible { outline: 2px solid var(--ops-accent-strong); outline-offset: -2px; }
.spend-change-main { display: grid; gap: 1px; min-width: 0; }
.spend-change-main strong { overflow: hidden; color: var(--ops-text); font-size: 13px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.spend-change-main small { color: var(--ops-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.spend-change-delta { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.spend-dimension-tag { justify-self: start; color: var(--ops-muted); font-size: 10.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }

/* Flow */
.spend-flow { position: relative; margin: 0; padding: 22px 0 0; }
.spend-flow svg { display: block; width: 100%; height: 320px; overflow: visible; }
.spend-flow-columns { position: absolute; inset: 0 0 auto 0; display: flex; justify-content: space-between; color: var(--ops-muted); font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
.spend-flow-link { fill: var(--viz-color); opacity: .26; transition: opacity .12s ease; }
.spend-flow-link.viz-total { opacity: .14; }
.spend-flow-link:hover { opacity: .55; }
.spend-flow-node { fill: var(--viz-color); }
.spend-flow-labels { position: absolute; inset: 22px 0 0 0; pointer-events: none; }
.spend-flow-labels span { position: absolute; display: inline-flex; align-items: baseline; gap: 6px; max-width: 30%; padding: 1px 6px; border-radius: 6px; background: rgba(255, 255, 255, .86); font-size: 12px; line-height: 16px; white-space: nowrap; transform: translate(10px, -50%); }
.spend-flow-labels span.is-last { transform: translate(calc(-100% - 10px), -50%); }
.spend-flow-labels b { overflow: hidden; color: var(--ops-text); font-weight: 600; text-overflow: ellipsis; }
.spend-flow-labels small { color: var(--ops-muted); font-variant-numeric: tabular-nums; }

/* Breakdown pivot */
.spend-pivot-controls { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--ops-muted); font-size: 12px; }
.spend-pivot-scroll { max-height: 560px; overflow: auto; border-top: 1px solid var(--ops-border); }
.spend-pivot-scroll:focus-visible { outline: 2px solid var(--ops-accent-strong); outline-offset: -2px; }
.spend-pivot-table .is-number, .spend-limits-table .is-number { text-align: right; font-variant-numeric: tabular-nums; }
.spend-pivot-table tbody th { display: flex; align-items: flex-start; gap: 6px; min-width: 240px; max-width: 380px; white-space: normal; }
.spend-pivot-name a { color: inherit; text-decoration: none; }
.spend-pivot-name a:hover b { color: var(--ops-accent-text); text-decoration: underline; }
.spend-pivot-name a:focus-visible { border-radius: 3px; outline: 2px solid var(--ops-accent-strong); outline-offset: 2px; }
.spend-pivot-row.level-1 th { padding-left: 34px; }
.spend-pivot-row.level-2 th { padding-left: 58px; }
.spend-pivot-row.level-1, .spend-pivot-row.level-2 { background: var(--ops-surface-raised); }
.spend-pivot-row.level-2 .spend-pivot-name b { font-weight: 500; }
.spend-expand { flex: none; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 5px; color: var(--ops-muted); background: transparent; font: inherit; cursor: pointer; }
.spend-expand:hover { background: var(--viz-hover); }
.spend-expand:focus-visible { outline: 2px solid var(--ops-accent-strong); }
.spend-pivot-name { display: grid; gap: 1px; min-width: 0; }
.spend-pivot-name b { color: var(--ops-text); font-weight: 600; }
.spend-pivot-name small { color: var(--ops-muted); font-size: 11.5px; font-weight: 400; }

.spend-spark { display: block; overflow: visible; }
.spend-spark-line { fill: none; stroke: var(--viz-color); stroke-width: 1.5; stroke-linejoin: round; }
.spend-spark-area { fill: var(--viz-color); opacity: .12; }
.spend-spark-empty { color: var(--ops-muted); }

/* Matrices and calendar share one sequential blue scale */
.spend-matrix-scroll { overflow: auto; border-top: 1px solid var(--ops-border); }
.spend-matrix { width: 100%; border-collapse: separate; border-spacing: 3px; font-size: 12px; font-variant-numeric: tabular-nums; }
.spend-matrix thead th { padding: 8px 6px 4px; overflow: hidden; max-width: 120px; color: var(--ops-muted); font-size: 11px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.spend-matrix tbody th { padding: 0 10px 0 14px; overflow: hidden; max-width: 200px; color: var(--ops-text); font-weight: 600; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.spend-matrix td { padding: 0; text-align: center; }
.spend-matrix .is-total { padding: 0 14px 0 8px; color: var(--ops-text); font-weight: 600; text-align: right; white-space: nowrap; }
.spend-cell { display: block; width: 100%; min-width: 56px; min-height: 30px; border: 0; border-radius: 6px; color: var(--ops-text); font: inherit; font-weight: 600; cursor: pointer; }
.spend-cell.is-empty { display: grid; place-items: center; color: #b7b7bd; background: var(--spend-seq-0); cursor: default; }
.spend-cell:focus-visible { outline: 2px solid var(--ops-accent-strong); outline-offset: 1px; }
.spend-cell.level-1 { background: var(--spend-seq-1); }
.spend-cell.level-2 { background: var(--spend-seq-2); }
.spend-cell.level-3 { color: #fff; background: var(--spend-seq-3); }
.spend-cell.level-4 { color: #fff; background: var(--spend-seq-4); }
.spend-cell:hover { filter: brightness(.95); }

.spend-month-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-rows: minmax(46px, auto); gap: 4px; }
.spend-month-grid > .spend-month-weekday { grid-row: 1; align-self: end; color: var(--ops-muted); font-size: 11px; font-weight: 600; text-align: center; }
.spend-month-day { display: grid; align-content: space-between; gap: 2px; padding: 5px 7px; border-radius: 7px; color: var(--ops-text); background: var(--spend-seq-0); font-variant-numeric: tabular-nums; outline: none; }
.spend-month-day small { color: var(--ops-muted); font-size: 11px; }
.spend-month-day b { font-size: 12px; font-weight: 600; }
.spend-month-day:focus-visible { box-shadow: 0 0 0 2px var(--ops-accent-strong); }
.spend-month-day.level-1, .spend-month-swatch.level-1 { background: var(--spend-seq-1); }
.spend-month-day.level-2, .spend-month-swatch.level-2 { background: var(--spend-seq-2); }
.spend-month-day.level-3, .spend-month-swatch.level-3 { color: #fff; background: var(--spend-seq-3); }
.spend-month-day.level-4, .spend-month-swatch.level-4 { color: #fff; background: var(--spend-seq-4); }
.spend-month-day.level-1 small, .spend-month-day.level-2 small { color: #24456e; }
.spend-month-day.level-3 small, .spend-month-day.level-4 small { color: #fff; }
.spend-month-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--spend-seq-0); }
.spend-calendar-legend { display: flex; align-items: center; gap: 4px; color: var(--ops-muted); font-size: 11px; }

/* Token mix */
.spend-token-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0; padding: 0 18px; list-style: none; color: var(--ops-muted); font-size: 12px; }
.spend-token-legend li { display: inline-flex; align-items: center; gap: 6px; }
.spend-token-rows { display: grid; gap: 12px; margin: 0; padding: 4px 18px 18px; list-style: none; }
.spend-token-rows li { display: grid; grid-template-columns: minmax(150px, 34%) minmax(0, 1fr); align-items: center; gap: 14px; }
.spend-token-name { display: grid; min-width: 0; }
.spend-token-name b { overflow: hidden; color: var(--ops-text); font-size: 13px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.spend-token-name small { color: var(--ops-muted); font-size: 11.5px; }
.spend-token-bar { display: flex; gap: 2px; height: 14px; overflow: hidden; border-radius: 4px; }
.spend-token-bar span { min-width: 0; background: var(--viz-color); }

/* Shared legend for charts outside the stacked-column component */
.spend-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0; padding: 0; list-style: none; }
.spend-legend li { display: inline-flex; align-items: center; gap: 7px; color: var(--ops-muted); font-size: 12px; }
.spend-legend li > span:not(.viz-swatch):not(.spend-line-key) { color: var(--ops-text); }
.spend-legend strong { color: var(--ops-text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* Burn-up line chart */
.spend-line { --plot-height: 232px; --gutter: 46px; display: grid; gap: 12px; margin: 0; min-width: 0; }
.spend-line-key { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--viz-color); }
.spend-line-key.is-dashed { border-top-style: dashed; }
.spend-line-plot { position: relative; height: var(--plot-height); margin: 18px 0 0 var(--gutter); }
.spend-line-plot svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.spend-line .stack-grid { position: absolute; inset: 0; pointer-events: none; }
.spend-line .stack-tick { position: absolute; left: 0; right: 0; height: 0; border-top: 1px solid var(--viz-grid); }
.spend-line .stack-tick:first-child { border-top-color: var(--viz-baseline); }
.spend-line .stack-tick span { position: absolute; right: calc(100% + 8px); top: -8px; color: var(--ops-muted); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.spend-line-path { fill: none; stroke: var(--viz-color); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spend-line-path.is-dashed { stroke-dasharray: 5 4; }
.spend-line-axis { position: relative; height: 16px; margin-left: var(--gutter); }
.spend-line-axis span { position: absolute; top: 0; color: var(--ops-muted); font-size: 11px; white-space: nowrap; transform: translateX(-50%); }
.spend-line-axis span.is-first { transform: none; }
.spend-line-axis span.is-last { transform: translateX(-100%); }

/* Treemap */
.spend-treemap { position: relative; width: 100%; overflow: hidden; border-radius: 10px; }
.spend-tile { position: absolute; display: grid; align-content: start; gap: 2px; padding: 6px 8px; overflow: hidden; border: 1px solid #fff; border-left: 4px solid var(--viz-color); border-radius: 6px; color: var(--ops-text); background: color-mix(in srgb, var(--viz-color) 18%, #fff); font-size: 12px; outline: none; }
.spend-tile:hover, .spend-tile:focus { background: color-mix(in srgb, var(--viz-color) 30%, #fff); }
.spend-tile:focus-visible { box-shadow: inset 0 0 0 2px var(--ops-accent-strong); }
.spend-tile b { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.spend-tile span { color: #3a3a3f; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Limits */
.spend-limits-table tbody tr[data-status="Blocked"] { background: #fff5f5; }
.spend-source { display: block; color: var(--ops-muted); font-size: 11.5px; }
.spend-bullet-col { min-width: 260px; }
.spend-bullet { display: grid; gap: 4px; min-width: 240px; }
.spend-bullet-track { position: relative; display: flex; height: 10px; overflow: visible; border-radius: 5px; background: #eceef2; }
.spend-bullet-spent { height: 100%; border-radius: 5px 0 0 5px; background: var(--viz-s1); }
.spend-bullet-spent.is-near { background: var(--viz-s4); }
.spend-bullet-spent.is-blocked { background: var(--viz-critical); }
.spend-bullet-reserved { height: 100%; background: repeating-linear-gradient(135deg, #8fb6e8 0 3px, #d6e6f8 3px 6px); }
.spend-bullet-projected { position: absolute; top: -3px; width: 2px; height: 16px; border-radius: 1px; background: var(--ops-text); }
.spend-bullet-text { color: var(--ops-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.spend-status { display: inline-block; padding: 2px 9px; border-radius: 999px; color: #3d4a5c; background: #eef0f3; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.spend-status[data-status="Ok"] { color: #18713c; background: #e7f5ec; }
.spend-status[data-status="Near"], .spend-status[data-status="HourlyLimit"] { color: #7a4b00; background: #fff1d6; }
.spend-status[data-status="Blocked"] { color: #a11d1d; background: #fde7e7; }
.spend-external { display: grid; margin: 0; padding: 0; list-style: none; }
.spend-external li { display: grid; grid-template-columns: minmax(0, 1fr) minmax(120px, 35%); align-items: center; gap: 14px; padding: 12px 18px; border-top: 1px solid var(--ops-border); }
.spend-meter { display: block; height: 8px; overflow: hidden; border-radius: 4px; background: #eceef2; }
.spend-meter span { display: block; height: 100%; border-radius: 4px; background: var(--viz-s1); }
.spend-meter.is-near span { background: var(--viz-s4); }

@media (max-width: 1180px) {
    .spend-grid-main { grid-template-columns: minmax(0, 1fr); }
}

.spend-search { min-width: 220px; min-height: 30px; padding: 0 10px; border: 1px solid var(--ops-control-border); border-radius: 8px; color: var(--ops-text); background: var(--ops-card); font: inherit; font-size: 13px; }
.spend-search:focus-visible { outline: 2px solid var(--ops-accent-strong); outline-offset: 1px; }
.spend-versions summary { color: var(--ops-accent-text); font-size: 11.5px; font-weight: 600; cursor: pointer; }
.spend-versions ul { display: grid; gap: 2px; margin: 6px 0 0; padding: 0; list-style: none; }
.spend-versions li { display: grid; grid-template-columns: minmax(120px, auto) auto auto; gap: 12px; color: var(--ops-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.spend-versions li b { color: var(--ops-text); font-weight: 600; }
.spend-people-unavailable { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

.spend-unavailable { display: grid; gap: 4px; }
.spend-unavailable strong { color: var(--ops-text); font-size: 14px; }
