/* NutriScan AI — mobile-first. Base: arena #f3f0e8 + terracota #b8422e.
   Colores de score: verde #16a34a (≥7.0) · ámbar #f59e0b (4.0–6.9) · rojo #dc2626 (<4.0) */
:root {
  --arena: #f3f0e8;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e0d6;
  --terracotta: #b8422e;
  --green: #16a34a;
  --amber: #f59e0b;
  --red: #dc2626;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 14px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--arena);
  color: var(--ink);
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 12px calc(env(safe-area-inset-bottom, 0px) + 24px);
  min-height: 100vh;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 4px 16px;
}
.logo { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; }
.logo em { font-style: normal; color: var(--terracotta); }
.logo-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--green); display: inline-block; }
.icon-btn {
  border: none; background: var(--card); color: var(--ink);
  width: 42px; height: 42px; border-radius: 12px; font-size: 19px;
  box-shadow: var(--shadow); cursor: pointer;
}

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card h3 { font-size: 15px; margin-bottom: 10px; letter-spacing: 0.01em; }

/* ---------- Scan ---------- */
.field-label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.barcode-row { display: flex; gap: 8px; }
.barcode-row input {
  flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 12px;
  padding: 13px 14px; font-size: 16px; background: #faf9f5; color: var(--ink);
}
.barcode-row input:focus { outline: 2px solid var(--terracotta); outline-offset: 1px; border-color: transparent; }
.btn-primary {
  border: none; background: var(--terracotta); color: #fff; font-weight: 700;
  padding: 13px 18px; border-radius: 12px; font-size: 15px; cursor: pointer; white-space: nowrap;
}
.btn-primary:active { transform: scale(0.98); }
.btn-secondary {
  border: 1.5px solid var(--terracotta); background: var(--card); color: var(--terracotta);
  font-weight: 700; padding: 12px 16px; border-radius: 12px; font-size: 15px; cursor: pointer; width: 100%;
}
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 14px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.hint { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.45; }

/* ---------- Score gigante ---------- */
.result-card { text-align: center; }
.score-ring {
  width: 220px; height: 220px; margin: 6px auto 16px;
  border-radius: 50%; border: 12px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: border-color 0.45s ease;
}
.score-value {
  font-size: 64px; font-weight: 800; line-height: 1; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  transition: color 0.45s ease;
}
.score-label { margin-top: 10px; font-size: 14px; font-weight: 600; color: var(--muted); }

/* ---------- Violaciones / estado ---------- */
.violations-box {
  border-radius: 12px; padding: 12px 14px; font-size: 13.5px; line-height: 1.45;
  background: #fef3c7; color: #92400e; margin-bottom: 14px; text-align: left;
}
.violations-box.danger { background: #fee2e2; color: #991b1b; }
.violations-box.error { background: #fee2e2; color: #991b1b; }
.violations-box.loading { background: #ecfdf5; color: #065f46; }

/* ---------- Producto ---------- */
.product-info { text-align: left; margin-bottom: 14px; }
.product-img {
  width: 100%; max-height: 220px; object-fit: contain; border-radius: 12px;
  background: #faf9f5; margin-bottom: 12px;
}
#product-name { font-size: 19px; letter-spacing: -0.01em; }
.product-brand { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.macros-table { width: 100%; margin-top: 12px; border-collapse: collapse; font-size: 13.5px; }
.macros-table td { padding: 7px 0; border-top: 1px solid var(--line); }
.macros-table td:last-child { text-align: right; color: var(--muted); }
.macros-table strong { color: var(--ink); }

/* ---------- Pros / Contras ---------- */
.reasons-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; text-align: left; }
.reasons ul { list-style: none; font-size: 13.5px; line-height: 1.5; }
.reasons li { padding-left: 18px; position: relative; margin-bottom: 6px; }
.reasons.pros li::before { content: "✓"; position: absolute; left: 0; color: var(--green); font-weight: 700; }
.reasons.cons li::before { content: "✕"; position: absolute; left: 0; color: var(--red); font-weight: 700; }
.reasons .muted { color: var(--muted); padding-left: 0; }
.reasons .muted::before { content: none; }

/* ---------- Historial ---------- */
.history-list { list-style: none; }
.history-item { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.history-item:first-child { border-top: none; }
.score-chip { color: #fff; font-weight: 800; font-size: 13px; padding: 3px 9px; border-radius: 999px; flex-shrink: 0; }
.history-name { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-ts { color: var(--muted); font-size: 12px; }

/* ---------- Settings modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35);
  display: flex; align-items: flex-end; justify-content: center; z-index: 50;
}
/* El atributo hidden debe ganar a display:flex del backdrop */
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--card); width: 100%; max-width: 520px;
  border-radius: 20px 20px 0 0; padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  max-height: 88vh; overflow-y: auto;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.modal-header h2 { font-size: 20px; }
.modal-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 14px; }

.restrictions-list { margin-bottom: 16px; }
.toggle-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 0;
  border-top: 1px solid var(--line); cursor: pointer; position: relative;
}
.toggle-row:first-child { border-top: none; }
.toggle-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.toggle-title { font-size: 14.5px; font-weight: 600; }
.toggle-desc { font-size: 12px; color: var(--muted); }

/* Switch */
.switch { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  width: 46px; height: 26px; border-radius: 999px; background: #d6d0c4;
  position: relative; transition: background 0.2s; flex-shrink: 0;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: #fff; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.switch:checked + .switch-track { background: var(--green); }
.switch:checked + .switch-track::after { transform: translateX(20px); }

.modal input[type="text"], .modal input[type="password"] {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font-size: 15px; background: #faf9f5; margin-bottom: 12px;
}
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn-secondary { flex: 1; }
.modal-actions .btn-primary { flex: 1; }

@media (min-width: 540px) {
  .modal { border-radius: 20px; margin-bottom: 24px; }
}
