/* Registro Alimentario — estilos base, adaptables a teléfono, tableta y escritorio. */
:root {
  --bg: #f6f7f4; --surface: #ffffff; --text: #1d2420; --muted: #5d6a63; --border: #d9dfda;
  --primary: #2f7a4f; --primary-text: #ffffff; --accent: #e8f3ec; --warn-bg: #fff6e0; --warn: #8a5a00;
  --error-bg: #fdecea; --error: #a3261b; --over: #c0392b; --bar: #3d9a63; --bar-bg: #e3e8e4;
  --radius: 10px; --gap: 1rem; --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614; --surface: #1b211e; --text: #e6ebe8; --muted: #9daaa3; --border: #2e3833;
    --primary: #4fae78; --primary-text: #0d130f; --accent: #1f2e25; --warn-bg: #3a2f12; --warn: #f2c56b;
    --error-bg: #3d1c19; --error: #ff9b8f; --over: #ff7b6b; --bar: #4fae78; --bar-bg: #2b3530;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.45; font-size: 16px; }
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: .5rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: .5rem; z-index: 10; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .6rem 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; text-decoration: none; color: var(--text); margin-right: auto; }
.menu-toggle { display: none; }
.nav { display: flex; flex-wrap: wrap; gap: .25rem .75rem; align-items: center; }
.nav a { text-decoration: none; padding: .35rem .5rem; border-radius: 6px; color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent); color: var(--primary); font-weight: 600; }
.logout { margin: 0; }
@media (max-width: 860px) {
  .menu-toggle { display: inline-block; }
  .nav { display: none; width: 100%; flex-direction: column; align-items: stretch; }
  .nav.open { display: flex; }
  .nav a { padding: .6rem .5rem; }
}

.grid { display: grid; gap: var(--gap); grid-template-columns: 1fr; }
@media (min-width: 760px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.three { grid-template-columns: repeat(3, 1fr); } .grid.cards { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1080px) { .grid.cards { grid-template-columns: repeat(3, 1fr); } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: var(--gap); min-width: 0; }
.card.wide { grid-column: 1 / -1; }
.row { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: flex-end; }
.row > label { flex: 1 1 160px; }
fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 0 0 .75rem; padding: .5rem .75rem; }
legend { font-weight: 600; font-size: .95rem; }
label { display: block; margin: 0 0 .6rem; font-size: .95rem; }
input, select, textarea, button { font: inherit; }
input, select, textarea { display: block; width: 100%; margin-top: .25rem; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); min-height: 42px; }
input[type=radio], input[type=checkbox] { display: inline; width: auto; min-height: 0; margin-right: .4rem; }
button { padding: .5rem .9rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); cursor: pointer; min-height: 42px; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
button.link { border: 0; background: none; color: var(--primary); padding: .35rem .5rem; min-height: 0; }
button.small, .list button { padding: .25rem .6rem; min-height: 34px; font-size: .9rem; }
button:disabled { opacity: .55; cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.big { font-size: 1.6rem; font-weight: 700; margin: .25rem 0; }
.alert { padding: .6rem .8rem; border-radius: 8px; background: var(--accent); }
.alert.error { background: var(--error-bg); color: var(--error); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.badge { display: inline-block; font-size: .75rem; padding: .05rem .45rem; border-radius: 999px; background: var(--accent); color: var(--primary); margin-left: .3rem; vertical-align: middle; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--error-bg); color: var(--error); }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; z-index: 20; max-width: calc(100% - 32px); }
.toast.error { background: var(--error); color: #fff; }

.datebar { display: flex; gap: .5rem; align-items: center; margin-bottom: var(--gap); flex-wrap: wrap; }
.datebar input { width: auto; margin: 0; }

.progress { position: relative; height: 22px; background: var(--bar-bg); border-radius: 999px; overflow: hidden; margin: .5rem 0; }
.progress > span { display: block; height: 100%; background: var(--bar); border-radius: 999px; }
.progress.over > span { background: var(--over); }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
@media (min-width: 520px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--accent); border-radius: 8px; padding: .5rem; }
.kpi b { display: block; font-size: 1.25rem; }
.kpi span { font-size: .8rem; color: var(--muted); }
.over-text { color: var(--over); font-weight: 600; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table td.num, .table th.num { text-align: right; white-space: nowrap; }
.table input, .table select { min-height: 36px; padding: .3rem .4rem; margin: 0; }
.list { list-style: none; padding: 0; margin: .5rem 0; }
.list li { display: flex; flex-wrap: wrap; gap: .25rem .75rem; justify-content: space-between; align-items: center; padding: .45rem 0; border-bottom: 1px solid var(--border); }
.list li .actions { display: flex; gap: .3rem; }
.results { list-style: none; padding: 0; margin: .25rem 0; max-height: 420px; overflow-y: auto; }
.results li button { width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: none; padding: .55rem .25rem; }
.results li button:hover, .results li button:focus { background: var(--accent); }
.meal h3 { font-size: 1rem; margin: .75rem 0 .25rem; display: flex; justify-content: space-between; }
.nutrients { columns: 2; column-gap: 1.5rem; font-size: .9rem; padding: 0; list-style: none; }
.nutrients li { break-inside: avoid; display: flex; justify-content: space-between; border-bottom: 1px dotted var(--border); padding: .15rem 0; }
@media (max-width: 480px) { .nutrients { columns: 1; } }
.preview { background: var(--accent); border-radius: 8px; padding: .5rem .75rem; margin: .5rem 0; font-size: .92rem; }
.photo-preview { max-width: 100%; max-height: 360px; border-radius: 8px; margin: .5rem 0; display: block; }
.filebtn { display: inline-block; flex: 0 0 auto; }
.filebtn input { font-size: .9rem; }
.warnlist li { color: var(--warn); }
.chart { width: 100%; min-height: 220px; }
.small-chart { min-height: 160px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--bar); }
.chart .bar.over { fill: var(--over); }
.chart .axis { stroke: var(--border); }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .line { stroke: var(--primary); fill: none; stroke-width: 2; }
.chart .dot { fill: var(--primary); }
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); max-width: min(520px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.option h3 { margin-top: 0; }
.footer { color: var(--muted); font-size: .82rem; padding-bottom: 2rem; }
.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; width: 100%; max-width: 380px; }
.login-box button { width: 100%; }
