:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light;
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --surface-3: #e5eaf0;
  --text: #0f172a;
  --muted: #64748b;
  --border: #dbe2ea;
  --header: rgba(255,255,255,.92);
  --header-text: #0f172a;
  --accent: #f59e0b;
  --accent-soft: #fff3d6;
  --accent-text: #3b2500;
  --button: #0f172a;
  --button-text: #ffffff;
  --success: #15803d;
  --success-soft: #dcfce7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --shadow: 0 10px 30px rgba(15,23,42,.08);
  --shadow-soft: 0 2px 10px rgba(15,23,42,.06);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: #121c2d;
  --surface-2: #182235;
  --surface-3: #223047;
  --text: #f8fafc;
  --muted: #94a3b8;
  --border: #2a3a52;
  --header: rgba(11,18,32,.92);
  --header-text: #f8fafc;
  --accent: #f59e0b;
  --accent-soft: #3b2b0c;
  --accent-text: #fde7ac;
  --button: #f8fafc;
  --button-text: #0f172a;
  --success: #4ade80;
  --success-soft: #123522;
  --danger: #f87171;
  --danger-soft: #3b171b;
  --shadow: 0 14px 36px rgba(0,0,0,.28);
  --shadow-soft: 0 3px 14px rgba(0,0,0,.18);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input { font: inherit; }
button { color: inherit; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  padding-top: env(safe-area-inset-top);
  background: var(--header);
  color: var(--header-text);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 75%, transparent);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
}
.app-header-inner {
  height: 60px;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: inherit;
  font-weight: 800;
  font-size: 1.03rem;
  letter-spacing: -.02em;
  text-decoration: none;
}
.brand-mark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--button);
  color: var(--accent);
  font-size: 23px;
  font-weight: 300;
  line-height: 1;
}
.header-actions { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-email {
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: .84rem;
}
.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}
.icon-button:active { transform: scale(.97); }
.icon-button svg { width: 20px; height: 20px; fill: currentColor; }

.app-main {
  width: min(100%, 820px);
  margin: 0 auto;
  padding: 22px 18px calc(32px + env(safe-area-inset-bottom));
}
h1, h2, h3 { letter-spacing: -.03em; }
h1 { margin: 0; font-size: clamp(1.85rem, 5vw, 2.45rem); line-height: 1.05; }
p { line-height: 1.5; }

.list-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 6px 2px 18px;
}
.list-title-block { min-width: 0; }
.eyebrow {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .12em;
}
.store-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 9px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .84rem;
  font-weight: 650;
}
.store-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.shopping-mode {
  min-height: 46px;
  padding: 0 16px;
  border: 0;
  border-radius: 14px;
  background: var(--button);
  color: var(--button-text);
  font-weight: 750;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-soft);
}
.shopping-mode.active { background: var(--danger); color: #fff; }

.add-item {
  display: grid;
  gap: 10px;
  margin: 0 0 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.add-item input {
  width: 100%;
  min-width: 0;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 0 14px;
  outline: 0;
  background: var(--surface-2);
  color: var(--text);
}
.add-item input::placeholder { color: var(--muted); opacity: .85; }
.add-item input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
.add-item .product-input { height: 52px; font-size: 1rem; }
.add-item-meta { display: grid; grid-template-columns: 88px 110px minmax(120px, 1fr); gap: 9px; }
.add-item button {
  min-height: 48px;
  border: 0;
  border-radius: 13px;
  padding: 0 16px;
  background: var(--button);
  color: var(--button-text);
  font-weight: 800;
  cursor: pointer;
}
.add-item button::before { content: "+"; margin-right: 6px; color: var(--accent); font-size: 1.2em; font-weight: 400; }

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin: 0 0 14px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-2);
}
.tabs button {
  min-height: 42px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 750;
  cursor: pointer;
}
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-soft); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.lists, .items { list-style: none; padding: 0; margin: 0; }
.lists { display: grid; gap: 10px; }
.lists li, .items li {
  border: 1px solid var(--border);
  border-radius: 17px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}
.lists li { padding: 15px 16px; }
.lists a { display: flex; flex-direction: column; gap: 4px; color: inherit; text-decoration: none; }
.lists small, .items small { display: block; margin-top: 4px; color: var(--muted); font-size: .82rem; }
.items { display: grid; gap: 9px; }
.items li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 14px;
}
.items li > div:first-child { min-width: 0; }
.items strong { font-size: .98rem; }
.items li.later { opacity: .64; }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.actions button {
  min-height: 38px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--text);
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
}
.actions button[data-status="bought"] { border-color: color-mix(in srgb, var(--success) 35%, var(--border)); background: var(--success-soft); color: var(--success); }
.actions button[data-status="later"] { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); background: var(--accent-soft); color: var(--accent-text); }
.actions button[data-status="unavailable"] { border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); background: var(--danger-soft); color: var(--danger); }

.is-new { animation: newitem 1.8s ease; }
@keyframes newitem {
  0%, 35% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 55%, transparent), var(--shadow-soft); }
  100% { box-shadow: var(--shadow-soft); }
}

#toast {
  position: fixed;
  z-index: 1400;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(130px);
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 12px 15px;
  border-radius: 13px;
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--shadow);
  transition: transform .22s ease;
  font-size: .9rem;
}
#toast.show { transform: translateX(-50%) translateY(0); }

.settings-dialog {
  width: min(92vw, 500px);
  max-height: min(82vh, 620px);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0,0,0,.34);
}
.settings-dialog::backdrop { background: rgba(3,7,18,.58); backdrop-filter: blur(3px); }
.settings-handle { display: none; }
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 20px 10px;
}
.settings-kicker { color: var(--muted); font-size: .7rem; font-weight: 800; text-transform: uppercase; letter-spacing: .11em; }
.settings-head h2 { margin: 2px 0 0; font-size: 1.55rem; }
.dialog-close { font-size: 27px; line-height: 1; box-shadow: none; }
.setting-row { display: grid; gap: 13px; padding: 14px 20px 20px; }
.setting-row small { display: block; margin-top: 3px; color: var(--muted); font-size: .82rem; }
.theme-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  padding: 5px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface-2);
}
.theme-switch button {
  min-height: 42px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 750;
  cursor: pointer;
}
.theme-switch button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-soft); }
.version-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .88rem;
}
.version-row strong { color: var(--text); font-variant-numeric: tabular-nums; }

@media (max-width: 820px) {
  .app-header-inner { height: 56px; padding: 0 14px; }
  .app-main { padding: 18px 14px calc(28px + env(safe-area-inset-bottom)); }
  .user-email { display: none; }
  .icon-button { width: 40px; height: 40px; flex-basis: 40px; }
  .list-hero { align-items: center; gap: 12px; padding: 3px 2px 15px; }
  .list-hero h1 { font-size: 1.9rem; }
  .shopping-mode { min-height: 44px; padding: 0 13px; font-size: .82rem; }
  .add-item { padding: 11px; border-radius: 18px; }
  .add-item-meta { grid-template-columns: 76px 92px 1fr; gap: 7px; }
  .add-item input { height: 46px; padding: 0 11px; }
  .add-item .product-input { height: 50px; }
  .add-item button { min-height: 46px; padding: 0 10px; }
  .items li { align-items: flex-start; flex-direction: column; gap: 11px; padding: 13px; }
  .actions { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); }
  .actions:has(button:only-child) { grid-template-columns: 1fr; }
  .actions button { min-height: 42px; padding: 0 7px; }
  .settings-dialog {
    width: 100%;
    max-width: none;
    max-height: 78vh;
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: 24px 24px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .settings-handle { display: block; width: 42px; height: 5px; margin: 9px auto 0; border-radius: 999px; background: var(--surface-3); }
  .settings-head { padding-top: 12px; }
}

@media (max-width: 430px) {
  .list-hero { align-items: flex-start; }
  .shopping-mode { margin-top: 18px; }
  .add-item-meta { grid-template-columns: 72px 86px minmax(0,1fr); }
  .tabs button { font-size: .8rem; }
  .theme-switch button { font-size: .8rem; }
}
