:root {
  --bg: #f4f6f9; --panel: #fff; --text: #1d2433; --muted: #6b7486; --line: #e2e6ee; --line2: #eef1f5;
  --accent: #2f6fdf; --accent-weak: #e8f0fd; --danger: #d43c3c; --danger-weak: #fde7e7;
  --ok: #1f8a4c; --ok-weak: #e3f5ea; --warn-weak: #fff4d6; --group: #f6f8fb; --weekend: #f1f2f4;
  --side: #1f2a3d; --side-text: #c9d2e3; --radius: 10px; --shadow: 0 1px 3px rgba(20,30,50,.08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141922; --panel: #1c2330; --text: #e3e8f1; --muted: #8e98aa; --line: #2d3646; --line2: #252d3b;
    --accent: #5b8ff0; --accent-weak: #22324f; --danger: #f06a6a; --danger-weak: #47242a;
    --ok: #4cc27f; --ok-weak: #1e3b2b; --warn-weak: #403719; --group: #212938; --weekend: #232a36;
    --side: #10151d; --side-text: #aeb8ca; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 10px; font-weight: 650; }
.sub { color: var(--muted); margin-bottom: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); padding: 28px; border-radius: 14px; width: 340px; max-width: 100%; box-shadow: 0 6px 30px rgba(0,0,0,.08); display: grid; gap: 14px; }
.brand-big { font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 6px; }

/* ---------- shell */
.shell { display: flex; min-height: 100%; }
.side { width: 232px; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { font-weight: 700; color: #fff; padding: 18px 18px 14px; font-size: 15px; }
nav { flex: 1; overflow-y: auto; padding: 4px 8px; }
nav .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7d889c; padding: 14px 10px 4px; }
nav a { display: block; color: var(--side-text); padding: 7px 10px; border-radius: 7px; }
nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
nav a.active { background: var(--accent); color: #fff; }
.side-foot { padding: 14px 18px; font-size: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.side-foot a { color: #9fb3d6; }
.me { color: #fff; font-weight: 600; margin-bottom: 4px; }
.main { flex: 1; min-width: 0; padding: 22px 26px 40px; }
.burger { display: none; }
@media (max-width: 860px) {
  .side { position: fixed; left: -240px; z-index: 30; transition: left .2s; }
  .side.open { left: 0; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .burger { display: inline-block; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; font-size: 18px; margin-bottom: 10px; color: var(--text); }
  .main { padding: 14px 16px 40px; }
}

/* ---------- controls */
label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
textarea { resize: vertical; min-height: 60px; }
.chk { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text); font-weight: 400; cursor: pointer; }
.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 7px 14px; border-radius: 7px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn.wide { width: 100%; padding: 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: none; background: none; cursor: pointer; padding: 3px 6px; border-radius: 5px; color: var(--muted); font-size: 14px; }
.icon-btn:hover { background: var(--line2); color: var(--text); }
.err { color: var(--danger); font-size: 13px; min-height: 1em; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex-wrap: wrap; background: var(--panel); }
.seg button { font: inherit; border: none; background: none; padding: 6px 12px; cursor: pointer; color: var(--text); border-right: 1px solid var(--line); }
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--accent); color: #fff; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { font: inherit; border: none; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--line2); color: var(--muted); }
.badge.arch { background: var(--warn-weak); color: #9a6b00; }
.badge.red { background: var(--danger-weak); color: var(--danger); }

/* ---------- cards & layout */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.toolbar .grow { flex: 1; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }

/* ---------- day page */
.daynav { display: flex; align-items: center; gap: 6px; }
.daynav input { width: 150px; }
.progress { height: 8px; background: var(--line2); border-radius: 5px; overflow: hidden; width: 220px; }
.progress > div { height: 100%; background: var(--ok); }
.progress.low > div { background: #e5a23a; }
.daytotal { display: flex; align-items: center; gap: 12px; }
.daytotal b { font-size: 20px; }
.entry-form { display: grid; gap: 14px; }
.entry-form .line { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.entry-form .line > label { flex: 1; min-width: 160px; }
.work-hint { font-size: 12px; color: var(--muted); white-space: pre-line; background: var(--group); border-radius: 7px; padding: 8px 10px; max-height: 110px; overflow: auto; }
.req::after { content: " *"; color: var(--danger); }
.time-in { width: 92px; }
.locked-note { padding: 10px 12px; border-radius: 8px; background: var(--warn-weak); margin-bottom: 12px; }

/* ---------- tables */
.tbl-wrap { overflow: auto; max-height: calc(100vh - 230px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table.t { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
table.t th, table.t td { padding: 6px 9px; border-bottom: 1px solid var(--line2); border-right: 1px solid var(--line2); text-align: left; vertical-align: top; }
table.t th { position: sticky; top: 0; background: var(--group); font-weight: 600; z-index: 2; white-space: nowrap; }
table.t thead tr.grp th { top: 0; text-align: left; color: var(--accent); border-bottom: 2px solid var(--accent-weak); }
table.t thead tr.grp + tr th { top: 31px; }
table.t th.num, table.t td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.t td.first, table.t th.first { position: sticky; left: 0; background: var(--panel); z-index: 1; min-width: 220px; max-width: 380px; }
table.t th.first { z-index: 3; background: var(--group); }
table.t tr.group td { background: var(--group); font-weight: 600; }
table.t tr.group td.first { background: var(--group); }
table.t tr.total td { background: var(--warn-weak); font-weight: 700; position: sticky; bottom: 0; }
table.t tr.internal td { color: var(--muted); font-style: italic; }
table.t tr.clickable { cursor: pointer; }
table.t tr.clickable:hover td { background: var(--accent-weak); }
table.t td.bad { background: var(--danger-weak) !important; color: var(--danger); font-weight: 600; }
table.t td.good { background: var(--ok-weak) !important; }
table.t td.empty { background: repeating-linear-gradient(45deg, transparent 0 4px, var(--line2) 4px 6px); }
table.t .wkd { background: var(--weekend); }
table.t th .wd { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
table.t td .tog { display: inline-block; width: 16px; color: var(--muted); cursor: pointer; user-select: none; }
table.t tbody tr:hover td { background-color: var(--accent-weak); }
table.t td.actions { white-space: nowrap; width: 1%; }
table.t td.comment { max-width: 340px; white-space: pre-wrap; color: var(--muted); }
.list-tbl { max-height: none; }

/* ---------- multiselect / combobox */
.ms { position: relative; min-width: 200px; }
.ms-btn { width: 100%; text-align: left; font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 7px 26px 7px 9px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative; }
.ms-btn::after { content: "▾"; position: absolute; right: 9px; color: var(--muted); }
.ms-pop { position: absolute; z-index: 40; top: calc(100% + 4px); left: 0; min-width: 100%; width: max-content; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; box-shadow: 0 8px 28px rgba(0,0,0,.16); padding: 6px; }
.ms-pop input.q { width: 100%; margin-bottom: 6px; }
.ms-list { max-height: 280px; overflow: auto; }
.ms-item { display: flex; gap: 8px; align-items: center; padding: 5px 7px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text); }
.ms-item:hover, .ms-item.hl { background: var(--accent-weak); }
.ms-item .arch { color: var(--muted); font-size: 11px; }
.ms-actions { display: flex; gap: 6px; border-top: 1px solid var(--line2); padding-top: 6px; margin-top: 4px; }

/* ---------- modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(10,15,25,.45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; width: 560px; max-width: 100%; max-height: 92vh; overflow: auto; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h2 { margin-bottom: 16px; }
.modal .fields { display: grid; gap: 12px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1f2a3d; color: #fff; padding: 10px 18px; border-radius: 9px; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 90vw; }
.toast.error { background: var(--danger); }

.split { display: grid; grid-template-columns: minmax(260px, 360px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.cat-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-radius: 8px; cursor: pointer; gap: 8px; }
.cat-item:hover { background: var(--line2); }
.cat-item.on { background: var(--accent-weak); }
.cat-item .code { font-weight: 700; min-width: 50px; display: inline-block; }
.stat { display: inline-flex; flex-direction: column; padding: 0 16px 0 0; }
.stat b { font-size: 18px; }
.stat span { font-size: 12px; color: var(--muted); }
.import-res { font-size: 13px; }
.import-res li { margin-bottom: 6px; }
