:root {
  --bg: #F4F6F9; --surface: #FFFFFF; --sunk: #EEF1F5; --fg: #18233A; --muted: #5A657B; --line: #D9DEE7;
  --field: #7D879A;
  --navy: #1B2A4A; --navy-ink: #FFFFFF; --gold: #A97C22; --gold-soft: #F5EBD6;
  --ok: #1E7A4C; --ok-soft: #DFF2E7; --warn: #9A6100; --warn-soft: #FBEFD6; --bad: #B3261E; --bad-soft: #FBE3E1;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: Consolas, "Cascadia Mono", ui-monospace, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; color: var(--muted); }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login form { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login h1 { margin: 0; font-size: 22px; color: var(--navy); }
.login h1 span { color: var(--gold); }

/* shell */
.shell { display: grid; grid-template-columns: 210px 1fr; min-height: 100%; }
.side { background: var(--navy); color: var(--navy-ink); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 14px; }
.brand span { color: #DDB35E; }
.side .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .55; padding: 12px 10px 4px; }
.side a { color: inherit; text-decoration: none; padding: 7px 10px; border-radius: 6px; opacity: .85; }
.side a:hover { background: rgba(255,255,255,.08); opacity: 1; }
.side a.on { background: rgba(255,255,255,.16); opacity: 1; font-weight: 600; }
.side .who { margin-top: auto; padding: 12px 10px 4px; font-size: 12px; opacity: .8; display: flex; flex-direction: column; gap: 6px; }
.side .who button { background: transparent; border: 1px solid rgba(255,255,255,.35); color: inherit; border-radius: 6px; padding: 4px 8px; cursor: pointer; text-align: left; }
.main { padding: 22px 26px 60px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.menu-btn { display: none; }
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .shell.open .side { transform: none; }
  .menu-btn { display: inline-block; }
  .main { padding: 14px 16px 60px; }
}

h1.page { margin: 0; font-size: 22px; }
.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.bar .left, .bar .right { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); }

.btn { border: 1px solid var(--navy); background: var(--navy); color: var(--navy-ink); border-radius: 7px; padding: 7px 14px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn.ghost { background: var(--surface); color: var(--fg); border-color: var(--line); font-weight: 500; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #1B2A4A; }
.btn.danger { background: var(--surface); color: var(--bad); border-color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.link { background: none; border: 0; padding: 0; color: var(--navy); text-decoration: underline; cursor: pointer; }

input, select, textarea { border: 1.5px solid var(--field); border-radius: 7px; padding: 8px 10px; background: var(--surface); min-width: 0; }
input:hover, select:hover, textarea:hover { border-color: var(--navy); }
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); outline: none; }
input:disabled, select:disabled, textarea:disabled { background: var(--sunk); border-color: var(--line); color: var(--fg); }
input::placeholder, textarea::placeholder { color: #8A93A5; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--navy); }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 14px; font-weight: 600; color: var(--fg); }
label.f > input, label.f > select, label.f > textarea { color: var(--fg); font-size: 15px; font-weight: 400; }
label.chk { display: flex; gap: 8px; align-items: center; font-weight: 500; color: var(--fg); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 600px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: inherit; }
.tile b { font-size: 24px; font-variant-numeric: tabular-nums; }
.tile span { color: var(--muted); font-size: 12.5px; }

.tablewrap { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--sunk); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
/* adjustable columns */
th .rz { position: absolute; top: 0; right: -4px; bottom: 0; width: 9px; cursor: col-resize; z-index: 2; touch-action: none; }
th .rz::after { content: ""; position: absolute; top: 20%; bottom: 20%; left: 4px; width: 1px; background: var(--field); opacity: .45; }
th .rz:hover::after, body.resizing th .rz::after { background: var(--gold); opacity: 1; width: 2px; top: 0; bottom: 0; }
th:last-child .rz { right: 0; }
table.fixed { table-layout: fixed; }
table.fixed th { overflow: hidden; text-overflow: ellipsis; }
table.fixed td { overflow-wrap: anywhere; }
body.resizing, body.resizing * { cursor: col-resize !important; user-select: none; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--sunk); }
td.num, th.num { text-align: right; }
tr.off td { color: var(--muted); }
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--sunk); white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.gold { background: var(--gold-soft); color: var(--gold); }
.code { font-family: var(--mono); font-size: 13px; white-space: nowrap; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

dialog { border: 0; border-radius: 12px; padding: 0; width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 20px 60px rgba(10,20,40,.3); }
dialog::backdrop { background: rgba(15,25,45,.45); }
dialog form, dialog .dbody { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
dialog h2 { margin: 0; font-size: 21px; color: var(--navy); }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding-top: 4px; }
.err { color: var(--bad); background: var(--bad-soft); border-radius: 7px; padding: 8px 12px; }
.note { background: var(--gold-soft); border-radius: 7px; padding: 8px 12px; }
.lines { display: flex; flex-direction: column; gap: 8px; }
.line { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; align-items: end; border-bottom: 1px dashed var(--line); padding-bottom: 8px; }
[hidden] { display: none !important; }
.preview { font-family: var(--mono); background: var(--sunk); border-radius: 6px; padding: 6px 10px; }

.tabs-row { display: flex; gap: 4px; border-bottom: 2px solid var(--line); flex-wrap: wrap; }
.tabb { background: none; border: 0; border-bottom: 3px solid transparent; margin-bottom: -2px; padding: 8px 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabb.on { color: var(--navy); border-bottom-color: var(--gold); }
.tabb:hover { color: var(--navy); }
#ctb input, #ctb select { min-width: 90px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: var(--navy-ink); padding: 10px 18px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 100; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; }
#toast.bad { background: var(--bad); }
