:root {
  --bg: #f3d999;
  --bg2: #f8e7bd;
  --card: #fffaf0;
  --ink: #3b2616;
  --ink2: #6e5238;
  --line: #e2c68a;
  --gold: #d9a441;
  --done: #1f8a84;
  --done-bg: #d8efe9;
  --red: #c0392b;
  --red-bg: #fbe0dc;
  --amber: #b9770e;
  --amber-bg: #fdebc8;
  --shadow: 0 2px 10px rgba(59, 38, 22, 0.12);
  --radius: 18px;
  color-scheme: light;
}
/* Oscuro: automático según el teléfono, o forzado con el botón ☀️/🌙 (data-theme en <html>) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d150e;
    --bg2: #2a1f15;
    --card: #2f2318;
    --ink: #f6e6c6;
    --ink2: #cdb48d;
    --line: #4a3726;
    --gold: #e0ad4f;
    --done: #49c1b8;
    --done-bg: #173b38;
    --red: #ff7a6b;
    --red-bg: #4a1f1a;
    --amber: #f2b45a;
    --amber-bg: #45311a;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1d150e;
  --bg2: #2a1f15;
  --card: #2f2318;
  --ink: #f6e6c6;
  --ink2: #cdb48d;
  --line: #4a3726;
  --gold: #e0ad4f;
  --done: #49c1b8;
  --done-bg: #173b38;
  --red: #ff7a6b;
  --red-bg: #4a1f1a;
  --amber: #f2b45a;
  --amber-bg: #45311a;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}
/* Color de cada medicina (borde del bloque y punto) */
:root { --c-aci: #2f7fc1; --c-met: #c0392b; --c-nov: #8e44ad; --c-bis: #d0638f; --c-hem: #a0522d; --c-cic: #2e8b57; --c-ore: #2e8b57; --c-flc: #e67e22; --c-meal: #d9a441; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 17px;
  line-height: 1.4;
  min-height: 100dvh;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--done); }
h1, h2, h3 { margin: 0; line-height: 1.15; }
h2 { font-size: 22px; margin: 22px 4px 10px; }
h3 { font-size: 18px; }
.muted { color: var(--ink2); }
.small { font-size: 14px; }
.wrap { max-width: 640px; margin: 0 auto; padding: 0 14px; }

/* Encabezado */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  padding: calc(10px + env(safe-area-inset-top)) 0 6px;
  border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; gap: 10px; }
.logo { width: 38px; height: 38px; border-radius: 50%; flex: none; }
.top h1 { font-size: 24px; font-weight: 700; }
.top .sub { font-size: 14px; color: var(--ink2); }
.top .me { margin-left: auto; font-size: 13px; color: var(--ink2); text-align: right; }
.live { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ink2); margin-right: 4px; vertical-align: middle; }
.live.on { background: var(--done); }

.days { display: flex; gap: 6px; overflow-x: auto; padding: 10px 2px 4px; scrollbar-width: none; scroll-snap-type: x proximity; }
.days::-webkit-scrollbar { display: none; }
.day {
  flex: none; scroll-snap-align: center;
  border: 1px solid var(--line); background: var(--bg2); border-radius: 14px;
  padding: 6px 10px; text-align: center; min-width: 58px;
}
.day b { display: block; font-size: 18px; }
.day span { font-size: 12px; color: var(--ink2); }
.day.today { border-color: var(--gold); border-width: 2px; }
.day.sel { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.day.sel span { color: var(--bg2); }
.day .dot { display: block; height: 4px; border-radius: 2px; margin-top: 4px; background: var(--line); }
.day .dot.full { background: var(--done); }
.day .dot.part { background: var(--gold); }
.day .dot.bad { background: var(--red); }

/* Tarjetas */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; margin: 10px 0;
}
.banner { border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; display: flex; gap: 10px; align-items: center; }
.banner.warn { background: var(--amber-bg); }
.banner.alert { background: var(--red-bg); color: var(--red); font-weight: 600; }
.banner.ok { background: var(--done-bg); }
.banner .grow { flex: 1; }

.progress { height: 12px; background: var(--bg2); border-radius: 6px; overflow: hidden; display: flex; }
.progress i { display: block; height: 100%; background: var(--done); }
.progress i.skip { background: var(--red); opacity: 0.6; }
.progress-label { display: flex; justify-content: space-between; font-size: 14px; color: var(--ink2); margin: 6px 2px 0; }

/* Línea de tiempo */
.slot-title { display: flex; align-items: baseline; gap: 8px; margin: 22px 4px 4px; }
.slot-title h2 { margin: 0; }
.tl { position: relative; }
.item { display: grid; grid-template-columns: 64px 1fr; gap: 10px; margin: 10px 0; }
.time { text-align: right; padding-top: 12px; }
.time b { font-size: 22px; font-weight: 700; display: block; letter-spacing: -0.5px; }
.time s { font-size: 12px; color: var(--ink2); }
.dose {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px; border: 2px solid transparent; border-left: 8px solid var(--pc, var(--line)); position: relative;
}
.pdot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--pc, var(--line)); margin-right: 6px; vertical-align: middle; }
.done-badge { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; color: var(--done); }
.done-badge b { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--done); color: #fff; font-size: 16px; }
.dose.next { border-top-color: var(--gold); border-right-color: var(--gold); border-bottom-color: var(--gold); }
.dose.given { background: var(--done-bg); box-shadow: none; }
.dose.skipped { background: var(--red-bg); box-shadow: none; opacity: 0.85; }
.dose.late { border-color: var(--red); }
.dose.paused { opacity: 0.6; }
.dose-head { display: flex; gap: 12px; align-items: flex-start; }
.thumb {
  width: 84px; height: 84px; border-radius: 14px; object-fit: cover; flex: none;
  background: var(--bg2); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 34px; overflow: hidden; padding: 0;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.dose-info { flex: 1; min-width: 0; }
.dose-name { font-size: 19px; font-weight: 700; }
.dose-amt { font-size: 18px; font-weight: 600; color: var(--done); }
.dose.given .dose-amt { color: var(--ink2); }
.dose-meta { font-size: 14px; color: var(--ink2); margin-top: 2px; }
.dose-instr { font-size: 15px; margin-top: 4px; }
.tag {
  display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: 0.4px;
  padding: 3px 8px; border-radius: 999px; margin: 0 4px 4px 0; vertical-align: middle;
}
.tag.red { background: var(--red); color: #fff; }
.tag.gold { background: var(--gold); color: #3b2616; }
.tag.grey { background: var(--bg2); color: var(--ink2); }
.tag.green { background: var(--done); color: #fff; }

.actions { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; margin-top: 12px; }
.btn {
  border: 0; border-radius: 14px; padding: 13px 10px; font-weight: 700; font-size: 17px;
  background: var(--bg2); color: var(--ink); min-height: 50px;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--done); color: #fff; }
.btn.danger { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn.small { min-height: 0; padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn[disabled] { opacity: 0.5; }
.status-line { margin-top: 10px; font-size: 15px; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.link { background: none; border: 0; color: var(--done); text-decoration: underline; padding: 4px; font-size: 14px; }

/* Formularios */
.field { margin: 14px 0; }
.field > label, .label { display: block; font-weight: 600; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--bg2); border-radius: 999px;
  padding: 10px 14px; font-weight: 600; font-size: 16px;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip.red.on { background: var(--red); border-color: var(--red); color: #fff; }
input[type=text], input[type=number], input[type=datetime-local], input[type=password], textarea, select {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 12px; font-size: 17px;
}
textarea { min-height: 80px; resize: vertical; }
.scale { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.scale button { padding: 12px 0; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); font-weight: 700; font-size: 18px; }
.scale button.on { background: var(--ink); color: var(--bg); }
.scale-desc { font-size: 14px; color: var(--ink2); margin-top: 6px; min-height: 20px; }

/* Galería */
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.gallery figure { margin: 0; background: var(--card); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.gallery img, .gallery .noimg { width: 100%; aspect-ratio: 1; object-fit: cover; display: grid; place-items: center; background: var(--bg2); font-size: 30px; }
.gallery figcaption { font-size: 12px; padding: 6px; }
.strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.strip figure { flex: none; width: 110px; margin: 0; }
.strip img, .strip .noimg { width: 110px; height: 110px; border-radius: 12px; object-fit: cover; background: var(--bg2); display: grid; place-items: center; font-size: 28px; }
.strip figcaption { font-size: 12px; color: var(--ink2); margin-top: 4px; }

/* Listas */
.row { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.bar { height: 10px; border-radius: 5px; background: var(--bg2); overflow: hidden; display: flex; margin-top: 6px; }
.bar i { display: block; background: var(--done); }
.bar i.skip { background: var(--red); opacity: 0.7; }
.bar i.miss { background: var(--amber); opacity: 0.7; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--card); border-radius: 14px; padding: 12px; text-align: center; box-shadow: var(--shadow); }
.kpi b { font-size: 26px; display: block; }
.kpi span { font-size: 13px; color: var(--ink2); }
.appetite { display: grid; grid-template-columns: repeat(var(--n, 7), 1fr); gap: 6px; align-items: end; height: 110px; }
.appetite div { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; gap: 2px; }
.appetite i { display: block; border-radius: 4px; background: var(--gold); }
.appetite span { font-size: 11px; text-align: center; color: var(--ink2); }

/* Más */
.menu { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.menu button { background: var(--card); border: 0; border-radius: var(--radius); padding: 18px 12px; text-align: left; box-shadow: var(--shadow); }
.menu button b { display: block; font-size: 18px; margin-top: 6px; }
.menu button span { font-size: 28px; }
.menu button small { color: var(--ink2); }

.risk { position: relative; height: 18px; border-radius: 9px; background: linear-gradient(90deg, #2e9e6a, #e2b33c, #d0542f); margin: 14px 0 26px; }
.risk i { position: absolute; top: -6px; width: 6px; height: 30px; background: var(--ink); border-radius: 3px; }
.risk span { position: absolute; top: 24px; font-size: 12px; color: var(--ink2); }
.diagram { width: 100%; height: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
td, th { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
pre.export { white-space: pre-wrap; background: var(--card); border-radius: 14px; padding: 14px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; max-height: 50vh; overflow: auto; }

/* Navegación inferior */
nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--card); border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(6, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button { background: none; border: 0; padding: 8px 0 10px; font-size: 11px; color: var(--ink2); font-weight: 600; }
nav.tabs button span { display: block; font-size: 24px; line-height: 1.2; }
nav.tabs button.on { color: var(--ink); }
nav.tabs button.on span { transform: scale(1.1); }
nav.tabs .badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; margin-left: 2px; }

/* Hojas y visor */
.sheet-back { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--card); width: 100%; max-width: 640px; border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 90dvh; overflow: auto;
  animation: up 0.18s ease-out;
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h3 { font-size: 20px; margin-bottom: 8px; }
.sheet .btn { margin-top: 8px; }
.viewer { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.92); z-index: 60; display: grid; place-items: center; padding: 16px; }
.viewer img { max-width: 100%; max-height: 82dvh; border-radius: 12px; }
.viewer p { color: #fff; text-align: center; margin: 10px 0 0; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px; z-index: 70;
  font-weight: 600; box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}

/* Login */
.login { max-width: 420px; margin: 0 auto; padding: 40px 18px; text-align: center; }
.login img { width: 96px; height: 96px; border-radius: 50%; }
.login h1 { font-size: 30px; margin: 12px 0 4px; }
.login .who { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0; }
.login input { text-align: center; font-size: 26px; letter-spacing: 8px; }
.empty { text-align: center; color: var(--ink2); padding: 30px 10px; }

/* Botón de tema */
.theme-btn { background: var(--bg2); border: 1px solid var(--line); border-radius: 999px; width: 38px; height: 38px; font-size: 18px; flex: none; }
.top .me { margin-left: auto; }

/* Bitácora */
.log-day { margin: 18px 4px 6px; font-size: 18px; }
.log { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.log td { padding: 9px 8px; border-bottom: 1px solid var(--line); font-size: 15px; vertical-align: top; }
.log tr:last-child td { border-bottom: 0; }
.log td.t { width: 56px; font-weight: 700; white-space: nowrap; }
.log td.w { width: 64px; color: var(--ink2); font-size: 13px; }
.log .bad { color: var(--red); font-weight: 600; }
.seg { display: flex; gap: 6px; margin: 10px 0; }
.seg button { flex: 1; }
