:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #1f2421;
  --muted: #6b716d;
  --line: #e3e1da;
  --brand: #2f7d4f;
  --brand-soft: #e6f2ea;
  --danger: #b4372f;
  --warn-bg: #fff6dd;
  --warn-line: #f0d98a;
  --today: #fff9ec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141715;
    --card: #1e2220;
    --text: #e9ece9;
    --muted: #9aa39d;
    --line: #2f3531;
    --brand: #5cc08a;
    --brand-soft: #1f3328;
    --danger: #ef7d74;
    --warn-bg: #2f2a18;
    --warn-line: #5a4d1f;
    --today: #262418;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
body.modal-open { overflow: hidden; }
a { color: var(--brand); }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
h4 { font-size: .9rem; }
p { margin: .4em 0; }
code { background: var(--brand-soft); padding: 0 .3em; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Layout */
.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px calc(90px + env(safe-area-inset-bottom));
}
.center-card {
  max-width: 420px;
  margin: 0 auto;
  padding: 40px 16px;
  text-align: center;
}
.center-card form { text-align: left; }
.logo { font-size: 3rem; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
  box-shadow: var(--shadow);
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }

.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.bar-title { flex: 1; text-align: center; }
.bar-title h1 { margin: 0; }
.bar-title .muted { font-size: .9rem; }

/* Forms */
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: 6px; color: var(--text); display: inline-flex; margin-right: 14px; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  min-width: 0;
}
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--brand); flex: none; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0; }
legend { color: var(--muted); font-size: .9rem; padding: 0 4px; }

.btn {
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  padding: 10px 16px;
  cursor: pointer;
  min-height: 44px;
}
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.danger { color: var(--danger); }
.btn.link { background: none; border: none; color: var(--brand); padding: 8px; }
.btn.link.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: default; }
.icon {
  font: inherit;
  font-size: 1.6rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
}
.icon.small { font-size: 1rem; width: 36px; height: 36px; border: none; background: none; color: var(--muted); }

.notice {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 8px 0;
  font-size: .95rem;
}
.notice.busy { display: flex; align-items: center; gap: 10px; background: var(--brand-soft); border-color: transparent; }
.spinner {
  width: 18px; height: 18px; flex: none;
  border: 3px solid var(--brand); border-right-color: transparent; border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.badge {
  display: inline-block;
  font-size: .72rem;
  background: var(--brand-soft);
  color: var(--brand);
  border-radius: 99px;
  padding: 1px 8px;
  font-weight: 600;
}
.empty-state { text-align: center; color: var(--muted); padding: 30px 10px; }

/* Menú */
.day {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin: 10px 0;
  box-shadow: var(--shadow);
}
.day.today { background: var(--today); }
.day h3 small { color: var(--muted); font-weight: 400; }
.meal {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  border-top: 1px solid var(--line);
  padding: 10px 2px;
  cursor: pointer;
}
.meal:first-of-type { border-top: none; }
.meal-name { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.dish { font-weight: 600; }
.dish.empty { color: var(--brand); font-weight: 500; }
.notes { font-size: .88rem; color: var(--muted); }
ul.ing { margin: 8px 0 0; padding-left: 18px; }

/* Lista de la compra */
.add-row { display: grid; grid-template-columns: 1fr 80px; gap: 8px; margin: 6px 0 12px; }
.add-row select { grid-column: 1; }
.add-row .btn { grid-column: 2; grid-row: 2; font-size: 1.3rem; }
@media (min-width: 560px) {
  .add-row { grid-template-columns: 1fr 90px 170px 52px; }
  .add-row select, .add-row .btn { grid-column: auto; grid-row: auto; }
}
.shop-sec h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 18px 0 6px; display: flex; align-items: center; justify-content: space-between; }
.shop-sec ul { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.shop-item { display: flex; align-items: center; border-top: 1px solid var(--line); }
.shop-item:first-child { border-top: none; }
.check { flex: 1; flex-direction: row; align-items: center; gap: 12px; padding: 12px; color: var(--text); font-size: 1rem; cursor: pointer; }
.check .name { flex: 1; }
.check .qty { color: var(--muted); font-size: .9rem; }
.shop-item.done .name { text-decoration: line-through; color: var(--muted); }

/* Gustos */
.member h2 small { font-weight: 400; }
.pref-group { margin-top: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--brand-soft); border-radius: 99px; padding: 4px 4px 4px 12px; font-size: .92rem;
}
.pref-group.dislike .chip { background: var(--line); }
.pref-group.allergy .chip { background: var(--warn-bg); border: 1px solid var(--warn-line); }
.chip button { border: none; background: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; width: 26px; height: 26px; border-radius: 50%; }
.mini-add { display: flex; gap: 8px; margin-top: 6px; }
.mini-add input { padding: 8px 10px; }

/* Familia */
.code { font: 700 1.6rem/1 ui-monospace, monospace; letter-spacing: .15em; text-align: center; padding: 14px; margin: 10px 0; background: var(--brand-soft); border-radius: 10px; }
.members { list-style: none; padding: 0; margin: 0; }
.members li { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.members li:first-child { border-top: none; }

/* Pestañas */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 10;
}
.tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .75rem; color: var(--muted); text-decoration: none; padding: 4px 0; max-width: 140px;
}
.tabs a span { font-size: 1.35rem; filter: grayscale(1); opacity: .7; }
.tabs a.on { color: var(--brand); font-weight: 700; }
.tabs a.on span { filter: none; opacity: 1; }

/* Modal y avisos */
#modal {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 20;
}
#modal[hidden], #toast[hidden] { display: none; }
.sheet {
  background: var(--bg);
  width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
@media (min-width: 600px) {
  #modal { align-items: center; }
  .sheet { border-radius: 18px; }
}
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(84px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; z-index: 30;
  max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}
