:root {
  --bg: #FAFBFC;
  --card: #FFFFFF;
  --text: #1F2430;
  --muted: #8A93A3;
  --line: #EEF1F5;
  --primary: #3E6DF3;
  --primary-soft: #EAF0FE;
  --red: #D0342C;
  --red-soft: #FBEAEA;
  --green: #1E8E5A;
  --green-soft: #E7F6EE;
  --amber: #B4740E;
  --amber-soft: #FDF3E2;
  --shadow-sm: 0 1px 3px rgba(31, 36, 48, .04);
  --shadow-md: 0 10px 30px rgba(31, 36, 48, .08);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-family: 'SF Pro Display', Inter, ui-sans-serif, system-ui, sans-serif; color: var(--text); font-size: 16px; line-height: 1.4; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.icon { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.page { max-width: 480px; margin: 0 auto; padding: 8px 20px 104px; }

header.app-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px 2px; max-width: 480px; margin: 0 auto; }
.greeting { font-weight: 700; font-size: 1.7rem; letter-spacing: -.02em; color: var(--text); }
.icon-btn { border: 0; background: none; width: 40px; height: 40px; display: grid; place-items: center; cursor: pointer; color: var(--muted); border-radius: 10px; }
.icon-btn:active { background: var(--line); }

.section-title { font-size: .8rem; letter-spacing: .04em; color: var(--muted); font-weight: 600; margin: 28px 0 12px; text-transform: none; }
.panel-title-row { display: flex; align-items: center; justify-content: space-between; }

.btn { border: 0; border-radius: 14px; padding: 12px 16px; font-weight: 600; cursor: pointer; flex: 1; text-align: center; transition: opacity .15s, transform .15s; }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-ghost { background: var(--card); color: var(--text); border: 1px solid var(--line); }
.btn-danger { color: var(--red); }
.btn-sm { padding: 9px 12px; font-size: .85rem; flex: none; }
.btn-full { width: 100%; }
.btn-danger-solid { background: var(--red); color: #fff; }

.timeline-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: .92rem; align-items: baseline; }
.timeline-item:last-child { border-bottom: 0; }
.timeline-item .tl-time { color: var(--muted); font-size: .78rem; white-space: nowrap; min-width: 62px; }
.timeline-item .tl-badge { font-weight: 600; }
.empty-note { color: var(--muted); font-size: .9rem; text-align: center; padding: 24px 0; line-height: 1.5; }

.scrim { position: fixed; inset: 0; background: rgba(20,24,32,.35); opacity: 0; pointer-events: none; transition: opacity .18s; z-index: 40; }
.scrim.open { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-radius: 24px 24px 0 0; box-shadow: 0 -12px 40px rgba(31,36,48,.16); transform: translateY(100%); transition: transform .2s ease-out; z-index: 41; max-height: 88vh; overflow-y: auto; }
.sheet.open { transform: translateY(0); }
.sheet-inner { padding: 22px 22px 30px; }
.sheet-inner h2 { margin: 0 0 16px; font-size: 1.3rem; font-weight: 700; }
.sheet-inner label { display: grid; gap: 6px; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: 14px; }
.sheet-inner input, .sheet-inner select, .sheet-inner textarea { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--bg); color: var(--text); }

.push-banner { background: var(--card); border: 1px solid var(--line); color: var(--muted); border-radius: 12px; padding: 9px 12px; font-size: .78rem; margin: 8px 0 12px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.push-banner button { flex: none; }
.toast-stack { position: fixed; bottom: 104px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 100; width: 100%; max-width: 440px; padding: 0 20px; }
.toast { background: var(--text); color: #fff; padding: 12px 18px; border-radius: 14px; font-size: .86rem; box-shadow: var(--shadow-md); text-align: center; }

.login-card { max-width: 340px; width: 100%; background: var(--card); border-radius: 24px; padding: 30px; box-shadow: var(--shadow-md); margin: 60px auto; }
.login-card h1 { font-size: 1.3rem; margin: 0 0 20px; font-weight: 700; }
.login-card label { display: grid; gap: 6px; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 16px; }
.login-card input { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--bg); color: var(--text); width: 100%; }
.login-error { color: var(--red); font-size: .86rem; min-height: 1.2em; }

/* ---------- Header / menú ---------- */
.menu-scrim { position: fixed; inset: 0; background: transparent; z-index: 30; display: none; }
.menu-scrim.open { display: block; }
.menu-dropdown { position: fixed; top: 68px; right: 20px; background: var(--card); border-radius: 16px; box-shadow: var(--shadow-md); overflow: hidden; z-index: 31; opacity: 0; pointer-events: none; transform: translateY(-6px); transition: opacity .18s, transform .18s; min-width: 220px; }
.menu-dropdown.open { opacity: 1; pointer-events: auto; transform: translateY(0); }
.menu-dropdown button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 15px 18px; background: none; border: 0; font-weight: 600; font-size: .92rem; cursor: pointer; color: var(--text); }
.menu-dropdown button:active { background: var(--bg); }
.menu-dropdown button + button { border-top: 1px solid var(--line); }

.view .section-title:first-child { margin-top: 8px; }

/* Home compacto */
#viewHoy { display: flex; flex-direction: column; }
#viewHoy .section-title { margin: 16px 0 8px; }

/* ---------- Próxima toma (hero) ---------- */
.hero-dose { background: var(--card); border-radius: 24px; padding: 20px 22px 18px; box-shadow: var(--shadow-sm); margin-top: 2px; }
.hero-dose.due { box-shadow: 0 0 0 2px var(--primary-soft), var(--shadow-md); }
.hero-dose .hero-label { font-size: .8rem; letter-spacing: .04em; color: var(--primary); font-weight: 700; display: flex; align-items: center; gap: 6px; }
.hero-dose .hero-top { display: flex; justify-content: space-between; align-items: flex-start; margin-top: 8px; gap: 10px; }
.hero-dose .hero-name { font-weight: 700; font-size: clamp(24px, 7.5vw, 34px); letter-spacing: -.02em; line-height: 1.1; }
.hero-dose .hero-when { font-weight: 600; font-size: .8rem; color: var(--muted); background: var(--bg); padding: 6px 12px; border-radius: 99px; white-space: nowrap; display: flex; align-items: center; gap: 5px; }
.hero-dose .hero-when.due { color: var(--red); background: var(--red-soft); }
.hero-dose .hero-dose-label { color: var(--muted); font-size: .95rem; margin-top: 4px; }
.hero-dose .hero-take-btn { width: 100%; margin-top: 14px; background: var(--primary); color: #fff; border: 0; border-radius: 14px; padding: 14px; font-weight: 700; font-size: 1rem; cursor: pointer; min-height: 52px; display: flex; align-items: center; justify-content: center; gap: 10px; transition: transform .15s, opacity .15s; }
.hero-dose .hero-take-btn:active { transform: scale(.98); opacity: .92; }
.hero-dose.read-only { padding: 18px 22px; }
.hero-dose .hero-meta { color: var(--muted); font-size: .9rem; margin-top: 6px; }

/* ---------- Lista compacta de próximos medicamentos ---------- */
.med-pill-row { background: var(--card); border-radius: 16px; padding: 12px 14px; margin-top: 8px; font-size: .9rem; cursor: pointer; display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow-sm); }
.med-pill-row .mp-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.med-pill-row .mp-body { flex: 1; min-width: 0; }
.med-pill-row .mp-name { font-weight: 700; }
.med-pill-row .mp-meta { color: var(--muted); font-size: .82rem; }
.med-pill-row .mp-time { color: var(--muted); white-space: nowrap; font-weight: 600; font-size: .82rem; }

/* ---------- Reportar ahora ---------- */
.big-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 2px; }
.big-btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; border: none; border-radius: 18px; padding: 14px 8px; font-weight: 700; font-size: .95rem; cursor: pointer; min-height: 74px; transition: transform .15s; }
.big-btn:active { transform: scale(.98); }
.big-btn .icon { width: 24px; height: 24px; stroke-width: 1.6; }
.big-btn.freezing { background: var(--amber-soft); color: var(--amber); }
.big-btn.fall { background: var(--red-soft); color: var(--red); }

/* ---------- Estado ON/OFF ---------- */
.motor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.motor-btn { display: flex; align-items: center; justify-content: center; gap: 8px; background: var(--card); border: none; border-radius: 16px; padding: 12px 6px; font-weight: 700; font-size: 1rem; cursor: pointer; min-height: 54px; box-shadow: var(--shadow-sm); transition: transform .15s; }
.motor-btn:active { transform: scale(.98); }
.motor-btn .state-dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.motor-btn.on .state-dot { background: var(--green-soft); color: var(--green); }
.motor-btn.off .state-dot { background: var(--red-soft); color: var(--red); }
.motor-btn-outline { width: 100%; margin-top: 10px; display: flex; align-items: center; justify-content: center; gap: 8px; background: var(--card); border: 1.5px solid var(--line); border-radius: 16px; padding: 13px 8px; font-weight: 600; font-size: .92rem; color: var(--text); cursor: pointer; min-height: 50px; transition: transform .15s; }
.motor-btn-outline:active { transform: scale(.98); background: var(--bg); }
.motor-btn-outline .icon { color: var(--muted); width: 20px; height: 20px; }

.field-label { font-size: .85rem; font-weight: 700; color: var(--text); margin: 18px 0 10px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 99px; padding: 11px 16px; font-size: .87rem; font-weight: 600; cursor: pointer; }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.chip-row.scale-row .chip.scale { font-size: 1.3rem; line-height: 1.2; padding: 10px 16px; text-align: center; }
.chip-row.scale-row .chip.scale small { display: block; font-size: .6rem; }

.stepper { display: flex; align-items: center; gap: 18px; }
.stepper button { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 1.3rem; font-weight: 700; cursor: pointer; }
.stepper span { font-size: 1.2rem; font-weight: 700; min-width: 24px; text-align: center; }

.checkin-status-card { background: var(--card); border-radius: 18px; padding: 16px 18px; font-size: .92rem; display: flex; justify-content: space-between; align-items: center; box-shadow: var(--shadow-sm); gap: 10px; }
.checkin-status-card.done { color: var(--green); background: var(--green-soft); box-shadow: none; }

/* ---------- Bottom nav ---------- */
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); box-shadow: 0 -1px 0 var(--line); display: flex; z-index: 25; padding-bottom: env(safe-area-inset-bottom, 0); }
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 11px 4px 12px; background: none; border: 0; font-size: .72rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.nav-item .icon { width: 22px; height: 22px; stroke-width: 1.6; }
.nav-item.active { color: var(--primary); }
