:root {
  --green: #1f7a4d;
  --green-dark: #165c3a;
  --bg: #f6f7f5;
  --card: #fff;
  --text: #1d2420;
  --muted: #69726d;
  --line: #e3e6e3;
  --danger: #b3261e;
  --tabs-h: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 80px); }
input, select, textarea, button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

header {
  position: sticky; top: 0; z-index: 5;
  background: var(--green); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
}
header h1 { font-size: 1.15rem; margin: 0; }
header .store { font-size: .8rem; display: flex; align-items: center; gap: 6px; }
header select { background: rgba(255,255,255,.15); color: #fff; border: 1px solid rgba(255,255,255,.4); border-radius: 8px; padding: 4px 6px; max-width: 60vw; }
header select option { color: var(--text); }

main { padding: 16px; max-width: 640px; margin: 0 auto; }
h2 { font-size: 1rem; margin: 22px 0 8px; }
.hint { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }

.big-btn {
  display: block; text-align: center; cursor: pointer;
  background: var(--green); color: #fff; font-weight: 600; font-size: 1.1rem;
  padding: 22px 16px; border-radius: 16px; box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.big-btn:active { background: var(--green-dark); }
.btn { border: 1px solid var(--green); background: #fff; color: var(--green); font-weight: 600; padding: 12px 16px; border-radius: 12px; width: 100%; cursor: pointer; }
.btn.primary { background: var(--green); color: #fff; }
.btn:disabled { opacity: .5; }
.link { background: none; border: none; color: var(--green); padding: 8px 0; cursor: pointer; text-decoration: underline; }
.link.danger { color: var(--danger); }

.typebox { margin: 12px 0 4px; background: var(--card); border-radius: 12px; padding: 10px 14px; border: 1px solid var(--line); }
.typebox summary { cursor: pointer; color: var(--muted); }
.typebox textarea { width: 100%; margin: 10px 0; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }

.recipes { display: grid; gap: 8px; margin-top: 16px; }
.recipe { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.recipe .rtitle { flex: 1; min-width: 0; border: none; font-weight: 600; background: transparent; }
.recipe .scale { color: var(--muted); font-size: .9rem; }
.recipe .rscale { border: 1px solid var(--line); border-radius: 8px; padding: 2px 4px; background: #fff; }
.recipe .servings { width: 100%; font-size: .8rem; color: var(--muted); }
.recipe .rdel { text-decoration: none; color: var(--muted); padding: 4px 6px; }

ul.rows { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: 12px; border: 1px solid var(--line); overflow: hidden; }
.rows .section { background: #eef3ef; color: var(--green-dark); font-weight: 600; font-size: .85rem; padding: 6px 12px; }
.rows .row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--line); }
.rows .section + .row, .rows .row:first-child { border-top: none; }
.rows .row.off .main { opacity: .45; }
.rows .inc { width: 22px; height: 22px; accent-color: var(--green); flex: none; }
.rows .main { flex: 1; min-width: 0; }
.rows .name { width: 100%; border: none; padding: 2px 0; background: transparent; font-weight: 500; }
.rows .title { padding: 4px 0; }
.rows .sub { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; font-size: .82rem; color: var(--muted); }
.rows .qty { border: none; border-bottom: 1px dashed var(--line); width: 7.5em; padding: 0; background: transparent; color: var(--text); }
.rows .from { background: #f0f0ec; border-radius: 6px; padding: 0 6px; }
.rows .cat { flex: none; width: 2.6em; border: 1px solid var(--line); border-radius: 8px; padding: 4px 2px; background: #fff; font-size: 1rem; }

.field { display: block; margin: 10px 0; font-weight: 500; }
.field input, .field textarea { display: block; width: 100%; margin-top: 4px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-weight: 400; }
.field .hint { font-weight: 400; }

.layout { list-style: none; padding: 0; margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.layout li { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-top: 1px solid var(--line); }
.layout li:first-child { border-top: none; }
.layout .lbl { flex: 1; font-size: .9rem; }
.layout .aisle { width: 4.5em; padding: 6px; border: 1px solid var(--line); border-radius: 8px; text-align: center; }
.layout .mv { border: 1px solid var(--line); background: #fff; border-radius: 8px; width: 34px; height: 34px; }
.layout .mv:disabled { opacity: .3; }

.sendbar { position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding: 10px 16px; background: linear-gradient(transparent, var(--bg) 30%); z-index: 4; }
.sendbar .btn { max-width: 608px; display: block; margin: 0 auto; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.bar-spacer { height: 70px; }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: flex; background: #fff; border-top: 1px solid var(--line); z-index: 6; }
.tabs button { flex: 1; border: none; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 1.2rem; color: var(--muted); cursor: pointer; }
.tabs button span { font-size: .75rem; }
.tabs button.active { color: var(--green); font-weight: 600; }

.busy { position: fixed; inset: 0; background: rgba(255,255,255,.85); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; z-index: 20; font-weight: 500; text-align: center; padding: 20px; }
.spinner { width: 40px; height: 40px; border: 4px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 76px); background: #1d2420; color: #fff; padding: 12px 16px; border-radius: 12px; opacity: 0; transform: translateY(10px); transition: all .25s; pointer-events: none; z-index: 30; max-width: 608px; margin: 0 auto; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--green); background: #fff; color: var(--green-dark); font-weight: 600; border-radius: 999px; padding: 10px 16px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip small { background: #eef3ef; border-radius: 999px; padding: 0 7px; font-weight: 500; font-size: .75rem; }
.chip.add { border-style: dashed; color: var(--muted); border-color: var(--muted); }
.chip:active { background: #eef3ef; }

dialog#groupDlg { border: none; border-radius: 18px; padding: 0; width: min(92vw, 520px); max-height: 85vh; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog#groupDlg::backdrop { background: rgba(0,0,0,.4); }
#groupBody { padding: 16px; }
#groupBody h2 { margin-top: 4px; }
#groupBody .field input { font-size: 1rem; }
.rows.edit .cat { width: auto; max-width: 8.5em; font-size: .85rem; }
.rows.edit .rm { text-decoration: none; color: var(--muted); padding: 4px; }
.dlg-actions { margin-top: 16px; }
.dlg-row { display: flex; justify-content: space-between; margin-top: 6px; }
.recipe .rsave { text-decoration: none; color: var(--muted); padding: 4px 6px; font-size: 1.1rem; }
