:root,
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f1f3f7;
  --surface: #ffffff;
  --surface-2: #f4f6f9;
  --surface-3: #e9edf2;
  --line: #e8ebf0;
  --line-strong: #d6dbe3;
  --text: #0f1621;
  --text-2: #687280;
  --text-3: #9aa3ae;
  --accent: #3390ec;
  --accent-hover: #2a82db;
  --accent-soft: #e9f3fe;
  --accent-text: #1f73cc;
  --on-accent: #ffffff;
  --good: #1a8f4c;
  --good-soft: #e5f6ec;
  --bad: #d43c3c;
  --bad-soft: #fdeceb;
  --warn: #a8670a;
  --warn-soft: #fff4dc;
  --today: #f3f8ff;
  --overlay: rgba(15, 22, 33, 0.32);
  --shadow-1: 0 1px 2px rgba(15, 22, 33, 0.04), 0 2px 10px rgba(15, 22, 33, 0.04);
  --shadow-2: 0 12px 40px rgba(15, 22, 33, 0.16);
  --series-1: #3390ec;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --grid: #eef1f4;
  --axis: #cfd5dd;
  --chip-winter: #e8eefc;
  --chip-winter-ink: #3557a8;
  --chip-summer: #e6f5ee;
  --chip-summer-ink: #1f7a4f;
  --chip-up: #fff1e3;
  --chip-up-ink: #a35512;
  --chip-peak: #fdecec;
  --chip-peak-ink: #b42f2f;
  --chip-off: #f1ecfb;
  --chip-off-ink: #6040a8;
  --sh-day: #fff1d1;
  --sh-day-ink: #8a5a00;
  --sh-eve: #ebe7fd;
  --sh-eve-ink: #5640c4;
  --sh-full: #ddeefe;
  --sh-full-ink: #1d68b8;
  --weekend: #fafbfc;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1621;
  --surface: #17212b;
  --surface-2: #1e2a37;
  --surface-3: #263546;
  --line: #22303e;
  --line-strong: #2f4052;
  --text: #f0f4f8;
  --text-2: #8d9caf;
  --text-3: #66778a;
  --accent: #3a8fe5;
  --accent-hover: #4d9cec;
  --accent-soft: rgba(58, 143, 229, 0.16);
  --accent-text: #6cb0f5;
  --on-accent: #ffffff;
  --good: #4cc47a;
  --good-soft: rgba(76, 196, 122, 0.14);
  --bad: #f07070;
  --bad-soft: rgba(240, 112, 112, 0.14);
  --warn: #e6a43c;
  --warn-soft: rgba(230, 164, 60, 0.14);
  --today: rgba(58, 143, 229, 0.08);
  --overlay: rgba(0, 0, 0, 0.5);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-2: 0 12px 40px rgba(0, 0, 0, 0.5);
  --series-1: #3a8fe5;
  --series-2: #d95926;
  --series-3: #199e70;
  --grid: #213040;
  --axis: #34465a;
  --chip-winter: rgba(96, 140, 230, 0.16);
  --chip-winter-ink: #9bb8f2;
  --chip-summer: rgba(76, 196, 122, 0.14);
  --chip-summer-ink: #7fd6a2;
  --chip-up: rgba(230, 140, 60, 0.16);
  --chip-up-ink: #f0ad6e;
  --chip-peak: rgba(240, 112, 112, 0.16);
  --chip-peak-ink: #f39a9a;
  --chip-off: rgba(150, 120, 230, 0.16);
  --chip-off-ink: #bba7f2;
  --sh-day: rgba(230, 164, 60, 0.2);
  --sh-day-ink: #f2c47c;
  --sh-eve: rgba(140, 120, 240, 0.22);
  --sh-eve-ink: #bcaef8;
  --sh-full: rgba(58, 143, 229, 0.22);
  --sh-full-ink: #8cc2f7;
  --weekend: #1a2531;
}

* { 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 Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
svg { display: block; flex: none; }

.app { display: flex; height: 100%; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 264px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 14px 10px 12px;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 4px 10px 16px; }
.brand .logo { width: 42px; height: 42px; border-radius: 13px; background: #111924; display: flex; align-items: center; justify-content: center; flex: none; }
:root[data-theme="dark"] .brand .logo { background: #0b1118; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45); }
.brand-mark { overflow: visible; }
.brand-title { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.brand-sub { color: var(--text-2); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 170px; }
.brand-sub.org-pick {
  display: flex; align-items: center; gap: 3px;
  border: none; background: none; font: inherit; font-size: 12.5px; cursor: pointer;
  padding: 1px 4px 1px 0; margin-left: -2px; border-radius: 6px; color: var(--text-2);
}
.brand-sub.org-pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }
.brand-sub.org-pick:hover { color: var(--text); background: var(--surface-3); }
.brand-sub.org-pick .ico { flex: none; opacity: 0.7; }

.nav-title { color: var(--text-3); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; padding: 14px 12px 6px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  height: 42px; padding: 0 12px; margin: 1px 0;
  border-radius: 12px; color: var(--text); font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item .ico { color: var(--text-2); }
.nav-item.active { background: var(--accent); color: var(--on-accent); }
.nav-item.active .ico { color: var(--on-accent); }

.sidebar-foot { margin-top: auto; padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }

.sync-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px; background: var(--surface-2);
  font-size: 12.5px; color: var(--text-2);
}
.sync-card b { color: var(--text); font-weight: 600; display: block; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-3); }
.dot.ok { background: var(--good); box-shadow: 0 0 0 4px var(--good-soft); }
.dot.run { background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); animation: pulse 1.2s ease-in-out infinite; }
.dot.err { background: var(--bad); box-shadow: 0 0 0 4px var(--bad-soft); }
@keyframes pulse { 50% { opacity: 0.35; } }

.sync-progress { height: 4px; border-radius: 4px; background: var(--surface-3); overflow: hidden; margin-top: 6px; }
.sync-progress > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.4s ease; }

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; overflow-y: auto; padding: 22px 28px 48px; }

.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.page-head .sub { color: var(--text-2); margin-top: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent;
  background: var(--surface); color: var(--text); font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow-1); white-space: nowrap;
  transition: background 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn.primary { background: var(--accent); color: var(--on-accent); box-shadow: 0 4px 14px rgba(51, 144, 236, 0.28); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.soft { background: var(--accent-soft); color: var(--accent-text); box-shadow: none; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { color: var(--bad); }
.btn.sm { height: 32px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
.btn.icon-only { width: 38px; padding: 0; }
.btn.sm.icon-only { width: 32px; }

.field {
  height: 38px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); outline: none; min-width: 0;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.field::placeholder { color: var(--text-3); opacity: 1; font-weight: 400; }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.field { height: auto; padding: 10px 12px; min-height: 160px; width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; resize: vertical; }
input.field[type="number"] { text-align: right; }
input[type="date"].field, input[type="month"].field { padding-right: 8px; }

.select { position: relative; display: inline-flex; align-items: center; }
.select select {
  appearance: none; height: 38px; padding: 0 36px 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600;
  box-shadow: var(--shadow-1); cursor: pointer; outline: none; max-width: 340px;
}
.select select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.select .chev { position: absolute; right: 12px; pointer-events: none; color: var(--text-2); }
.select .lead { position: absolute; left: 12px; pointer-events: none; color: var(--text-2); }
.select.has-lead select { padding-left: 38px; }

.stepper {
  display: inline-flex; align-items: center; height: 38px; border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow-1); border: 1px solid var(--line);
}
.stepper button { border: none; background: none; height: 100%; width: 36px; display: grid; place-items: center; color: var(--text-2); cursor: pointer; border-radius: 12px; }
.stepper button:hover { color: var(--text); background: var(--surface-2); }
.stepper .label { position: relative; padding: 0 6px; font-weight: 600; min-width: 128px; text-align: center; cursor: pointer; }
.stepper .label input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }

.seg { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--surface-3); gap: 2px; }
.seg button {
  border: none; background: none; height: 32px; padding: 0 14px; border-radius: 9px;
  font-weight: 600; color: var(--text-2); cursor: pointer; white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(15, 22, 33, 0.12); }

.inline-field { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); font-weight: 500; }
.inline-field .field { width: 76px; }

.switch { position: relative; width: 40px; height: 24px; flex: none; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch i { position: absolute; inset: 0; border-radius: 24px; background: var(--surface-3); transition: background 0.2s ease; cursor: pointer; }
.switch i::after { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.2s ease; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(16px); }
.switch input:focus-visible + i { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- cards ---------- */
.card { background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-1); border: 1px solid var(--line); margin-bottom: 16px; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px 6px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.card-head .hint { color: var(--text-2); font-size: 13px; }
.card-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-body { padding: 12px 18px 18px; }
.card-body.flush { padding: 8px 0 0; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }

/* ---------- KPI ---------- */
.brand-title { display: flex; align-items: baseline; }
.brand-title .wm-x { background: linear-gradient(135deg, #5AD2F0, #1B86D4); -webkit-background-clip: text; background-clip: text; color: transparent; }
.perm-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.perm-row:last-child { border-bottom: none; }
.perm-row > div:first-child { flex: 1; min-width: 0; }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-box { width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 40px 32px; box-shadow: 0 10px 40px rgba(15, 22, 33, 0.08); text-align: center; }
.login-box h1 { font-size: 26px; margin: 0; }
.login-box .muted { margin-top: -6px; }
.login-logo { width: 68px; height: 68px; border-radius: 20px; background: #111924; display: flex; align-items: center; justify-content: center; align-self: center; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--surface-2); margin-top: 8px; }
.user-card b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sidebar.hidden, #tabbar.hidden { display: none; }
.load-preview { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.load-preview:empty { display: none; }
.lp-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.lp-row .lp-k { color: var(--text-2); min-width: 118px; }
.lp-row .lp-v { font-weight: 600; }
.lp-row .lp-u { color: var(--text-3); font-size: 13px; }
.lp-row.strong { padding: 8px 12px; border-radius: 10px; background: var(--accent-soft); }
.lp-row.strong .lp-k, .lp-row.strong .lp-v { color: var(--accent-text); }
.lp-row.strong .lp-v { font-weight: 700; }
.check-strip { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.check-head { display: flex; align-items: center; gap: 10px; }
.check-toggle { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; background: none; border: 0; padding: 6px 0; cursor: pointer; color: var(--text-2); font: inherit; text-align: left; }
.check-toggle:hover { color: var(--text); }
.check-dot { display: inline-flex; color: var(--text-3); }
.check-dot.ok { color: var(--good); }
.check-dot.bad { color: var(--bad); }
.check-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.check-body { padding-top: 10px; }
.share-bar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: var(--surface-3); min-width: 120px; }
.share-bar i { display: block; height: 100%; }
.share-bar i + i { box-shadow: inset 1px 0 0 var(--surface); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; box-shadow: var(--shadow-1); min-width: 0; }
.kpi .k-label { color: var(--text-2); font-size: 13px; font-weight: 500; }
.kpi .k-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .k-value small { font-size: 15px; color: var(--text-2); font-weight: 600; margin-left: 2px; }
.kpi .k-sub { color: var(--text-2); font-size: 12.5px; margin-top: 4px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.kpi.warn { border-color: color-mix(in srgb, var(--warn) 40%, var(--line)); }
.kpi.warn .k-value { color: var(--warn); }
.meter { height: 6px; border-radius: 6px; background: var(--accent-soft); overflow: hidden; margin-top: 10px; }
.meter > i { display: block; height: 100%; border-radius: 6px; background: var(--accent); }
.meter.over > i { background: var(--good); }

.delta { display: inline-flex; align-items: center; gap: 3px; height: 22px; padding: 0 8px; border-radius: 8px; font-size: 12.5px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.delta.pos { background: var(--good-soft); color: var(--good); }
.delta.neg { background: var(--bad-soft); color: var(--bad); }
.delta.zero { background: var(--surface-2); color: var(--text-2); }

.chip { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 8px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--text-2); }
.chip.winter { background: var(--chip-winter); color: var(--chip-winter-ink); }
.chip.summer { background: var(--chip-summer); color: var(--chip-summer-ink); }
.chip.up { background: var(--chip-up); color: var(--chip-up-ink); }
.chip.peak { background: var(--chip-peak); color: var(--chip-peak-ink); }
.chip.off { background: var(--chip-off); color: var(--chip-off-ink); }
.chip.accent { background: var(--accent-soft); color: var(--accent-text); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- table ---------- */
.table-scroll { overflow: auto; max-width: 100%; }
.table-scroll.tall { max-height: calc(100vh - 160px); }

table.t { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; }
table.t th, table.t td { padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; text-align: left; }
table.t thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface);
  color: var(--text-2); font-size: 12.5px; font-weight: 600; vertical-align: bottom;
  white-space: nowrap; line-height: 1.25; border-bottom: 1px solid var(--line-strong);
}
table.t th.num, table.t td.num { text-align: right; }
table.t th.c, table.t td.c { text-align: center; }
table.t tbody tr { transition: background 0.1s ease; }
table.t tbody tr:hover td { background: var(--surface-2); }
table.t td { background: var(--surface); }
table.t tbody tr:last-child td { border-bottom: none; }
table.t tfoot td { position: sticky; bottom: 0; z-index: 1; background: var(--surface-2); font-weight: 700; border-top: 1px solid var(--line-strong); border-bottom: none; }
table.t .sticky-col { position: sticky; left: 0; z-index: 1; }
table.t thead .sticky-col { z-index: 3; }
table.t tr.today td { background: var(--today); }
table.t tr.today td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
table.t tr.dim td { color: var(--text-3); }
table.t td.muted { color: var(--text-3); }
table.t td.we { color: var(--bad); font-weight: 600; }
table.t td.wrap { white-space: normal; min-width: 160px; }
table.t td.plan { cursor: pointer; }
table.t td.plan:hover { color: var(--accent-text); }
table.t td.edited { color: var(--accent-text); font-weight: 600; }
table.t td.edited::after { content: " ✎"; font-size: 11px; }
table.t tr.excluded td.fact { text-decoration: line-through; color: var(--text-3); }
table.t td.frozen { background: color-mix(in srgb, var(--accent-soft) 45%, var(--surface)); }
table.t .day { font-weight: 600; }
table.t .day small { color: var(--text-3); font-weight: 500; margin-left: 6px; }
table.t a.row-link { color: var(--text); font-weight: 600; }

.icon-btn { border: none; background: none; width: 30px; height: 30px; border-radius: 9px; display: inline-grid; place-items: center; color: var(--text-3); cursor: pointer; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.on { color: var(--bad); background: var(--bad-soft); }

.bar-cell { display: flex; align-items: center; gap: 10px; justify-content: flex-end; }
.bar-cell .track { width: 90px; height: 6px; border-radius: 6px; background: var(--accent-soft); overflow: hidden; flex: none; }
.bar-cell .track i { display: block; height: 100%; border-radius: 6px; background: var(--accent); }
.bar-cell .track.over i { background: var(--good); }
.bar-cell .track.gray i { background: var(--text-3); }

/* ---------- chart ---------- */
.chart { position: relative; width: 100%; user-select: none; }
.chart svg text { font: 11.5px system-ui, -apple-system, "Segoe UI", sans-serif; fill: var(--text-3); font-variant-numeric: tabular-nums; }
.chart .legend { display: flex; flex-wrap: wrap; gap: 16px; padding: 0 2px 8px; color: var(--text-2); font-size: 13px; }
.chart .legend span { display: inline-flex; align-items: center; gap: 8px; }
.chart .key-bar { width: 12px; height: 12px; border-radius: 3px; }
.chart .key-line { width: 18px; height: 0; border-top: 2.5px solid; border-radius: 2px; }
.chart .key-line.dash { border-top-style: dashed; }
.chart .tip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 180px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow-2); padding: 10px 12px; font-size: 12.5px; opacity: 0; transition: opacity 0.1s ease;
}
.chart .tip.show { opacity: 1; }
.chart .tip .t-head { color: var(--text-2); font-weight: 600; margin-bottom: 6px; }
.chart .tip .t-row { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.chart .tip .t-row b { margin-left: auto; padding-left: 16px; font-variant-numeric: tabular-nums; color: var(--text); }
.chart .tip .t-row i { width: 12px; height: 0; border-top: 2.5px solid; border-radius: 2px; }
.chart .tip .t-row i.box { height: 10px; border: none; border-radius: 3px; }
.chart .tip .t-row i.dash { border-top-style: dashed; }

/* ---------- heat cells ---------- */
.heat { border-radius: 8px; padding: 4px 8px; text-align: right; min-width: 92px; }
.heat .v { font-weight: 600; }
.heat .p { color: var(--text-3); font-size: 11.5px; }

/* ---------- calendar ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.cal-wd { color: var(--text-3); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; padding: 0 4px 2px; }
.cal-day {
  min-height: 96px; border-radius: 14px; background: var(--surface-2); padding: 8px 10px; cursor: pointer;
  border: 1px solid transparent; display: flex; flex-direction: column; gap: 6px; transition: border-color 0.15s ease, background 0.15s ease;
}
.cal-day:hover { border-color: var(--accent); background: var(--surface); }
.cal-day.empty { background: transparent; cursor: default; }
.cal-day.empty:hover { border-color: transparent; }
.cal-day.today { border-color: var(--accent); }
.cal-day .n { font-weight: 700; font-size: 15px; }
.cal-day.we .n { color: var(--bad); }
.cal-day .ev { font-size: 12px; color: var(--text); line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- list rows ---------- */
.list-row { display: flex; align-items: center; gap: 14px; padding: 12px 18px; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: none; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .title { font-weight: 600; }
.list-row .meta { color: var(--text-2); font-size: 12.5px; margin-top: 2px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px; flex: none; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 16px; }
.form-grid label, .lbl { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.form-grid .field, .form-grid .select, .form-grid .select select { width: 100%; max-width: none; }
.form-grid .full { grid-column: 1 / -1; }
.help { color: var(--text-3); font-size: 12.5px; font-weight: 400; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }
.ok { color: var(--good); }
.err { color: var(--bad); }

.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 14px; margin-bottom: 16px; font-size: 13.5px; }
.banner.info { background: var(--accent-soft); color: var(--text); }
.banner.info .ico { color: var(--accent-text); }
.banner.warn { background: var(--warn-soft); color: var(--text); }
.banner.warn .ico { color: var(--warn); }
.banner.bad { background: var(--bad-soft); }

.steps { display: flex; flex-direction: column; gap: 8px; }
.step { display: flex; gap: 10px; align-items: flex-start; }
.step .ico { margin-top: 1px; }
.step.ok .ico { color: var(--good); }
.step.fail .ico { color: var(--bad); }
.step b { display: block; }

.log { font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: var(--surface-2); border-radius: 12px; padding: 10px 12px; max-height: 200px; overflow: auto; white-space: pre-wrap; color: var(--text-2); }

.empty { text-align: center; padding: 56px 20px; color: var(--text-2); }
.empty .ico { margin: 0 auto 12px; color: var(--text-3); }
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 17px; }
.loading { padding: 80px 0; display: grid; place-items: center; color: var(--text-3); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--surface-3); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- drawer & dialog ---------- */
.overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 40; opacity: 0; transition: opacity 0.2s ease; }
.overlay.show { opacity: 1; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); z-index: 41;
  background: var(--surface); box-shadow: var(--shadow-2); display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.drawer.show { transform: none; }
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0; font-size: 17px; }
.drawer-head .sub { color: var(--text-2); font-size: 13px; margin-top: 2px; }
.drawer-head .icon-btn { margin-left: auto; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px 24px; }
.drawer-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.section-title { font-size: 12px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; margin: 18px 0 8px; }
.section-title:first-child { margin-top: 0; }
.mini-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mini-kpis div { background: var(--surface-2); border-radius: 12px; padding: 10px; }
.mini-kpis span { display: block; color: var(--text-2); font-size: 12px; }
.mini-kpis b { font-size: 15px; }
.basis-row { display: grid; grid-template-columns: 96px 1fr 72px; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; font-variant-numeric: tabular-nums; }
.basis-row:last-child { border-bottom: none; }
.basis-row .w { height: 6px; border-radius: 6px; background: var(--accent-soft); overflow: hidden; }
.basis-row .w i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.basis-row .r { text-align: right; color: var(--text-2); }

.dialog { position: fixed; z-index: 42; left: 50%; top: 18vh; transform: translate(-50%, 8px) scale(0.98); opacity: 0; width: min(440px, calc(100vw - 32px)); background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-2); transition: transform 0.18s ease, opacity 0.18s ease; }
.dialog.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
.dialog .d-body { padding: 20px 20px 8px; }
.dialog .d-body h3 { margin: 0 0 8px; font-size: 17px; }
.dialog .d-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px 16px; }


/* ---------- staff: grids, shifts, timesheet ---------- */
.sg-wrap { overflow: auto; max-width: 100%; max-height: calc(100vh - 150px); border-radius: 0 0 18px 18px; }
table.sg { border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; min-width: 100%; }
table.sg th, table.sg td { border-bottom: 1px solid var(--line); padding: 0 2px; height: 38px; text-align: center; min-width: 36px; background: var(--surface); }
table.sg thead th { position: sticky; top: 0; z-index: 2; height: 46px; font-size: 11px; color: var(--text-3); font-weight: 600; line-height: 1.1; border-bottom: 1px solid var(--line-strong); }
table.sg thead th .d { display: block; font-size: 13.5px; color: var(--text); font-weight: 700; margin-bottom: 1px; }
table.sg thead th.we .d { color: var(--bad); }
table.sg td.we, table.sg th.we { background: var(--weekend); }
table.sg thead th.today { color: var(--accent-text); }
table.sg thead th.today .d { color: #fff; background: var(--accent); border-radius: 8px; width: 26px; height: 22px; line-height: 22px; margin: 0 auto 1px; }
table.sg th.clickable { cursor: pointer; }
table.sg th.clickable:hover .d { color: var(--accent-text); }
table.sg .name { position: sticky; left: 0; z-index: 1; text-align: left; padding: 0 12px 0 16px; min-width: 220px; max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: 1px 0 0 var(--line); }
table.sg thead .name { z-index: 3; vertical-align: bottom; padding-bottom: 8px; font-size: 12px; color: var(--text-2); }
table.sg .tot { position: sticky; right: 0; z-index: 1; min-width: 92px; padding: 0 12px; text-align: right; box-shadow: -1px 0 0 var(--line); font-weight: 600; white-space: nowrap; }
table.sg thead .tot { z-index: 3; vertical-align: bottom; padding-bottom: 8px; }
table.sg tr.group td { background: var(--surface-2); height: 34px; font-weight: 700; font-size: 12.5px; color: var(--text-2); text-align: left; padding: 0 16px; }
table.sg tr.group td.name { color: var(--text); font-size: 13px; }
table.sg tr.cov td { height: 26px; background: var(--surface); border-bottom: 1px solid var(--line); }
table.sg tr.cov td.name { color: var(--text-3); font-size: 12px; font-weight: 500; }
table.sg tfoot td { position: sticky; bottom: 0; z-index: 1; background: var(--surface-2); font-weight: 700; font-size: 12px; border-top: 1px solid var(--line-strong); border-bottom: none; height: 34px; }
table.sg tfoot td.name, table.sg tfoot td.tot { z-index: 2; }
table.sg td.cell { cursor: pointer; }
table.sg td.cell:hover { background: var(--surface-2); }
table.sg td.na { background-image: repeating-linear-gradient(135deg, transparent 0 6px, var(--line) 6px 7px); }
table.sg td.past { opacity: 0.72; }
.emp-name { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; }
.emp-meta { display: flex; align-items: center; gap: 8px; color: var(--text-3); font-size: 11.5px; margin-top: 1px; }
.mini-meter { width: 64px; height: 4px; border-radius: 4px; background: var(--surface-3); overflow: hidden; flex: none; }
.mini-meter i { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.mini-meter.over i { background: var(--bad); }
.emp-cell { display: flex; flex-direction: column; justify-content: center; height: 100%; padding: 2px 0; }

.shift { position: relative; display: inline-grid; place-items: center; min-width: 28px; height: 24px; padding: 0 4px; border-radius: 7px; font-size: 12px; font-weight: 700; }
.shift.day { background: var(--sh-day); color: var(--sh-day-ink); }
.shift.eve { background: var(--sh-eve); color: var(--sh-eve-ink); }
.shift.full, .shift.all { background: var(--sh-full); color: var(--sh-full-ink); }
.shift.open { background: var(--bad-soft); color: var(--bad); }
.shift.ghost { background: transparent; color: var(--text-3); box-shadow: inset 0 0 0 1px var(--line-strong); }
.shift.manual::after { content: ""; position: absolute; top: -2px; right: -2px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--surface); }
.cover { font-size: 11px; font-weight: 700; }
.cover.ok { color: var(--good); }
.cover.short { color: var(--bad); }
.cover.over { color: var(--warn); }
.cover.none { color: var(--text-3); font-weight: 500; }

.need { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; height: 26px; padding: 0 5px; border-radius: 8px; font-size: 12px; font-weight: 700; color: var(--text); }
.need .sep { color: var(--text-3); font-weight: 700; margin: 0 2px; }
.need.zero { color: var(--text-3); font-weight: 500; }
.need .fd { font-size: 10px; margin-left: 3px; font-weight: 700; }
.need .fd.up { color: var(--bad); }
.need .fd.down { color: var(--good); }

.ts-v { position: relative; display: inline-grid; place-items: center; min-width: 32px; height: 24px; padding: 0 3px; border-radius: 7px; font-size: 12px; font-weight: 600; }
.ts-v.plan { color: var(--text-3); font-weight: 600; box-shadow: inset 0 0 0 1px var(--line-strong); }
.ts-v.absent { background: var(--bad-soft); color: var(--bad); }
.ts-v.unplanned { background: var(--chip-off); color: var(--chip-off-ink); }
.ts-v.diff { background: var(--warn-soft); color: var(--warn); }
.ts-v.open { background: var(--good-soft); color: var(--good); }
.ts-v.manual::after { content: ""; position: absolute; top: -2px; right: -2px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--surface); }

.legend-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; color: var(--text-2); font-size: 12.5px; padding: 10px 18px 0; }
.legend-row span.k { display: inline-flex; align-items: center; gap: 7px; }

/* popover menu */
.pop { position: fixed; z-index: 45; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-2); border: 1px solid var(--line); padding: 6px; min-width: 220px; max-width: min(320px, calc(100vw - 16px)); max-height: min(70vh, 520px); overflow-y: auto; opacity: 0; transform: translateY(4px) scale(0.98); transition: opacity 0.12s ease, transform 0.12s ease; }
.pop.show { opacity: 1; transform: none; }
.pop .pop-title { font-size: 12px; color: var(--text-2); padding: 6px 10px 4px; font-weight: 600; }
.pop .item { display: flex; align-items: center; gap: 10px; width: 100%; border: none; background: none; padding: 8px 10px; border-radius: 10px; cursor: pointer; text-align: left; font-size: 13.5px; color: var(--text); }
.pop .item:hover { background: var(--surface-2); }
.pop .item.on { background: var(--accent-soft); color: var(--accent-text); }
.pop .item .grow { flex: 1; min-width: 0; }
.pop .item .hint { color: var(--text-3); font-size: 12px; }
.pop .item.danger { color: var(--bad); }
.pop .sep { height: 1px; background: var(--line); margin: 4px 6px; }

/* toggle chips (multi-select) */
.tchips { display: flex; flex-wrap: wrap; gap: 6px; }
.tchips button { height: 30px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text-2); font-weight: 600; font-size: 13px; cursor: pointer; }
.tchips button:hover { border-color: var(--accent); color: var(--text); }
.tchips button.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* roles list */
.role-row { display: grid; grid-template-columns: minmax(180px, 1.3fr) minmax(200px, 2fr) 110px 120px 28px; gap: 12px; align-items: center; padding: 12px 18px; border-top: 1px solid var(--line); cursor: pointer; }
.role-row:hover { background: var(--surface-2); }
.role-row .t { font-weight: 600; }
.role-row .m { color: var(--text-2); font-size: 12.5px; }
.role-row .ico { color: var(--text-3); }
.div-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px 6px; font-size: 12px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; }
.div-head:first-child { padding-top: 4px; }
.div-head .icon-btn { width: 26px; height: 26px; }
.rule-box { background: var(--surface-2); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.win-grid { display: grid; grid-template-columns: 120px repeat(var(--cols, 2), minmax(0, 1fr)); gap: 8px 10px; align-items: center; }
.win-grid .h { font-size: 12px; color: var(--text-2); font-weight: 600; }
.win-grid .field { width: 100%; }
.place-row { display: grid; grid-template-columns: 22px 1fr 96px; gap: 10px; align-items: center; padding: 4px 0; }
.place-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.suggest { border: 1px dashed var(--accent); background: var(--accent-soft); border-radius: 14px; padding: 12px 14px; font-size: 13px; }
.suggest b { color: var(--accent-text); }
.mini-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.mini-cal .wd { font-size: 11px; color: var(--text-3); text-align: center; font-weight: 600; }
.mini-cal button { height: 32px; border-radius: 8px; border: 1px solid transparent; background: var(--surface-2); cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--text); }
.mini-cal button:hover { border-color: var(--accent); }
.mini-cal button.on { background: var(--bad-soft); color: var(--bad); border-color: var(--bad); }
.mini-cal button.we { color: var(--bad); }
.mini-cal span.blank { height: 32px; }
.hour-bars { display: grid; gap: 3px; align-items: end; height: 120px; }
.hour-bars .b { background: var(--accent); border-radius: 4px 4px 0 0; min-height: 1px; position: relative; }
.hour-bars .b.f { background: var(--series-2); }
.hours-axis { display: grid; gap: 3px; font-size: 10.5px; color: var(--text-3); text-align: center; margin-top: 4px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; background: rgba(28, 32, 38, 0.94); color: #fff; padding: 11px 16px; border-radius: 14px; box-shadow: var(--shadow-2); font-weight: 500; max-width: min(520px, 92vw); animation: toast-in 0.2s ease; }
.toast.error { background: #c43a3a; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- tabbar (mobile) ---------- */
.tabbar { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 16px 14px calc(88px + env(safe-area-inset-bottom)); }
  .page-head h1 { font-size: 21px; }
  .page-head .actions { margin-left: 0; width: 100%; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px);
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--text-2); padding: 4px 0; text-decoration: none; }
  .tabbar a.active { color: var(--accent-text); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .k-value { font-size: 19px; }
  .cal-grid { gap: 4px; }
  .cal-day { min-height: 64px; padding: 6px; border-radius: 10px; }
  .cal-day .ev { display: none; }
  .stepper .label { min-width: 104px; }
  .select select { max-width: 220px; }
  table.sg .name { min-width: 150px; max-width: 170px; padding-left: 10px; }
  table.sg .tot { display: none; }
  .role-row { grid-template-columns: 1fr auto; }
  .role-row .m.rule, .role-row .m.rate { display: none; }
  .sg-wrap { max-height: calc(100vh - 210px); }
}
