:root {
  --ink: #241f18;
  --muted: #6d6458;
  --paper: #f6f0e4;
  --card: #fffaf3;
  --line: #e3d6c4;
  --line-soft: #ece1cf;
  --olive: #243023;
  --olive-2: #3c5140;
  --olive-3: #5c7a52;
  --paprika: #a33b24;
  --paprika-deep: #862f1c;
  --cream: #fff8ee;
  --good: #1f4d32;
  --warn-bg: #f8e6d4;
  --warn-ink: #7a3d12;
  --ring: rgba(60, 81, 64, 0.22);
  --shadow: 0 10px 30px rgba(36, 48, 35, 0.08);
  --card-shadow: 0 1px 2px rgba(36, 32, 24, 0.05), 0 10px 24px rgba(36, 48, 35, 0.06);
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.45;
  background:
    radial-gradient(900px 420px at 0% -10%, rgba(255, 248, 236, 0.9), transparent 50%),
    radial-gradient(700px 380px at 100% 0%, rgba(163, 59, 36, 0.16), transparent 42%),
    #e7dccb;
}

button, input, textarea { font: inherit; color: inherit; }

.app {
  width: min(460px, 100%);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.top {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  padding: calc(18px + env(safe-area-inset-top)) 20px 16px;
  background: linear-gradient(160deg, var(--olive) 0%, #2e3d2b 100%);
  color: var(--cream);
  box-shadow: 0 4px 18px rgba(36, 48, 35, 0.28);
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.72rem;
  opacity: 0.75;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 2.4rem;
  font-style: italic;
  line-height: 0.95;
}

h2, h3 {
  font-family: var(--serif);
  font-weight: 500;
  margin: 0;
}

.card h2 { font-size: 1.3rem; }
.card h3 { font-size: 1.05rem; color: var(--olive); }

main {
  flex: 1;
  padding: 18px 16px calc(96px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: 20px;
  padding: 18px 16px;
  box-shadow: var(--card-shadow);
}

.stack { display: flex; flex-direction: column; gap: 12px; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
}

input, textarea, select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  background: #fffdf8;
  border-radius: 12px;
  padding: 12px;
  font-weight: 400;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--olive-2);
  box-shadow: 0 0 0 3px var(--ring);
  outline: none;
}

textarea { resize: vertical; min-height: 64px; }

button {
  border: 0;
  border-radius: 999px;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 650;
  letter-spacing: 0.01em;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease, color 0.15s ease;
}

button:active:not(:disabled) { transform: translateY(1px) scale(0.99); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.primary, .secondary { min-height: 48px; }

.primary {
  background: var(--paprika);
  color: white;
  box-shadow: 0 4px 14px rgba(163, 59, 36, 0.28);
}
.primary:hover:not(:disabled) { background: var(--paprika-deep); }
.secondary {
  background: var(--olive-2);
  color: white;
  box-shadow: 0 4px 14px rgba(60, 81, 64, 0.25);
}
.secondary:hover:not(:disabled) { background: var(--olive); }

.text-btn {
  background: transparent;
  color: inherit;
  padding: 6px 0;
  border-radius: 8px;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-underline-offset: 3px;
}

.text-btn:hover { text-decoration-color: currentColor; }

.top-actions { display: flex; gap: 14px; align-items: center; }
.top .text-btn { color: var(--cream); }

.meter { display: flex; flex-direction: column; gap: 5px; }
.meter-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}
.meter-track { display: block; height: 10px; border-radius: 99px; background: #ece0cb; overflow: hidden; }
.meter-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--olive-2), var(--olive-3));
  border-radius: 99px;
  transition: width 0.4s ease;
}
.meter-fill.over { background: linear-gradient(90deg, var(--paprika), var(--paprika-deep)); }

.muted { color: var(--muted); margin: 0; line-height: 1.45; font-weight: 400; }

.alert {
  margin: 0;
  background: var(--warn-bg);
  color: var(--warn-ink);
  border-radius: 12px;
  border-left: 3px solid var(--warn-ink);
  padding: 10px 12px;
  font-weight: 400;
}

.alert.success {
  background: #e5f0e6;
  color: var(--good);
  border-left-color: var(--good);
}

.today-line {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.35rem;
  color: var(--olive);
}

.quota {
  margin: 0;
  align-self: flex-start;
  color: var(--olive-2);
  font-size: 0.9rem;
  font-weight: 600;
  background: #eef3e8;
  border-radius: 999px;
  padding: 6px 12px;
}

.file {
  position: relative;
  display: block;
}

.file input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file span, .primary, .secondary { text-align: center; }

.file span {
  display: block;
  border: 1.5px dashed var(--olive-2);
  border-radius: 14px;
  padding: 16px;
  background: #f3f6ef;
  font-weight: 600;
  color: var(--olive-2);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.file:hover span { background: #ebf1e4; border-color: var(--olive); }

#preview {
  width: 100%;
  border-radius: 14px;
  max-height: 240px;
  object-fit: cover;
  background: #ddd;
}

.section-head, .food-head, .meal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.draft { display: flex; flex-direction: column; gap: 10px; }

#draft-empty {
  text-align: center;
  padding: 8px 4px;
}

.food, .meal {
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  padding: 12px;
  background: var(--cream);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.food input { padding: 8px 10px; min-height: 40px; }

.search-row, .grams-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}

.search-row .secondary, .grams-row .secondary { min-height: 48px; }

.grams-row { grid-template-columns: 120px 1fr; }

.kcal {
  margin: 0;
  font-family: var(--serif);
  font-size: 2.1rem;
  color: var(--good);
  font-variant-numeric: tabular-nums;
}

.kcal small { font-size: 1rem; color: var(--muted); }

.macros, .match, .confidence { margin: 0; color: var(--muted); font-size: 0.92rem; }

.totals {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  padding-top: 4px;
  border-top: 1px dashed var(--line);
}

.block-title { margin: 4px 2px; font-size: 1.45rem; color: var(--olive); }

.day-link, .history-list { display: flex; flex-direction: column; gap: 8px; }

.day-link {
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 400;
  box-shadow: var(--card-shadow);
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}

.day-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.day-sub {
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.history-summary { margin: 2px 2px 4px; }

.day-link:hover { transform: translateY(-1px); }

.day-link strong { font-family: var(--serif); font-size: 1.4rem; font-weight: 500; color: var(--good); }

.tabs {
  position: sticky;
  bottom: calc(10px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin: 10px 12px 0;
  padding: 6px;
  background: rgba(255, 250, 243, 0.94);
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  box-shadow: 0 12px 28px rgba(36, 48, 35, 0.18);
  backdrop-filter: blur(10px);
}

.tabs button {
  background: transparent;
  border-radius: 12px;
  min-height: 56px;
  padding: 6px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.74rem;
  font-weight: 600;
}

.tabs .ico { width: 24px; height: 24px; }

.top-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.15rem;
  color: var(--cream);
  opacity: 0.9;
  padding-bottom: 2px;
}

.goto-add { width: 100%; margin-top: 12px; }

.tabs button[aria-current="page"] {
  background: var(--olive);
  color: var(--cream);
  box-shadow: 0 3px 10px rgba(36, 48, 35, 0.3);
}

.add-form { border-top: 1px dashed var(--line); padding-top: 12px; }

.noscript {
  max-width: 30rem;
  margin: 2rem auto;
  padding: 0 1rem;
}

:focus-visible {
  outline: 3px solid var(--paprika);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}


/* Añadir rápido */
#repeat h3 { margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--cream);
}
.chip small { color: var(--muted, #6b6558); }
.chip b { color: var(--paprika-deep, #a33a22); font-size: 1.15rem; line-height: 1; }
.chip:active { background: var(--line-soft); }
.quick-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: var(--cream);
}
.quick-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.quick-info small { color: var(--muted, #6b6558); }
.quick-add { min-height: 44px; padding: 0 16px; }
.quick-remove { grid-column: 2; justify-self: end; font-size: 0.85rem; }
#favourites { display: flex; flex-direction: column; gap: 8px; }
.draft-bar {
  position: sticky;
  bottom: 96px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--olive);
  color: var(--cream);
  border-radius: 16px;
  box-shadow: 0 8px 22px rgba(36, 48, 35, 0.3);
}
.draft-bar[hidden] { display: none; }
.draft-bar .primary { min-height: 40px; padding: 0 14px; white-space: nowrap; }
