/* Listahan — adapts to device size in portrait AND landscape. Zoom is locked
   off (see viewport meta in index.html), so the layout must do the work. */
:root {
  --green: #1e7a34;
  --green-dark: #155c26;
  --green-soft: #e7f4ea;
  --ink: #1c241d;
  --muted: #5c6b5e;
  --line: #dfe6df;
  --surface: #ffffff;
  --bg: #f6f8f6;
  --danger: #b3261e;
  --amber: #8a5a00;
  --amber-bg: #fff4d6;
  --radius: 14px;
  --tap: 56px; /* minimum row height */
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
}
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 8px; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }
input[type="text"], input[type="number"], select, textarea {
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 3px solid #9ecfa9;
  outline-offset: 1px;
}
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error-text { color: var(--danger); font-weight: 600; }
.hidden, [hidden] { display: none !important; }

/* ---- Header: logo never cropped ---- */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.logo {
  width: 48px; height: 48px;
  object-fit: contain; /* full basket + check, never cropped */
  flex: 0 0 auto;
}
.logo-large { width: 96px; height: 96px; object-fit: contain; display: block; margin: 8px auto; }
.header-titles { flex: 1 1 auto; min-width: 0; }
.tagline { margin: 0; color: var(--muted); font-size: 0.9rem; }
.household-chip {
  display: flex; align-items: center; gap: 8px;
  background: var(--green-soft);
  border: 1px solid #c4e0cb;
  border-radius: 999px;
  padding: 6px 6px 6px 12px;
  font-size: 0.9rem;
  white-space: nowrap;
}
.household-label { color: var(--muted); }
.chip-btn {
  border: none; background: var(--green); color: #fff;
  border-radius: 999px; padding: 8px 14px; min-height: 36px;
}

main { max-width: 860px; margin: 0 auto; padding: 12px 16px 24px; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.tab {
  flex: 1; min-height: 52px;
  border: 1.5px solid var(--line); background: var(--surface);
  border-radius: 12px; font-weight: 700; font-size: 1rem; color: var(--ink);
}
.tab.active { background: var(--green); border-color: var(--green); color: #fff; }

/* ---- Buttons ---- */
.btn {
  min-height: 56px; padding: 12px 20px;
  border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 600;
}
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:active { background: var(--green-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-big { width: 100%; min-height: 72px; font-size: 1.1rem; }
.btn-small { min-height: 44px; padding: 8px 14px; font-size: 0.9rem; }
.btn-finish { min-height: 72px; min-width: 180px; font-size: 1.1rem; }

/* ---- Sample banner / regulars ---- */
.sample-banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  background: var(--amber-bg); border: 1px solid #ecd28a;
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px;
}
.regulars-box, .learned-box, .alerts-box, .hints-box {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 14px;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1.5px solid var(--green); background: var(--green-soft); color: var(--green-dark);
  border-radius: 999px; padding: 10px 16px; min-height: 48px; font-weight: 600;
}

/* ---- Add bar ---- */
.add-bar {
  display: flex; gap: 8px; align-items: stretch; margin-bottom: 8px;
}
.add-bar input[type="text"] { flex: 1 1 auto; min-width: 0; min-height: 56px; }
.add-bar #qtyInput { flex: 0 0 76px; text-align: center; }
.add-bar .btn-primary { flex: 0 0 auto; }
.icon-btn {
  flex: 0 0 auto; min-width: 56px; min-height: 56px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--surface); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; font-size: 0.75rem;
  color: var(--ink);
}
.icon-btn .mic-icon { font-size: 1.3rem; line-height: 1; }
.mic-idle { color: #6b7a6d; }
.mic-listening {
  background: var(--green); border-color: var(--green); color: #fff;
  animation: mic-pulse 1.1s ease-in-out infinite;
}
.mic-stop {
  background: #c62828; border-color: #c62828; color: #fff;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(30, 122, 52, 0.55); }
  50% { box-shadow: 0 0 0 12px rgba(30, 122, 52, 0); }
}
.qty-hint {
  background: var(--green-soft); border: 1px solid #c4e0cb; color: var(--green-dark);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-weight: 600;
  cursor: pointer; min-height: 48px; display: flex; align-items: center;
}
.voice-live {
  display: flex; align-items: center; gap: 10px;
  background: var(--green-soft); border-radius: 10px;
  padding: 12px; margin-bottom: 10px; font-weight: 600; color: var(--green-dark);
}
.voice-dot {
  width: 12px; height: 12px; border-radius: 50%; background: var(--green);
  animation: mic-pulse 1.1s ease-in-out infinite; flex: 0 0 auto;
}

/* ---- List sections ---- */
.section-title { margin: 18px 0 8px; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.aisle-group { margin-bottom: 6px; }
.item-row {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--tap);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 10px; margin-bottom: 8px;
}
.item-check {
  flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid var(--green); background: #fff; color: transparent;
  font-size: 1.3rem; line-height: 1; padding: 0;
}
.item-check[aria-pressed="true"] { background: var(--green); color: #fff; }
.item-main { flex: 1 1 auto; min-width: 0; text-align: left; background: none; border: none; padding: 6px 0; }
.item-name { display: block; font-weight: 600; overflow-wrap: anywhere; }
.item-name .original { color: var(--muted); font-weight: 400; font-size: 0.9em; }
.item-sub { display: block; color: var(--muted); font-size: 0.85rem; }
.item-row.checked { opacity: 0.6; }
.item-row.checked .item-name { text-decoration: line-through; color: var(--muted); }
.item-x, .item-edit {
  flex: 0 0 auto; min-width: 44px; min-height: 44px;
  border: none; background: transparent; font-size: 1.2rem; color: var(--muted);
  border-radius: 10px;
}
.empty-state { text-align: center; color: var(--muted); padding: 28px 12px; }

/* ---- Learned words ---- */
.learned-list { list-style: none; margin: 0; padding: 0; }
.learned-list li {
  display: flex; align-items: center; gap: 10px;
  min-height: 48px; border-top: 1px solid var(--line); padding: 6px 0;
}
.learned-list li span { flex: 1 1 auto; }
.learned-list button {
  min-width: 44px; min-height: 44px; border: none; background: transparent;
  color: var(--muted); font-size: 1.1rem; border-radius: 10px;
}

/* ---- Trips ---- */
.trip-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
}
.trip-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.trip-head strong { font-size: 1.05rem; }
.trip-head .muted { font-size: 0.9rem; }
.trip-spent { margin: 6px 0; font-size: 1.1rem; font-weight: 700; }
.trip-spent button { background: none; border: none; font: inherit; color: inherit; text-decoration: underline; padding: 6px 0; }
.trip-items { color: var(--muted); font-size: 0.9rem; margin: 4px 0 10px; }
.trip-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.trip-actions .btn { min-height: 48px; padding: 10px 16px; }
.trip-receipt { display: block; margin-top: 10px; max-width: 220px; border-radius: 10px; border: 1px solid var(--line); }
.alerts-list, .hints-list { margin: 0; padding-left: 20px; }
.alerts-list li { color: var(--amber); font-weight: 600; margin-bottom: 6px; }
.hints-list li { margin-bottom: 6px; }

/* ---- Household screen ---- */
.household-screen {
  max-width: 480px; margin: 24px auto; padding: 24px 20px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; text-align: center;
}
.household-screen h2 { font-size: 1.3rem; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 20px 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.join-form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.join-form label { font-weight: 600; }
.join-form input { text-transform: uppercase; letter-spacing: 0.2em; font-size: 1.2rem; text-align: center; min-height: 56px; }

/* ---- Bottom bar: ONE single line, never stacked, at every width ---- */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; flex-wrap: nowrap;
  gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.08);
}
.bar-btn {
  flex: 1 1 0; min-width: 0;
  min-height: 72px; height: 72px;
  border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface); font-weight: 700; font-size: 1rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; justify-content: center; padding: 0 6px;
}
.bar-btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.bar-btn:disabled { opacity: 0.45; }

/* Compact one-word labels below 640px */
@media (max-width: 639px) {
  .bar-btn .bar-label { font-size: 0.95rem; }
  #clearCheckedBtn .bar-label::after { content: ""; }
  .add-bar #qtyInput { flex-basis: 64px; }
  .icon-btn span:last-child { display: none; }
  .icon-btn { min-width: 52px; }
  .household-label { display: none; }
}

/* ---- Sheets (modals / confirm) ---- */
.sheet {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-card {
  background: var(--surface); width: 100%; max-width: 640px;
  max-height: 88vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 20px;
}
.sheet-card label { display: block; font-weight: 600; margin-bottom: 12px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }
/* The review Finish button: big, 72px, lower right */
#reviewAddBtn { flex: 0 0 auto; margin-left: auto; }
.review-list { list-style: none; margin: 0; padding: 0; }
.review-list li {
  display: flex; align-items: center; gap: 10px;
  min-height: 56px; border-top: 1px solid var(--line); padding: 8px 0;
}
.review-list .review-item { flex: 1 1 auto; min-width: 0; }
.review-list .review-item input {
  border: none; padding: 6px 2px; font-weight: 600;
}
.review-list .review-item input:focus { outline: 2px solid #9ecfa9; }
.review-list .review-aisle { color: var(--muted); font-size: 0.85rem; }
.review-list .review-x {
  flex: 0 0 auto; min-width: 48px; min-height: 48px;
  border: none; background: transparent; font-size: 1.3rem; color: var(--muted);
}
.review-photo { width: 100%; border-radius: 10px; border: 1px solid var(--line); }
.receipt-photo-wrap { margin: 10px 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  background: var(--ink); color: #fff; border-radius: 999px;
  padding: 12px 20px; font-weight: 600; max-width: calc(100vw - 32px);
  text-align: center;
}

/* ---- Landscape: two-column list, narrower add bar ---- */
@media (orientation: landscape) and (min-width: 700px) {
  main { max-width: 1020px; }
  #listSections { columns: 2; column-gap: 16px; }
  .aisle-group { break-inside: avoid; }
  .sheet { align-items: center; }
  .sheet-card { border-radius: 18px; }
}
@media (min-width: 700px) {
  .sheet { align-items: center; }
  .sheet-card { border-radius: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .mic-listening, .voice-dot { animation: none; }
}
