/* =========================================================
   Alarmedics — sistema de diseño
   Paleta inspirada en frascos de farmacia (ámbar/vidrio),
   pensada para alto contraste y lectura cómoda.
========================================================= */

:root {
  --ink: #1f3a3d;
  --ink-soft: #3f5a5d;
  --paper: #faf6ed;
  --surface: #ffffff;
  --line: #ddd2b8;
  --line-soft: #e9e0ca;

  --brand: #2f6b5e;
  --brand-dark: #234f45;
  --brand-soft: #e1ece8;

  --amber: #b6701e;
  --amber-dark: #8f5414;
  --amber-soft: #f3e3c8;

  --error: #b3261e;
  --error-soft: #f7dedc;

  --success: #4f7a32;
  --success-soft: #e4eed9;

  --radius-lg: 14px;
  --radius: 10px;
  --radius-sm: 7px;

  --font: "Work Sans", "Segoe UI", -apple-system, BlinkMacSystemFont, Arial, sans-serif;

  --tap: 48px;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 18px;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  margin: 0;
  padding: 20px 16px 48px;
  line-height: 1.5;
}

main,
body > form,
body > h1,
body > .alert-box,
body > .tabbar,
body > .tab-panel {
  max-width: 720px;
  margin-left: auto;
  margin-right: auto;
}

h1 {
  color: var(--ink);
  font-size: 1.9rem;
  font-weight: 700;
  margin: 4px auto 18px;
  max-width: 720px;
  display: flex;
  align-items: center;
  gap: 10px;
}

h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
  margin: 0 0 10px;
}

h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 18px 0 6px;
  color: var(--ink);
}

a {
  color: var(--brand-dark);
}

/* =====================
   FOCO Y ACCESIBILIDAD
===================== */
:focus-visible {
  outline: 3px solid var(--brand-dark);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* =====================
   PORTADA
===================== */
.splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, var(--paper) 0%, var(--brand-soft) 100%);
  padding: 24px;
  cursor: pointer;
  transition: opacity 0.35s ease;
}

.splash[hidden] {
  display: none;
}

.splash.splash-out {
  opacity: 0;
}

.splash-content {
  max-width: 360px;
  text-align: center;
  cursor: default;
  animation: splash-in 0.6s ease both;
}

.splash-art {
  display: block;
  margin: 0 auto 18px;
}

.splash-title {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0 0 10px;
  color: var(--ink);
  max-width: none;
}

.splash-sub {
  margin: 0 0 22px;
  color: var(--ink-soft);
  font-size: 1.02rem;
  line-height: 1.5;
}

.splash-btn {
  width: 100%;
  font-size: 1.05rem;
}

@keyframes splash-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .splash-content {
    animation: none;
  }
}

/* =====================
   PESTAÑAS
===================== */
.tabbar {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  margin: 0 auto 18px;
}

.tab-btn {
  flex: 1;
  min-height: var(--tap);
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font);
  font-size: 0.98rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tab-btn:hover {
  background: var(--brand-soft);
}

.tab-btn.active {
  background: var(--brand);
  color: #fff;
}

.tab-panel[hidden] {
  display: none;
}

/* =====================
   TARJETAS DE SECCIÓN
===================== */
.settings {
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius);
  margin: 0 0 16px;
  border: 1px solid var(--line);
}

.settings h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings label {
  display: block;
  margin: 6px 0;
  font-weight: 600;
}

.settings .inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.help-text {
  color: var(--ink-soft);
  font-size: 0.92rem;
  margin: 4px 0 10px;
}

.wa-box {
  border-color: #c9d9c3;
  background: #fbfdf8;
}

/* =====================
   BOTONES
===================== */
.action-btn,
button[type="submit"],
#waAddBtn {
  min-height: var(--tap);
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease, transform 0.05s ease;
}

.action-btn:hover:enabled,
button[type="submit"]:hover,
#waAddBtn:hover {
  background: var(--brand-dark);
}

.action-btn:active:enabled,
button[type="submit"]:active {
  transform: translateY(1px);
}

.action-btn:disabled {
  background: #b9c2bf;
  cursor: not-allowed;
  opacity: 0.85;
}

.action-btn.secondary {
  background: transparent;
  color: var(--brand-dark);
  border: 2px solid var(--brand);
}

.action-btn.secondary:hover:enabled {
  background: var(--brand-soft);
}

.action-btn.danger {
  background: transparent;
  color: var(--error);
  border: 2px solid var(--error);
}

.action-btn.danger:hover:enabled {
  background: var(--error-soft);
}

.picker-btn {
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  cursor: pointer;
  font-size: 1rem;
}

.picker-btn:hover {
  background: var(--brand-dark);
}

/* =====================
   FORMULARIOS
===================== */
form#medForm {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 20px;
}

form input,
.register-card input,
.country-picker select,
.phone-input input,
input[type="month"] {
  min-height: var(--tap);
  width: 100%;
  padding: 10px 12px;
  margin: 5px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 1rem;
  background: var(--paper);
  color: var(--ink);
}

form input:focus,
.register-card input:focus {
  border-color: var(--brand);
  background: #fff;
}

form button[type="submit"] {
  margin-top: 8px;
  width: 100%;
}

.horarios-box {
  margin-top: 4px;
  background: var(--paper);
  border-style: dashed;
}

.horarios-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hora-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hora-label {
  font-weight: 600;
  min-width: 90px;
}

.hora-input {
  width: auto;
  flex: 1;
  min-width: 140px;
}

.ampm-select {
  min-height: var(--tap);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 1rem;
  background: var(--paper);
}

/* =====================
   TARJETAS DE MEDICAMENTO
===================== */
#listaMedicamentos {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.med-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 6px solid var(--brand);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 0;
}

.med-card.med-card-low {
  border-left-color: var(--amber);
  background: #fffdf8;
}

.med-card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.med-name {
  margin: 0 0 4px;
  font-size: 1.25rem;
}

.med-meta {
  margin: 0 0 10px;
  color: var(--ink-soft);
  font-size: 0.98rem;
}

.med-horarios {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.time-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  border: 1px solid #c3dad3;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 0.92rem;
  font-weight: 600;
}

.time-chip-empty {
  background: var(--error-soft);
  color: var(--error);
  border-color: #eac3bf;
}

.med-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.med-history {
  margin-top: 10px;
  border-top: 1px solid var(--line-soft);
  padding-top: 8px;
}

.med-history summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--ink-soft);
}

.med-history ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.med-history li {
  background: transparent;
  padding: 2px 0;
  margin: 0;
  border-radius: 0;
}

/* =====================
   PÁGINA DE REGISTRO
===================== */
.register-page {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.register-card {
  max-width: 440px;
  width: 100%;
  background: var(--surface);
  padding: 26px 24px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
}

.register-card h1 {
  margin: 0 0 8px;
  font-size: 1.6rem;
}

.register-sub {
  margin: 0 0 16px;
  color: var(--ink-soft);
  line-height: 1.5;
}

.register-card form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.register-card label {
  font-weight: 600;
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--ink);
}

.register-card button {
  min-height: var(--tap);
  margin-top: 8px;
  padding: 12px;
  font-size: 1.05rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.register-card button:hover {
  background: var(--brand-dark);
}

.register-card button:active {
  transform: translateY(1px);
}

.register-note {
  margin-top: 14px;
  font-size: 0.92rem;
  color: var(--ink-soft);
}

/* =====================
   TELÉFONOS / WHATSAPP
===================== */
.phone-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 6px 0 4px;
}

.country-picker,
.phone-input {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-weight: 600;
  flex: 1;
  min-width: 160px;
}

.wa-actions {
  margin: 4px 0 12px;
}

.phone-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}

.phone-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid #c3dad3;
  font-size: 0.95rem;
  font-weight: 600;
}

.phone-pill.empty {
  background: var(--paper);
  color: var(--ink-soft);
  border-color: var(--line);
  font-weight: 500;
}

.pill-remove {
  background: transparent;
  border: none;
  color: var(--error);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  min-height: auto;
}

/* =====================
   INSTALAR / NOTIFICACIONES / PUSH
===================== */
.install-row,
.notif-row,
.push-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.push-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 6px 0;
}

#notifStatus,
#pushStatus {
  font-weight: 600;
  color: var(--brand-dark);
}

#installStatus {
  font-weight: 600;
  color: var(--ink-soft);
}

/* =====================
   CALENDARIO
===================== */
#filtroMedicamento {
  min-height: var(--tap);
}

.calendario-titulo {
  margin: 18px 0 6px;
  text-transform: capitalize;
  color: var(--brand-dark);
}

.calendario-semana {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-top: 6px;
}

.dia-semana {
  text-align: center;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink-soft);
  padding: 2px 0 6px;
}

#calendario {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-top: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

.dia {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: var(--paper);
  border: 1px solid var(--line-soft);
  text-align: center;
  border-radius: var(--radius-sm);
  font-weight: 600;
  color: var(--ink-soft);
}

.dia-vacio {
  background: transparent;
  border-color: transparent;
}

.dia.hoy {
  border: 2px solid var(--brand);
  color: var(--brand-dark);
  font-weight: 700;
}

.dia.consumido {
  background: var(--brand);
  border-color: var(--brand-dark);
  color: #fff;
}

.dia.consumido.hoy {
  border-color: var(--amber);
  box-shadow: 0 0 0 2px var(--amber);
}

.dia.consumido::after {
  content: "";
  position: absolute;
  bottom: 5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff;
}

@media (max-width: 420px) {
  .dia {
    font-size: 0.85rem;
  }
}

/* =====================
   HISTORIAL
===================== */
.historial-filtros {
  display: flex;
  gap: 14px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin: 10px 0 16px;
}

.historial-filtros label {
  font-weight: 600;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#historialLista {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}

#historialLista h3:first-child {
  margin-top: 0;
}

#historialLista ul {
  padding-left: 18px;
  margin: 0 0 4px;
}

#historialLista li {
  background: transparent;
  padding: 2px 0;
  margin: 0;
  border-radius: 0;
}

/* =====================
   ALERTAS
===================== */
.alert-box {
  margin: 0 auto 16px;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-weight: 700;
  display: none;
}

.alert-error {
  display: block;
  color: var(--error);
  background: var(--error-soft);
  border: 1px solid #eac3bf;
}

.alert-warn,
.alert-Atención {
  display: block;
  color: var(--amber-dark);
  background: var(--amber-soft);
  border: 1px solid #e3cda0;
}

.alert-success,
.alert-Completo {
  display: block;
  color: var(--success);
  background: var(--success-soft);
  border: 1px solid #c7dcb5;
}

.alert-umbral {
  display: block;
  color: #fff;
  background: var(--error);
  border: 1px solid var(--error);
  animation: parpadeo 1s infinite;
}

@keyframes parpadeo {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* =====================
   RESPONSIVE
===================== */
@media (max-width: 640px) {
  html {
    font-size: 17px;
  }

  body {
    padding: 14px 12px 40px;
  }

  .install-row,
  .notif-row,
  .push-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .phone-row {
    flex-direction: column;
  }

  .med-card-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .med-actions .action-btn {
    flex: 1;
    min-width: 0;
  }

  #calendario {
    gap: 4px;
  }
}
