:root {
  --brand: #1d4f91; --brand-dark: #163e73; --bg: #fff; --panel: #fbfbfc; --border: #e1e3e8; --border-strong: #c9ccd3;
  --text: #1d1f25; --text-2: #4c505a; --muted: #7a7f8a; --row-hover: #f5f7fb; --accent: #166ee1; --danger: #c4314b;
  --good: #0d7a3a; --warn: #9a5b00; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 16px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

.shell { display: flex; flex-direction: column; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 12px 0 14px; background: var(--brand); color: #fff; flex: none; }
.topbar img { width: 26px; height: 26px; border-radius: 6px; background: #fff; }
.topbar .title { font-weight: 650; font-size: 16px; }
.topbar .spacer { flex: 1; }
.topbar .who { opacity: .9; font-size: 12px; }
.topbar button { border: 0; background: rgba(255,255,255,.14); color: #fff; padding: 5px 10px; border-radius: 6px; }
.topbar button:hover { background: rgba(255,255,255,.24); }
.tabs { display: flex; align-items: flex-end; gap: 2px; padding: 0 10px; background: var(--brand-dark); height: 36px; overflow-x: auto; flex: none; }
.tabs button { border: 0; background: transparent; color: rgba(255,255,255,.85); padding: 7px 14px; border-radius: 6px 6px 0 0; white-space: nowrap; font-weight: 500; }
.tabs button:hover { background: rgba(255,255,255,.1); color: #fff; }
.tabs button.active { background: var(--bg); color: var(--text); font-weight: 600; }
.tabs .count { opacity: .7; font-weight: 400; margin-left: 4px; }

.toolbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid var(--border); flex: none; }
.toolbar .spacer { flex: 1; }
.toolbar h2 { font-size: 15px; margin: 0 8px 0 0; }
.search, .input, select.input { border: 1px solid var(--border-strong); border-radius: 6px; padding: 5px 8px; background: #fff; }
.search { width: 200px; }
.chip { border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; color: var(--text-2); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip .n { opacity: .7; margin-left: 4px; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); background: #fff; padding: 6px 12px; border-radius: 6px; font-weight: 500; white-space: nowrap; }
.btn:hover { background: #f4f5f7; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #105bc0; }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

.scroll { flex: 1; overflow: auto; min-height: 0; }
.footer { border-top: 1px solid var(--border); padding: 5px 12px; font-size: 12px; color: var(--muted); background: var(--panel); flex: none; }
.pad { padding: 14px 16px; }

table.grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
.grid th, .grid td { height: 32px; padding: 0 9px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); white-space: nowrap; text-align: left; vertical-align: middle; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.grid thead th { position: sticky; top: 0; z-index: 3; background: #f4f5f7; font-weight: 600; color: var(--text-2); font-size: 12px; cursor: pointer; user-select: none; }
.grid thead th.nosort { cursor: default; }
.grid thead th .arrow { color: #8a4300; margin-left: 3px; }
.grid tbody tr:hover td { background: var(--row-hover); }
.grid td.sticky, .grid th.sticky { position: sticky; left: 0; z-index: 2; background: #fff; border-right: 2px solid var(--border-strong); font-weight: 600; }
.grid thead th.sticky { z-index: 4; background: #f4f5f7; }
.grid tbody tr:hover td.sticky { background: var(--row-hover); }
.grid td.edit { cursor: text; }
.grid td.edit:hover { box-shadow: inset 0 0 0 2px #9cc1f5; }
.grid td.ro { background: #eceef2; color: #555a65; }
.grid tbody tr:hover td.ro { background: #e1e5ec; }
.grid td.edit { background: #fff; }
.grid thead th.ro { background: #e2e5ea; color: #6b707b; }
.grid thead th.can { background: #dceafc; color: var(--brand-dark); box-shadow: inset 0 -2px 0 var(--accent); }
.fbtn { display: inline-block; margin-left: 5px; padding: 0 4px; border-radius: 3px; color: #8d939e; font-size: 10px; line-height: 16px; }
.fbtn:hover { background: #cfd5df; color: var(--text); }
.fbtn.on { background: var(--accent); color: #fff; }
.key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin: 0 4px 0 10px; border: 1px solid var(--border-strong); }
.key.can { background: #fff; box-shadow: inset 0 -2px 0 var(--accent); }
.key.ro { background: #eceef2; }
.legend-inline { white-space: nowrap; margin-left: 6px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.grid thead th.can::before { content: "✎ "; color: var(--accent); }
.fchips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 6px 12px; border-bottom: 1px solid var(--border); background: #f6f9fe; font-size: 12px; color: var(--text-2); flex: none; }
.fchip { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid #b9d0f3; border-radius: 999px; padding: 2px 4px 2px 10px; }
.fchip b { cursor: pointer; color: var(--muted); font-weight: 400; padding: 0 5px; border-radius: 50%; }
.fchip b:hover { background: #fdecee; color: var(--danger); }
.pop { position: fixed; z-index: 60; width: 290px; background: #fff; border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: var(--shadow); padding: 10px; display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; }
.pop-h { font-weight: 650; color: var(--brand-dark); }
.pop .search { width: 100%; }
.pop-acts { display: flex; gap: 14px; font-size: 12px; }
.pop-list { max-height: 280px; overflow: auto; display: flex; flex-direction: column; }
.pop-list.tall { max-height: 420px; }
.pop-list label { display: flex; align-items: center; gap: 7px; padding: 3px 2px; border-radius: 4px; cursor: pointer; }
.pop-list label:hover { background: var(--row-hover); }
.pop-list label > span:first-of-type { flex: 1; }
.pop-sep { margin: 8px 0 3px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; }
.pop-range { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pop-range input { border: 1px solid var(--border-strong); border-radius: 5px; padding: 4px 6px; width: 110px; }
.pop-f { display: flex; gap: 6px; border-top: 1px solid var(--border); padding-top: 8px; }
.pop-f .spacer { flex: 1; }
.grid td select, .grid td input { width: 100%; border: 1px solid #6ea2ea; border-radius: 4px; padding: 3px 4px; background: #fff; }
.grid td.group { background: #eef2f8; font-weight: 600; color: var(--brand-dark); }
.link { color: var(--accent); cursor: pointer; }
.link:hover { text-decoration: underline; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: #eef0f4; color: var(--text-2); }
.p1 { background: #d8f3e2; color: #0b5a2b; }
.p2 { background: #fde2c8; color: #8a4300; }
.p3 { background: #dbe8fd; color: #163e73; }
.p4 { background: #efe6fd; color: #4b2a8c; }
.p5 { background: #eef0f4; color: #4c505a; }
.psale { background: #fff3c4; color: #6b5200; }
.pdone { background: #f0f1f3; color: #8a8f99; }
.phold { background: #fbdde2; color: #8c1d33; }
.s-done { color: var(--good); font-weight: 600; }
.s-almost { color: #2a7f62; }
.s-ongoing { color: #1d4f91; }
.s-pending { color: var(--muted); }
.s-pause, .s-retrofit { color: var(--danger); }
.late { color: var(--danger); font-weight: 600; }
.ok { color: var(--good); }
.warn { color: var(--warn); }
.bar { display: inline-block; width: 60px; height: 8px; background: #eceef2; border-radius: 4px; vertical-align: middle; margin-right: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: #4caf7a; }
.flag { display: inline-block; margin-right: 4px; padding: 0 6px; border-radius: 4px; background: #fdecee; color: #8c1d33; font-size: 11px; }

.cards { display: flex; gap: 10px; flex-wrap: wrap; padding: 12px; border-bottom: 1px solid var(--border); flex: none; }
.card { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; min-width: 150px; background: #fff; cursor: pointer; }
.card.on { outline: 2px solid var(--brand); }
.card .k { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; }
.card .v { font-size: 22px; font-weight: 700; margin-top: 2px; }
.card .d { font-size: 12px; color: var(--text-2); }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 190px; padding: 12px 16px 0; border-bottom: 1px solid var(--border); }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 34px; }
.chart .stack { width: 70%; display: flex; flex-direction: column-reverse; }
.chart .stack i { display: block; width: 100%; }
.chart .lbl { font-size: 11px; color: var(--muted); padding: 4px 0; white-space: nowrap; }
.chart .val { font-size: 10.5px; color: var(--text-2); margin-bottom: 2px; white-space: nowrap; }
.legend { display: flex; gap: 14px; padding: 6px 16px; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.35); display: flex; justify-content: flex-end; z-index: 50; }
.drawer { width: min(860px, 100vw); height: 100%; background: #fff; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.drawer header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.drawer header h3 { margin: 0; font-size: 17px; }
.drawer .body { overflow: auto; padding: 12px 16px 30px; }
.drawer section { margin-bottom: 18px; }
.drawer h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 14px; }
.field label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 2px; }
.field .val { min-height: 28px; padding: 4px 7px; border: 1px solid transparent; border-radius: 5px; }
.field .val.edit { border-color: var(--border); cursor: text; }
.field .val.edit:hover { border-color: #9cc1f5; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid #6ea2ea; border-radius: 5px; padding: 4px 7px; }
.field.wide { grid-column: 1 / -1; }
.explain { background: #f6f8fb; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; line-height: 1.6; }
.scopes { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 4px 14px; }
.scopes .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-bottom: 1px dashed var(--border); padding: 3px 0; }
.scopes select { border: 1px solid var(--border-strong); border-radius: 4px; padding: 1px 4px; }
.act { font-size: 12px; border-bottom: 1px solid var(--border); padding: 5px 0; }

.login { max-width: 360px; margin: 10vh auto; border: 1px solid var(--border); border-radius: 10px; padding: 24px; box-shadow: var(--shadow); }
.login h1 { font-size: 18px; margin: 0 0 4px; }
.login input { width: 100%; margin: 6px 0 10px; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 6px; }
.login .err { color: var(--danger); min-height: 18px; }
.form-grid { display: grid; grid-template-columns: 260px 140px 1fr; gap: 6px 12px; align-items: center; max-width: 900px; }
.form-grid input { width: 120px; }
.form-grid .h { font-weight: 650; grid-column: 1 / -1; margin-top: 12px; color: var(--brand-dark); }

.toast-root, #toast-root { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: 6px; }
.toast { background: #1d1f25; color: #fff; padding: 8px 14px; border-radius: 8px; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }
