/* =========================================================================
   Serie · food.css — módulo de Comida. Solo tokens de base.css (sin hex).
   Prefijo .fd- para no chocar con otros módulos. Macros: --p, --c, --f; exceso: --warn.
   ========================================================================= */

/* ---------- Día: cabecera, semana, resumen ---------- */
.fd-day { display: flex; flex-direction: column; gap: 16px; }
.fd-side, .fd-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.fd-head { display: flex; align-items: center; gap: 4px; }
.fd-when { flex: 1; min-width: 0; }
.fd-when h1 { margin-top: 4px; overflow-wrap: anywhere; }
.fd-today { margin-right: 4px; }

.fd-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.fd-wd { display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 64px; padding: 7px 0 6px; border-radius: var(--radius-sm); color: var(--text); }
.fd-wd:hover { background: var(--surface2); }
.fd-wl { font-size: 11px; font-weight: 650; letter-spacing: .06em; color: var(--muted); }
.fd-wn { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.fd-wb { position: relative; width: 5px; height: 18px; border-radius: 3px; background: var(--surface2); overflow: hidden; }
.fd-wb i { position: absolute; left: 0; right: 0; bottom: 0; background: var(--accent); border-radius: 3px; }
.fd-wb.over i { background: var(--warn); }
.fd-wd.today .fd-wn { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 2px; }
.fd-wd.on { background: var(--text); color: var(--bg); }
.fd-wd.on .fd-wl { color: var(--bg); opacity: .75; }
.fd-wd.on .fd-wb { background: color-mix(in srgb, var(--bg) 30%, transparent); }
.fd-wd.on .fd-wb i { background: var(--bg); }

.fd-sum { gap: 8px; }
.fd-kcal { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.fd-kcal-n { font-size: 52px; line-height: 1; font-weight: 720; letter-spacing: -2px; }
.fd-goal-link { margin-left: auto; align-self: center; }
.fd-left { color: var(--muted); font-size: 15px; }
.fd-left b { color: var(--text); font-weight: 650; }
.fd-left.over b { color: var(--warn); }
.fd-kbar { height: 8px; --bar: var(--accent); }
.fd-kbar.over { --bar: var(--warn); }
.fd-macros { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 8px; }
.fd-macro { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.fd-macro-l { display: flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 650; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.fd-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bar); flex: none; }
.fd-macro-v { font-size: 17px; font-weight: 650; white-space: nowrap; }
.fd-macro-v small { font-size: 13px; font-weight: 400; color: var(--muted); }
.fd-macro .progress { height: 5px; }

.fd-links { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.fd-links .btn { padding-left: 6px; padding-right: 6px; gap: 6px; }
.fd-links .btn svg { width: 18px; height: 18px; }
.fd-kbd { display: none; }
kbd { font: inherit; font-size: 12px; padding: 1px 6px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface2); }

/* ---------- Comidas ---------- */
.fd-meal { padding: 12px 12px 8px 18px; gap: 2px; }
.fd-meal-h { display: flex; align-items: center; gap: 4px; min-height: 48px; }
.fd-meal-h h2 { flex: 1; font-size: 19px; }
.fd-meal-k { color: var(--muted); font-size: 14px; margin-right: 2px; }
.fd-add { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 14px; background: var(--accent); color: var(--accent-ink); flex: none; }
.fd-add svg { width: 24px; height: 24px; }
.fd-add:hover { filter: brightness(1.06); }
.fd-entries { list-style: none; margin: 0; padding: 0 6px 4px 0; }
.fd-entries li + li { border-top: 1px solid var(--line); }
.fd-entry { display: grid; grid-template-columns: minmax(0, 1fr) auto 3.2em; gap: 10px; align-items: baseline; width: 100%; min-height: 48px; padding: 12px 0; text-align: left; }
.fd-entry:hover .fd-en { color: var(--accent); }
.fd-en { overflow-wrap: anywhere; }
.fd-eg { color: var(--muted); font-size: 14px; white-space: nowrap; }
.fd-ek { text-align: right; font-weight: 650; }
.fd-suggest { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 6px 6px 8px 0; color: var(--accent); font-size: 14px; text-align: left; }
.fd-suggest svg { width: 18px; height: 18px; }
.fd-empty { margin-top: 4px; }

/* ---------- Vistas secundarias ---------- */
.fd-sub-view .back { margin-bottom: 4px; }
.fd-week-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.fd-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 12px; margin: 4px 0; }
.fd-stat { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface2); border-left: 3px solid var(--bar, var(--accent)); }
.fd-stat b { font-size: 22px; font-weight: 700; letter-spacing: -.5px; }
.fd-stat b small { font-size: 13px; font-weight: 400; color: var(--muted); }
.fd-stat > span:first-child { font-size: 13px; }
.fd-target b { font-size: 18px; }
.fd-over { color: var(--warn); }
.fd-chart { width: 100%; height: auto; display: block; }
.fd-bar { fill: var(--accent); }
.fd-bar.under { fill: var(--accent2); opacity: .55; }
.fd-bar.over { fill: var(--warn); }
.fd-bar.none { fill: var(--surface2); }
.fd-bar-v { font-size: 10px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.fd-bar-l { font-size: 11px; fill: var(--muted); font-weight: 600; }
.fd-goal-line { stroke: var(--text); stroke-width: 1.2; stroke-dasharray: 4 4; opacity: .7; }
.fd-goal-t { font-size: 10px; fill: var(--text); opacity: .8; }
.fd-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); }
.fd-legend span { display: inline-flex; align-items: center; gap: 6px; }
.fd-legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); }
.fd-legend i.under { background: var(--accent2); opacity: .55; }
.fd-legend i.over { background: var(--warn); }
.fd-week-days { gap: 0; padding-top: 8px; padding-bottom: 8px; }
.fd-week-days .list-row { border-bottom: 1px solid var(--line); }
.fd-week-days .list-row:last-child { border-bottom: 0; }
.fd-form { display: flex; flex-direction: column; gap: 12px; }
.fd-form .field { margin-bottom: 0; }
.fd-est { display: flex; flex-direction: column; gap: 10px; padding-top: 6px; border-top: 1px solid var(--line); }
.fd-est p { line-height: 1.6; }

/* ---------- Formularios (vistas y hojas) ---------- */
.fd-field { margin-bottom: 0; }
.fd-input-wrap { position: relative; display: flex; align-items: center; }
.fd-input-wrap input { width: 100%; padding-right: 44px; }
.fd-input-wrap > i { position: absolute; right: 12px; font-style: normal; font-size: 14px; color: var(--muted); pointer-events: none; }
.fd-grid2, .fd-grid3, .fd-grid4 { display: grid; gap: 10px; }
.fd-grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fd-grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.fd-grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fd-sub { font-size: 13px; font-weight: 650; color: var(--muted); letter-spacing: .02em; margin-top: 4px; }
.fd-hint { font-size: 14px; color: var(--muted); min-height: 0; line-height: 1.5; }
.fd-hint:empty, .fd-status:empty { display: none; }
.fd-error { color: var(--error); }
.fd-note { font-size: 13px; color: var(--muted); line-height: 1.5; padding: 8px 12px; border-left: 3px solid var(--accent2); background: var(--surface2); border-radius: 0 10px 10px 0; }
.fd-seg [role=radio][aria-checked="true"], .fd-seg > button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px color-mix(in srgb, var(--text) 18%, transparent); }
.fd-seg > button { min-height: 44px; padding: 0 6px; }

/* ---------- Hojas ---------- */
.fd-sheet { display: flex; flex-direction: column; gap: 14px; }
.fd-sheet > p { margin-bottom: 0; }
dialog.sheet.fd .sheet-foot { padding-bottom: max(14px, calc(10px + env(safe-area-inset-bottom))); }
.fd-big { min-height: 52px; font-size: 17px; }
.fd .btn.ghost.danger { background: none; border-color: transparent; color: var(--danger); }
.fd .btn.ghost.danger:hover { background: var(--danger-soft); }
.fd-linkbtn { align-self: flex-start; }
.fd-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; }
.fd-vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

/* Añadir */
.fd-add-sheet .sheet-body { padding-top: 14px; }
.fd-search { position: relative; display: flex; align-items: center; }
.fd-search > svg { position: absolute; left: 14px; color: var(--muted); pointer-events: none; }
.fd-search input { width: 100%; min-height: 50px; padding-left: 44px; border-radius: 14px; }
.fd-search input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.fd-meal-pick { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.fd-tools { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }
.fd-tool { flex-direction: column; gap: 4px; min-height: 64px; padding: 8px 6px; font-size: 13px; }
.fd-tool svg { width: 22px; height: 22px; }
.fd-tabs > button { padding: 0 6px; font-size: 13px; }
.fd-tabs > button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px color-mix(in srgb, var(--text) 18%, transparent); }
.fd-list { display: flex; flex-direction: column; }
.fd-row { display: flex; align-items: center; gap: 2px; border-bottom: 1px solid var(--line); }
.fd-row:last-child { border-bottom: 0; }
.fd-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; min-height: 56px; padding: 9px 0; text-align: left; }
.fd-row-main:hover .fd-row-name { color: var(--accent); }
.fd-row-name { display: flex; align-items: center; gap: 6px; overflow-wrap: anywhere; font-weight: 550; }
.fd-row-sub { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.fd-row-add { background: var(--accent-soft); color: var(--accent); }
.fd-row-add:hover { background: var(--accent); color: var(--accent-ink); }
.fd-star-mini { display: inline-grid; color: var(--amber); }
.fd-star-mini svg { width: 14px; height: 14px; }
.fd-empty-line { color: var(--muted); font-size: 14px; line-height: 1.55; padding: 10px 0; list-style: none; }
.fd-off { display: flex; flex-direction: column; gap: 4px; }
.fd-off:empty { display: none; }
.fd-off-btn { justify-content: flex-start; text-align: left; }
.fd-off-head { display: flex; align-items: center; gap: 8px; margin-top: 6px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.fd-off-head svg { width: 16px; height: 16px; }
.fd-status { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); line-height: 1.5; }
.fd-spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: fd-spin .8s linear infinite; flex: none; }
@keyframes fd-spin { to { transform: rotate(360deg); } }

/* Cantidad */
.fd-per { font-size: 14px; color: var(--muted); }
.fd-qty-row { display: flex; align-items: flex-end; gap: 8px; }
.fd-grams { flex: 1; }
.fd-grams input { font-size: 24px; font-weight: 650; min-height: 56px; }
.fd-star { width: 56px; height: 56px; border-radius: 14px; border: 1px solid var(--line); color: var(--muted); }
.fd-star svg { width: 24px; height: 24px; }
.fd-star.on { color: var(--amber); background: var(--warn-soft); border-color: var(--warn-line); }
.fd-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.fd-chips-l { font-size: 13px; width: 100%; }
.fd-chip { min-height: 44px; font-variant-numeric: tabular-nums; }
.fd-chip small { color: var(--muted); font-size: 12px; }
button.chip.fd-chip.on, button.chip.fd-chip[aria-checked="true"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.fd-live { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.fd-live b { font-size: 26px; font-weight: 720; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.fd-live span { font-size: 14px; }

/* Entrada y receta */
.fd-details { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0 12px; }
.fd-details summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--muted); font-size: 14px; }
.fd-details[open] { padding-bottom: 12px; }
.fd-mini-list { list-style: none; margin: 0; padding: 0; }
.fd-mini-list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.fd-mini-list li span:last-child { white-space: nowrap; font-size: 14px; }
.fd-ritems { list-style: none; margin: 0; padding: 0; }
.fd-ritem { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.fd-ritem-name { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-wrap: anywhere; }
.fd-ritem-name small { font-size: 12px; }
.fd-ritem-g { width: 96px; flex: none; }
.fd-ritem-g input { text-align: right; padding-right: 30px; }
.fd-ritem-g > i { right: 10px; }
.fd-factor { width: 96px; }
.fd-factor input { padding-left: 26px; padding-right: 10px; }
.fd-factor > i { left: 10px; right: auto; }

/* Menú de comida */
.fd-menu { display: flex; flex-direction: column; }
.fd-menu-row { gap: 14px; min-height: 56px; border-bottom: 1px solid var(--line) !important; }
.fd-menu-row:last-child { border-bottom: 0 !important; }
.fd-menu-row .grow { display: flex; flex-direction: column; }
.fd-menu-row small { color: var(--muted); font-size: 13px; }

/* Escáner */
.fd-cam { position: relative; border-radius: var(--radius-sm); overflow: hidden; background: var(--text); aspect-ratio: 4 / 3; }
.fd-cam video { width: 100%; height: 100%; object-fit: cover; display: block; }
.fd-cam-frame { position: absolute; inset: 28% 8%; border: 2px solid var(--accent); border-radius: 12px; box-shadow: 0 0 0 999px color-mix(in srgb, var(--text) 35%, transparent); }
.fd-cam-done { opacity: .5; }
.fd-file { cursor: pointer; position: relative; }
.fd-file:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.fd-typed { display: flex; gap: 8px; align-items: flex-end; }
.fd-typed .field { flex: 1; }

/* ---------- Móvil ---------- */
@media (max-width: 760px) {
  .fd-kcal-n { font-size: 46px; }
  .fd-meal { padding: 10px 8px 6px 14px; }
  dialog.sheet.fd-add-sheet { height: 92dvh; }
  .fd-week-grid .card { padding: 16px; }
  .fd-goals .fd-grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 380px) {
  .fd-tabs > button { font-size: 12px; padding: 0 3px; }
  .fd-seg > button { font-size: 13px; padding: 0 3px; }
  .fd-macros { gap: 10px; }
  .fd-macro-v { font-size: 15px; }
}

/* ---------- Escritorio (≥900px): resumen y semana fijos a la izquierda, comidas a la derecha ---------- */
@media (min-width: 900px) {
  .fd-day { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: 24px; align-items: start; }
  .fd-side { position: sticky; top: 24px; }
  .fd-kbd { display: block; }
  .fd-week-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fd-week-days { grid-column: 1 / -1; }
  .fd-grid4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
