:root {
  --teal: #148a8e;
  --teal-d: #0e6e72;
  --bg: #f4f6f7;
  --card: #ffffff;
  --ink: #16232a;
  --muted: #6b7a82;
  --line: #e6ebec;
  --ok: #1f9d6b;
  --warn: #d98324;
  --danger: #d1495b;
  --radius: 18px;
  --shadow: 0 2px 14px rgba(20, 40, 45, .06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}
.hidden { display: none !important; }

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 14px;
  background: linear-gradient(180deg, var(--teal), var(--teal-d));
  color: #fff;
}
.topbar h1 { font-size: 20px; font-weight: 700; margin: 0; letter-spacing: .3px; }
.icon-btn {
  background: rgba(255, 255, 255, .18); color: #fff; border: 0;
  width: 38px; height: 38px; border-radius: 12px; font-size: 18px; cursor: pointer;
}

.banner {
  margin: 14px 16px 0; padding: 12px 14px; border-radius: 14px;
  background: #fff7e8; color: #7a5320; font-size: 14px; line-height: 1.4;
  border: 1px solid #f2e2c4;
}
.banner.cta {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  background: #e9f6f6; color: var(--teal-d); border-color: #cfeaea;
}
.banner.cta button {
  background: var(--teal); color: #fff; border: 0; padding: 9px 16px;
  border-radius: 10px; font-weight: 600; cursor: pointer; white-space: nowrap;
}

#content { padding: 8px 16px 20px; }
.loading, .fatal { text-align: center; color: var(--muted); padding: 40px 20px; }
.fatal { color: var(--danger); }

.treatment { margin-top: 14px; }
.tr-name { font-size: 14px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 18px 4px 8px; font-weight: 700; }

.card {
  background: var(--card); border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow); margin-bottom: 12px; border: 1px solid var(--line);
}
.card.done { opacity: .72; }
.card.urgent { border-color: var(--teal); box-shadow: 0 0 0 2px rgba(20, 138, 142, .15); }
.card-h {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  font-size: 17px; font-weight: 700;
}
.card-h .hora {
  margin-left: auto; font-size: 14px; font-weight: 700; color: var(--teal-d);
  background: #e9f6f6; padding: 3px 10px; border-radius: 10px;
}
.sub { color: var(--muted); font-size: 14px; margin: 6px 0 12px; line-height: 1.4; }
.taken { color: var(--ok); font-weight: 600; font-size: 15px; }

/* Progreso del tratamiento */
.prog { margin: 4px 0 14px; }
.prog-bar { height: 7px; background: var(--line); border-radius: 6px; overflow: hidden; }
.prog-bar span { display: block; height: 100%; background: var(--teal); border-radius: 6px; transition: width .3s; }
.prog-txt { font-size: 12px; color: var(--muted); margin-top: 5px; }
.mcount { font-size: 12px; color: var(--teal-d); font-weight: 600; }

/* Semáforo de efecto */
.semaforo {
  display: flex; align-items: center; gap: 11px;
  margin: 10px 0 4px; padding: 9px 11px; border-radius: 13px; background: var(--bg);
  border: 1px solid var(--line);
}
.luces { display: flex; flex-direction: column; gap: 3px; background: #23292b; padding: 4px; border-radius: 8px; }
.luz { width: 12px; height: 12px; border-radius: 50%; background: #4a5254; opacity: .28; transition: .3s; }
.estado-rojo    .luz.r { background: #e5484d; opacity: 1; box-shadow: 0 0 7px #e5484d; }
.estado-amarillo .luz.a { background: #f5a623; opacity: 1; box-shadow: 0 0 7px #f5a623; }
.estado-verde   .luz.v { background: #30a46c; opacity: 1; box-shadow: 0 0 7px #30a46c; }
.sem-txt { display: flex; flex-direction: column; line-height: 1.3; }
.sem-txt b { font-weight: 600; font-size: 14px; }
.estado-rojo    .sem-txt b { color: #d1495b; }
.estado-amarillo .sem-txt b { color: #c47d17; }
.estado-verde   .sem-txt b { color: #1f9d6b; }
.sem-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.btn {
  border: 0; border-radius: 13px; padding: 13px 16px; font-size: 16px; font-weight: 600;
  cursor: pointer; width: 100%; transition: transform .05s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--teal); color: #fff; }
.btn.ghost { background: #eef2f3; color: var(--ink); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { width: auto; padding: 8px 14px; font-size: 14px; }
.btn[disabled] { opacity: .45; cursor: default; }

/* Mañana */
.mrow { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-top: 1px solid var(--line); }
.mrow:first-of-type { border-top: 0; }
.mrow.done { opacity: .6; }
.mrow-t { display: flex; flex-direction: column; }
.mrow-t span { font-size: 13px; color: var(--muted); }
.chk { color: var(--ok); font-weight: 600; font-size: 14px; }

/* Analgesia */
.card.pain .pill-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 0; border-top: 1px solid var(--line);
}
.pill-info b { font-size: 16px; }
.pill-info .food { font-size: 12px; color: var(--warn); margin-left: 6px; }
.pill-state { font-size: 13px; color: var(--muted); margin-top: 3px; }
.pill-row .btn { width: auto; min-width: 92px; }
.badge { background: var(--teal); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 8px; vertical-align: middle; }
.ok { color: var(--ok); font-weight: 600; }
.wait { color: var(--warn); font-weight: 600; }
.lim { color: var(--danger); font-weight: 600; }

/* Pregunta destacada */
.card.question { border: 2px solid var(--teal); }
.q-actions { display: flex; gap: 10px; }
.q-actions .btn { flex: 1; }

/* Switch */
.switch { position: relative; display: inline-block; width: 50px; height: 30px; margin-left: auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0; background: #cdd6d8;
  border-radius: 30px; transition: .2s;
}
.slider:before {
  content: ""; position: absolute; height: 24px; width: 24px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}
.switch input:checked + .slider { background: var(--teal); }
.switch input:checked + .slider:before { transform: translateX(20px); }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 10px 24px 30px; line-height: 1.5; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%) translateY(20px);
  background: #16232a; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90%; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(10, 25, 30, .45); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 24px; }
.modal-card { background: #fff; border-radius: 20px; padding: 22px; max-width: 380px; width: 100%; }
.modal-card h2 { margin: 0 0 8px; font-size: 19px; }
.modal-card p { color: var(--muted); font-size: 15px; line-height: 1.45; margin: 0 0 18px; }
.modal-card #modal-body { color: var(--muted); font-size: 15px; line-height: 1.45; margin: 0 0 18px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }

/* Diálogo de registrar toma */
.take-dlg { text-align: left; }
.td-med { font-weight: 700; font-size: 17px; color: var(--ink); margin-bottom: 14px; }
.td-lbl { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
#take-time {
  width: 100%; padding: 12px 14px; font-size: 20px; text-align: center;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink);
}
.td-hint { font-size: 12px; color: var(--muted); margin-top: 12px; line-height: 1.4; }

@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1719; --card: #172226; --ink: #e8eeef; --muted: #93a3a8; --line: #24333a; }
  .banner { background: #2a2415; color: #e6c98a; border-color: #3d3620; }
  .btn.ghost { background: #22303550; color: var(--ink); }
  .card-h .hora, .banner.cta { background: #10393a; }
  .modal-card { background: #172226; }
}
