:root {
  --bg: #f4f5f8; --card: #ffffff; --text: #1e2330; --muted: #687083; --line: #e1e4ea;
  --brand: #34507a; --brand-ink: #ffffff; --red: #c0392b; --red-bg: #fdecea;
  --amber: #a86a12; --amber-bg: #fff4dc; --green: #2e7d4f; --green-bg: #e7f5ec;
  --blue-bg: #e9eef7; --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d; --card: #1d212a; --text: #eceef2; --muted: #9aa1b0; --line: #2d3240;
    --brand: #7f9fd1; --brand-ink: #0e1117; --red: #ff6b5b; --red-bg: #3a1f1c;
    --amber: #f0b44c; --amber-bg: #3a2f1a; --green: #6fcf97; --green-bg: #1b3326; --blue-bg: #222b3b;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Arial, sans-serif; }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button, .btn { cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 8px 14px; min-height: 40px; text-decoration: none; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px; color: var(--text); }
button.primary, .btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--red); }
button.ghost { background: transparent; border-color: transparent; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
  background: var(--card); min-height: 42px; }
input[type=checkbox] { width: auto; min-height: 0; }
label { display: block; margin: 10px 0; color: var(--muted); font-size: 14px; }
label input, label select, label textarea { margin-top: 4px; color: var(--text); }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.err { color: var(--red); min-height: 1.2em; }
.muted { color: var(--muted); font-size: 14px; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--brand); color: var(--brand-ink); }
.top h1 { font-size: 18px; margin: 0; }
.topbtn { color: var(--brand-ink); text-decoration: none; font-weight: 600; padding: 6px 10px; border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--brand-ink) 40%, transparent); }
main { max-width: 1000px; margin: 0 auto; padding: 12px 16px 96px; }
.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
.tabs a { flex: 1; text-align: center; padding: 8px 0 6px; text-decoration: none; color: var(--muted); font-size: 18px; }
.tabs a span { display: block; font-size: 11px; }
.tabs a.active { color: var(--brand); font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.card h2 { margin: 0 0 8px; font-size: 17px; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; }
.login h1 { margin-top: 0; font-size: 22px; }
.login button { width: 100%; margin-top: 8px; }

.banner { border-radius: var(--radius); padding: 10px 14px; margin: 10px 0; }
.banner.red { background: var(--red-bg); color: var(--red); }
.banner.amber { background: var(--amber-bg); color: var(--amber); }
.banner.green { background: var(--green-bg); color: var(--green); }
.banner.blue { background: var(--blue-bg); color: var(--text); }
.banner h3 { margin: 0 0 6px; font-size: 15px; }
.banner ul { margin: 0; padding-inline-start: 18px; }
.banner li { margin: 3px 0; }
.banner a { color: inherit; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.toolbar input[type=search] { flex: 1; min-width: 160px; }
.toolbar select { width: auto; }
.chip { border-radius: 999px; padding: 6px 12px; min-height: 34px; font-size: 14px; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.row { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 12px; margin: 8px 0; text-decoration: none; color: inherit; }
.row .main { flex: 1; min-width: 0; }
.row .name { font-weight: 600; overflow-wrap: anywhere; }
.row .amt { font-weight: 700; white-space: nowrap; }
.row.err { border-color: var(--red); }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--muted); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.blue { background: var(--blue-bg); color: var(--brand); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: start; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tablewrap { overflow-x: auto; }

dialog { border: none; border-radius: var(--radius); padding: 0; width: min(520px, calc(100vw - 32px));
  background: var(--card); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog form { padding: 16px; }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
.actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 20; max-width: 90vw; }
.toast.show { opacity: 1; }
h2.section { font-size: 17px; margin: 18px 0 6px; }

/* home */
.period { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.tile b { display: block; font-size: 24px; }
.tile span { color: var(--muted); font-size: 13px; }
.progress { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progress i { display: block; height: 100%; background: var(--green); border-radius: 4px; }
.bigbtns { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 12px 0; }
.bigbtns .btn, .bigbtns button { min-height: 56px; font-size: 16px; font-weight: 600; }
.chart { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding: 8px 4px 0; border-bottom: 1px solid var(--line); }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.chart .bar { width: 100%; max-width: 56px; background: color-mix(in srgb, var(--brand) 35%, var(--card)); border-radius: 6px 6px 0 0; min-height: 2px; }
.chart .col.cur .bar { background: var(--brand); }
.chart .v { font-size: 12px; color: var(--muted); margin-bottom: 4px; white-space: nowrap; }
.chart .col.cur .v { color: var(--text); font-weight: 700; }
.chartlabels { display: flex; gap: 10px; padding: 4px 4px 0; }
.chartlabels span { flex: 1; text-align: center; font-size: 11px; line-height: 1.25; color: var(--muted); min-width: 0; }

/* invoice detail */
.split { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 860px) { .split { grid-template-columns: 1.1fr 1fr; align-items: start; } .split .preview { position: sticky; top: 64px; } }
.preview { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.preview iframe { width: 100%; height: 75vh; border: 0; display: block; }
.preview img { width: 100%; display: block; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.issues { list-style: none; padding: 0; margin: 0 0 8px; }
.issues li { padding: 6px 10px; border-radius: 8px; margin: 4px 0; font-size: 14px; }
.issues .error { background: var(--red-bg); color: var(--red); }
.issues .warn { background: var(--amber-bg); color: var(--amber); }
.issues .info { background: var(--blue-bg); }

/* upload */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px 16px; text-align: center; background: var(--card); }
.drop.over { border-color: var(--brand); background: var(--blue-bg); }
.drop p { margin: 6px 0; }
.drop .actions { justify-content: center; }
.uplist { list-style: none; padding: 0; }
.uplist li { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.uplist li .main { flex: 1; min-width: 0; overflow-wrap: anywhere; }
