:root {
  --bg: #f4f6f3;
  --card: #ffffff;
  --text: #17211b;
  --muted: #5d6b63;
  --line: #dde3de;
  --accent: #1f7a4d;
  --accent-strong: #17613c;
  --accent-soft: #e6f3ec;
  --danger: #b3261e;
  --danger-soft: #fbeceb;
  --shadow: 0 1px 2px rgba(20, 40, 30, .06), 0 4px 14px rgba(20, 40, 30, .05);
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111613;
    --card: #1a211d;
    --text: #edf2ee;
    --muted: #9daba3;
    --line: #2b352f;
    --accent: #4cc38a;
    --accent-strong: #6fd5a2;
    --accent-soft: #1d3327;
    --danger: #ff8a80;
    --danger-soft: #3a1f1d;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.1rem; margin-bottom: 14px; }
p { margin: 0; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* ---------- layout ---------- */

.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.top-inner {
  max-width: 560px; margin: 0 auto; padding: 12px 16px 0;
}
.brand { font-size: 1.15rem; color: var(--accent); margin-bottom: 10px; }

.tabs { display: flex; gap: 4px; }
.tab {
  flex: 1; padding: 10px 6px 12px;
  background: none; border: 0; border-bottom: 3px solid transparent;
  color: var(--muted); font: inherit; font-weight: 600; cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

.page { max-width: 560px; margin: 0 auto; padding: 16px; }
.view { display: grid; gap: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.foot { max-width: 560px; margin: 0 auto; padding: 4px 16px 32px; text-align: center; }

/* ---------- forms ---------- */

label { display: block; font-size: .875rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }

input[type="text"], input[type="password"], input[type="date"] {
  width: 100%; height: 50px; padding: 0 14px;
  font: inherit; font-size: 17px; color: var(--text);
  background: var(--card);
  border: 1.5px solid var(--line); border-radius: 10px;
  appearance: none; -webkit-appearance: none;
}
input:focus-visible, button:focus-visible, .entry-row:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.row { display: flex; gap: 12px; margin-top: 14px; }
.field { min-width: 0; }
.field.grow { flex: 1; }
.field input[type="date"] { min-width: 150px; }

.money-input { position: relative; }
.money-input span {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 17px; pointer-events: none;
}
.money-input input { padding-left: 28px; font-variant-numeric: tabular-nums; }

label.check {
  display: flex; align-items: center; gap: 10px;
  margin: 14px 0 0; padding: 4px 0;
  font-size: .95rem; font-weight: 500; cursor: pointer;
}
label.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }

button { font: inherit; cursor: pointer; }
button:disabled { opacity: .6; cursor: default; }

.primary {
  display: block; width: 100%; height: 52px; margin-top: 18px;
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  font-size: 17px; font-weight: 700;
}
@media (prefers-color-scheme: dark) { .primary { color: #0d1a13; } }
.primary:hover:not(:disabled) { background: var(--accent-strong); }
.primary.slim { width: auto; height: 46px; margin-top: 0; padding: 0 22px; }

.secondary {
  height: 46px; padding: 0 16px;
  background: none; color: var(--text);
  border: 1.5px solid var(--line); border-radius: 10px; font-weight: 600;
}
.danger {
  height: 46px; padding: 0 16px;
  background: var(--danger-soft); color: var(--danger);
  border: 0; border-radius: 10px; font-weight: 600; white-space: nowrap;
}
.link {
  background: none; border: 0; padding: 8px;
  color: var(--muted); text-decoration: underline; font-size: .875rem;
}
.link.strong { color: var(--accent); font-weight: 600; font-size: .95rem; padding-left: 0; }

.error {
  margin-top: 12px; padding: 10px 12px;
  background: var(--danger-soft); color: var(--danger);
  border-radius: 8px; font-size: .925rem;
}

/* ---------- store drop-down ---------- */

.combo { position: relative; }
.combo input { padding-right: 54px; }
.combo-toggle {
  position: absolute; right: 4px; top: 4px;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  border: 0; border-radius: 8px;
}
.combo-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 10;
  margin: 0; padding: 6px; list-style: none;
  max-height: 280px; overflow-y: auto;
  background: var(--card);
  border: 1.5px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(10, 30, 20, .18);
}
.combo-list li {
  padding: 12px; border-radius: 8px; cursor: pointer; font-size: 17px;
}
.combo-list li.active, .combo-list li:hover { background: var(--accent-soft); }
.combo-list li.none { color: var(--muted); cursor: default; background: none; font-size: .95rem; }

/* ---------- figures ---------- */

.figures { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.figure-box {
  padding: 14px; border-radius: 12px;
  background: var(--bg); min-width: 0;
}
.figure-box.accent { background: var(--accent-soft); }
.figure-box.accent .figure { color: var(--accent); }
.label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.figure { display: block; font-size: 1.55rem; font-weight: 750; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.accent-text { color: var(--accent); }
.figures + .muted { margin-top: 10px; }

/* ---------- lists of purchases ---------- */

.entry-list { list-style: none; margin: 0; padding: 0; }
.entry-list li + li { border-top: 1px solid var(--line); }
.entry-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 12px 4px;
  background: none; border: 0; border-radius: 8px;
  color: inherit; text-align: left;
}
.entry-row:hover { background: var(--bg); }
.entry-main { min-width: 0; }
.entry-vendor { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-date { display: block; font-size: .85rem; color: var(--muted); }
.entry-amount { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.entry-amount.refund { color: var(--accent); }

.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.month-nav h2 { margin: 0; text-align: center; }
.icon-button {
  width: 44px; height: 44px;
  background: var(--bg); color: var(--text);
  border: 0; border-radius: 10px; font-size: 1.6rem; line-height: 1;
}

.log-total {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin: 12px 0; padding-top: 14px; border-top: 2px solid var(--line);
}

/* ---------- summary ---------- */

#summary-list { display: grid; gap: 16px; }
.month-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.month-head h2 { margin: 0; }
.badge {
  padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: .75rem; font-weight: 700;
}
details { margin-top: 14px; }
summary { cursor: pointer; color: var(--muted); font-size: .925rem; font-weight: 600; padding: 4px 0; }
.store-list { list-style: none; margin: 8px 0 6px; padding: 0; }
.store-list li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 9px 0; border-top: 1px solid var(--line);
}
.store-list .store-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.store-list .store-count { color: var(--muted); font-size: .85rem; margin-left: 6px; }
.store-list .store-amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

/* ---------- sign-in screen ---------- */

label.spaced { margin-top: 14px; }

.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { color: var(--accent); margin-bottom: 8px; }
.login-card p.muted { margin-bottom: 18px; }

/* ---------- edit dialog ---------- */

dialog {
  width: min(480px, calc(100vw - 24px));
  padding: 20px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
}
dialog::backdrop { background: rgba(8, 16, 12, .55); }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 20px; }
.spacer { flex: 1; }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 12px 18px; border-radius: 16px; text-align: center;
  background: #17211b; color: #fff; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.toast.bad { background: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .toast { background: #edf2ee; color: #111613; } .toast.bad { background: #b3261e; color: #fff; } }

@media (max-width: 380px) {
  .row { flex-direction: column; }
  .figure { font-size: 1.3rem; }
}
