/* Usage and billing (#186): the organisation Usage page, spend on the
   project Usage tab, and the admin Billing and Pricing pages. Shared by both
   dashboards; built on the role tokens in style.css.

   Charts stack six resources, so they need six series colours: a data-viz
   exception to the single accent (validated for colour-vision deficiency on
   both surfaces with the dataviz checker; light slots under 3:1 always come
   with visible labels and a table). Text never wears a series colour. */

:root {
  --ku-cpu: #3987e5;
  --ku-memory: #d95926;
  --ku-volume: #199e70;
  --ku-bucket: #c98500;
  --ku-egress: #d55181;
  --ku-build: #9085e9;
  /* The gateway's lines (#194): one neutral slate in three steps, apart
     from the six hues by lightness alone. */
  --ku-browser: #8b98a9;
  --ku-browser-action: #b7c1cd;
  --ku-proxy: #5f6c7d;
  /* Sandboxes (#195): a muted teal in two steps, apart from the slate. */
  --ku-sandbox-cpu: #4e9a96;
  --ku-sandbox-memory: #8cc3bf;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --ku-cpu: #2a78d6;
    --ku-memory: #eb6834;
    --ku-volume: #1baf7a;
    --ku-bucket: #eda100;
    --ku-egress: #e87ba4;
    --ku-build: #6250d6;
    --ku-browser: #6b7a8c;
    --ku-browser-action: #9aa7b6;
    --ku-proxy: #44505f;
    --ku-sandbox-cpu: #2f7f7a;
    --ku-sandbox-memory: #69aaa5;
  }
}
:root[data-theme="light"] {
  --ku-cpu: #2a78d6;
  --ku-memory: #eb6834;
  --ku-volume: #1baf7a;
  --ku-bucket: #eda100;
  --ku-egress: #e87ba4;
  --ku-build: #6250d6;
  --ku-browser: #6b7a8c;
  --ku-browser-action: #9aa7b6;
  --ku-proxy: #44505f;
  --ku-sandbox-cpu: #2f7f7a;
  --ku-sandbox-memory: #69aaa5;
}

.ku-c-cpu { --c: var(--ku-cpu); }
.ku-c-memory { --c: var(--ku-memory); }
.ku-c-volume { --c: var(--ku-volume); }
.ku-c-bucket { --c: var(--ku-bucket); }
.ku-c-egress { --c: var(--ku-egress); }
.ku-c-build { --c: var(--ku-build); }
.ku-c-browser { --c: var(--ku-browser); }
.ku-c-browser_action { --c: var(--ku-browser-action); }
.ku-c-proxy { --c: var(--ku-proxy); }
.ku-c-sandbox_cpu { --c: var(--ku-sandbox-cpu); }
.ku-c-sandbox_memory { --c: var(--ku-sandbox-memory); }
.ku-c-total { --c: var(--vivid); }

/* Toolbar: period picker, custom dates, export. */
.ku-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ku-toolbar .seg, .ku-root .head .seg { margin-bottom: 0; }
.ku-root .head .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ku-custom { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ku-custom input[type="date"] { width: auto; min-width: 0; padding: 5px 8px; font: 13px var(--mono); background: var(--field); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-sm); color-scheme: inherit; }
.ku-custom input[type="date"]:focus { outline: none; border-color: var(--vivid); box-shadow: 0 0 0 3px var(--vivid-soft); }
.ku-custom[hidden] { display: none; }
.ku-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; font: 12px var(--mono); color: var(--text-2); margin: -12px 0 16px; }

/* Headline. */
.stats.ku-hero { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.ku-hero .stat .value { font-size: 32px; }
.ku-hero .stat .value.ku-big { font-size: 40px; }
.ku-hero .stat .sub .up { color: var(--text); }

/* Legend and keys. */
.ku-legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0 0 12px; font-size: 12px; color: var(--text-2); }
.ku-key { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.ku-key::before { content: ''; width: 10px; height: 10px; border-radius: 3px; background: var(--c, var(--text-2)); flex: none; }

/* Charts: hand-written SVG, like the project Usage tab. */
.ku-chart { position: relative; }
.ku-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.ku-chart svg text { fill: var(--text-2); font: 11px var(--mono); }
.ku-grid { stroke: var(--line); stroke-width: 1; }
.ku-axis { stroke: var(--line-hover); stroke-width: 1; }
.ku-seg { fill: var(--c); stroke: var(--surface); stroke-width: 1; pointer-events: none; }
.ku-bar-hit { fill: transparent; cursor: default; }
.ku-bar-hit:hover { fill: var(--hover); }
.ku-future { fill: var(--line); opacity: .35; }
.ku-tip {
  position: fixed; z-index: 60; pointer-events: none; max-width: 280px;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-pop); padding: 10px 12px; font: 12px/1.6 var(--mono);
}
.ku-tip[hidden] { display: none; }
.ku-tip .t { color: var(--text-2); margin-bottom: 4px; }
.ku-tip .r { display: flex; justify-content: space-between; gap: 16px; }
.ku-tip .r .ku-key { color: var(--text-2); }
.ku-tip .r.total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }

/* Share of the total, as a thin bar in the resource colour. */
.ku-share { display: flex; align-items: center; gap: 10px; min-width: 120px; }
.ku-share .track { flex: 1; height: 6px; border-radius: var(--r-pill); background: var(--line); overflow: hidden; }
.ku-share .track > i { display: block; height: 100%; background: var(--c, var(--vivid)); border-radius: var(--r-pill); }
.ku-share .pct { font: 12px var(--mono); color: var(--text-2); width: 3.5em; text-align: right; }

/* A whole-spend bar split by resource. */
.ku-split { display: flex; height: 8px; border-radius: var(--r-pill); overflow: hidden; background: var(--line); gap: 2px; margin: 4px 0 16px; }
.ku-split > i { display: block; background: var(--c); min-width: 2px; }

/* Project → subject table. */
.ku-table td, .ku-table th { white-space: nowrap; }
.ku-table td.name { white-space: normal; min-width: 220px; }
.ku-table tr.ku-proj { cursor: pointer; }
.ku-table tr.ku-proj td.name { white-space: nowrap; }
.ku-table tr.ku-proj:hover td { background: var(--hover); }
.ku-table .ku-toggle { display: inline-flex; align-items: center; gap: 8px; background: none; border: 0; padding: 0; color: var(--text); font: inherit; cursor: pointer; text-align: left; }
.ku-table .ku-toggle .i { transition: transform .15s; color: var(--text-2); flex: none; }
.ku-table tr.open .ku-toggle .i.caret { transform: rotate(90deg); }
.ku-table tr.ku-sub td { background: var(--well); font-size: 13px; }
.ku-table tr.ku-sub td.name { padding-left: 44px; }
.ku-table tr.ku-sub[hidden] { display: none; }
.ku-table .kind { display: inline-flex; align-items: center; gap: 6px; }
.ku-table .kind .i { color: var(--text-2); }
.ku-table tfoot td { border-top: 1px solid var(--line-hover); font-weight: 500; }
.ku-table .ku-gone { color: var(--text-2); font-style: italic; }
.ku-env { margin-left: 8px; }

.ku-note { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--text-2); margin: 0 0 16px; }
.ku-note .i { margin-top: 3px; flex: none; }

/* Sparklines in the admin org table. */
.ku-spark { display: block; width: 96px; height: 24px; }
.ku-spark path { fill: none; stroke: var(--vivid-ink); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.ku-spark .area { fill: var(--vivid-soft); stroke: none; }
.ku-delta { font: 12px var(--mono); color: var(--text-2); }
.ku-delta.up::before { content: '▲ '; font-size: 9px; }
.ku-delta.down::before { content: '▼ '; font-size: 9px; }
.ku-sort { background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.ku-sort[aria-sort="descending"]::after { content: '↓'; }
.ku-sort[aria-sort="ascending"]::after { content: '↑'; }

.ku-grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.ku-grid2 { margin-top: 16px; }
.app .content .ku-grid2 > .section, .ku-grid2 > .section { margin-top: 0; }
@media (max-width: 900px) { .ku-grid2 { grid-template-columns: minmax(0, 1fr); } }

/* Pricing editor. */
.ku-prices td input { width: 120px; text-align: right; font-family: var(--mono); }
.ku-prices td .sub { max-width: 52ch; white-space: normal; font: 13px/1.5 var(--sans); margin-top: 4px; }
.ku-prices td.num .sub { font-family: var(--mono); font-size: 12px; }
.ku-prices tr.changed td { background: var(--vivid-soft); }
.ku-price-form { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; margin-top: 20px; }
.ku-price-form .field { flex: 1 1 220px; }
.ku-price-form .ku-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.ku-price-form input[type="datetime-local"] {
  width: 100%; background: var(--field); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 8px 10px; font: 13px var(--mono); color-scheme: inherit;
}
.ku-price-form input[type="datetime-local"]:focus { outline: none; border-color: var(--vivid); box-shadow: 0 0 0 3px var(--vivid-soft); }

@media (max-width: 640px) {
  .stats.ku-hero { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .ku-hero .stat { padding: 16px; }
  .ku-chart svg text { font-size: 20px; }
  .ku-hero .stat .value { font-size: 26px; }
  .ku-hero .stat .value.ku-big { font-size: 30px; }
  .ku-toolbar { width: 100%; }
  .ku-toolbar .seg { flex: 1 1 auto; }
  .ku-table td.name { min-width: 140px; }

  /* The price book as cards: the explanation needs the width. */
  .ku-prices thead { display: none; }
  .ku-prices, .ku-prices tbody { display: block; width: 100%; }
  .ku-prices tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
  .ku-prices td { display: block; padding: 0; border: 0; text-align: left; }
  .ku-prices td.name { grid-column: 1 / -1; min-width: 0; }
  .ku-prices tr.changed { background: var(--vivid-soft); }
  .ku-prices tr.changed td { background: none; }
  .ku-prices td.num { text-align: left; }
  .ku-prices td.num:nth-child(3) { display: none; }
  .ku-prices td input { width: 100%; text-align: left; }
  .ku-prices td:last-child { grid-column: 1 / -1; }
}

/* Budgets and the Browsers tab (#194). */
.kb-bar.warn { --c: var(--ku-bucket); }
.kb-bar.over { --c: var(--ku-memory); }
.kb-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 16px; align-items: end; padding: 16px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface, transparent); }
.kb-form .form-error, .kb-form .kb-form-foot { grid-column: 1 / -1; }
.kb-form-foot { display: flex; justify-content: flex-end; gap: 8px; }
.kb-edit td { padding: 0; }
.kb-edit .kb-form { margin: 8px 0; }
.kb-more { display: flex; justify-content: center; margin-top: 12px; }
.kb-table .actions { white-space: nowrap; text-align: right; }
.kb-banner .iconbtn { flex: none; }

/* A session's recording, replayed in the right drawer (R-187). The player's
   own stylesheet is rrweb-player's; its colours are brought to the theme. */
.kb-replay-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.kb-replay-stage { width: 100%; overflow: hidden; }
.kb-replay-stage .rr-player { float: none !important; background: var(--well) !important; box-shadow: none !important; border: 1px solid var(--line); border-radius: var(--r) !important; overflow: hidden; }
.kb-replay-stage .rr-controller { background: var(--surface) !important; border-radius: 0 !important; border-top: 1px solid var(--line); }
.kb-replay-stage .rr-timeline__time { color: var(--text-2) !important; font-family: var(--mono); font-size: 12px; }
.kb-replay-stage .rr-progress { background: var(--line) !important; border-color: var(--surface) !important; }
.kb-replay-stage .rr-progress__step { background: var(--vivid-soft) !important; }
.kb-replay-stage .rr-progress__handler { background: var(--vivid) !important; }
.kb-replay-stage .rr-controller__btns { color: var(--text); }
.kb-replay-stage .rr-controller__btns button { color: var(--text) !important; }
.kb-replay-stage .rr-controller__btns button svg { fill: currentColor; }
.kb-replay-stage .rr-controller__btns button.active { background: var(--vivid) !important; color: var(--on-vivid) !important; }
.kb-replay-stage .switch input[type='checkbox'] + label::before { background: var(--line-hover) !important; }
.kb-replay-stage .switch input[type='checkbox']:checked + label::before { background: var(--vivid) !important; }
.kb-replay-stage .replayer-mouse::after { background: var(--vivid) !important; }

/* The model gateway's pages (#214): models.js. */
.km-logging { display: flex; align-items: end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 12px; }
.km-projects { gap: 8px; }
.kb-form .km-projects, .kb-form .km-wide { grid-column: 1 / -1; }
.km-project-list { display: flex; flex-wrap: wrap; gap: 8px 16px; padding-left: 25px; }
.km-call .kvl { margin-bottom: 16px; }
.km-bodies .json { max-height: 420px; }

/* The Billing page (#281): credit, payments and the history. */
.kc-stats .value { font-family: var(--mono); }
.kc-stats .kc-date { font-family: var(--sans); font-size: 20px; }
.kc-plus { color: var(--accent-ink); }
.kc-presets { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; padding: 0; border: 0; }
.kc-preset { position: relative; }
.kc-preset input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.kc-preset span { display: inline-flex; align-items: center; min-height: 36px; padding: 0 16px; border: 1px solid var(--line); border-radius: var(--r-sm); font-family: var(--mono); font-size: 13px; color: var(--text-2); }
.kc-preset input:checked + span { border-color: var(--vivid); background: var(--vivid-soft); color: var(--text); }
.kc-preset input:focus-visible + span { outline: 2px solid var(--vivid-ring); outline-offset: 2px; }
.callout.ok .i { color: var(--accent-ink); }
.callout .btn { margin-left: auto; flex: none; }
.callout.kc-note .i { color: var(--text-2); }
[data-kc-body] > .callout { margin-bottom: 16px; }
