:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --line: #e2e0d9;
  --text: #121211;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;          /* series-1, also used for interactive accents */
  --accent-ink: #1d5fb0;      /* accent for text/links (passes contrast) */
  --accent-wash: rgba(42, 120, 214, 0.10);
  --good: #0f7a3d;
  --bad: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --line: #2f2f2c;
    --text: #f4f4f2;
    --text-2: #c3c2b7;
    --text-3: #93928a;
    --accent: #3987e5;
    --accent-ink: #7fb1f0;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --good: #4cc27a;
    --bad: #f2827b;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #232321; --line: #2f2f2c;
  --text: #f4f4f2; --text-2: #c3c2b7; --text-3: #93928a;
  --accent: #3987e5; --accent-ink: #7fb1f0; --accent-wash: rgba(57,135,229,.16);
  --good: #4cc27a; --bad: #f2827b; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--accent-ink); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
}
.brand { font-size: 17px; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: 50%; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.spinning svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.status {
  margin: 0 16px 8px; padding: 10px 12px; border-radius: 10px;
  background: var(--surface-2); color: var(--text-2); font-size: 13px;
}

main { max-width: 760px; margin: 0 auto; padding: 4px 16px 24px; outline: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; color: var(--text-3); font-size: 11px; font-weight: 550;
}
.tabbar svg { width: 22px; height: 22px; }
.tabbar a[aria-current="page"] { color: var(--accent-ink); }

.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--line);
  padding: 16px; margin-bottom: 14px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { font-size: 15px; }
.muted { color: var(--text-3); }
.small { font-size: 13px; }

/* month selector */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; color: var(--text-2);
}
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

/* hero + stat tiles */
.hero-label { color: var(--text-2); font-size: 13px; }
.hero { font-size: 48px; font-weight: 680; letter-spacing: -0.02em; line-height: 1.1; margin: 2px 0 4px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px; }
.stat .v { font-size: 18px; font-weight: 650; }
.stat .k { font-size: 12px; color: var(--text-3); }

/* charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--text-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .tick-sel { fill: var(--text); font-weight: 650; }
.chart .bar { fill: var(--accent); }
.chart .bar.dim { fill: color-mix(in srgb, var(--accent) 45%, var(--surface)); }
.chart .val { fill: var(--text); font-size: 11px; font-weight: 600; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent-wash); }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .bar, .chart .hit:focus + .bar { filter: brightness(1.08); }
.tooltip {
  position: fixed; z-index: 20; pointer-events: none;
  background: var(--text); color: var(--bg); border-radius: 8px;
  padding: 6px 9px; font-size: 12px; line-height: 1.35; max-width: 220px;
  box-shadow: 0 4px 16px rgba(0,0,0,.18);
}

/* horizontal store bars */
.hbars { display: grid; gap: 10px; }
a.hbar-row { color: inherit; border-radius: 8px; }
a.hbar-row:hover .hbar-name { color: var(--accent-ink); }
.hbar-row { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.hbar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.hbar-track { height: 12px; }
.hbar-fill { height: 12px; background: var(--accent); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar-val { font-variant-numeric: tabular-nums; font-weight: 600; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 0; color: var(--text); }
.row .main { min-width: 0; display: block; }
.row .title, .row .sub { display: block; }
.row .title { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 12px; color: var(--text-3); }
.row .amt { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
a.row:hover .title { color: var(--accent-ink); }

/* last-3 price strip */
.prices { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.price-pill {
  font-size: 12px; background: var(--surface-2); border-radius: 8px; padding: 4px 8px;
  font-variant-numeric: tabular-nums; color: var(--text-2);
}
.price-pill b { color: var(--text); font-weight: 650; }
.trend { font-size: 12px; font-weight: 600; white-space: nowrap; }
.trend.up { color: var(--bad); }
.trend.down { color: var(--good); }
.trend.same { color: var(--text-3); }

/* search */
.search {
  display: flex; align-items: center; gap: 8px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; margin: 4px 0 14px;
}
.search input { flex: 1; border: 0; background: transparent; padding: 12px 0; outline: none; font-size: 16px; }
.search svg { color: var(--text-3); flex: 0 0 auto; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--text-3); font-weight: 600; font-size: 12px; }
td.nowrap { white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.best td { background: var(--accent-wash); }
.badge { display: inline-block; font-size: 11px; font-weight: 650; padding: 1px 6px; border-radius: 6px; background: var(--accent-wash); color: var(--accent-ink); margin-left: 6px; }

.back { display: inline-flex; align-items: center; gap: 4px; margin: 4px 0 10px; font-size: 14px; }
.page-title { font-size: 22px; margin: 2px 0 2px; text-transform: capitalize; }
.page-sub { color: var(--text-3); font-size: 13px; margin-bottom: 14px; }
.month-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-3); margin: 18px 0 6px; font-weight: 600; }

/* settings */
label { display: block; font-size: 13px; color: var(--text-2); margin: 12px 0 6px; font-weight: 550; }
.field {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); font-size: 16px;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 600; cursor: pointer;
  background: var(--accent); color: #fff;
}
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.empty { text-align: center; color: var(--text-3); padding: 36px 12px; }
.empty h2 { color: var(--text); font-size: 17px; margin-bottom: 6px; }

@media (min-width: 640px) {
  .hero { font-size: 56px; }
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
  .grid-2 > .card { margin-bottom: 0; }
  .grid-2 { margin-bottom: 14px; }
}
@media (prefers-reduced-motion: reduce) { .icon-btn.spinning svg { animation: none; } }

/* add bill */
.top-actions { display: flex; align-items: center; gap: 4px; }
.add-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 14px;
}
.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  border-radius: 18px 18px 0 0; background: var(--surface); color: var(--text);
}
.sheet::backdrop { background: rgba(0,0,0,.4); }
@media (min-width: 640px) { .sheet { margin: auto; border-radius: 18px; } }
.sheet-inner { padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head h2 { font-size: 18px; }
.pick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0 12px; }
.pick {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 92px; border: 1.5px dashed var(--line); border-radius: 14px; cursor: pointer;
  color: var(--text); font-weight: 600; font-size: 14px; background: var(--surface-2); text-align: center; padding: 10px;
}
.pick:hover { border-color: var(--accent); }
.pick svg { color: var(--accent-ink); }
.pick input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.file-list { list-style: none; margin: 0 0 8px; padding: 0; }
.file-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.file-list img, .file-list .pdf { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; background: var(--surface-2); flex: 0 0 auto; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: var(--text-3); }
.file-list .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .fstate { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.file-list .fstate.done { color: var(--good); }
.file-list .fstate.err { color: var(--bad); }
.remove { border: 0; background: transparent; color: var(--text-3); cursor: pointer; font-size: 18px; padding: 4px 6px; }
.btn[disabled] { opacity: .5; cursor: default; }
.notice { display: flex; gap: 10px; align-items: flex-start; }
.notice .ico { flex: 0 0 auto; font-size: 16px; line-height: 1.4; }
.attention li { padding: 10px 0; }
.attention .reason { font-weight: 600; }
.attention .details { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.attention .fn { font-size: 12px; color: var(--text-2); word-break: break-all; }
.link-btn { border: 0; background: transparent; color: var(--accent-ink); cursor: pointer; padding: 0; font-size: 13px; font-weight: 600; }
@media (max-width: 360px) { .add-btn span { display: none; } .add-btn { padding: 8px 10px; } }
