:root {
  --ink: #0f2027;
  --ink-2: #3c4f57;
  --muted: #6b7c83;
  --line: #dfe5e7;
  --bg: #f5f3ef;
  --card: #ffffff;
  --accent: #ff5a36;
  --accent-ink: #ffffff;
  --ok: #1f8a5b;
  --warn: #b7791f;
  --info: #2b6cb0;
  --danger: #c53030;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--info); }

.demo-banner {
  display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap;
  background: #fff4e0; color: #7a4a00; font-size: 13px; padding: 6px 16px; text-align: center;
}
.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; }

.topbar {
  background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 24px; flex-wrap: wrap; position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand small { display: block; color: #9fb3ba; font-size: 12px; }
.logo {
  width: 36px; height: 36px; border-radius: 9px; background: #16323c; color: var(--accent);
  display: grid; place-items: center; font: 700 22px/1 ui-monospace, monospace;
}
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav a { color: #cfdade; text-decoration: none; padding: 8px 12px; border-radius: 999px; font-size: 14px; }
nav a.active { background: #fff; color: var(--ink); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; outline: none; }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.sub { color: var(--muted); font-size: 14px; margin: 4px 0 0; }

.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 9px 16px;
  cursor: pointer; font-size: 14px; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-2); }
a.btn { text-decoration: none; color: var(--ink); display: inline-block; }
a.btn.primary { color: var(--accent-ink); }
select.btn { max-width: 100%; white-space: normal; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(0.95); }
.btn.small { padding: 5px 11px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); margin-bottom: 24px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px;
  font-size: 13px; cursor: pointer;
}
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.search { flex: 1 1 220px; border: 1px solid var(--line); border-radius: 999px; padding: 7px 14px; background: var(--card); }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #fafbfb; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #fafbfb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.empty { padding: 32px; text-align: center; color: var(--muted); }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.b-grey { background: #eef1f2; color: var(--ink-2); }
.b-blue { background: #e6f0fb; color: var(--info); }
.b-amber { background: #fdf3e1; color: var(--warn); }
.b-green { background: #e4f4ec; color: var(--ok); }
.b-red { background: #fbe9e9; color: var(--danger); }
.b-ink { background: var(--ink); color: #fff; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.list li:last-child { border-bottom: 0; }

label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 12px; }
label > input, label > select, label > textarea {
  display: block; width: 100%; margin-top: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff;
}
.form-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }

.lines input, .lines select { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; }
.lines td { padding: 6px 8px; }
.lines .qty { width: 80px; }
.lines .price { width: 110px; }
.totals { margin-left: auto; width: min(320px, 100%); font-size: 14px; }
.totals div { display: flex; justify-content: space-between; padding: 6px 0; font-variant-numeric: tabular-nums; }
.totals .grand { border-top: 2px solid var(--ink); font-weight: 700; font-size: 17px; margin-top: 4px; padding-top: 10px; }

dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 32, 39, .45); }
dialog form { padding: 22px; }
dialog h2 { margin-bottom: 16px; }
dialog .actions { justify-content: flex-end; margin-top: 8px; }

.doc { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 40px; max-width: 820px; margin: 0 auto; }
.doc-head { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 28px; flex-wrap: wrap; }
.doc-head h1 { font-size: 26px; }
.doc small { color: var(--muted); }
.doc .from, .doc .to { font-size: 14px; line-height: 1.5; }
.doc table th { background: none; }
.doc-foot { margin-top: 28px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.no-print { }

@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  nav { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .doc { padding: 20px; }
  .hide-sm { display: none; }
  .lines thead { display: none; }
  .lines tbody tr { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 6px; padding: 10px; border-bottom: 1px solid var(--line); align-items: center; }
  .lines tbody td { padding: 0; border: 0; }
  .lines tbody td:first-child { grid-column: 1 / -1; }
  .lines tbody td.empty { grid-column: 1 / -1; }
  .lines .qty, .lines .price { width: 100%; }
  .lines td.num { text-align: left; }
  .lines td[data-import] { font-weight: 600; }
}

@media print {
  .demo-banner, .topbar, .no-print, .page-head .actions { display: none !important; }
  body, :root { background: #fff; }
  main { padding: 0; max-width: none; }
  .doc { border: 0; padding: 0; max-width: none; }
}
