/* =====================================================================
   Pantry styles. Designed for one-handed use on an iPhone in a kitchen:
   big tap targets (at least 52px tall), large text, high contrast.
   Colors are variables so dark mode only has to change them once.
   ===================================================================== */

:root {
  --bg: #f7f5ef;
  --card: #ffffff;
  --text: #1d2420;
  --muted: #66706a;
  --line: #e2e0d8;
  --green: #2f6b3a;
  --green-soft: #e3efe3;
  --red: #c0392b;
  --red-soft: #fbe5e2;
  --amber: #b9770e;
  --amber-soft: #fdf0d5;
  --radius: 14px;
  --tap: 52px; /* minimum height of anything you tap */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816;
    --card: #1f2522;
    --text: #eef2ef;
    --muted: #9aa59f;
    --line: #2f3833;
    --green: #5fae6c;
    --green-soft: #22362a;
    --red: #ff7b6b;
    --red-soft: #3b2220;
    --amber: #f0b44c;
    --amber-soft: #3a2f1a;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 18px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Leave room for the fixed top bar and tab bar */
  padding-top: calc(56px + var(--safe-top));
  padding-bottom: calc(76px + var(--safe-bottom));
}
body.no-scroll { overflow: hidden; }
body.logged-out .tabbar, body.logged-out .topbar .icon-btn { display: none; }

a { color: var(--green); }

/* ---- Top bar and tab bar ---------------------------------------------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  height: calc(56px + var(--safe-top)); padding: var(--safe-top) 16px 0;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 22px; margin: 0; }

.tabbar {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 64px; font-size: 12px; color: var(--muted); text-decoration: none;
}
.tabbar a span { font-size: 24px; line-height: 1.1; }
.tabbar a.on { color: var(--green); font-weight: 600; }

/* ---- Layout ------------------------------------------------------------ */
.screen { padding: 12px 16px 24px; max-width: 640px; margin: 0 auto; }
.row { display: flex; gap: 8px; align-items: center; }
.row > input, .row > select { flex: 1; min-width: 0; }
.grow { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 15px; }
.error { color: var(--red); }
.warn { color: var(--red); font-weight: 600; }
.empty { color: var(--muted); padding: 8px 0; margin: 0; }

.section { margin: 20px 0; }
.section h3 { font-size: 17px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.count {
  display: inline-block; margin-left: 8px; padding: 0 8px; border-radius: 10px;
  background: var(--line); color: var(--text); font-size: 14px; letter-spacing: 0;
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.card h3 { margin: 0 0 6px; }

/* ---- Buttons and inputs ------------------------------------------------- */
button, .link-btn {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  min-height: var(--tap); padding: 8px 14px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:active { transform: scale(.98); }
button:disabled { opacity: .5; }
button.big, .link-btn.big { display: block; width: 100%; margin: 8px 0; font-size: 19px; font-weight: 600; text-align: center; text-decoration: none; }
button.primary { background: var(--green); border-color: var(--green); color: #fff; }
button.danger { color: var(--red); }
button.big.danger { border-color: var(--red); }
button.secondary { background: var(--green-soft); }
button.link { background: none; border: none; color: var(--green); text-decoration: underline; }
.icon-btn { min-width: var(--tap); padding: 0; font-size: 22px; background: none; border: none; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); }

input, select, textarea {
  font: inherit; font-size: 18px; /* 16px+ stops iPhone zooming in */
  color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px;
  min-height: var(--tap); padding: 10px 12px; width: 100%; margin: 4px 0;
}
textarea { min-height: 120px; }
input[type="checkbox"] { width: 28px; height: 28px; min-height: 0; margin: 0; accent-color: var(--green); }

.field { display: block; margin: 10px 0; }
.field > span { display: block; font-size: 15px; color: var(--muted); }

/* Big toggle buttons in a row (location, container, etc.) */
.seg { display: flex; gap: 6px; margin: 8px 0; flex-wrap: wrap; }
.seg button { flex: 1 1 0; min-width: 72px; padding: 6px 4px; font-size: 16px; }
.seg button.on { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }

.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper button { width: var(--tap); font-size: 24px; padding: 0; }
.stepper-value { min-width: 36px; text-align: center; font-size: 20px; font-weight: 600; }

/* ---- Item rows ----------------------------------------------------------- */
.item-row {
  display: flex; align-items: stretch; gap: 0;
  background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--line);
  border-radius: var(--radius); margin: 8px 0; overflow: hidden;
}
.item-row.red { border-left-color: var(--red); background: var(--red-soft); }
.item-row.amber { border-left-color: var(--amber); background: var(--amber-soft); }
.item-main {
  flex: 1; display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  border: none; background: none; text-align: left; border-radius: 0; padding: 10px 12px; min-width: 0;
}
.item-name { font-weight: 600; font-size: 19px; }
.item-sub { font-size: 15px; color: var(--muted); }
.item-days { display: flex; align-items: center; padding: 0 8px; font-size: 15px; color: var(--muted); white-space: nowrap; }
.item-row.red .item-days { color: var(--red); font-weight: 600; }
.item-row.amber .item-days { color: var(--amber); font-weight: 600; }
.used-btn {
  width: 64px; border: none; border-left: 1px solid var(--line); border-radius: 0;
  font-size: 26px; color: var(--green); background: transparent;
}

.item-row-btn, .shelf-row, .forgot-row, .preserved-row, .batch-row, .sl-row, .check-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; margin: 8px 0; min-height: var(--tap); text-decoration: none; color: var(--text); text-align: left;
}
.check-item { flex-direction: column; align-items: stretch; }
.shelf-row.done { opacity: .7; }
.forgot-row { flex-wrap: wrap; }
.days-input { width: 90px; flex: none; }
.pill { background: var(--green-soft); color: var(--green); border-radius: 12px; padding: 4px 10px; font-weight: 600; white-space: nowrap; }

.badges { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 8px; }
.badge {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px;
  border-radius: 22px; background: var(--amber-soft); color: var(--text); text-decoration: none; font-weight: 600;
}
.banner {
  display: block; width: 100%; margin: 8px 0; padding: 14px; text-align: center; text-decoration: none;
  background: var(--amber-soft); border: 2px solid var(--amber); border-radius: var(--radius);
  font-weight: 700; color: var(--text); min-height: var(--tap);
}

/* ---- Add screen tiles ---------------------------------------------------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 130px; padding: 12px; text-align: center; text-decoration: none; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
}
.tile.wide { flex-direction: row; justify-content: flex-start; min-height: 80px; gap: 12px; margin: 8px 0; text-align: left; flex-wrap: wrap; }
.tile-icon { font-size: 36px; }

/* ---- Review cards ------------------------------------------------------- */
.review-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin: 10px 0; }
.name-input { font-weight: 600; font-size: 19px; }
.qty-input { max-width: 90px; flex: none !important; }
.split-row { justify-content: space-between; margin-top: 6px; }
.ages { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.ages button { font-size: 15px; padding: 4px; }
.ages button.on { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }

.checklist { margin: 8px 0; }
.check-row { display: flex; align-items: center; gap: 12px; min-height: var(--tap); padding: 4px 0; border-bottom: 1px solid var(--line); }
.check-row span:nth-child(2) { flex: 1; }

/* ---- Sheets (pop-up panels) ------------------------------------------- */
.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .35);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; transition: opacity .2s;
}
.backdrop.open { opacity: 1; }
.sheet {
  width: 100%; max-width: 640px; max-height: 88vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 20px 20px 0 0;
  transform: translateY(30px); transition: transform .2s;
  padding-bottom: var(--safe-bottom);
}
.backdrop.open .sheet { transform: none; }
.sheet.full { height: 94vh; max-height: 94vh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 0 16px; }
.sheet-head h2 { font-size: 20px; margin: 0; }
.sheet-body { overflow-y: auto; padding: 8px 16px 24px; -webkit-overflow-scrolling: touch; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; transition: all .25s;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 24px;
  max-width: 90vw; text-align: center; font-size: 16px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.spinner-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(0, 0, 0, .45); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.spinner { width: 48px; height: 48px; border: 5px solid rgba(255, 255, 255, .3); border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Shop & insights ----------------------------------------------------- */
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.alexa { font-size: 20px; font-weight: 600; margin: 0 0 8px; user-select: all; -webkit-user-select: all; }
.verdict h3 { font-size: 24px; }
.verdict.worth-it { border: 2px solid var(--green); }
.verdict.buy-less { border: 2px solid var(--amber); }
.verdict.skip { border: 2px solid var(--red); }

.table { width: 100%; border-collapse: collapse; }
.table td { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 80px; gap: 8px; align-items: center; padding: 4px 0; }
.bar { display: block; height: 14px; background: var(--line); border-radius: 7px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--green); }
details summary { min-height: var(--tap); display: flex; align-items: center; cursor: pointer; font-weight: 600; }
.receipt-img { width: 100%; border-radius: 10px; }

.barcode-view { width: 100%; min-height: 260px; border-radius: var(--radius); overflow: hidden; background: #000; }
.big-note { font-size: 19px; }
.back { display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; font-weight: 600; }

/* ---- Login ---------------------------------------------------------------- */
.login { max-width: 420px; padding-top: 40px; text-align: center; }
.logo { font-size: 64px; }
