/* ---------- Tokens ---------- */
:root {
  --paper: #fafbf4;
  --card: #ffffff;
  --ink: #1c2418;
  --ink-soft: #5c6653;
  --leaf: #2e7d4f;
  --leaf-deep: #1c5936;
  --marigold: #f5b32b;
  --line: #dee4d3;
  --danger: #b3402e;
  --radius: 14px;
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

.view {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.page {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

/* ---------- Brand & top bar ---------- */
.brand-mark {
  font-family: var(--display);
  font-weight: 800;
  font-size: 2.6rem;
  letter-spacing: -0.03em;
  color: var(--leaf-deep);
}
.brand-mark.small { font-size: 1.3rem; }

.brand-sub {
  display: block;
  color: var(--ink-soft);
  font-size: 0.95rem;
  margin-top: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.topbar-right { display: flex; align-items: center; gap: 10px; }

.whoami {
  font-size: 0.9rem;
  color: var(--ink-soft);
}
.whoami::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--marigold);
  margin-right: 6px;
}

/* ---------- Headings ---------- */
h1, .list-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.7rem;
  letter-spacing: -0.02em;
  margin: 4px 0 0;
}
.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

/* ---------- Buttons & inputs ---------- */
.btn {
  font-family: var(--body);
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  padding: 12px 16px;
  cursor: pointer;
  min-height: 44px;
  color: var(--ink);
  background: transparent;
}
.btn:focus-visible {
  outline: 3px solid var(--marigold);
  outline-offset: 2px;
}
.btn.primary {
  background: var(--leaf);
  color: #fff;
}
.btn.primary:active { background: var(--leaf-deep); }
.btn.ghost {
  color: var(--leaf-deep);
  padding: 8px 10px;
}
.btn.wide { width: 100%; }
.btn.done {
  background: var(--ink);
  color: var(--paper);
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: 0.01em;
}
.btn.done:active { background: #000; }

input[type="text"],
input[type="password"] {
  width: 100%;
  font-size: 1rem;
  padding: 12px 14px;
  min-height: 44px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
}
input:focus-visible {
  outline: none;
  border-color: var(--leaf);
  box-shadow: 0 0 0 3px rgba(46, 125, 79, 0.18);
}

.add-bar {
  display: flex;
  gap: 8px;
}
.add-bar input { flex: 1; }

/* ---------- Login ---------- */
#view-login {
  justify-content: center;
  align-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 10px 30px rgba(28, 89, 54, 0.08);
}
.login-card form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.login-card label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-top: 8px;
}
.error {
  color: var(--danger);
  font-size: 0.9rem;
  margin: 4px 0 0;
}

/* ---------- Store list ---------- */
.store-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.store-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 8px 6px 16px;
  min-height: 60px;
}
.store-open {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: none;
  border: none;
  padding: 12px 4px;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  min-height: 44px;
}
.store-open:focus-visible { outline: 3px solid var(--marigold); border-radius: 8px; }
.store-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}
.store-count {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--leaf-deep);
  background: rgba(46, 125, 79, 0.12);
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}
.store-count.empty-count {
  color: var(--ink-soft);
  background: var(--paper);
  border: 1px solid var(--line);
}

.row-actions {
  display: flex;
  gap: 4px;
}
.icon-btn {
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 10px;
  min-width: 42px;
  min-height: 42px;
  font-size: 1rem;
  cursor: pointer;
  color: var(--ink);
}
.icon-btn:active { background: var(--line); }
.icon-btn.danger { color: var(--danger); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.icon-btn:focus-visible { outline: 3px solid var(--marigold); }

/* ---------- Receipt (item list) ---------- */
.receipt {
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 4px 0 14px;
  position: relative;
}
.receipt-tear {
  position: absolute;
  left: 0; right: 0;
  bottom: -9px;
  height: 10px;
  background:
    linear-gradient(-45deg, transparent 7px, var(--card) 0) 0 0 / 14px 10px repeat-x,
    linear-gradient(45deg, transparent 7px, var(--card) 0) 7px 0 / 14px 10px repeat-x;
  filter: drop-shadow(0 1px 0 var(--line));
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px dashed var(--line);
}
.item-row:last-child { border-bottom: none; }

.item-check {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border: 2px solid var(--leaf);
  border-radius: 8px;
  background: var(--card);
  cursor: pointer;
  display: grid;
  place-items: center;
  color: transparent;
  font-size: 15px;
  line-height: 1;
}
.item-row.checked .item-check {
  background: var(--leaf);
  color: #fff;
}
.item-check:focus-visible { outline: 3px solid var(--marigold); }

.item-main {
  flex: 1;
  min-width: 0;
  padding: 6px 0;
  cursor: pointer;
}
.item-name {
  display: block;
  font-size: 1.05rem;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.item-row.checked .item-name {
  text-decoration: line-through;
  text-decoration-color: var(--leaf);
  color: var(--ink-soft);
}
.item-meta {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 2px;
}

.empty {
  color: var(--ink-soft);
  text-align: center;
  padding: 18px 12px;
  margin: 0;
}

@media (prefers-reduced-motion: no-preference) {
  .item-row, .store-row { transition: opacity 0.15s ease; }
}

@media (min-width: 700px) {
  .brand-mark { font-size: 3rem; }
  h1, .list-title { font-size: 2rem; }
}
