/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green-dark:  #2d6a4f;
  --green:       #40916c;
  --green-light: #74c69d;
  --green-pale:  #d8f3dc;
  --amber:       #e9c46a;
  --amber-dark:  #f4a261;
  --red:         #e63946;
  --text:        #1a1a2e;
  --text-muted:  #6b7280;
  --border:      #e5e7eb;
  --surface:     #ffffff;
  --bg:          #f7faf8;
  --header-h:    56px;
  --nav-h:       64px;
  --radius:      12px;
  --shadow:      0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

/* ── Screens ── */
.screen { height: 100dvh; }
.hidden { display: none !important; }

/* ── Login ── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--green-dark);
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
}
.app-title {
  text-align: center;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--green-dark);
  margin-bottom: 28px;
}
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: .875rem;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-muted);
}
.field input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color .15s;
  outline: none;
}
.field input:focus { border-color: var(--green); }

.error-msg {
  color: var(--red);
  font-size: .875rem;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: #fef2f2;
  border-radius: 6px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 18px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.97); }
.btn-primary  { background: var(--green); color: #fff; }
.btn-danger   { background: var(--red); color: #fff; }
.btn-ghost    { background: transparent; color: var(--green-dark); border: 1.5px solid var(--green); }
.btn-full     { width: 100%; }
.btn-sm       { padding: 8px 14px; font-size: .875rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  font-size: 1.25rem;
  border-radius: 8px;
  -webkit-tap-highlight-color: transparent;
  color: #fff;
  opacity: .85;
}
.icon-btn:hover { opacity: 1; }

/* ── Header ── */
#main-screen { display: flex; flex-direction: column; }

.app-header {
  height: var(--header-h);
  background: var(--green-dark);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  flex-shrink: 0;
  position: relative;
  z-index: 100;
}
.app-name {
  font-weight: 700;
  font-size: 1.1rem;
  flex: 1;
}
.household-btn {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: .9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 200px;
  -webkit-tap-highlight-color: transparent;
}
.household-btn:hover { background: rgba(255,255,255,.25); }
.chevron { font-size: .7rem; opacity: .8; }

.dropdown {
  position: absolute;
  top: calc(var(--header-h) - 4px);
  right: 48px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 200px;
  overflow: hidden;
  z-index: 200;
  border: 1px solid var(--border);
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 16px;
  cursor: default;
  font-size: .95rem;
  border-bottom: 1px solid var(--border);
  background: none;
  color: var(--text);
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover, .dropdown-item.active { background: var(--green-pale); }
.dropdown-item.active .dropdown-item-name { color: var(--green-dark); font-weight: 600; }

.dropdown-item-name {
  flex: 1;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  font-size: .95rem;
  color: inherit;
  padding: 10px 0;
}
.dropdown-item-name:hover { color: var(--green-dark); }

.dropdown-star {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 8px 6px;
  color: var(--text-muted);
  line-height: 1;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.dropdown-star:hover { color: var(--amber-dark); }
.dropdown-star-active { color: var(--amber-dark); cursor: default; }

/* ── View container ── */
#view-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 8px;
}

/* ── Bottom nav ── */
.bottom-nav {
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-shrink: 0;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  color: var(--text-muted);
  transition: color .15s;
}
.nav-btn.active { color: var(--green-dark); }
.nav-icon { font-size: 1.4rem; }
.nav-label { font-size: .7rem; font-weight: 500; }

/* ── Shared view styles ── */
.view-header {
  padding: 16px 16px 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.view-title {
  flex: 1;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--green-dark);
}
.back-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.4rem;
  padding: 4px;
  -webkit-tap-highlight-color: transparent;
  color: var(--green-dark);
}

/* ── Card list ── */
.card-list { padding: 0 12px; }
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  overflow: hidden;
}
.card-row {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}
.card-row:last-child { border-bottom: none; }
.card-row-main { flex: 1; min-width: 0; }
.card-row-title {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-row-sub {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Badge ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-green  { background: var(--green-pale); color: var(--green-dark); }
.badge-amber  { background: #fef3c7; color: #92400e; }
.badge-gray   { background: #f3f4f6; color: var(--text-muted); }

/* ── Shopping overview ── */
.store-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 0 12px 12px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  border: 2px solid transparent;
  transition: border-color .15s;
}
.store-card:active { border-color: var(--green); }
.store-card-icon { font-size: 2rem; flex-shrink: 0; }
.store-card-body { flex: 1; min-width: 0; }
.store-card-name {
  font-size: 1.05rem;
  font-weight: 700;
}
.store-card-count {
  font-size: .875rem;
  color: var(--text-muted);
  margin-top: 3px;
}
.store-card-arrow { color: var(--text-muted); font-size: 1.2rem; }

/* ── Checklist (store shopping view) ── */
.section-label {
  padding: 10px 16px 4px;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
}
.check-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  -webkit-tap-highlight-color: transparent;
}
.check-item.non-preferred { background: #fafafa; }
.check-item.checked { opacity: .45; }
.check-item label { flex: 1; cursor: pointer; }
.check-item-name { font-weight: 500; font-size: 1rem; }
.check-item-tags { margin-top: 3px; display: flex; gap: 5px; flex-wrap: wrap; }

/* Custom checkbox */
.check-item input[type=checkbox] {
  width: 24px;
  height: 24px;
  accent-color: var(--green);
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Add form ── */
.add-form {
  padding: 12px 12px 16px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.add-form input {
  flex: 1;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  background: var(--surface);
}
.add-form input:focus { border-color: var(--green); }

/* ── Autocomplete ── */
.autocomplete-wrapper {
  flex: 1;
  position: relative;
}
.autocomplete-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  outline: none;
  background: var(--surface);
}
.autocomplete-input:focus { border-color: var(--green); }

.autocomplete-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1.5px solid var(--green);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 50;
  overflow: hidden;
}
.autocomplete-suggestion {
  display: block;
  width: 100%;
  padding: 12px 14px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.autocomplete-suggestion:last-child { border-bottom: none; }
.autocomplete-suggestion:hover,
.autocomplete-suggestion:focus { background: var(--green-pale); outline: none; }
.autocomplete-suggestion mark {
  background: none;
  color: var(--green-dark);
  font-weight: 700;
}

/* ── Desired list ── */
.desired-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.desired-item-body { flex: 1; min-width: 0; }
.desired-item-name { font-weight: 500; }
.desired-item-actions { display: flex; gap: 8px; align-items: center; }
.must-buy-toggle {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: .8rem;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 500;
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.must-buy-toggle.active {
  border-color: var(--amber-dark);
  background: #fef3c7;
  color: #92400e;
}
.delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.3rem;
  color: var(--text-muted);
  padding: 4px;
  -webkit-tap-highlight-color: transparent;
  line-height: 1;
}
.delete-btn:hover { color: var(--red); }

/* ── Store preferences editor ── */
.pref-list { padding: 0 12px 12px; }
.pref-item {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 6px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.pref-order {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--green-pale);
  color: var(--green-dark);
  font-size: .8rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.pref-name { flex: 1; font-weight: 500; }
.pref-move-btns { display: flex; flex-direction: column; gap: 2px; }
.pref-move-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  padding: 2px 8px;
  font-size: .8rem;
  color: var(--text-muted);
  -webkit-tap-highlight-color: transparent;
}
.pref-move-btn:hover { background: var(--green-pale); color: var(--green-dark); }
.pref-remove-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text-muted);
  padding: 4px;
  -webkit-tap-highlight-color: transparent;
}
.pref-remove-btn:hover { color: var(--red); }

.store-select-section { padding: 0 12px 16px; }
.store-select-section label {
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
  margin-bottom: 6px;
}
.store-select-section select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--surface);
  margin-bottom: 8px;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state-text { font-size: .95rem; }

/* ── Spinner ── */
.spinner {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
}

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: calc(var(--nav-h) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: .9rem;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 1000;
  white-space: nowrap;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
