:root {
  --dark: #0C1A26;
  --dark-2: #14263a;
  --green: #22C55E;
  --green-dark: #16a34a;
  --mint: #E8F9EF;
  --surface: #F1F5F9;
  --slate: #64748B;
  --white: #FFFFFF;
  --amber: #B45309;
  --amber-bg: #FEF3C7;
  --red: #B91C1C;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(12, 26, 38, 0.06), 0 1px 1px rgba(12, 26, 38, 0.04);
  --shadow-md: 0 8px 24px rgba(12, 26, 38, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--surface);
  color: var(--dark);
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

button, input, select {
  font-family: inherit;
}

a { color: inherit; }

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--surface);
  position: relative;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px 14px;
  background: var(--dark);
  color: var(--white);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar img.logo-mark {
  width: 34px;
  height: 34px;
}

.topbar .brand {
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.01em;
}

.topbar .brand .accent { color: var(--green); }

.topbar .tagline {
  margin-left: auto;
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  text-align: right;
  max-width: 130px;
  line-height: 1.3;
}

/* Screens */
.screen {
  display: none;
  padding: 18px 20px 28px;
  animation: fadein 0.18s ease;
}
.screen.active { display: block; }

@keyframes fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

h1.screen-title {
  font-size: 22px;
  font-weight: 800;
  margin: 4px 0 2px;
}

p.screen-sub {
  color: var(--slate);
  font-size: 13.5px;
  margin: 0 0 18px;
}

/* Cards */
.card {
  background: var(--white);
  border: 1px solid rgba(12,26,38,0.06);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.card + .card { margin-top: 14px; }

/* Add item bar */
.add-bar-wrapper {
  position: relative;
  margin-bottom: 14px;
}

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

.add-bar input[type="text"] {
  flex: 1;
  border: 1px solid rgba(12,26,38,0.12);
  border-radius: var(--radius-md);
  padding: 13px 14px;
  font-size: 15px;
  background: var(--white);
}
.add-bar input[type="text"]:focus {
  outline: 2px solid var(--green);
  outline-offset: 1px;
}

/* Autocomplete dropdown */
.autocomplete-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 25;
  background: var(--white);
  border: 1px solid rgba(12,26,38,0.10);
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  box-shadow: var(--shadow-md);
  margin-top: -2px;
  overflow: hidden;
}
.autocomplete-list.visible { display: block; }

.autocomplete-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-bottom: 1px solid rgba(12,26,38,0.05);
  background: var(--white);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  color: var(--dark);
  transition: background 0.1s;
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover,
.autocomplete-item:focus {
  background: var(--mint);
}
.autocomplete-item:active {
  background: rgba(34,197,94,0.15);
}

.ac-emoji {
  font-size: 18px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.ac-name {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ac-price {
  font-weight: 700;
  color: var(--green-dark);
  font-size: 13px;
  flex-shrink: 0;
}

/* Store logo badge */
.store-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 800;
  flex-shrink: 0;
  letter-spacing: -0.02em;
  line-height: 1;
}

/* Product emoji in lists */
.product-emoji {
  margin-right: 5px;
  font-size: 15px;
}

.btn {
  border: none;
  border-radius: var(--radius-md);
  padding: 13px 18px;
  font-weight: 700;
  font-size: 14.5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
}
.btn-primary { background: var(--green); color: var(--dark); }
.btn-primary:active { background: var(--green-dark); color: var(--white); }
.btn-outline {
  background: var(--white);
  color: var(--dark);
  border: 1.5px solid rgba(12,26,38,0.14);
}
.btn-block { width: 100%; }
.btn-ghost {
  background: transparent;
  color: var(--slate);
  padding: 8px 10px;
  min-height: auto;
  font-size: 13px;
  font-weight: 600;
}

/* quick add chips */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.chip {
  background: var(--mint);
  color: var(--green-dark);
  border: none;
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

/* list items */
.list-items { list-style: none; margin: 0; padding: 0; }
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 4px;
  border-bottom: 1px solid rgba(12,26,38,0.06);
}
.list-item:last-child { border-bottom: none; }

.list-item .check {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  border: 1.5px solid rgba(12,26,38,0.2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--white);
}
.list-item.done .check {
  background: var(--green);
  border-color: var(--green);
  color: var(--dark);
}
.list-item .info { flex: 1; min-width: 0; }
.list-item .name {
  font-weight: 600;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-item.done .name {
  text-decoration: line-through;
  color: var(--slate);
}
.list-item .meta {
  font-size: 12px;
  color: var(--slate);
  margin-top: 1px;
}
.list-item .remove {
  background: none;
  border: none;
  color: var(--slate);
  font-size: 18px;
  padding: 6px;
  cursor: pointer;
  line-height: 1;
}

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--slate);
}
.empty-state .icon { font-size: 34px; margin-bottom: 8px; }

/* stat row on home */
.stat-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.stat-card .label { font-size: 12.5px; color: var(--slate); font-weight: 600; }
.stat-card .value { font-size: 22px; font-weight: 800; color: var(--green-dark); }
.stat-card .sub { font-size: 11.5px; color: var(--slate); margin-top: 2px; }

/* comparison result */
.result-hero {
  background: var(--dark);
  color: var(--white);
  border-radius: var(--radius-lg);
  padding: 20px;
}
.result-hero .kicker {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255,255,255,0.55);
  font-weight: 700;
}
.result-hero .store-name {
  font-size: 17px;
  font-weight: 700;
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.result-hero .price {
  font-size: 34px;
  font-weight: 800;
  color: var(--green);
  margin-top: 4px;
}
.result-hero .savings {
  font-size: 13px;
  color: rgba(255,255,255,0.75);
  margin-top: 6px;
}
.result-hero .badges {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.badge {
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 600;
  color: rgba(255,255,255,0.85);
}

.rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid rgba(12,26,38,0.06);
}
.rank-row:last-child { border-bottom: none; }
.rank-row .num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--mint);
  color: var(--green-dark);
  font-weight: 800;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.rank-row.rank-1 .num { background: var(--green); color: var(--dark); }
.rank-row .store { flex: 1; }
.rank-row .store .n { font-weight: 700; font-size: 14.5px; }
.rank-row .store .m { font-size: 11.5px; color: var(--slate); }
.rank-row .amount { font-weight: 800; font-size: 15px; }

.disclaimer {
  background: var(--amber-bg);
  color: var(--amber);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  font-size: 12px;
  line-height: 1.45;
  margin-top: 14px;
}

.section-title {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--slate);
  margin: 22px 0 10px;
}
.section-title:first-child { margin-top: 0; }

.missing-item, .sub-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  font-size: 13.5px;
  border-bottom: 1px solid rgba(12,26,38,0.05);
}
.missing-item:last-child, .sub-item:last-child { border-bottom: none; }

/* bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--white);
  border-top: 1px solid rgba(12,26,38,0.08);
  display: flex;
  max-width: 480px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--slate);
  cursor: pointer;
  font-size: 10.5px;
  font-weight: 700;
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn.active { color: var(--green-dark); }

.field-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--slate);
  margin-bottom: 6px;
  display: block;
}
.field {
  width: 100%;
  border: 1px solid rgba(12,26,38,0.12);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 14.5px;
  margin-bottom: 14px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid rgba(12,26,38,0.06);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-row .t-label { font-weight: 600; font-size: 14px; }
.toggle-row .t-sub { font-size: 11.5px; color: var(--slate); margin-top: 1px; }

.switch {
  position: relative;
  width: 42px;
  height: 25px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute;
  inset: 0;
  background: rgba(12,26,38,0.18);
  border-radius: 999px;
  transition: 0.15s;
}
.switch .track::before {
  content: "";
  position: absolute;
  width: 19px; height: 19px;
  left: 3px; top: 3px;
  background: var(--white);
  border-radius: 50%;
  transition: 0.15s;
}
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::before { transform: translateX(17px); }

.progress-track {
  height: 6px;
  background: rgba(12,26,38,0.08);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0;
}
.progress-fill {
  height: 100%;
  background: var(--green);
  border-radius: 999px;
  transition: width 0.3s;
}

.spinner {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 3.5px solid rgba(34,197,94,0.2);
  border-top-color: var(--green);
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--dark);
  color: var(--white);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s;
  z-index: 50;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
