:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #16202c;
  --muted: #5b6776;
  --line: #dde2e8;
  --brand: #1f5fd1;
  --brand-ink: #ffffff;
  --good: #137a3f;
  --good-bg: #e6f5ec;
  --bad: #b42318;
  --bad-bg: #fdecea;
  --warn-bg: #fff6e0;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #171e26;
    --text: #e6ebf1;
    --muted: #9aa6b4;
    --line: #2a3440;
    --brand: #5b8ff0;
    --brand-ink: #0b1220;
    --good: #5fd08f;
    --good-bg: #12301f;
    --bad: #ff8a80;
    --bad-bg: #3a1714;
    --warn-bg: #3a2f12;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); }
h1 { font-size: clamp(1.7rem, 4vw, 2.6rem); line-height: 1.15; margin: 0 0 .6rem; }
h2 { font-size: 1.35rem; margin: 2rem 0 .6rem; }
h3 { margin: 0 0 .4rem; }
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
main { min-height: 70vh; padding-bottom: 3rem; }
main > section { margin-top: 2rem; }

.top { background: var(--surface); border-bottom: 1px solid var(--line); }
.nav { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 58px; flex-wrap: wrap; }
.brand { display: flex; gap: .45rem; align-items: center; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.nav nav { display: flex; gap: 1.1rem; flex-wrap: wrap; }
.nav nav a { color: var(--muted); text-decoration: none; }
.nav nav a:hover { color: var(--text); }

.foot { border-top: 1px solid var(--line); color: var(--muted); font-size: .88rem; padding: 1.5rem 0; }
.foot a { color: var(--muted); }

.hero { padding: 3.5rem 0 1rem; }
.eyebrow { color: var(--brand); font-weight: 600; margin: 0 0 .6rem; }
.lead { font-size: 1.15rem; color: var(--muted); max-width: 720px; }
.lead.small { font-size: 1rem; }
.cta { display: flex; gap: .7rem; flex-wrap: wrap; margin: 1.4rem 0 .4rem; }
.fine { color: var(--muted); font-size: .88rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .62rem 1.1rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); text-decoration: none; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.big { padding: .85rem 1.6rem; font-size: 1.05rem; }
.btn.small { padding: .35rem .7rem; font-size: .9rem; }
.btn:disabled { opacity: .6; cursor: wait; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.3rem; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }
.prose { max-width: 780px; }
.formats dt { font-weight: 700; margin-top: .7rem; }
.formats dd { margin: .1rem 0 0; color: var(--muted); }
.price { font-size: 2rem; font-weight: 700; margin: .2rem 0; }

/* Form */
.form fieldset { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem 1.2rem; margin: 0 0 1.2rem; }
.form legend { font-weight: 700; padding: 0 .4rem; }
.row { display: flex; gap: .8rem; flex-wrap: wrap; }
.row > label { flex: 2 1 200px; }
.row > label.s { flex: 1 1 120px; }
label { display: block; font-size: .88rem; color: var(--muted); margin-bottom: .7rem; }
input, select, textarea { display: block; width: 100%; margin-top: .25rem; padding: .55rem .6rem; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); color: var(--text); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.hint { color: var(--muted); font-size: .88rem; margin: -.2rem 0 1rem; }
.lines { width: 100%; border-collapse: collapse; margin-bottom: .6rem; }
.lines th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: 0 .3rem .3rem; }
.lines td { padding: .2rem .3rem; vertical-align: middle; }
.lines td:nth-child(1) { width: 44%; }
.lines .amt { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.lines input, .lines select { margin: 0; }
.del { border: 0; background: none; color: var(--muted); font-size: 1.3rem; cursor: pointer; }
.totals { margin: 1rem 0 1.2rem auto; max-width: 300px; }
.totals div, .sum div { display: flex; justify-content: space-between; padding: .2rem 0; font-variant-numeric: tabular-nums; }
.totals .grand, .sum .grand { border-top: 1px solid var(--line); margin-top: .3rem; padding-top: .5rem; font-size: 1.1rem; }
.errors { background: var(--bad-bg); color: var(--bad); border-radius: var(--radius); padding: .8rem 1rem; margin: 1rem 0; }
.errors ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.ok { color: var(--good); font-weight: 600; }

/* Invoice page */
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 2rem; align-items: start; }
.pdf { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.plans { display: grid; gap: .6rem; margin: .8rem 0; }
.plan { width: 100%; justify-content: space-between; flex-wrap: wrap; text-align: left; }
.plan small { width: 100%; font-weight: 400; opacity: .85; }
.inline { display: flex; gap: .5rem; margin-top: .6rem; }
.inline input { margin: 0; }
.keyval code { font-size: 1.4rem; letter-spacing: .04em; user-select: all; }

/* Viewer */
.upload { display: flex; gap: .7rem; flex-wrap: wrap; align-items: center; background: var(--surface); border: 2px dashed var(--line); border-radius: var(--radius); padding: 1.4rem; }
.upload input { flex: 1 1 260px; margin: 0; }
.verdict { padding: .9rem 1.1rem; border-radius: var(--radius); font-weight: 700; margin-bottom: 1rem; }
.verdict.good { background: var(--good-bg); color: var(--good); }
.verdict.bad { background: var(--bad-bg); color: var(--bad); }
.verdict.warn { background: var(--warn-bg); }
.msgs { padding-left: 1.1rem; font-size: .92rem; }
.msgs li { margin: .35rem 0; }
.msgs li.e code { color: var(--bad); }
.paper { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.6rem; margin: 1rem 0; }
.paper-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.paper-head h2 { margin: 0; }
.kv { display: grid; grid-template-columns: auto auto; gap: .1rem .9rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.parties { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; margin: 1.2rem 0; }
.items { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.items th, .items td { padding: .45rem .4rem; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
.items th:nth-child(2), .items td:nth-child(2) { text-align: left; }
.items th:first-child, .items td:first-child { text-align: left; }
.sum { max-width: 380px; margin: 1rem 0 1rem auto; }

@media (max-width: 760px) {
  .split { grid-template-columns: 1fr; }
  .pdf { height: 60vh; }
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: .3rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
  .lines td:nth-child(1) { grid-column: 1 / -1; width: auto; }
  .lines .amt { align-self: center; }
  .items { font-size: .85rem; }
}
@media print {
  .top, .foot, .upload, .noprint, .verdict, details, main > section:first-child { display: none; }
  .paper { border: 0; padding: 0; }
}
