/* FructoScan · móvil primero, claro/oscuro, accesible (WCAG AA) */
:root {
  --bg: #f5f7f2;
  --surface: #ffffff;
  --surface-2: #eef2ea;
  --text: #1a1f1a;
  --muted: #4e5a4e;
  --line: #d5ddd1;
  --control: #6b7a6a;
  --brand: #1f6b3a;
  --brand-text: #ffffff;
  --focus: #0b57d0;
  --red-bg: #fde8e6;
  --red-fg: #8c1d13;
  --red-line: #e0726a;
  --yel-bg: #fff4d1;
  --yel-fg: #6b4e00;
  --yel-line: #d9a91c;
  --grn-bg: #e3f4e6;
  --grn-fg: #17542b;
  --grn-line: #5fb074;
  --unk-bg: #eceeed;
  --unk-fg: #444a46;
  --unk-line: #a7aeaa;
  color-scheme: light dark;
  --radius: 14px;
  --nav-h: 64px;
  accent-color: var(--brand);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121512;
    --surface: #1c211c;
    --surface-2: #252b25;
    --text: #e9eee7;
    --muted: #a9b5a8;
    --line: #343c34;
    --control: #7f8c7e;
    --brand: #7fd29a;
    --brand-text: #0d2716;
    --focus: #9ec2ff;
    --red-bg: #3a1714;
    --red-fg: #ffb4a9;
    --red-line: #a8433a;
    --yel-bg: #33290c;
    --yel-fg: #f5d27a;
    --yel-line: #8f6f17;
    --grn-bg: #13301b;
    --grn-fg: #9be0ae;
    --grn-line: #2f7a45;
    --unk-bg: #2a2d2b;
    --unk-fg: #c3c9c5;
    --unk-line: #5b625e;
  }
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 1rem/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
h1, h2 { line-height: 1.25; text-wrap: balance; }
h1 { font-size: 1.5rem; margin: .25rem 0 .75rem; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
h1:focus { outline: none; }
img { max-width: 100%; }

.skip { position: absolute; left: 8px; top: -60px; background: var(--surface); padding: 8px 12px; z-index: 50; }
.skip:focus { top: 8px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px; background: var(--bg); background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; gap: 8px; align-items: center; font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.brand img { border-radius: 7px; }
.offline { background: var(--yel-bg); color: var(--yel-fg); border: 1px solid var(--yel-line); padding: 2px 10px; border-radius: 99px; font-size: .85rem; font-weight: 600; }

.view { max-width: 640px; margin: 0 auto; padding: 12px 16px 24px; outline: none; }
.lead { font-size: 1.1rem; color: var(--muted); }
.sub, .hint { color: var(--muted); font-size: .92rem; }
.hint { display: block; }
.note, .disclaimer { color: var(--muted); font-size: .85rem; }
.disclaimer { margin-top: 1.25rem; text-align: center; }
.req { color: var(--muted); font-weight: 400; font-size: .9rem; }
.stack { display: grid; gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 12px; }
.card.warn { background: var(--yel-bg); color: var(--yel-fg); border-color: var(--yel-line); }
.card.info { background: var(--grn-bg); color: var(--grn-fg); border-color: var(--grn-line); }
.callout { border-width: 2px; border-color: var(--brand); }

/* botones: objetivo táctil ≥ 48px */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 10px 16px;
  border-radius: 12px; border: 1px solid var(--control); background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; text-align: center; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); color: var(--brand-text); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.block { display: flex; width: 100%; }
.btn.small { min-height: 48px; padding: 6px 12px; font-size: .9rem; }
.btn.link { background: none; border: 0; color: var(--brand); text-decoration: underline; justify-content: flex-start; padding-inline: 0; }
.btn.danger { background: var(--red-fg); color: var(--surface); border-color: var(--red-fg); }
.btn.danger-outline { color: var(--red-fg); border-color: var(--red-line); }
.btn:disabled { opacity: .6; cursor: progress; }
.grid-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr)); gap: 10px; margin: 12px 0; }
.btn { min-width: 0; overflow-wrap: anywhere; }

/* formularios */
label { font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 1rem; min-height: 48px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--control); background: var(--surface); color: var(--text); }
textarea { min-height: 7rem; resize: vertical; line-height: 1.45; }
input:user-invalid, textarea:user-invalid { border-color: var(--red-line); }
.field-row { display: flex; gap: 8px; align-items: center; }
.field-row > input, .field-row > select { flex: 1; }
.inline-form { display: grid; gap: 6px; margin-top: 10px; }
.error { color: var(--red-fg); font-weight: 600; min-height: 1.5em; margin: 0; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; }
.check input { width: 22px; height: 22px; margin-top: 2px; flex: none; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 700; margin-bottom: 8px; padding: 0; }
.choices { display: grid; gap: 8px; }
.choice { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border: 1px solid var(--control); border-radius: 12px; background: var(--surface); font-weight: 400; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--brand); border-width: 2px; padding: 11px; background: var(--grn-bg); }
.choice input { width: 22px; height: 22px; margin-top: 2px; flex: none; }
.choice strong { display: block; }
.pill { display: inline-flex; position: relative; }
.pill input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.pill span { display: inline-flex; align-items: center; min-height: 44px; padding: 8px 14px; border: 1px solid var(--control); border-radius: 99px; background: var(--surface); font-weight: 600; }
.pill input:checked + span { background: var(--brand); color: var(--brand-text); border-color: var(--brand); }
.pill input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.chips, .tol { display: flex; flex-wrap: wrap; gap: 8px; }
.tol legend { width: 100%; }
.chips { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 4px; }
.chips .pill span { white-space: nowrap; }

/* escáner */
.scanner { position: relative; aspect-ratio: 4 / 3; background: #0c0f0c; border-radius: var(--radius); overflow: hidden; display: grid; place-items: center; color: #fff; }
.cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scanner:not(.on) .cam { display: none; }
.frame { position: absolute; inset: 28% 10%; border: 3px solid rgba(255,255,255,.9); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); display: none; }
.scanner.on .frame { display: block; }
.cam-status { position: absolute; left: 12px; right: 12px; bottom: 10px; margin: 0; text-align: center; font-weight: 600; text-shadow: 0 1px 3px #000; }
.scanner:not(.on) .cam-status { position: static; padding: 0 20px; text-shadow: none; }
.cam-actions { position: absolute; top: 10px; right: 10px; display: flex; gap: 8px; }
.scanner:not(.on) .cam-actions { position: static; }
.scanner:not(.on) { display: flex; flex-direction: column; justify-content: center; gap: 12px; }

/* listas */
.list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; min-height: 60px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; color: var(--text); text-decoration: none; }
.row:hover { background: var(--surface-2); }
.row-main { flex: 1; display: grid; min-width: 0; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: .85rem; }
.dot { font-size: 1.2rem; }
.empty { text-align: center; padding: 32px 12px; color: var(--muted); }

/* resultado */
.prod-img { float: right; width: 96px; height: 96px; object-fit: contain; background: #fff; border-radius: 12px; border: 1px solid var(--line); margin: 0 0 8px 12px; }
.profile-chip { display: inline-block; font-size: .85rem; padding: 2px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.ind { clear: both; border-radius: var(--radius); padding: 12px 16px; margin: 0 0 10px; border: 2px solid; }
.ind h2 { font-size: 1.2rem; margin: 0 0 4px; }
.ind ul { margin: 0; padding-left: 1.2rem; }
.lv-red { background: var(--red-bg); color: var(--red-fg); border-color: var(--red-line); }
.lv-yellow { background: var(--yel-bg); color: var(--yel-fg); border-color: var(--yel-line); }
.lv-green { background: var(--grn-bg); color: var(--grn-fg); border-color: var(--grn-line); }
.lv-unknown { background: var(--unk-bg); color: var(--unk-fg); border-color: var(--unk-line); }
.dot.lv-red, .dot.lv-yellow, .dot.lv-green, .dot.lv-unknown { background: none; border: 0; }
.badge { display: inline-flex; gap: 4px; align-items: center; padding: 3px 10px; border-radius: 99px; border: 1px solid; font-weight: 600; font-size: .9rem; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.ingr { line-height: 1.6; }
mark { border-radius: 4px; padding: 0 2px; color: inherit; }
mark.hl-fru.hl-high, mark.hl-pol.hl-high { background: var(--red-bg); box-shadow: inset 0 -2px var(--red-line); }
mark.hl-fru.hl-med, mark.hl-pol.hl-med { background: var(--yel-bg); box-shadow: inset 0 -2px var(--yel-line); }
mark.hl-fru.hl-low, mark.hl-pol.hl-low, mark.hl-fod { background: var(--surface-2); box-shadow: inset 0 -2px var(--unk-line); }
details > summary { cursor: pointer; font-weight: 700; min-height: 32px; }
details[open] > summary { margin-bottom: 8px; }

/* bienvenida y consejos */
.onboard { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 10px; }
.onboard-icon { font-size: 2rem; display: block; }
.tips-list { padding-left: 1.3rem; margin: 0; display: grid; gap: 8px; }
.tips-list strong, .tips-list span { display: block; }
.tips-list span { color: var(--muted); }
.cols { columns: 2; padding-left: 1.1rem; margin: 0; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.tbl thead th { font-size: .85rem; color: var(--muted); }
.tbl tbody th { font-weight: 500; }
.food h2 { margin-bottom: 6px; }

/* foto */
.photo-prev { max-height: 180px; border-radius: 10px; margin: 8px 0; object-fit: contain; }
.tips { margin: 8px 0 0; padding-left: 1.2rem; }
progress { width: 100%; height: 10px; }

/* navegación inferior */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line); }
.nav a { min-width: 0; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 600; }
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.nav a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav a[aria-current="page"] { color: var(--brand); }
@media (max-width: 330px) { .nav a { font-size: .62rem; } .nav svg { width: 20px; height: 20px; } }
.nav a[aria-current="page"] svg { stroke-width: 2.6; }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 30; max-width: calc(100% - 32px); }
.dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; max-width: min(92vw, 420px); }
.dialog::backdrop { background: rgba(0,0,0,.5); }
.dialog .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.loading { color: var(--muted); }

@media (prefers-reduced-motion: no-preference) {
  .btn, .row, .pill span { transition: background-color .15s, filter .15s; }
}
@media (min-width: 700px) {
  .nav { max-width: 640px; margin: 0 auto; border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; }
}
