:root {
  --bg: #f4f5f7; --card: #fff; --text: #14171c; --muted: #667085; --line: #e3e6ea;
  --accent: #1d4ed8; --accent-soft: #e6edfd; --ok: #0f7b4b; --warn: #b54708; --bad: #c0262d;
  --radius: 14px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --card: #1a1d23; --text: #eceef2; --muted: #98a2b3; --line: #2b2f37;
    --accent: #6d97ff; --accent-soft: #1d2a4a; --ok: #3ccb7f; --warn: #f5a524; --bad: #ff6b6b; --shadow: none; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
button, input, select { font: inherit; color: inherit; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px; border-bottom: 1px solid var(--line);
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 28px; margin: 4px 0; letter-spacing: -.02em; }
.icon-btn { border: 0; background: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; font-size: 26px; color: var(--accent); }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: var(--accent); stroke-width: 1.7; }
.icon-btn:active { background: var(--accent-soft); }
.period-row { display: flex; align-items: center; justify-content: center; gap: 8px; }
.period { position: relative; font-weight: 600; font-size: 17px; padding: 6px 14px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); min-width: 170px; text-align: center; }
.period input { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; }

main { padding: 12px 16px; max-width: 720px; margin: 0 auto; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }

/* Summary */
.summary .total { font-size: 34px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.summary .meta { color: var(--muted); font-size: 14px; display: flex; gap: 12px; flex-wrap: wrap; }
.bar { display: flex; height: 8px; border-radius: 99px; overflow: hidden; margin: 14px 0 10px; background: var(--line); gap: 2px; }
.bar span { display: block; height: 100%; }
.legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 12px; font-size: 13px; }
.legend div { display: flex; align-items: center; gap: 6px; }
.legend i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.legend b { margin-left: auto; font-weight: 600; font-variant-numeric: tabular-nums; }

.alert { margin-top: 10px; padding: 10px 12px; border-radius: 10px; font-size: 14px; background: color-mix(in srgb, var(--warn) 12%, var(--card)); color: var(--text); border-left: 3px solid var(--warn); }
.alert.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 10%, var(--card)); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600; cursor: pointer; color: var(--accent); text-align: center; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); margin-top: 24px; width: 100%; }
.btn:disabled { opacity: .5; }
.btn:active { transform: scale(.98); }

/* Expense list */
.expense-list { list-style: none; margin: 0; padding: 0; }
.day { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 4px 6px; }
.item { display: flex; align-items: center; gap: 12px; background: var(--card); padding: 12px 14px; cursor: pointer; border-bottom: 1px solid var(--line); }
.day + .item { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.item.last { border-bottom: 0; border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.item:active { background: var(--accent-soft); }
.item .dot { width: 36px; height: 36px; border-radius: 10px; flex: none; display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 700; }
.item .main { min-width: 0; flex: 1; }
.item .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.item .amt small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 6px; margin-left: 4px; vertical-align: 1px; font-weight: 600; }
.badge.up { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.badge.pending { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.badge.err, .badge.none { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.empty { text-align: center; color: var(--muted); margin-top: 48px; }

.fab {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom)); width: 60px; height: 60px; border-radius: 50%;
  border: 0; background: var(--accent); color: #fff; font-size: 34px; line-height: 1; box-shadow: 0 6px 18px rgba(29,78,216,.4); cursor: pointer;
}

/* Sheets (dialogs) */
dialog.sheet { border: 0; padding: 0; margin: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%; background: var(--bg); color: var(--text); }
dialog.sheet.small { height: auto; top: auto; bottom: 0; position: fixed; border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom); }
dialog::backdrop { background: rgba(0,0,0,.35); }
@media (min-width: 760px) {
  dialog.sheet { max-width: 620px; height: auto; max-height: 92vh; margin: auto; border-radius: 18px; }
  dialog.sheet.small { position: static; border-radius: 18px; }
}
.sheet-head { position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: calc(env(safe-area-inset-top) + 10px) 12px 10px; background: var(--card); border-bottom: 1px solid var(--line); }
dialog.small .sheet-head { padding-top: 12px; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-head > :last-child { justify-self: end; }
.link { border: 0; background: none; color: var(--accent); font-size: 17px; padding: 6px; cursor: pointer; }
.link.strong { font-weight: 700; }
.sheet-body { padding: 16px; padding-bottom: calc(32px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; max-width: 620px; margin: 0 auto; }
.sheet-body h3 { margin: 8px 0 -4px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
input, select { width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 16px; font-weight: 400; color: var(--text); appearance: none; -webkit-appearance: none; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[aria-invalid="true"] { border-color: var(--bad); }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt { font-weight: 400; }
.hint { margin: -6px 2px 0; font-size: 13px; color: var(--muted); }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; padding: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; min-height: 0; }
.chip span { display: inline-block; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 14px; font-weight: 600; color: var(--text); cursor: pointer; }
.chip span small { color: var(--muted); font-weight: 400; margin-left: 4px; }
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip input:checked + span small { color: rgba(255,255,255,.75); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.switch { flex-direction: row; align-items: center; gap: 10px; font-size: 15px; color: var(--text); font-weight: 500; cursor: pointer; }
.switch input { width: 46px; min-height: 28px; height: 28px; border-radius: 99px; padding: 0; position: relative; background: var(--line); border: 0; flex: none; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { transform: translateX(18px); }
.vat-row { display: grid; grid-template-columns: 1fr 130px; align-items: end; gap: 10px; }
.vat-amt input:disabled { opacity: .45; }

.receipts { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.receipts:empty { display: none; }
.thumb { position: relative; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; font-size: 12px; color: var(--muted); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 16px; line-height: 1; cursor: pointer; }
.thumb .st { position: absolute; left: 4px; bottom: 4px; }
.receipt-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.receipt-buttons .btn { font-size: 15px; }
#generated .sheet-body .btn { width: 100%; }
code { font-size: 12px; background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; word-break: break-all; }

.toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: #1f2430; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: calc(100% - 32px); transition: .2s; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
