:root {
  --bg: #f4f6f7; --panel: #ffffff; --ink: #16202a; --muted: #5d6b78; --line: #dde3e8;
  --accent: #0f4c5c; --accent-ink: #ffffff; --accent-soft: #e3eff2;
  --good: #1f7a4d; --good-soft: #e2f3ea; --warn: #9a6200; --warn-soft: #fbf0d9;
  --bad: #b3261e; --bad-soft: #fbe6e4; --info: #2b5c9e; --info-soft: #e4edf9;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.shell { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.side { background: var(--accent); color: #fff; padding: 20px 12px; display: flex; flex-direction: column; gap: 4px; }
.brand { font-weight: 700; font-size: 1.15rem; padding: 0 10px 16px; }
.side a { color: #dbe9ec; text-decoration: none; padding: 9px 10px; border-radius: 6px; }
.side a:hover { background: rgba(255,255,255,.1); color: #fff; }
.side a.on { background: #fff; color: var(--accent); font-weight: 600; }
.side .who { margin-top: auto; font-size: .8rem; color: #c3d8dc; padding: 10px; word-break: break-all; }
.side .who button { margin-top: 6px; }
.env { margin: 0 10px 10px; font-size: .75rem; padding: 3px 8px; border-radius: 99px; background: #ffd98a; color: #4a3200; align-self: flex-start; font-weight: 600; }
main { padding: 26px 30px 60px; min-width: 0; max-width: 1180px; }
.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.head .grow { flex: 1; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; }
.grid { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.two { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
.stats { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .k { color: var(--muted); font-size: .8rem; }
.stat .v { font-size: 1.55rem; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .s { color: var(--muted); font-size: .8rem; }
.stat.bad .v { color: var(--bad); }

label { display: flex; flex-direction: column; gap: 4px; font-size: .8rem; color: var(--muted); font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); font-size: .9rem; }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #c3ccd4; border-radius: 6px; padding: 8px 10px; width: 100%; min-width: 0; }
input[type=checkbox] { width: auto; }
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.hint { font-size: .8rem; color: var(--muted); font-weight: 400; }

button, .btn { font: inherit; font-weight: 600; cursor: pointer; border-radius: 6px; padding: 8px 14px; border: 1px solid #c3ccd4; background: #fff; color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { background: #f0f3f5; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover, .btn.primary:hover { background: #0b3a47; }
button.danger { color: var(--bad); border-color: #e3b5b1; }
button.small { padding: 4px 9px; font-size: .82rem; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 500; text-decoration: underline; }
button:disabled { opacity: .55; cursor: wait; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: #f7f9fa; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 34px 10px; }

.pill { display: inline-block; font-size: .75rem; font-weight: 650; padding: 2px 9px; border-radius: 99px; white-space: nowrap; background: #e9edf0; color: #44505c; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }

.rows input, .rows select { padding: 6px 8px; }
.rows td { padding: 5px 4px; border: 0; vertical-align: top; }
.rows th { padding: 6px 4px; }
.rows .w-s { width: 78px; } .rows .w-m { width: 104px; } .rows .w-x { width: 36px; }
.totals { margin-left: auto; width: 290px; max-width: 100%; margin-top: 12px; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; font-variant-numeric: tabular-nums; }
.totals .sum { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 8px; font-weight: 700; font-size: 1.1rem; }

.note { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 18px; white-space: pre-line; border: 1px solid; }
.note.warn { background: var(--warn-soft); border-color: #ecd49b; color: #5c3b00; }
.note.bad { background: var(--bad-soft); border-color: #eebfbb; color: #7c1a14; }
.note.info { background: var(--info-soft); border-color: #bcd0ee; color: #1c3f73; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; }
.pdf { width: 100%; height: 760px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.history { list-style: none; margin: 0; padding: 0; font-size: .87rem; }
.history li { padding: 6px 0; border-bottom: 1px solid var(--line); } .history li:last-child { border: 0; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 130px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; height: 100%; min-width: 0; }
.bars .fill { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; }
.bars .lbl { font-size: .7rem; color: var(--muted); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .panel { width: 380px; max-width: 100%; text-align: center; padding: 34px 28px; }
.login h1 { margin-bottom: 6px; } .login p { color: var(--muted); margin: 0 0 22px; }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; max-width: 90vw; white-space: pre-line; z-index: 20; box-shadow: 0 6px 24px rgba(0,0,0,.25); }
#toast.bad { background: var(--bad); }
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 22px; width: 640px; max-width: calc(100vw - 30px); }
dialog::backdrop { background: rgba(15, 30, 40, .45); }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .brand { padding: 0 10px 0 6px; } .side .who { margin: 0 0 0 auto; padding: 0 6px; } .env { margin: 0; }
  main { padding: 18px 16px 50px; }
  .two { grid-template-columns: 1fr; }
  .pdf { height: 520px; }
}
