/* Platform console: accounts, one account's page, AI usage, analytics
   (js/views/admin/console.js). Built on admin.css tokens (--bg, --card-bg,
   --border, --text, --text-muted, --accent, --danger ...) so both themes work. */

/* series colours: dataviz reference palette, fixed order; dark is the default */
:root, [data-theme="dark"] { --cs-s1: #3987e5; --cs-s2: #d95926; --cs-s3: #199e70; --cs-s4: #c98500; --cs-s5: #d55181; --cs-s6: #0ca30c; --cs-s7: #9085e9; --cs-s-other: #6b6b70; }
[data-theme="light"] { --cs-s1: #2a78d6; --cs-s2: #eb6834; --cs-s3: #1baf7a; --cs-s4: #eda100; --cs-s5: #e87ba4; --cs-s6: #008300; --cs-s7: #6250d6; --cs-s-other: #a3a3a8; }

/* hidden must win over display rules below */
#app [hidden], .cs-range__pop[hidden], .cs-tip[hidden] { display: none !important; }

.cs-muted { color: var(--text-muted); font-size: 12px; }
.cs-sub { display: block; font-size: 11px; color: var(--text-muted); margin-top: 2px; font-weight: 400; }
.cs-num { white-space: nowrap; font-variant-numeric: tabular-nums; }
.cs-over { color: var(--danger) !important; font-weight: 600; }
.cs-empty { padding: 28px 16px !important; text-align: center; color: var(--text-muted); }
.cs-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.cs-head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cs-danger-text { color: var(--danger) !important; }

/* inputs */
.cs-input { height: 34px; padding: 0 10px; background: var(--card-bg); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit; font-size: 13px; }
textarea.cs-input { height: auto; padding: 8px 10px; resize: vertical; }
.cs-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cs-input--search { flex: 1 1 220px; min-width: 180px; max-width: 320px; }
.cs-input--sm { height: 28px; font-size: 12px; padding: 0 6px; }
[data-theme="dark"] .cs-input[type="date"] { color-scheme: dark; }

/* KPI cards (some are buttons that apply a filter) */
.cs-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.cs-kpi { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 14px 16px; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-md); color: var(--text); text-align: left; font: inherit; }
.cs-kpi--btn { cursor: pointer; transition: border-color .15s ease; }
.cs-kpi--btn:hover { border-color: var(--accent); }
.cs-kpi--btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cs-kpi.is-on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cs-kpi__label { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); }
.cs-kpi__value { font-size: 22px; font-weight: 700; line-height: 1.2; }
.cs-kpi__hint { font-size: 12px; color: var(--text-muted); }
.cs-kpi__hint.is-up { color: var(--warning); }
.cs-kpi__hint.is-down { color: var(--secondary); }

/* toolbar, notes */
.cs-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.cs-toolbar--in { padding: 14px 16px 6px; margin: 0; }
.cs-count { margin-left: auto; font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.cs-note { margin: 0 0 12px; padding: 9px 12px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--text); font-size: 13px; }
.cs-note.is-bad { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.modal .cs-note { margin-top: 12px; }

/* tables */
.cs-table-wrap { overflow-x: auto; }
.cs-table-wrap--menus { overflow: visible; }
.cs-table-wrap td, .cs-table-wrap th { padding: 11px 12px; }
.cs-sort { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer; white-space: nowrap; }
.cs-sort-icon { font-size: 9px; opacity: .5; }
th[aria-sort] .cs-sort { color: var(--text); }
th[aria-sort] .cs-sort-icon, .cs-sort:hover .cs-sort-icon { opacity: 1; }
.cs-sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
tr.cs-link { cursor: pointer; }
tr.cs-link:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.cs-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 8px; vertical-align: -1px; }
.cs-share { display: inline-block; width: 80px; height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; vertical-align: middle; margin-right: 6px; }
.cs-share > span { display: block; height: 100%; background: var(--accent); }

/* status switch */
.cs-status { white-space: nowrap; }
.cs-switch { position: relative; display: inline-block; width: 38px; height: 21px; vertical-align: middle; margin-right: 8px; cursor: pointer; }
.cs-switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.cs-switch span { position: absolute; inset: 0; border-radius: 99px; background: color-mix(in srgb, var(--danger) 25%, transparent); transition: background .15s ease; pointer-events: none; }
.cs-switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 15px; height: 15px; border-radius: 50%; background: var(--danger); transition: transform .15s ease, background .15s ease; }
.cs-switch input:checked + span { background: var(--secondary); }
.cs-switch input:checked + span::after { transform: translateX(17px); background: #fff; }
.cs-switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.cs-status__text { font-size: 12px; color: var(--text-muted); vertical-align: middle; }
.cs-status__text.is-bad { color: var(--danger); font-weight: 600; }

/* date range picker */
.cs-range { position: relative; }
.cs-range__btn { display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px; background: var(--card-bg); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; }
.cs-range__btn:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cs-range__btn small { color: var(--text-muted); font-size: 11px; }
.cs-range__pop { position: absolute; top: calc(100% + 6px); right: 0; z-index: 60; width: 280px; padding: 6px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--glass-shadow); }
.cs-toolbar .cs-range__pop { left: 0; right: auto; }
.cs-range__preset { display: flex; justify-content: space-between; width: 100%; padding: 7px 10px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--text); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.cs-range__preset:hover, .cs-range__preset:focus-visible { background: var(--accent-soft); outline: none; }
.cs-range__preset[aria-checked="true"] { font-weight: 600; }
.cs-range__preset[aria-checked="true"]::after { content: "\2713"; color: var(--accent); }
.cs-range__custom { margin-top: 6px; padding: 10px 6px 4px; border-top: 1px solid var(--border); display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cs-range__custom p { grid-column: 1 / -1; margin: 0; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); }
.cs-range__custom label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); }
.cs-range__custom input { height: 32px; padding: 0 8px; background: var(--card-bg); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); font: inherit; font-size: 12px; }
[data-theme="dark"] .cs-range__custom input { color-scheme: dark; }
.cs-range__custom .cs-range__err { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--danger); text-transform: none; letter-spacing: 0; font-weight: 400; }
.cs-range__custom .btn { grid-column: 1 / -1; }

/* cards and layout */
.cs-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-lg); margin-bottom: 16px; overflow: hidden; }
.cs-grid2 .cs-card { margin-bottom: 0; }
.cs-card__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px 12px; border-bottom: 1px solid var(--border); }
.cs-card__head--col { flex-direction: column; align-items: flex-start; gap: 4px; }
.cs-card__head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.cs-card__body { padding: 16px 20px 18px; display: flex; flex-direction: column; gap: 12px; }
.cs-grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
@media (max-width: 1000px) { .cs-grid2 { grid-template-columns: 1fr; } }
.cs-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.cs-big { margin: 0; font-size: 15px; font-weight: 600; }
.cs-viewhead { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.cs-link-text { font-size: 12px; color: var(--accent); text-decoration: none; }
.cs-link-text:hover { text-decoration: underline; }
.cs-dl { margin: 0; padding: 6px 20px 14px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.cs-dl > div { padding: 10px 0; border-bottom: 1px solid var(--border); min-width: 0; }
.cs-dl dt { font-size: 11px; color: var(--text-muted); margin-bottom: 3px; }
.cs-dl dd { margin: 0; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* account page header + tabs */
.cs-back { display: inline-block; margin-bottom: 12px; font-size: 13px; color: var(--text-muted); text-decoration: none; }
.cs-back:hover { color: var(--text); }
.cs-acc-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.cs-acc-id { display: flex; align-items: center; gap: 14px; min-width: 0; }
.cs-acc-id h2 { margin: 0 0 3px; font-size: 22px; font-weight: 700; }
.cs-acc-id p { margin: 0; font-size: 13px; color: var(--text-muted); }
.cs-avatar { width: 44px; height: 44px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-md); background: var(--accent-soft); color: var(--accent); font-size: 18px; font-weight: 700; }
.cs-suspended { margin-bottom: 12px; padding: 10px 12px; border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); background: color-mix(in srgb, var(--danger) 12%, transparent); border-radius: var(--radius-sm); font-size: 13px; }
.cs-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.cs-tab { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; margin-bottom: -1px; border: 0; border-bottom: 2px solid transparent; background: none; color: var(--text-muted); font: inherit; font-size: 13px; font-weight: 500; white-space: nowrap; cursor: pointer; }
.cs-tab:hover { color: var(--text); }
.cs-tab.is-on { color: var(--text); border-bottom-color: var(--accent); }
.cs-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 4px; }
.cs-pill { min-width: 20px; padding: 0 6px; border-radius: 99px; background: var(--accent-soft); font-size: 11px; line-height: 18px; text-align: center; }
.cs-pane[hidden] { display: none !important; }

/* manage menu */
.cs-menu { position: relative; display: inline-block; }
.cs-menu > summary { list-style: none; }
.cs-menu > summary::-webkit-details-marker { display: none; }
.cs-manage { display: inline-flex; align-items: center; height: 28px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.cs-manage:hover, .cs-menu[open] > .cs-manage { background: var(--accent-soft); }
.cs-manage:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cs-menu__list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; min-width: 200px; padding: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--glass-shadow); display: flex; flex-direction: column; }
.cs-menu__list button { padding: 7px 10px; border: 0; border-radius: 4px; background: none; color: var(--text); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.cs-menu__list button:hover, .cs-menu__list button:focus-visible { background: var(--accent-soft); outline: none; }
.cs-menu__list button.is-danger { color: var(--danger); }

/* meters, bars, history */
.cs-meters { gap: 22px; }
.cs-meter__top { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; font-size: 13px; }
.cs-meter__label { font-weight: 600; }
.cs-meter__val { font-variant-numeric: tabular-nums; }
.cs-meter__track { display: block; height: 10px; background: var(--border); border-radius: 99px; overflow: hidden; }
.cs-meter__fill { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.cs-meter__fill.is-full { background: var(--danger); }
.cs-meter__note { margin: 8px 0 0; font-size: 12px; color: var(--text-muted); }
.cs-bars { display: flex; flex-direction: column; gap: 7px; }
.cs-bar { display: grid; grid-template-columns: 110px minmax(0, 1fr) 90px; align-items: center; gap: 10px; font-size: 12px; color: var(--text-muted); }
.cs-bar__track { display: block; height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; }
.cs-bar__fill { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.cs-bar__val { text-align: right; color: var(--text); font-variant-numeric: tabular-nums; }
.cs-hist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.cs-hist li { font-size: 13px; }
.cs-hist small { display: block; font-size: 11px; color: var(--text-muted); }
.cs-hist__what { font-weight: 600; }
.cs-hist__detail { display: block; color: var(--text-muted); overflow-wrap: anywhere; }
.cs-hist--full li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.cs-hist--full li:last-child { border-bottom: 0; }

/* charts */
.cs-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0; padding: 14px 20px 0; list-style: none; }
.cs-legend li { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.cs-legend i { width: 10px; height: 10px; border-radius: 2px; }
.cs-chart { padding: 16px 20px 18px; overflow-x: auto; }
.cs-cols { display: flex; align-items: flex-end; gap: 3px; height: 180px; min-width: 100%; }
.cs-col { flex: 1 1 0; min-width: 8px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.cs-col:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 3px; }
.cs-stack { width: 100%; min-height: 2px; display: flex; flex-direction: column-reverse; border-radius: 4px 4px 0 0; overflow: hidden; }
.cs-stack.is-zero { background: var(--border); }
.cs-seg { width: 100%; flex-shrink: 0; }
.cs-seg + .cs-seg { border-bottom: 2px solid var(--bg); box-sizing: content-box; }
.cs-col:hover .cs-stack, .cs-col:focus-visible .cs-stack { filter: brightness(1.15); }
.cs-col__x { height: 12px; font-size: 10px; color: var(--text-muted); white-space: nowrap; }
.cs-col__v { font-size: 10px; color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.cs-tip { position: fixed; z-index: 2000; min-width: 200px; max-width: 320px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--glass-shadow); pointer-events: none; font-size: 12px; color: var(--text-muted); }
.cs-tip__head { margin: 0 0 6px; }
.cs-tip__total { margin: 0; font-size: 17px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.cs-tip__sub { margin: 2px 0 8px; }
.cs-tip__row { display: grid; grid-template-columns: 12px auto 1fr; align-items: center; gap: 8px; padding: 2px 0; }
.cs-tip__key { width: 12px; height: 3px; border-radius: 2px; }
.cs-tip__val { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.cs-tip__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* dialogs */
.cs-modal-wide { max-width: 680px; width: 100%; }
.cs-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; margin-top: 14px; }
.cs-form--one { grid-template-columns: 1fr; }
.cs-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 600; color: var(--text); }
.cs-form__wide { grid-column: 1 / -1; }
.cs-check { flex-direction: row !important; align-items: center; gap: 8px !important; font-weight: 400 !important; }
@media (max-width: 600px) { .cs-form { grid-template-columns: 1fr; } .cs-dl { grid-template-columns: 1fr; } }
.cs-danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
/* an open menu sits above the rows after it */
.cs-menu[open] { z-index: 50; }
tr:has(.cs-menu[open]) { position: relative; z-index: 5; }
/* main is a flex item: without this a wide table stretches the whole page
   sideways instead of scrolling inside its own box */
#app main { min-width: 0; }
