:root {
  --blue: #4f78ae;
  --blue-dark: #34557f;
  --green: #c5df73;
  --green-soft: #eef5d6;
  --ink: #1f2933;
  --muted: #5b6672;
  --line: #dde3ea;
  --bg: #f4f6f9;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding-bottom: env(safe-area-inset-bottom);
}

.top {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--blue);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 0.75rem) 1rem 0.5rem;
}

.top h1 {
  margin: 0 0 0.5rem;
  font-size: 1.4rem;
}

#view-nav {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

#view-nav button {
  flex: 1;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.15;
}

#view-nav button[aria-current="true"] {
  background: #fff;
  color: var(--blue-dark);
}

#sub-nav {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

#sub-nav:empty {
  display: none;
}

#sub-nav a {
  flex: none;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 0.9rem;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
}

main {
  max-width: 40rem;
  margin: 0 auto;
  padding: 0.75rem;
}

.card {
  background: #fff;
  border-radius: 14px;
  padding: 1rem;
  margin-bottom: 0.9rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  scroll-margin-top: 7rem;
}

h2 {
  margin: 0 0 0.5rem;
  color: var(--blue-dark);
  font-size: 1.35rem;
}

h3 {
  margin: 1.1rem 0 0.25rem;
  font-size: 1.05rem;
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.group h4 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0.9rem 0 0.35rem;
  font-size: 1.05rem;
}

.rule {
  flex: none;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--green-soft);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
}

.rule-free {
  background: #fff3d6;
}

.portions {
  list-style: none;
  margin: 0;
  padding: 0;
}

.portion {
  padding: 0.55rem 0;
  border-top: 1px solid var(--line);
}

.portion-text {
  display: block;
}

.note {
  display: block;
  font-size: 0.9rem;
  color: var(--blue-dark);
  font-style: italic;
}

.note::before {
  content: "Preparación: ";
  font-style: normal;
  color: var(--muted);
}

.collapsible {
  margin-top: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.collapsible summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 0.8rem;
  font-weight: 600;
  color: var(--blue-dark);
  cursor: pointer;
}

.templates {
  list-style: none;
  margin: 0;
  padding: 0 0.8rem 0.4rem;
}

.template {
  padding: 0.6rem 0;
  border-top: 1px solid var(--line);
}

.template-title {
  margin: 0 0 0.3rem;
  font-weight: 700;
}

.template dl {
  margin: 0;
}

.template dt {
  font-size: 0.85rem;
  color: var(--muted);
}

.template dd {
  margin: 0 0 0.35rem;
}

.rest-snacks {
  margin: 0;
  padding-left: 1.4rem;
}

.rest-snacks li,
.reference li {
  padding: 0.3rem 0;
}

.drinks,
.meal-note,
.hint {
  font-size: 0.92rem;
  color: var(--muted);
}

.reference ul {
  margin: 0;
  padding-left: 1.2rem;
}

.status {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
}

.error {
  color: #a23b3b;
}

/* Mi día */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip {
  min-height: 44px;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  text-align: left;
}

.chip[aria-pressed="true"] {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.chip:disabled {
  opacity: 0.4;
}

.other-date {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.6rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.other-date input {
  min-height: 44px;
  font: inherit;
}

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.switch > span {
  display: flex;
  flex-direction: column;
}

.switch input {
  width: 1.6rem;
  height: 1.6rem;
  flex: none;
}

.meal-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.link {
  min-height: 44px;
  border: 0;
  background: none;
  color: var(--blue);
  font: inherit;
  font-weight: 600;
}

.rule-done {
  background: var(--green);
}

.snack-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.snack-option {
  border-radius: 12px;
}

.starters {
  margin: 0.6rem 0;
}

.starter-list {
  list-style: none;
  margin: 0;
  padding: 0 0.8rem 0.4rem;
}

.starter {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.6rem 0;
  border-top: 1px solid var(--line);
}

.starter-apply {
  align-self: flex-start;
  font-weight: 600;
}

.starter-text {
  font-size: 0.85rem;
}

.starter-actions {
  display: flex;
  gap: 0.8rem;
}

.starter-actions .link {
  padding: 0;
}

.danger {
  color: #a23b3b;
}

.source {
  margin: 0.2rem 0;
}

.note-field {
  display: block;
  margin-top: 0.6rem;
}

.note-label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
}

.note-field input {
  width: 100%;
  min-height: 44px;
  padding: 0 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-size: 16px; /* 16px keeps Safari from zooming in on focus */
}

.problem {
  margin: 0.3rem 0;
  color: #a23b3b;
  font-weight: 600;
}

.save-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 -0.75rem;
  padding: 0.6rem 0.75rem calc(0.6rem + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.save-status {
  flex: 1;
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
}

.primary {
  min-height: 48px;
  padding: 0 1.2rem;
  border: 0;
  border-radius: 12px;
  background: var(--blue);
  color: #fff;
  font: inherit;
  font-weight: 700;
}

.primary:disabled {
  opacity: 0.6;
}

/* Day message */

.message-meals {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  margin-bottom: 0.5rem;
}

.message-meal {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 44px;
}

.message-meal input {
  width: 22px;
  height: 22px;
}

.message-preview {
  margin: 0 0 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font: inherit;
  font-size: 0.95rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.whatsapp {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.whatsapp[aria-disabled="true"] {
  opacity: 0.6;
  pointer-events: none;
}

/* Historial */

.history {
  list-style: none;
  margin: 0;
  padding: 0;
}

.history-day {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 44px;
  margin-bottom: 0.5rem;
  padding: 0.75rem 1rem;
  border: 0;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  color: var(--ink);
  font: inherit;
  text-align: left;
}

/* "No hay" in the builder: the portion can still be picked. */

.badge-out {
  display: inline-block;
  margin-left: 0.2rem;
  padding: 0 0.45rem;
  border-radius: 999px;
  background: #f7dede;
  color: #a23b3b;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

/* Inventario */

.add-product {
  padding: 0;
}

.add-product .product-form {
  padding: 0 0.8rem 0.8rem;
}

.products {
  list-style: none;
  margin: 0;
  padding: 0;
}

.product {
  padding: 0.6rem 0;
  border-top: 1px solid var(--line);
}

.product-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.product-head > span:first-child {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.product-kind {
  font-size: 0.82rem;
}

.stepper {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.step {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--blue-dark);
  font: inherit;
  font-size: 1.3rem;
  font-weight: 700;
}

.step:disabled {
  opacity: 0.4;
}

.stepper input {
  width: 3.2rem;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  font: inherit;
  font-size: 16px;
}

.levels {
  flex: none;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.level {
  min-height: 44px;
  padding: 0 0.6rem;
  border: 0;
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
}

.level + .level {
  border-left: 1px solid var(--line);
}

.level-have[aria-pressed="true"] {
  background: var(--green);
  color: var(--ink);
}

.level-low[aria-pressed="true"] {
  background: #ffd98a;
  color: var(--ink);
}

.level-out[aria-pressed="true"] {
  background: #a23b3b;
  color: #fff;
}

.product-edit summary {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  color: var(--blue);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}

.product-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.4rem;
}

.field {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  color: var(--muted);
}

.field input,
.field select {
  min-height: 44px;
  padding: 0 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 16px keeps Safari from zooming in on focus */
}

.countable-fields {
  display: flex;
  gap: 0.6rem;
}

.countable-fields[hidden] {
  display: none;
}

.countable-fields .field {
  flex: 1;
}

.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Cocinado */

.cooking {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 0.3rem 0;
}

.chip.cook {
  border-color: var(--green);
  background: var(--green-soft);
  font-weight: 600;
}

.cooking-state {
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-weight: 600;
}

.cooking-cooked {
  background: var(--green);
}

.cooking-skipped {
  background: var(--line);
  color: var(--muted);
}

.cook-all .primary {
  width: 100%;
}

.pending,
.bulk-prompt {
  border: 2px solid var(--blue);
}

.pending-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.pending-dish {
  padding: 0.5rem 0;
  border-top: 1px solid var(--line);
}

.pending-dish:first-child {
  border-top: 0;
}
