:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #5d6779;
  --line: #e2e6ec;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --accent-soft: #e6eff6;
  --good: #1e7a4c;
  --good-soft: #e5f4ec;
  --warn: #9a5b00;
  --warn-soft: #fdf2df;
  --bad: #b3261e;
  --bad-soft: #fbe9e7;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1.2rem 0 .5rem; }
p { line-height: 1.5; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--bad); }
.pos { color: var(--good); }

/* Layout */
.app { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.sidebar { background: #16324a; color: #dbe6ef; display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 1.05rem; line-height: 1.25; padding: 0 8px 18px; color: #fff; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav button { all: unset; cursor: pointer; padding: 9px 10px; border-radius: 6px; color: #dbe6ef; display: flex; justify-content: space-between; align-items: center; }
nav button:hover { background: rgba(255,255,255,.08); }
nav button.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
nav .badge { background: #e8a33d; color: #1d2433; border-radius: 10px; font-size: .75rem; padding: 1px 7px; font-weight: 700; }
.part-pick { padding: 0 8px 16px; }
.part-pick label { display: flex; flex-direction: column; gap: 4px; font-size: .75rem; color: #9fb5c8; text-transform: uppercase; letter-spacing: .04em; }
.part-pick select { width: 100%; font-size: .9rem; text-transform: none; letter-spacing: 0; padding: 6px 8px; border-radius: 6px; border: 1px solid rgba(255,255,255,.3); background: #0f2537; color: #fff; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 8px; }
.save-state { font-size: .8rem; color: #9fb5c8; min-height: 1.2em; }
.sidebar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.35); }
main { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 28px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.period-picker { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
.view { padding: 22px 28px 60px; max-width: 1200px; }

/* Controls */
.btn { font: inherit; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); padding: 7px 14px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--panel); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--accent); border-color: var(--line); }
.btn.danger { background: var(--panel); color: var(--bad); border-color: #e7b9b5; }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.btn.link { background: none; border: none; color: var(--accent); padding: 2px 4px; text-decoration: underline; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #c9d0da; border-radius: 6px; background: #fff; color: var(--ink); max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #8fb6d4; outline-offset: 0; border-color: var(--accent); }
input[type=checkbox] { width: 16px; height: 16px; vertical-align: middle; }
textarea { width: 100%; min-height: 110px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
label.field > span { font-weight: 500; }
label.check { display: flex; gap: 8px; align-items: flex-start; padding: 5px 0; line-height: 1.4; }
.grid { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.grid .wide { grid-column: 1 / -1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }

/* Panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card .label { font-size: .8rem; color: var(--muted); }
.card .value { font-size: 1.35rem; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.card .sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }

.notice { border-radius: 6px; padding: 9px 12px; margin: 6px 0; line-height: 1.4; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--accent-soft); color: #164766; }
.notice.good { background: var(--good-soft); color: var(--good); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }

/* Tables */
table { border-collapse: collapse; width: 100%; background: var(--panel); }
th, td { padding: 7px 9px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; background: #fafbfc; position: sticky; top: 0; }
tr.total td { font-weight: 700; border-top: 2px solid var(--ink); }
tr.sub td { font-weight: 600; background: #fafbfc; }
td.actions { white-space: nowrap; text-align: right; }
.table-wrap { border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; max-height: 70vh; }
.table-wrap table { border: none; }
td select.inline { padding: 3px 5px; font-size: .85rem; max-width: 230px; }
tr.uncat td { background: #fffaf0; }
.tag { display: inline-block; font-size: .72rem; padding: 1px 7px; border-radius: 10px; background: var(--accent-soft); color: #164766; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.good { background: var(--good-soft); color: var(--good); }
.tag.bad { background: var(--bad-soft, #fde8e8); color: var(--bad, #b42318); font-weight: 600; }

/* Modal */
dialog { border: none; border-radius: 10px; padding: 0; width: min(720px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 25, 40, .45); }
dialog form { padding: 20px 22px; }
dialog h2 { margin-top: 0; }
dialog .row.end { margin-top: 18px; }
.preview { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; margin: 10px 0; font-size: .82rem; }

/* Lock screen */
.lock { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #16324a, #1f5f8b); }
.lock .box { background: var(--panel); border-radius: 12px; padding: 30px 32px; width: min(440px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.lock h1 { margin-bottom: 6px; }
.lock form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.lock .err { color: var(--bad); min-height: 1.2em; font-size: .9rem; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1d2433; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.toast.bad { background: var(--bad); }

/* Report */
.report { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 28px 34px; }
.report h2 { border-bottom: 2px solid var(--ink); padding-bottom: 4px; margin-top: 1.8rem; }
.report h2:first-of-type { margin-top: .5rem; }
.report table { margin: 6px 0 4px; }
.report th { position: static; }
.report .fig { display: inline-block; min-width: 1.6em; padding: 0 5px; border: 1.5px solid var(--ink); border-radius: 4px; text-align: center; font-weight: 700; font-size: .85rem; margin-left: 6px; }
.report .kv { display: grid; grid-template-columns: 220px 1fr; gap: 4px 14px; }
.report .kv div:nth-child(odd) { color: var(--muted); }
.report .indent td:first-child { padding-left: 26px; color: var(--muted); }
.sigline { border-bottom: 1px solid var(--ink); height: 34px; }
.sig { display: grid; grid-template-columns: 1fr 1fr 160px; gap: 24px; margin-top: 18px; font-size: .85rem; color: var(--muted); }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .view, .topbar { padding-left: 16px; padding-right: 16px; }
  .report { padding: 18px; }
  .report .kv { grid-template-columns: 1fr; }
}

@media print {
  body { background: #fff; }
  .sidebar, .topbar, .no-print, .toast { display: none !important; }
  .app { display: block; }
  .view { padding: 0; max-width: none; }
  .report { border: none; padding: 0; font-size: 11pt; }
  .report h2 { break-after: avoid; }
  .report table { break-inside: auto; }
  .report tr { break-inside: avoid; }
  .page-break { break-before: page; }
}
.compact th, .compact td { padding: 6px 7px; font-size: .86rem; }
.compact td:first-child { min-width: 120px; }

/* Accounts & security */
.who { color: #fff; font-size: .9rem; line-height: 1.3; }
.who span { color: #9fb5c8; font-size: .78rem; }
.qr { width: 190px; height: 190px; margin: 6px 0 4px; }
.qr svg { width: 100%; height: 100%; }
code.key { font-size: .95rem; letter-spacing: .04em; background: var(--accent-soft); padding: 2px 6px; border-radius: 4px; color: var(--ink); }
.fingerprint { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 1.25rem; letter-spacing: .08em; background: var(--accent-soft); padding: 12px 14px; border-radius: 8px; text-align: center; word-spacing: .3em; }
input.copy { width: 100%; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }
.lock .box h3 { margin: 1rem 0 .3rem; }
