:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e1e4ea;
  --text: #1c2230;
  --muted: #6a7385;
  --primary: #2f5bea;
  --primary-hover: #2449c4;
  --primary-soft: #e8eefe;
  --danger: #d23b3b;
  --danger-soft: #fdecec;
  --ok: #1f8a4c;
  --ok-soft: #e6f5ec;
  --warn-bg: #ffe58f;
  --warn-strong: #ffd23f;
  --warn-text: #5c4400;
  --weekend: #eceef2;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 16px rgba(20, 30, 50, .06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --surface: #1a1e26; --surface-2: #222733; --border: #2e3442;
    --text: #e6e9ef; --muted: #98a1b3; --primary: #5b80ff; --primary-hover: #7a98ff; --primary-soft: #243055;
    --danger: #ff6b6b; --danger-soft: #3a2124; --ok: #4cc27d; --ok-soft: #1d3327;
    --warn-bg: #6b5410; --warn-strong: #8a6c10; --warn-text: #ffe9a8; --weekend: #1e222b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; }
h2 { font-size: 16px; margin: 0; font-weight: 650; }
[hidden] { display: none !important; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; color: var(--text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  background: linear-gradient(135deg, var(--primary), #6d8dff);
  box-shadow: inset -6px -8px 0 rgba(255, 210, 63, .9);
}
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 550; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-menu { position: relative; }
.user-btn { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.dropdown button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none;
  color: var(--text); border-radius: 6px; cursor: pointer; font: inherit;
}
.dropdown button:hover { background: var(--surface-2); }

.main { padding: 20px; max-width: 1600px; margin: 0 auto; }

/* buttons & inputs */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 550;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: none; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-icon { padding: 4px 9px; }
.plus { font-size: 18px; line-height: 1; margin-top: -2px; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input.invalid { border-color: var(--danger); }
label.field { display: flex; flex-direction: column; gap: 5px; font-weight: 550; font-size: 13px; color: var(--muted); }
label.field > input, label.field > select { color: var(--text); font-weight: 400; font-size: 14px; }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--muted); }

/* layout pieces */
.page-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .spacer { flex: 1; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 16px 18px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; white-space: nowrap; color: var(--text);
}
.chip-queue { background: var(--primary-soft); border-color: transparent; color: var(--primary); font-weight: 600; }
.badge-warn {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  background: var(--warn-bg); color: var(--warn-text); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-ok { display: inline-flex; padding: 2px 8px; border-radius: 999px; background: var(--ok-soft); color: var(--ok); font-size: 12px; font-weight: 600; }
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.stat { padding: 10px 14px; min-width: 140px; }
.stat b { display: block; font-size: 20px; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty .btn { margin-top: 14px; }
.legend { display: flex; gap: 14px; align-items: center; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 3px; vertical-align: -3px; margin-right: 4px; }

/* tables */
.table-wrap { overflow: auto; border-radius: var(--radius); }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface); position: sticky; top: 0; z-index: 2; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* load grid */
.grid { font-variant-numeric: tabular-nums; }
.grid th.day, .grid td.day { width: 38px; min-width: 38px; padding: 6px 2px; text-align: center; font-size: 12px; }
.grid th.day { line-height: 1.15; }
.grid th.day small { display: block; font-weight: 400; }
.grid .weekend { background: var(--weekend); }
.grid th.today { color: var(--primary); }
.grid td.today { box-shadow: inset 1px 0 0 var(--primary), inset -1px 0 0 var(--primary); }
.grid td.warn { background: var(--warn-bg); color: var(--warn-text); font-weight: 650; }
.grid td.zero { color: var(--muted); opacity: .35; }
.grid .sticky {
  position: sticky; left: 0; z-index: 1; background: var(--surface); min-width: 220px; max-width: 260px;
  box-shadow: 1px 0 0 var(--border);
}
.grid th.sticky { z-index: 3; }
.grid tr.sub td { background: var(--surface-2); font-size: 12px; }
.grid tr.sub td.sticky { background: var(--surface-2); padding-left: 28px; }
.grid tr.sub td.warn { background: var(--warn-bg); }
.grid tr.emp:hover td { background: var(--surface-2); }
.grid tr.emp:hover td.warn { background: var(--warn-strong); }
.emp-name { display: flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 600; }
.caret { display: inline-block; width: 12px; color: var(--muted); transition: transform .15s; }
.open .caret { transform: rotate(90deg); }
.pct-bar { position: relative; height: 6px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 3px; }
.pct-bar span { position: absolute; inset: 0 auto 0 0; background: var(--primary); }
.pct-bar span.over { background: var(--warn-strong); }

/* project page */
.project-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.project-head .meta { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; color: var(--muted); }
.project-head .actions { margin-left: auto; display: flex; gap: 8px; }
.assign { margin-top: 14px; }
.assign-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.assign-head h2 { margin-right: 4px; }
.assign-head .spacer { flex: 1; }
.assign-body { padding: 14px 18px; }
.week-grid { border-collapse: separate; border-spacing: 6px; margin: -6px; }
.week-grid th, .week-grid td { border: 0; padding: 0; position: static; background: none; }
.week-grid th { text-align: center; padding-bottom: 2px; }
.week-grid td.week-label { font-size: 12px; color: var(--muted); padding-right: 6px; white-space: nowrap; }
.week-grid td.week-sum { font-size: 12px; color: var(--muted); padding-left: 8px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.daycell {
  width: 82px; border: 1px solid var(--border); border-radius: 8px; padding: 5px 6px; background: var(--surface);
}
.daycell.out { background: transparent; border-style: dashed; opacity: .45; height: 52px; }
.daycell.warn { background: var(--warn-bg); border-color: var(--warn-strong); }
.daycell.changed { box-shadow: 0 0 0 2px var(--primary-soft); border-color: var(--primary); }
.daycell .d { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; }
.daycell.warn .d { color: var(--warn-text); }
.daycell input { width: 100%; padding: 2px 4px; border-radius: 5px; text-align: right; font-variant-numeric: tabular-nums; }
.daycell .v { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; padding: 2px 4px; }
.sum-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.sum-bar .spacer { flex: 1; }
.sum-ok { color: var(--ok); font-weight: 650; }
.sum-bad { color: var(--danger); font-weight: 650; }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(15, 20, 30, .45);
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 560px; background: var(--surface); border-radius: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
  display: flex; flex-direction: column;
}
.modal.wide { max-width: 880px; }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { flex: 1; }
.modal-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
.note { padding: 10px 12px; border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: 13px; }
.note.warn { background: var(--warn-bg); color: var(--warn-text); }
.error-box { padding: 10px 12px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); font-size: 13px; }
.emp-rows { display: flex; flex-direction: column; gap: 8px; }
.emp-row {
  display: grid; grid-template-columns: minmax(180px, 2fr) 110px 100px minmax(140px, 1.4fr) 34px; gap: 8px; align-items: center;
  padding: 8px; border: 1px solid var(--border); border-radius: 10px;
}
.emp-row .result { font-size: 12px; color: var(--muted); line-height: 1.3; }
.emp-row .result .badge-warn { margin-top: 3px; }
.secret {
  font: 600 20px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .05em;
  padding: 12px; border-radius: 8px; background: var(--surface-2); text-align: center; user-select: all;
}
.overload-list { max-height: 220px; overflow: auto; font-size: 12px; }
.overload-list div { padding: 3px 0; border-bottom: 1px dashed var(--border); }

/* login */
.login-wrap { min-height: 80vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 100%; max-width: 380px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-card .brand { justify-content: center; font-size: 17px; margin-bottom: 6px; }

/* audit */
.audit-details { font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--muted); max-width: 560px; white-space: pre-wrap; word-break: break-word; }

/* toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 10px 14px; border-radius: 10px; background: var(--text); color: var(--surface); box-shadow: var(--shadow);
  max-width: 420px; animation: toast-in .2s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .nav { order: 3; width: 100%; }
  .topbar-right { margin-left: auto; }
  .add-label { display: none; }
  .main { padding: 16px; }
  .row2, .row3 { grid-template-columns: 1fr; }
  .emp-row { grid-template-columns: 1fr 1fr; }
  .emp-row > :first-child, .emp-row .result { grid-column: 1 / -1; }
  .grid .sticky { min-width: 150px; }
}
