/* Pantry Tracker */
:root {
  --green: #2f6b4f;
  --green-d: #23523c;
  --green-l: #e7f2ec;
  --ink: #1f2a24;
  --muted: #6b7a72;
  --line: #e3e8e4;
  --bg: #f6f4ef;
  --card: #fff;
  --warn: #b5651d;
  --warn-l: #fdf1e5;
  --red: #b23a3a;
  --radius: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--green); }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
code { background: #f0f0ec; padding: 2px 6px; border-radius: 6px; font-size: .9em; word-break: break-all; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--green); color: #fff; padding: .75rem 1.25rem;
  position: sticky; top: 0; z-index: 10;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.topnav { display: flex; gap: .25rem; }
.topnav a { color: #dcefe4; text-decoration: none; padding: .4rem .7rem; border-radius: 8px; font-size: .95rem; }
.topnav a:hover, .topnav a.active { background: rgba(255,255,255,.15); color: #fff; }

/* Bottom nav on phones */
.bottomnav {
  display: none; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: #fff; border-top: 1px solid var(--line);
  padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom));
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: .72rem; padding: .25rem 0;
}
.bottomnav a span { font-size: 1.35rem; line-height: 1; }
.bottomnav a.active { color: var(--green); font-weight: 600; }

.wrap { max-width: 860px; margin: 0 auto; padding: 1rem; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 1.25rem;
  margin-bottom: 1rem; box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 10px rgba(0,0,0,.03);
}
.card.narrow { max-width: 440px; margin: 2rem auto; }

.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: .5rem; }
.row-between h1, .row-between h2 { margin: 0; }
.stack { display: flex; flex-direction: column; gap: .85rem; margin: .5rem 0 1rem; }
.stack label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .92rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.grid2 label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .92rem; }
.inline { display: inline; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; font-weight: normal; }
.nowrap { white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 1.25rem .5rem; margin: 0; list-style: none; }
.warn { color: var(--warn); }
.ok-text { color: var(--green); font-weight: 600; }
[hidden] { display: none !important; }

/* Inputs & buttons */
input, select, button { font: inherit; }
input:not([type=checkbox]), select {
  padding: .6rem .7rem; border: 1px solid #cfd8d2; border-radius: 10px; background: #fff; color: var(--ink);
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--green); outline-offset: 1px; border-color: var(--green); }
input.qty { width: 5.5rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  background: var(--green); color: #fff; border: 1px solid var(--green);
  padding: .6rem 1rem; border-radius: 10px; cursor: pointer; text-decoration: none; font-weight: 600;
  white-space: nowrap; list-style: none;
}
.btn::-webkit-details-marker { display: none; }
.btn:hover { background: var(--green-d); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-ghost { background: #fff; color: var(--green); border-color: #cfe0d6; }
.btn-ghost:hover { background: var(--green-l); }
.btn-small { padding: .35rem .7rem; font-size: .88rem; border-radius: 8px; }
.btn-danger { background: #fff; color: var(--red); border-color: #e9c3c3; }
.btn-danger:hover { background: #fbeaea; }
.icon-btn {
  background: none; border: none; color: #9aa69f; cursor: pointer; font-size: 1.05rem;
  padding: .35rem .5rem; border-radius: 8px; list-style: none;
}
.icon-btn::-webkit-details-marker { display: none; }
.icon-btn:hover { background: #f1f3f1; color: var(--red); }
.file-btn { cursor: pointer; }

.addform { display: flex; gap: .5rem; flex-wrap: wrap; margin: .5rem 0 1rem; }
.addform .grow { flex: 1 1 200px; }
.addform .note { flex: 1 1 140px; }

/* Lists */
.items { list-style: none; padding: 0; margin: 0; }
.item {
  display: flex; align-items: center; gap: .6rem; padding: .7rem .25rem;
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.item:last-child { border-bottom: none; }
.item-main { flex: 1 1 180px; min-width: 0; }
.item-name { font-weight: 600; }
.item.done .item-name { text-decoration: line-through; color: var(--muted); }
.item.stale { background: var(--warn-l); border-radius: 10px; padding-left: .6rem; padding-right: .6rem; }
.check {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid #b9c8bf; background: #fff;
  color: #fff; cursor: pointer; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.item.done .check { background: var(--green); border-color: var(--green); }
.pill { display: inline-block; background: #f0f2ef; color: #49564f; border-radius: 99px; padding: 1px 8px; font-size: .8rem; margin-left: .3rem; }
.loc { display: inline-block; border-radius: 99px; padding: 1px 8px; font-size: .78rem; margin-left: .3rem; background: #eef; color: #335; }
.loc-fridge { background: #e3f0fb; color: #1f4e79; }
.loc-freezer { background: #e9e6fb; color: #3c2f80; }
.loc-shelf { background: #f6eedf; color: #6b4b16; }

details.putaway { position: relative; }
details.putaway > summary { list-style: none; cursor: pointer; }
details.putaway > summary::-webkit-details-marker { display: none; }
.putaway-form {
  display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap;
  background: #f8faf8; border: 1px solid var(--line); border-radius: 10px; padding: .75rem; margin-top: .5rem;
}
.putaway-form label { display: flex; flex-direction: column; font-size: .8rem; color: var(--muted); gap: .2rem; }
.item details[open] { flex-basis: 100%; order: 5; }
.check-label { display: flex !important; flex-direction: row !important; align-items: center; gap: .45rem; font-weight: normal !important; color: var(--ink) !important; font-size: .92rem !important; }
.check-label input { width: 18px; height: 18px; accent-color: var(--green); }

.actions-bar { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }

.suggestions { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.suggestions li {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  border: 1px dashed #cfe0d6; border-radius: 12px; padding: .6rem .75rem; background: #fbfdfb;
}
.suggest-actions { display: flex; gap: .3rem; flex-shrink: 0; }

/* Tabs */
.tabs { display: flex; gap: .35rem; overflow-x: auto; margin: .25rem 0 1rem; padding-bottom: .25rem; }
.tabs a {
  white-space: nowrap; text-decoration: none; color: var(--muted); padding: .45rem .8rem;
  border-radius: 99px; border: 1px solid var(--line); background: #fff; font-size: .92rem;
}
.tabs a.active { background: var(--green); border-color: var(--green); color: #fff; }
.count { display: inline-block; background: rgba(0,0,0,.08); border-radius: 99px; padding: 0 6px; font-size: .78rem; margin-left: 2px; }
.tabs a.active .count { background: rgba(255,255,255,.25); }
.segmented a { flex: 1; text-align: center; }

.filter { width: 100%; margin-bottom: .5rem; }
.add-inv { margin-bottom: .75rem; }
.add-inv > summary { margin-bottom: .25rem; }

/* Table */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: .8rem; padding: .5rem; border-bottom: 1px solid var(--line); }
.table td { padding: .6rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }

/* Flash & toast */
.flash { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; background: var(--green-l); color: var(--green-d); }
.flash-err { background: #fbeaea; color: var(--red); }
.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: .7rem 1.1rem; border-radius: 12px; max-width: 90vw;
  opacity: 0; transition: all .25s; z-index: 50; box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-err { background: var(--red); }

/* Scanner */
.scanner-box { background: #111; border-radius: var(--radius); overflow: hidden; margin-bottom: 1rem; }
#reader { width: 100%; min-height: 0; }
#reader video { width: 100% !important; display: block; }
.scanner-controls { display: flex; gap: .5rem; padding: .75rem; flex-wrap: wrap; justify-content: center; background: #1b1f1d; }

details.help { margin-top: 1.25rem; background: #f8faf8; border-radius: 10px; padding: .75rem 1rem; }
details.help summary { cursor: pointer; font-weight: 600; color: var(--green); }

@media (max-width: 720px) {
  .topnav { display: none; }
  .bottomnav { display: flex; }
  .wrap { padding: .75rem; }
  .card { padding: 1rem; }
  .grid2 { grid-template-columns: 1fr; }
  .addform .qty, .addform .note { flex: 1 1 30%; }
  .table thead { display: none; }
  .table tr { display: grid; grid-template-columns: 1fr auto; padding: .6rem 0; border-bottom: 1px solid var(--line); }
  .table td { border: none; padding: .1rem .25rem; }
  .table td:nth-child(2), .table td:nth-child(3), .table td:nth-child(4), .table td:nth-child(5) { font-size: .82rem; color: var(--muted); }
  .table td:nth-child(3)::before { content: "In: "; }
  .table td:nth-child(4)::before { content: "Out: "; }
  .table td:nth-child(5)::before { content: "Kept: "; }
  .table td:last-child { grid-column: 2; grid-row: 1 / span 3; align-self: center; }
}
@media (min-width: 721px) { body { padding-bottom: 0; } }
.suggestions li.low { border-color: #efc9a3; background: #fffaf3; }
input.qty-wide { width: 8.5rem; }
.count-pill { background: var(--green-l); color: var(--green-d); font-weight: 600; }
.count-pill.low { background: var(--warn-l); color: var(--warn); }
.stock-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
h2.sub { font-size: 1rem; margin: .75rem 0 0; padding-top: .75rem; border-top: 1px solid var(--line); }
