/* Grocery App - styles
   Calm palette: linen background, sage green, misty blue, soft clay. Dark mode follows the phone's setting. */

:root {
  --bg:           #f3f1ec;   /* linen */
  --surface:      #ffffff;
  --surface-2:    #eef3f0;   /* pale sage */
  --text:         #2f3e46;   /* deep slate */
  --muted:        #6b7a80;
  --primary:      #5f8d7e;   /* sage */
  --primary-dark: #4b7365;
  --primary-soft: #dce9e3;
  --accent:       #7fa3ba;   /* misty blue */
  --accent-soft:  #e3edf3;
  --warm:         #c99a82;   /* soft clay */
  --warm-soft:    #f6ebe4;
  --border:       #e1ddd5;
  --danger:       #b0655b;
  --danger-soft:  #f5e3e0;
  --shadow:       0 1px 3px rgba(47, 62, 70, .06), 0 4px 14px rgba(47, 62, 70, .05);
  --radius:       14px;
  --nav-height:   64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #1d2527;
    --surface:      #263134;
    --surface-2:    #2c393b;
    --text:         #e3e9e6;
    --muted:        #9aa8a6;
    --primary:      #8db8a8;
    --primary-dark: #a9cbbe;
    --primary-soft: #2f4742;
    --accent:       #9dbcd0;
    --accent-soft:  #2b3b45;
    --warm:         #d9b29e;
    --warm-soft:    #3d322d;
    --border:       #36474a;
    --danger:       #dc8f85;
    --danger-soft:  #43302d;
    --shadow:       0 1px 3px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; font-weight: 700; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p  { margin: 0 0 .75em; }
a  { color: var(--primary-dark); }

.hidden { display: none !important; }
.muted  { color: var(--muted); }
.small  { font-size: .875rem; }
.error  { color: var(--danger); min-height: 1.2em; margin: .5em 0 0; }
.center { text-align: center; }

/* ---------- Layout ---------- */
.view { min-height: 100vh; }

.centered-view {
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
}

.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.app-header .brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.1rem; color: var(--primary-dark); }
.app-header .brand i { font-size: 1.4rem; }
.app-header .household-chip {
  margin-left: auto; display: flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--primary-soft); color: var(--primary-dark);
  font-size: .85rem; font-weight: 700; border: 0; cursor: pointer;
}

main.content {
  max-width: 760px; margin: 0 auto;
  padding: 16px 16px calc(var(--nav-height) + 28px);
}

/* Bottom navigation */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: var(--nav-height);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.bottom-nav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--muted);
  font: inherit; font-size: .75rem; font-weight: 700; cursor: pointer;
}
.bottom-nav button i { font-size: 1.45rem; }
.bottom-nav button.active { color: var(--primary-dark); }
.bottom-nav button.active i {
  background: var(--primary-soft); border-radius: 999px; padding: 2px 16px;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}
.card.soft { background: var(--surface-2); box-shadow: none; }
.login-card { width: 100%; max-width: 400px; }
.login-card .logo {
  width: 64px; height: 64px; border-radius: 18px; margin: 0 auto 12px;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary-soft); color: var(--primary-dark); font-size: 2rem;
}

.section-title { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.section-title h2 { margin: 0; }
.section-title .spacer { flex: 1; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 700; font-size: .9rem; margin: 0 0 12px; }
label .hint { font-weight: 400; color: var(--muted); }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px;
  padding: 10px 12px;
  font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { min-height: 120px; resize: vertical; }
input[type="checkbox"] { display: inline-block; width: auto; margin: 0 6px 0 0; accent-color: var(--primary); }
label.check { display: flex; align-items: center; font-weight: 600; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 480px) { .row-3 { grid-template-columns: 1fr 1fr; } }

/* ---------- Buttons ---------- */
button { font: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 700; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #17201f; } }
.btn-soft { background: var(--primary-soft); border-color: transparent; color: var(--primary-dark); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); background: var(--danger-soft); }
.btn-link { background: none; border: 0; color: var(--primary-dark); font-weight: 700; cursor: pointer; padding: 6px 0; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px 10px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* ---------- Chips / badges ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chip {
  flex: none; padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 700; font-size: .85rem; cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
@media (prefers-color-scheme: dark) { .chip.active { color: #17201f; } }

.badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 800;
  background: var(--surface-2); color: var(--muted);
}
.badge.gf   { background: var(--primary-soft); color: var(--primary-dark); }
.badge.cat  { background: var(--accent-soft);  color: var(--text); }
.badge.warm { background: var(--warm-soft);    color: var(--text); }

/* ---------- Recipes list ---------- */
.search-box { position: relative; margin-bottom: 12px; }
.search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-box input { padding-left: 36px; margin: 0; }

.recipe-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.recipe-card {
  display: flex; flex-direction: column; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; padding: 0; color: inherit;
  transition: transform .15s, border-color .15s;
}
.recipe-card:hover { transform: translateY(-2px); border-color: var(--primary); }
.recipe-card .thumb {
  height: 110px; background: var(--surface-2) center / cover no-repeat;
  display: flex; align-items: center; justify-content: center; color: var(--primary); font-size: 2rem;
}
.recipe-card .body { padding: 12px 14px; }
.recipe-card h3 { margin: 0 0 6px; }
.recipe-card .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .8rem; color: var(--muted); }

.empty-state { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty-state i { font-size: 2.6rem; color: var(--primary); display: block; margin-bottom: 8px; }

/* ---------- Recipe page ---------- */
.recipe-photo { width: 100%; max-height: 320px; object-fit: cover; border-radius: var(--radius); margin-bottom: 12px; }
.recipe-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.scale-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.scale-bar input { width: 80px; display: inline-block; margin: 0; }
.ingredient-list { list-style: none; padding: 0; margin: 0; }
.ingredient-list li { padding: 8px 0; border-bottom: 1px dashed var(--border); }
.ingredient-list li:last-child { border-bottom: 0; }
.ingredient-list .amt { font-weight: 800; color: var(--primary-dark); }
.ingredient-list .alt { color: var(--muted); font-size: .85rem; }
.ingredient-list .group { font-weight: 800; padding-top: 14px; border-bottom: 0; color: var(--muted); text-transform: uppercase; font-size: .8rem; letter-spacing: .04em; }
.steps { padding-left: 1.3em; margin: 0; }
.steps li { margin-bottom: 10px; }

/* ---------- Ingredient review table (add/edit) ---------- */
.review-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.review-table th { text-align: left; color: var(--muted); font-size: .75rem; text-transform: uppercase; padding: 4px; }
.review-table td { padding: 4px; vertical-align: middle; border-top: 1px solid var(--border); }
.review-table input, .review-table select { margin: 0; padding: 6px 8px; font-size: .9rem; }
.review-table .amt-col { width: 72px; }
.review-table .unit-col { width: 96px; }
.review-table .orig { color: var(--muted); font-size: .8rem; }
.match { font-size: .75rem; font-weight: 800; white-space: nowrap; }
.match.ok   { color: var(--primary-dark); }
.match.new  { color: var(--warm); }
.match.none { color: var(--muted); }
.review-table tr.heading-row td { font-weight: 800; background: var(--surface-2); }
@media (max-width: 560px) {
  .review-table thead { display: none; }
  .review-table tr { display: grid; grid-template-columns: 70px 90px 1fr; gap: 4px; padding: 6px 0; border-top: 1px solid var(--border); }
  .review-table td { border: 0; padding: 0; }
  .review-table td.item-col, .review-table td.note-col { grid-column: 1 / -1; }
  .review-table tr.heading-row { display: block; }
}

/* ---------- Household ---------- */
.join-code {
  display: inline-block; font-family: ui-monospace, Consolas, monospace; font-size: 1.4rem; font-weight: 800;
  letter-spacing: .12em; padding: 6px 14px; border-radius: 10px;
  background: var(--accent-soft); color: var(--text);
}
.member-list { list-style: none; padding: 0; margin: 0; }
.member-list li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.member-list li:last-child { border-bottom: 0; }
.member-list .name { flex: 1; font-weight: 700; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary-soft); color: var(--primary-dark); font-weight: 800;
}

.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 14px; }
.tabs button {
  flex: 1; border: 0; background: none; padding: 8px; border-radius: 9px;
  font-weight: 700; color: var(--muted); cursor: pointer;
}
.tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-height) + 16px); transform: translateX(-50%);
  z-index: 50; padding: 10px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-weight: 700; font-size: .9rem;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: 1; }

.setup-message { max-width: 520px; margin: 60px auto; padding: 0 16px; }

/* ---------- Ingredient rows (Amount · Unit · Grocery item · Note) ---------- */
.ing-editor { margin: 4px 0 14px; }
.ing-editor-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 8px; }
.ing-row {
  display: grid; grid-template-columns: 92px 120px minmax(150px, 1.4fr) minmax(120px, 1fr) auto;
  gap: 6px; align-items: center; padding: 6px 0; border-top: 1px solid var(--border);
}
.ing-row input, .ing-row select { margin: 0; padding: 8px 10px; font-size: .92rem; }
.ing-labels { border-top: 0; padding: 0 0 2px; font-size: .72rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.ing-row.heading { grid-template-columns: 1fr auto; background: var(--surface-2); border-radius: 10px; padding: 6px 8px; border-top: 0; margin-top: 6px; }
.ing-row.heading input { font-weight: 800; background: transparent; border-color: transparent; }
.ing-row.heading input:focus { background: var(--surface); border-color: var(--primary); }
.ing-row .orig { grid-column: 1 / -1; font-size: .78rem; color: var(--muted); margin-top: -2px; }
.item-pick { position: relative; }
.item-pick input { padding-right: 64px; }
.item-pick .status { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.ing-tools { display: flex; gap: 2px; }
.icon-btn {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  width: 30px; height: 30px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
@media (max-width: 640px) {
  .ing-labels { display: none; }
  .ing-row { grid-template-columns: 84px 1fr auto; }
  .ing-row .item-pick, .ing-row [data-field="note"] { grid-column: 1 / -1; }
  .ing-row .ing-tools { grid-row: 1; grid-column: 3; }
}

/* The grocery item picker */
.item-picker {
  position: fixed; z-index: 60; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(47, 62, 70, .18); padding: 4px 0;
}
.pick-sec {
  position: sticky; top: -4px; background: var(--surface-2); color: var(--muted);
  font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding: 5px 12px;
}
.pick-opt { display: flex; align-items: center; gap: 6px; padding: 8px 12px; cursor: pointer; font-size: .92rem; }
.pick-opt:hover, .pick-opt.active { background: var(--primary-soft); }
.pick-opt .pick-tag { margin-left: auto; font-size: .72rem; color: var(--muted); }
.pick-opt.new { color: var(--primary-dark); font-weight: 700; border-top: 1px solid var(--border); }

/* ---------- This Week ---------- */
.week-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.week-title { flex: 1; text-align: center; }
.week-title h2 { margin: 0; }
.week-card h3 { margin: 0; display: flex; align-items: center; gap: 6px; }
.week-card h3 i { color: var(--primary); }
.pick-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px;
  padding: 8px 0; border-top: 1px dashed var(--border);
}
.pick-row:first-of-type { border-top: 0; }
.pick-icon { color: var(--primary); font-size: 1.15rem; }
.pick-icon.product { color: var(--accent); }
.pick-row.leftover .pick-icon { color: var(--warm); }
.pick-name { flex: 1; min-width: 140px; font-weight: 700; text-align: left; padding: 0; color: var(--text); }
button.pick-name:hover { color: var(--primary-dark); text-decoration: underline; }
.pick-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.pick-controls select, .pick-controls input { width: auto; margin: 0; padding: 5px 8px; font-size: .85rem; border-radius: 8px; }
.pick-controls .qty-input { width: 56px; }
.pick-controls .unit-mini { max-width: 110px; }
.vote { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 3px 9px; cursor: pointer; font-size: .85rem; }
.vote.on { background: var(--primary-soft); border-color: var(--primary); }

/* Dialogs */
.modal {
  position: fixed; inset: 0; z-index: 70; background: rgba(29, 37, 39, .45);
  display: flex; align-items: flex-end; justify-content: center; padding: 12px;
}
@media (min-width: 640px) { .modal { align-items: center; } }
.modal-card {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border-radius: 18px; padding: 18px; box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
.pick-list { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 12px; margin-bottom: 12px; }
.pick-list:empty { display: none; }
.pick-list > p { padding: 10px 12px; margin: 0; }
.pick-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 10px 12px; border: 0; border-bottom: 1px solid var(--border); background: none; color: var(--text); cursor: pointer;
}
.pick-item:last-child { border-bottom: 0; }
.pick-item:hover, .pick-item.active { background: var(--primary-soft); }
.pick-item .pick-tag { margin-left: auto; font-size: .75rem; color: var(--muted); }
.pick-item.new { color: var(--primary-dark); font-weight: 700; }

/* ---------- Grocery list ---------- */
.list-add { display: flex; gap: 8px; margin-bottom: 12px; }
.list-add input { margin: 0; }
.list-card h3 { margin-bottom: 4px; color: var(--primary-dark); }
.list-row {
  display: flex; align-items: flex-start; gap: 10px; padding: 9px 0; margin: 0;
  border-top: 1px dashed var(--border); font-weight: 400; cursor: pointer;
}
.list-row:first-of-type { border-top: 0; }
.list-row input[type="checkbox"] { width: 22px; height: 22px; margin-top: 1px; flex: none; }
.list-main { flex: 1; }
.list-amt { color: var(--primary-dark); font-weight: 800; }
.list-amt .alt { color: var(--muted); font-weight: 400; font-size: .82rem; }
.list-src { display: block; font-size: .78rem; color: var(--muted); }
.list-row.done .list-main { opacity: .5; text-decoration: line-through; }

/* ---------- Pantry + staples ---------- */
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.item-search { position: relative; margin-bottom: 12px; }
.item-search .search-box { margin-bottom: 6px; }
.pantry-row, .staple-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px dashed var(--border);
}
.pantry-row:first-of-type, .staple-row:first-of-type { border-top: 0; }
.pantry-name { flex: 1; min-width: 120px; font-weight: 700; }
.pantry-row.low .pantry-name { color: var(--warm); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 5px 12px; font-size: .82rem; font-weight: 700; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--primary-soft); color: var(--primary-dark); }
.seg button.on.low { background: var(--warm-soft); color: var(--text); }
.staple-row input, .staple-row select { width: auto; margin: 0; padding: 6px 8px; font-size: .88rem; }
.staple-row input { width: 80px; }

/* ---------- Scanner ---------- */
#scan-reader { width: 100%; min-height: 60px; border-radius: 12px; overflow: hidden; background: var(--surface-2); }
#scan-reader video { width: 100% !important; border-radius: 12px; }
.scan-product { display: flex; gap: 12px; align-items: flex-start; margin: 6px 0; }
.scan-product img { width: 72px; height: 72px; object-fit: contain; border-radius: 10px; background: #fff; border: 1px solid var(--border); }
.scan-actions .btn { flex: 1 1 45%; }
.scan-actions .btn.suggested { background: var(--primary); border-color: var(--primary); color: #fff; }
.gf-hint { display: inline-block; margin-top: 4px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 800; }
.gf-hint.yes { background: var(--primary-soft); color: var(--primary-dark); }
.gf-hint.no { background: var(--danger-soft); color: var(--danger); }
.gf-hint.unknown { background: var(--surface-2); color: var(--muted); }
.tiny { font-size: .72rem; margin: 10px 0 0; }
