:root {
  color-scheme: light;
  --bg: #f9f9f7; --surface: #ffffff; --surface-2: #f2f1ed; --ink: #1d1d1b; --ink-2: #52514e; --muted: #7a7973;
  --line: #e4e3de; --line-2: #d2d0c9; --accent: #0a72b8; --accent-soft: #e3eff8;
  --ord: #c6efce; --ot: #ffd977; --ot-ink: #8a5a00; --bad: #c62828; --bad-soft: #fdecea; --good: #2e7d32;
  --closed: repeating-linear-gradient(135deg, #ecebe6 0 4px, #f6f5f1 4px 8px);
  --hatch: repeating-linear-gradient(45deg, rgba(198,40,40,.22) 0 3px, transparent 3px 7px);
  --s1:#2a78d6; --s2:#eb6834; --s3:#1baf7a; --s4:#eda100; --s5:#e87ba4; --s6:#008300; --s7:#6250d6; --s8:#e34948;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141413; --surface: #1d1d1b; --surface-2: #262624; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #9a9890;
    --line: #34332f; --line-2: #45443f; --accent: #4ea3e0; --accent-soft: #1b3346;
    --ord: #234a2b; --ot: #6b5112; --ot-ink: #ffd977; --bad: #ef6b6b; --bad-soft: #3b1f1f; --good: #6cc070;
    --closed: repeating-linear-gradient(135deg, #22221f 0 4px, #1a1a18 4px 8px);
    --s1:#3987e5; --s2:#d95926; --s3:#199e70; --s4:#c98500; --s5:#d55181; --s6:#0ca30c; --s7:#9085e9; --s8:#e66767;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141413; --surface: #1d1d1b; --surface-2: #262624; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #9a9890;
  --line: #34332f; --line-2: #45443f; --accent: #4ea3e0; --accent-soft: #1b3346;
  --ord: #234a2b; --ot: #6b5112; --ot-ink: #ffd977; --bad: #ef6b6b; --bad-soft: #3b1f1f; --good: #6cc070;
  --closed: repeating-linear-gradient(135deg, #22221f 0 4px, #1a1a18 4px 8px);
  --s1:#3987e5; --s2:#d95926; --s3:#199e70; --s4:#c98500; --s5:#d55181; --s6:#0ca30c; --s7:#9085e9; --s8:#e66767;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body::before { content: ""; display: block; height: 3px; background: linear-gradient(90deg, #0a72b8, #d0458f 55%, #3aa85b); }
h1, h2, h3 { margin: 0 0 8px; font-weight: 600; }
h2 { font-size: 17px; } h3 { font-size: 15px; }
.muted { color: var(--muted); } .err { color: var(--bad); } .grow { flex: 1; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { background: var(--surface); border: 1px solid var(--line-2); border-radius: 6px; padding: 4px 6px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=number] { width: 64px; text-align: right; }
.btn { border: 1px solid var(--line-2); background: var(--surface); border-radius: 6px; padding: 5px 11px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 2px 8px; font-size: 13px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }

.top { display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 650; font-size: 16px; }
.top form { margin: 0; }
.from { color: var(--ink-2); display: flex; gap: 6px; align-items: center; }
.kpis { display: flex; gap: 10px; padding: 14px 20px 4px; flex-wrap: wrap; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; min-width: 160px; }
.kpi .k { font-size: 12px; color: var(--muted); }
.kpi .v { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--ink-2); }
.kpi.bad .v { color: var(--bad); }
.tabs { display: flex; gap: 2px; padding: 10px 20px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 14px; cursor: pointer; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
main { padding: 16px 20px 60px; }
.pane { display: none; } .pane.on { display: block; }
.bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.help { color: var(--ink-2); max-width: 900px; margin: 0 0 12px; }

/* ---- jars ---- */
.jars-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.jars { display: grid; grid-auto-flow: column; align-items: end; }
.jar-grid { display: grid; }
.jg-label { position: sticky; left: 0; z-index: 2; background: var(--surface); padding: 8px 12px; border-right: 1px solid var(--line); display: flex; flex-direction: column; justify-content: flex-end; min-width: 130px; }
.jg-label b { font-weight: 600; }
.jg-head { font-size: 12px; color: var(--muted); text-align: center; padding: 6px 0 4px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.jg-head.wk { border-left: 1px solid var(--line-2); }
.jg-head .dn { display: block; font-weight: 600; color: var(--ink-2); }
.jg-head.today .dn { color: var(--accent); }
.jg-cell { padding: 8px 4px 4px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: flex-end; cursor: pointer; }
.jg-cell.wk { border-left: 1px solid var(--line-2); }
.jg-cell.wkend { background: var(--surface-2); }
.jg-cell.past { opacity: .4; }
.jg-cell:hover { background: var(--accent-soft); }
.jar { width: 40px; border: 1.5px solid var(--line-2); border-top: 0; border-radius: 0 0 9px 9px; display: flex; flex-direction: column-reverse; overflow: hidden; background: var(--surface); position: relative; }
.jar.cap0 { border: 0; background: var(--closed); border-radius: 4px; }
.jar.intr { outline: 2px solid var(--bad); outline-offset: 2px; }
.jar .seg { width: 100%; border-top: 2px solid var(--surface); }
.jar .seg:last-child { border-top: 0; }
.jar .otband { position: absolute; left: 0; right: 0; top: 0; border-bottom: 1px dashed var(--ot-ink); background: color-mix(in srgb, var(--ot) 35%, transparent); pointer-events: none; }
.jar-n { font-size: 11px; color: var(--ink-2); margin-top: 3px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.jar-n.idle { color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: 13px; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; flex: none; }
.c0{background:var(--s1)} .c1{background:var(--s2)} .c2{background:var(--s3)} .c3{background:var(--s4)}
.c4{background:var(--s5)} .c5{background:var(--s6)} .c6{background:var(--s7)} .c7{background:var(--s8)}
.tent { background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.45) 0 3px, transparent 3px 7px) !important; }

/* ---- 24 hour ---- */
.hgrid { border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.hgrid th, .hgrid td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); }
.hgrid th { font-size: 11px; font-weight: 600; color: var(--muted); padding: 4px 2px; text-align: center; }
.hgrid th.day { text-align: left; padding: 4px 10px; font-size: 13px; color: var(--ink); white-space: nowrap; }
.hgrid td.h { width: 34px; height: 34px; padding: 0; position: relative; font-size: 10px; text-align: center; font-variant-numeric: tabular-nums; }
.hgrid td.h.ot::after { content: ""; position: absolute; inset: 1px; border: 2px solid var(--ot-ink); border-radius: 2px; pointer-events: none; }
.hgrid tr.past td.h { opacity: .35; }
.hgrid tr.past td.h.idle { background: var(--surface-2); }
.hgrid td.h .fill { position: absolute; inset: 0; display: flex; }
.hgrid td.h .fill i { display: block; height: 100%; }
.hgrid td.h .n { position: relative; color: var(--ink); mix-blend-mode: normal; }
.hgrid td.h.idle { background: var(--ord); }
.hgrid td.tot { padding: 0 10px; font-size: 12px; white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.hkey { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin-top: 8px; flex-wrap: wrap; }
.hkey span { display: inline-flex; gap: 5px; align-items: center; }

/* ---- tables ---- */
.tbl-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
table.t { border-collapse: collapse; width: 100%; }
table.t th { font-size: 12px; font-weight: 600; color: var(--muted); text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface); }
table.t td { padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t input.name { width: 100%; min-width: 140px; }
table.t tr.dragging { opacity: .4; }
table.t tr.over td { border-top: 2px solid var(--accent); }
table.t tr.hold td:not(.handle) { opacity: .55; }
.handle { cursor: grab; color: var(--muted); user-select: none; width: 18px; }
.vol { display: flex; flex-direction: column; gap: 2px; align-items: flex-end; }
.vol .d { font-size: 11px; color: var(--muted); }
.vol .d input { width: 52px; font-size: 11px; padding: 1px 4px; }
.prog { width: 70px; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.prog i { display: block; height: 100%; background: var(--good); }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.ok { color: var(--good); }
.tag.ot { background: var(--ot); color: var(--ink); }
.when { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* roster */
.roster td.rc { text-align: center; cursor: pointer; min-width: 86px; font-size: 13px; }
.roster td.rc:hover { background: var(--accent-soft); }
.roster td.rc.changed { background: color-mix(in srgb, var(--ot) 30%, transparent); }
.roster td.rc.off { color: var(--muted); }
.roster td.rc.absent { background: var(--bad-soft); color: var(--bad); }
.roster tfoot td { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; text-align: center; }
.pat { font-size: 12px; color: var(--ink-2); white-space: nowrap; }

/* hour painter */
.painter { display: grid; grid-template-columns: 54px repeat(24, 26px); gap: 2px; user-select: none; }
.painter .hl { font-size: 10px; color: var(--muted); text-align: center; }
.painter .dl { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; }
.painter .pc { height: 24px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--line); cursor: pointer; }
.painter .pc.v1 { background: var(--ord); border-color: color-mix(in srgb, var(--good) 50%, transparent); }
.painter .pc.v2 { background: var(--ot); border-color: var(--ot-ink); }
.brushes { display: flex; gap: 8px; margin: 8px 0; align-items: center; flex-wrap: wrap; }
.brushes button.on { outline: 2px solid var(--accent); }

/* gantt */
.gantt { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
.g-row { display: grid; grid-template-columns: 220px 1fr; border-bottom: 1px solid var(--line); min-height: 34px; }
.g-row.head { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.g-name { padding: 6px 10px; border-right: 1px solid var(--line); display: flex; gap: 8px; align-items: center; position: sticky; left: 0; background: var(--surface); z-index: 1; cursor: grab; }
.g-name .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-track { position: relative; }
.g-bar { position: absolute; height: 6px; border-radius: 3px; }
.g-bar.main { height: 12px; top: 6px; border-radius: 4px; }
.g-due { position: absolute; top: 2px; bottom: 2px; width: 2px; background: var(--bad); }
.g-tick { position: absolute; top: 0; bottom: 0; border-left: 1px solid var(--line); font-size: 11px; color: var(--muted); padding-left: 3px; white-space: nowrap; }
.g-today { position: absolute; top: 0; bottom: 0; border-left: 2px solid var(--accent); }
.g-row.over { box-shadow: inset 0 2px 0 var(--accent); }

/* tooltip, dialog, toast */
.tip { position: fixed; z-index: 50; background: var(--surface); color: var(--ink); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.14); pointer-events: none; max-width: 320px; }
.tip .r { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.tip .r b { font-weight: 600; font-variant-numeric: tabular-nums; }
.tip hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
dialog { border: 1px solid var(--line-2); border-radius: 12px; background: var(--surface); color: var(--ink); padding: 0; max-width: min(860px, 96vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }
#dlg-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; margin: 0; }
#dlg-body .row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
#dlg-body label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink-2); }
#dlg-body .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 13px; z-index: 60; }
.toast.bad { background: var(--bad); color: #fff; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.form-grid label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--ink-2); }
.stack { display: flex; flex-direction: column; gap: 16px; }

body.login { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: min(360px, 92vw); display: flex; flex-direction: column; gap: 10px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; color: var(--ink-2); font-size: 13px; }
.ro .edit-only { display: none !important; }
@media (max-width: 700px) { .top { padding: 8px 12px; } main, .kpis, .tabs { padding-left: 12px; padding-right: 12px; } .user { display: none; } }
