:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #ffffff;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --axis: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --hover: rgba(11, 11, 11, 0.04);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --c-prod: #2a78d6;
  --c-other: #1baf7a;
  --c-unprod: #eb6834;
  --c-idle: #c3c2b7;
  --good: #006300;
  --bad: #b3261e;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06);
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #222220;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #a3a197;
    --axis: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --hover: rgba(255, 255, 255, 0.05);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --c-prod: #3987e5;
    --c-other: #199e70;
    --c-unprod: #d95926;
    --c-idle: #5f5e59;
    --good: #0ca30c;
    --bad: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #222220; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #a3a197;
  --axis: #898781; --grid: #2c2c2a; --baseline: #383835; --border: rgba(255, 255, 255, 0.10); --hover: rgba(255, 255, 255, 0.05);
  --accent: #3987e5; --accent-ink: #86b6ef; --c-prod: #3987e5; --c-other: #199e70; --c-unprod: #d95926; --c-idle: #5f5e59;
  --good: #0ca30c; --bad: #e66767; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font-size: 14px; line-height: 1.45; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
a { color: var(--accent-ink); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 18px; }
.sub { margin: 0; color: var(--muted); font-size: 12px; }
.status { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; text-align: right; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: #0ca30c; flex: none; }
.status .dot.warn { background: #fab219; }
.status .dot.err { background: #d03b3b; }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.search { position: relative; flex: 1 1 320px; max-width: 480px; }
.search-icon { position: absolute; left: 11px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.search input { width: 100%; padding: 9px 12px 9px 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); outline: none; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.suggestions { position: absolute; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.12); max-height: 360px; overflow: auto; z-index: 20; }
.suggestions li { padding: 8px 10px; border-radius: 6px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; }
.suggestions li[aria-selected="true"], .suggestions li:hover { background: var(--hover); }
.suggestions .s-meta { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggestions .s-empty { color: var(--muted); cursor: default; }

.range { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.hours { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.hours-set { align-items: center; }
.hours-set select { padding: 5px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); }
.hours-set[hidden] { display: none; }
.presets { display: flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--page); border: 1px solid var(--border); border-radius: 8px; }
.presets button { border: 0; background: transparent; padding: 6px 10px; border-radius: 6px; cursor: pointer; color: var(--ink-2); white-space: nowrap; }
.presets button:hover { background: var(--hover); color: var(--ink); }
.presets button[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); font-weight: 600; box-shadow: var(--shadow), 0 0 0 1px var(--border); }
.custom { display: flex; gap: 8px; color: var(--muted); font-size: 12px; }
.custom label { display: flex; align-items: center; gap: 6px; }
.custom input { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); }

main { padding: 20px 24px 48px; max-width: 1280px; margin: 0 auto; outline: none; transition: opacity 120ms ease; }
main.is-loading { opacity: 0.55; pointer-events: none; }
.view-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.view-head h2 { font-size: 22px; }
.view-head .meta { color: var(--ink-2); margin-top: 4px; }
.view-head .meta span + span::before { content: "·"; margin: 0 8px; color: var(--muted); }
.online { color: var(--good); font-weight: 600; }
.back { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--accent-ink); cursor: pointer; padding: 0; margin-bottom: 10px; font-weight: 600; }
.actions { display: flex; gap: 8px; align-items: center; }
.btn { border: 1px solid var(--border); background: var(--surface-2); padding: 7px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.btn:hover { background: var(--hover); }
select.btn { padding-right: 8px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .label { color: var(--ink-2); font-size: 12px; }
.tile .value { font-size: 26px; font-weight: 600; margin-top: 4px; letter-spacing: -0.01em; }
.tile .note { color: var(--muted); font-size: 12px; margin-top: 2px; }
.delta-up { color: var(--good); font-weight: 600; }
.delta-down { color: var(--bad); font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px 16px; margin-bottom: 12px; }
.card-head h3 { font-size: 15px; }
.card-head .hint { color: var(--muted); font-size: 12px; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.grid-2 > .card { margin-bottom: 0; }
.stack-gap { margin-bottom: 16px; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; color: var(--ink-2); font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.sw-prod { background: var(--c-prod); }
.sw-other { background: var(--c-other); }
.sw-unprod { background: var(--c-unprod); }
.sw-idle { background: var(--c-idle); }

.chart { width: 100%; display: block; overflow: visible; }
.chart text { fill: var(--axis); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--baseline); stroke-width: 1; }
.chart .f-prod { fill: var(--c-prod); }
.chart .f-other { fill: var(--c-other); }
.chart .f-unprod { fill: var(--c-unprod); }
.chart .f-idle { fill: var(--c-idle); }
.chart .workband { fill: color-mix(in srgb, var(--accent) 7%, transparent); }
.chart text.workband-label { fill: var(--accent-ink); font-size: 11px; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover, .chart .hit.on { fill: var(--hover); }
.chart-empty { color: var(--muted); padding: 24px 0; text-align: center; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--ink-2); font-weight: 600; font-size: 12px; position: sticky; top: 0; background: var(--surface); }
th.num, td.num { text-align: right; }
th button { border: 0; background: none; padding: 0; color: inherit; font: inherit; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
th[aria-sort] button::after { content: ""; border: 4px solid transparent; }
th[aria-sort="descending"] button::after { border-top-color: currentColor; margin-top: 4px; }
th[aria-sort="ascending"] button::after { border-bottom-color: currentColor; margin-bottom: 4px; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--hover); }
tbody tr.clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
td .name { font-weight: 600; }
td .small { color: var(--muted); font-size: 12px; }
.pctbar { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.pctbar .track { display: inline-block; width: 72px; height: 6px; border-radius: 3px; background: var(--grid); overflow: hidden; }
.pctbar .fill { display: block; height: 100%; background: var(--c-prod); border-radius: 3px; }
.empty { color: var(--muted); padding: 32px; text-align: center; }

.apps { list-style: none; margin: 0; padding: 0; }
.apps li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.apps li:last-child { border-bottom: 0; }
.apps .a-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.apps .a-time { text-align: right; font-variant-numeric: tabular-nums; }
.apps .a-bar { grid-column: 1 / -1; height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; }
.apps .a-bar div { height: 100%; border-radius: 3px; }
.apps .a-meta { color: var(--muted); font-size: 12px; display: flex; gap: 10px; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 5px; }
.bar-Productive { background: var(--c-prod); }
.bar-Unproductive { background: var(--c-unprod); }
.bar-Neutral, .bar-Unclassified { background: var(--c-other); }
.linkbtn { border: 0; background: none; color: var(--accent-ink); cursor: pointer; padding: 8px 0 0; font-weight: 600; }

/* ---------- unproductive views, company apps ---------- */
.pctbar .fill-unprod { background: var(--c-unprod); }
.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--page); border: 1px solid var(--border); border-radius: 8px; }
.seg button { border: 0; background: transparent; padding: 6px 10px; border-radius: 6px; cursor: pointer; color: var(--ink-2); white-space: nowrap; }
.seg button:hover { background: var(--hover); color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); font-weight: 600; box-shadow: var(--shadow), 0 0 0 1px var(--border); }
.seg-sm button { padding: 4px 8px; font-size: 12px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 12px; cursor: pointer; }
.apps.company > li { display: block; padding: 0; }
.apps .a-row { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 9px 4px; border: 0; background: none; text-align: left; cursor: pointer; border-radius: 6px; }
.apps .a-row:hover { background: var(--hover); }
.apps .a-row .a-bar { display: block; grid-column: 1 / -1; height: 6px; background: var(--grid); border-radius: 3px; overflow: hidden; }
.apps .a-row .a-bar span { display: block; height: 100%; border-radius: 3px; }
.apps .a-row .a-meta { grid-column: 1 / -1; }
.a-more { margin-left: auto; color: var(--accent-ink); font-weight: 600; }
.who { margin: 0 0 10px; padding: 4px 4px 4px 28px; font-size: 13px; }
.who li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 12px; padding: 3px 0; border-bottom: 0; }
.who .small { color: var(--muted); font-size: 12px; }

/* ---------- AI search ---------- */
.btn-ai { background: var(--accent); border-color: transparent; color: #fff; font-weight: 600; }
.btn-ai:hover { background: var(--accent-ink); }
.ask-strip { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 16px; }
.ask-label { color: var(--accent-ink); font-weight: 600; font-size: 13px; margin-right: 2px; }
.chip-btn { border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); padding: 6px 10px; border-radius: 999px; cursor: pointer; font-size: 13px; }
.chip-btn:hover { color: var(--ink); border-color: var(--accent); }
.suggestions li.s-ai span:first-child { color: var(--accent-ink); font-weight: 600; }
.ask-page { max-width: 900px; }
.thread { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.thread .t-q { color: var(--muted); font-size: 13px; }
.thread .t-q::before { content: "Earlier: "; }
.ask-q { font-size: 20px; margin-bottom: 12px; }
.answer { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow); font-size: 15px; line-height: 1.6; }
.answer p { margin: 0 0 10px; }
.answer p:last-child { margin-bottom: 0; }
.answer ul, .answer ol { margin: 0 0 10px; padding-left: 22px; }
.answer h4 { margin: 12px 0 6px; font-size: 15px; }
.answer .table-wrap { margin: 6px 0 12px; }
.answer table { font-size: 14px; }
.answer code { font-size: 13px; background: var(--page); padding: 1px 4px; border-radius: 4px; }
.answer .loading { padding: 28px 0; }
#answer-meta { margin: 8px 2px 16px; color: var(--muted); font-size: 12px; min-height: 1em; }
.ask-form { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.ask-form input { flex: 1 1 320px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); outline: none; }
.ask-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }

/* ---------- signed-in person, gates ---------- */
.top-right { display: flex; align-items: center; gap: 16px; }
.userbox { display: flex; align-items: center; gap: 8px; }
.userbox .who { color: var(--ink-2); font-size: 13px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-sm { padding: 5px 10px; font-size: 13px; text-decoration: none; color: var(--ink); }
.notice.gate { max-width: 560px; margin: 40px auto; }

/* ---------- admin console ---------- */
.person-form { display: flex; flex-direction: column; gap: 14px; }
.pf-row { display: flex; flex-wrap: wrap; gap: 12px; }
.pf-row label { display: flex; flex-direction: column; gap: 4px; color: var(--ink-2); font-size: 12px; flex: 1 1 260px; }
.pf-row input { padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); font-size: 14px; }
.pf-row input[readonly] { background: var(--page); color: var(--ink-2); }
.pf-group { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; }
.pf-group legend { color: var(--ink-2); font-size: 12px; margin-bottom: 6px; width: 100%; }
.radio { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.radio .small { color: var(--muted); font-size: 12px; }
.dept-grid { width: 100%; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--page); }
.dept-grid[hidden], .pf-group[hidden] { display: none; }
.pf-admin-note { margin: 0; color: var(--ink-2); }
.pf-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pf-msg { color: var(--ink-2); font-size: 13px; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; color: var(--accent-ink); border: 1px solid var(--accent); border-radius: 999px; padding: 0 7px; margin-left: 6px; vertical-align: middle; }
.st { font-size: 12px; color: var(--muted); }
.st-on { color: var(--good); font-weight: 600; }
.st-off { color: var(--bad); font-weight: 600; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .linkbtn { padding: 0 6px; }
.linkbtn.danger { color: var(--bad); }
td.wrap { white-space: normal; max-width: 360px; }
table.log td { vertical-align: top; }

.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface-2); color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.16); font-size: 12px; min-width: 170px; }
.tooltip .t-title { font-weight: 600; margin-bottom: 4px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 16px; font-variant-numeric: tabular-nums; }
.tooltip .t-row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }

.notice { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; text-align: center; color: var(--ink-2); }
.notice h3 { color: var(--ink); margin-bottom: 6px; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); padding: 60px 0; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--grid); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.footnote { color: var(--muted); font-size: 12px; margin-top: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-2 > .card { margin-bottom: 16px; }
}
@media (max-width: 640px) {
  .topbar, .toolbar { padding-left: 16px; padding-right: 16px; }
  main { padding: 16px 16px 40px; }
  .status { display: none; }
  .toolbar { position: static; }
}
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }
