:root {
  --bg: #f6f8f8;
  --surface: #ffffff;
  --text: #11201f;
  --muted: #5b6b6a;
  --line: #e2e8e7;
  --primary: #0f766e;
  --on-primary: #ffffff;
  --soft: #e6f3f1;
  --good: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --radius: 16px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1514;
    --surface: #162120;
    --text: #e6efee;
    --muted: #9fb1af;
    --line: #26332f;
    --primary: #2dd4bf;
    --on-primary: #06201d;
    --soft: #133330;
    --good: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45; }
.app { max-width: 920px; margin: 0 auto; padding: 16px 16px 48px; }
.loading, .notice { color: var(--muted); text-align: center; padding: 48px 0; }

header.top { display: flex; align-items: center; gap: 12px; margin: 4px 0 16px; }
.mark { width: 44px; height: 44px; border-radius: 13px; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-weight: 800; font-size: 20px; flex: none; }
.top h1 { font-size: 20px; margin: 0; line-height: 1.2; }
.top p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.top .spacer { flex: 1; }

button, .btn { font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 12px; padding: 9px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; }
button:hover, .btn:hover { border-color: var(--primary); }
button:focus-visible, .btn:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.btn.primary, button.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); font-weight: 600; }
button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.chips button { white-space: nowrap; border-radius: 999px; min-height: 40px; }
.toolbar { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin: 4px 0 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; min-height: 40px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.total { display: flex; gap: 24px; flex-wrap: wrap; }
.total .big { font-size: 28px; font-weight: 800; }
.total .label { color: var(--muted); font-size: 13px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.tile .name { color: var(--muted); font-size: 14px; }
.tile .qty { font-size: 22px; font-weight: 800; }
.tile .amt { font-size: 13px; color: var(--muted); }

h2 { font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 22px 0 10px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th, td { padding: 10px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
th { color: var(--muted); font-weight: 600; font-size: 13px; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--soft); }
tfoot td { font-weight: 700; border-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

.invoice { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.invoice .no { font-weight: 700; }
.invoice .meta { color: var(--muted); font-size: 14px; }
.pill { display: inline-block; border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 600; }
.pill.due { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.pill.part { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.pill.paid { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

dialog { border: 0; border-radius: 20px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: 86vh; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.sheet { padding: 18px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.sheet-head h3 { margin: 0; font-size: 18px; }
.entry { padding: 10px 0; border-bottom: 1px solid var(--line); }
.entry:last-child { border-bottom: 0; }
.entry .time { font-weight: 700; }
.entry .items { color: var(--muted); }

.error { text-align: center; padding: 56px 16px; }
.error h1 { font-size: 20px; }
.error p { color: var(--muted); }
.foot { text-align: center; color: var(--muted); font-size: 13px; margin-top: 28px; }

/* Printable invoice */
.inv { font-size: 14px; }
.inv h3 { margin: 0 0 4px; }
.inv .two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.inv table th, .inv table td { font-size: 13px; padding: 6px 8px; }
.inv .sum td { border: 0; padding: 3px 8px; }
.inv .grand td { font-weight: 800; font-size: 15px; border-top: 2px solid var(--text); }

@media (max-width: 520px) {
  .inv .two { grid-template-columns: 1fr; }
  .total .big { font-size: 24px; }
}

@media print {
  body { background: #fff; color: #000; }
  .app, dialog::backdrop, .no-print { display: none !important; }
  dialog { position: static; width: auto; max-height: none; box-shadow: none; }
  dialog[open] { display: block; }
}
.error .mark { margin: 0 auto 12px; }
.chips { scrollbar-width: none; } .chips::-webkit-scrollbar { display: none; }
