:root {
  color-scheme: light;
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f8f9fb; --border: #e3e6eb; --border-strong: #cfd4dc;
  --text: #111827; --text-2: #4b5563; --muted: #8a919c;
  --accent: #2a78d6; --accent-ink: #ffffff; --accent-soft: #e8f1fc;
  --productive: #2a78d6; --unproductive: #eb6834; --undefined: #a3a29b; --meeting: #9085e9; --idle: #e5e7eb; --passive-alpha: .45;
  --good: #0f7b3f; --good-soft: #e5f5ec; --warn: #a15c00; --warn-soft: #fdf3e1; --bad: #b42318; --bad-soft: #fdecea;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111213; --surface: #1a1a19; --surface-2: #222321; --border: #2e2f2c; --border-strong: #3d3e3a;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #8d8c84;
    --accent: #3987e5; --accent-soft: #1d2b3d;
    --productive: #3987e5; --unproductive: #d95926; --undefined: #6b6a64; --meeting: #9085e9; --idle: #2b2c2a;
    --good: #4cc38a; --good-soft: #15291f; --warn: #e3a33b; --warn-soft: #2d2412; --bad: #f07167; --bad-soft: #321a18;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111213; --surface: #1a1a19; --surface-2: #222321; --border: #2e2f2c; --border-strong: #3d3e3a;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #8d8c84;
  --accent: #3987e5; --accent-soft: #1d2b3d;
  --productive: #3987e5; --unproductive: #d95926; --undefined: #6b6a64; --meeting: #9085e9; --idle: #2b2c2a;
  --good: #4cc38a; --good-soft: #15291f; --warn: #e3a33b; --warn-soft: #2d2412; --bad: #f07167; --bad-soft: #321a18;
  --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 13px; margin: 16px 0 8px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
code, pre { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }
p code, li code, td code { overflow-wrap: anywhere; }
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow: auto; white-space: pre-wrap; word-break: break-all; }

/* layout */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.shell > div { min-width: 0; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 17px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; }
.brand-logo { width: 34px; height: 34px; object-fit: contain; border-radius: 6px; flex: none; }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; }
.nav svg { width: 17px; height: 17px; flex: none; }
.main { min-width: 0; padding: 22px 28px 60px; }
.topbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.topbar .grow { flex: 1; }
.hdr { display: flex; justify-content: space-between; align-items: center; padding: 12px 28px 0; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 13px; }
.btn.menu-btn { display: none; }

/* controls */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=url], select, textarea {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; min-height: 36px; max-width: 100%; }
textarea { min-height: 80px; width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); background: var(--surface); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; min-height: 36px; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 3px 9px; min-height: 28px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 7px 12px; cursor: pointer; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-2); font-weight: 500; }
label.f small { color: var(--muted); font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-h h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .l { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.kpi .v { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.mt { margin-top: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.chart-box { position: relative; height: 260px; }

/* tables */
.tbl-wrap { overflow-x: auto; margin: 0 -4px; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.t th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
table.t td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.t tr:hover td { background: var(--surface-2); }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
.ellipsis { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.cat { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.cat::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.cat.productive { --c: var(--productive); } .cat.unproductive { --c: var(--unproductive); } .cat.undefined { --c: var(--undefined); } .cat.meeting { --c: var(--meeting); }

/* category picker */
.catpick { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.catpick button { border: 0; background: var(--surface); padding: 4px 9px; cursor: pointer; font-size: 12.5px; border-right: 1px solid var(--border); color: var(--text-2); }
.catpick button:last-child { border-right: 0; }
.catpick button.on.productive { background: var(--productive); color: #fff; }
.catpick button.on.unproductive { background: var(--unproductive); color: #fff; }
.catpick button.on.undefined { background: var(--undefined); color: #fff; }

/* live */
.live-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.live { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.live .who { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 650; font-size: 13px; color: #fff; flex: none; }
.live .now { font-size: 13px; color: var(--text-2); min-height: 38px; }
.state { font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--s); }
.state.active { --s: #16a34a; } .state.passive { --s: #eab308; } .state.idle { --s: #9ca3af; } .state.locked { --s: #6b7280; }
.state.break { --s: #f97316; } .state.meeting { --s: var(--meeting); } .state.offline { --s: transparent; color: var(--muted); }
.state.offline::before { border: 1.5px solid var(--muted); }

/* timeline */
.timeline { position: relative; height: 46px; background: var(--surface-2); border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.timeline .blk { position: absolute; top: 6px; bottom: 6px; border-radius: 2px; }
.timeline .blk.passive { opacity: var(--passive-alpha); }
.timeline .sched { position: absolute; top: 0; bottom: 0; border-left: 2px dashed var(--text-2); opacity: .5; }
.timeline .ev { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); opacity: .7; }
.tl-axis { position: relative; height: 18px; font-size: 11px; color: var(--muted); }
.tl-axis span { position: absolute; transform: translateX(-50%); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; display: flex; gap: 2px; min-width: 80px; }
.bar > i { display: block; height: 100%; }
.tip { position: fixed; pointer-events: none; z-index: 50; background: var(--text); color: var(--bg); padding: 6px 9px; border-radius: 6px; font-size: 12px; max-width: 360px; display: none; }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; padding: 22px; width: min(560px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal h2 { font-size: 17px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 500; display: none; z-index: 60; max-width: 90vw; }
#toast.err { background: var(--bad); color: #fff; }

/* login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 30px; box-shadow: var(--shadow); }
.auth h1 { margin: 14px 0 4px; }
.auth form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.auth .btn { justify-content: center; }
.err-msg { color: var(--bad); font-size: 13px; min-height: 18px; }

/* markdown report */
.md { line-height: 1.6; max-width: 900px; }
.md h1 { font-size: 22px; margin: 18px 0 8px; } .md h2 { font-size: 18px; margin: 22px 0 8px; } .md h3 { text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--text); }
.md table { border-collapse: collapse; margin: 10px 0; font-size: 13.5px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--surface-2); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--text-2); border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.tabs a.on { color: var(--accent); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; }

@media (max-width: 1100px) { .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-2-1 { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; z-index: 30; left: 0; top: 0; width: 250px; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.2); }
  .side.open { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .main { padding: 16px 16px 60px; }
  .hdr { padding: 12px 16px 0; }
  .user-chip { flex-wrap: wrap; justify-content: flex-end; }
  .g2, .g3 { grid-template-columns: 1fr; }
}
