/* ============================================================
   PirexiApp — estilos
   Mobile-first, tema claro/oscuro automático
   ============================================================ */

:root {
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --bg: #f3f2fb;
  --bg-gradient: radial-gradient(1200px 600px at 50% -10%, #e6e1ff 0%, #f3f2fb 60%);
  --surface: #ffffff;
  --surface-2: #f7f6fd;
  --text: #1d1b33;
  --text-soft: #6e6a8a;
  --border: rgba(29, 27, 51, 0.08);
  --shadow: 0 8px 30px rgba(60, 50, 130, 0.10);
  --shadow-soft: 0 2px 12px rgba(60, 50, 130, 0.07);

  --accent: #7c6cf0;
  --accent-strong: #6a58ec;
  --accent-soft: rgba(124, 108, 240, 0.12);

  --apiretal: #f0467d;
  --apiretal-soft: rgba(240, 70, 125, 0.10);
  --apiretal-grad: linear-gradient(135deg, #ff5c8f 0%, #e93a72 100%);

  --dalsy: #f59315;
  --dalsy-soft: rgba(245, 147, 21, 0.12);
  --dalsy-grad: linear-gradient(135deg, #ffae3d 0%, #ef8506 100%);

  --ok: #1fb878;
  --ok-soft: rgba(31, 184, 120, 0.12);
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, 0.10);

  --radius: 22px;
  --radius-sm: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12111f;
    --bg-gradient: radial-gradient(1200px 600px at 50% -10%, #221e44 0%, #12111f 60%);
    --surface: #1c1a2e;
    --surface-2: #232038;
    --text: #f1efff;
    --text-soft: #9b96b8;
    --border: rgba(255, 255, 255, 0.07);
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
    --shadow-soft: 0 2px 12px rgba(0, 0, 0, 0.25);
    --accent-soft: rgba(124, 108, 240, 0.20);
    --apiretal-soft: rgba(240, 70, 125, 0.16);
    --dalsy-soft: rgba(245, 147, 21, 0.16);
    --ok-soft: rgba(31, 184, 120, 0.16);
  }
}

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

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

body {
  font-family: var(--font);
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.45;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 18px calc(env(safe-area-inset-bottom, 0px) + 28px);
}

/* ---------- Cabecera ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.brand { display: flex; align-items: center; gap: 12px; }

.brand-logo {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  font-size: 24px;
  background: linear-gradient(135deg, #8d7bff 0%, #6a58ec 100%);
  border-radius: 15px;
  box-shadow: 0 6px 18px rgba(106, 88, 236, 0.35);
}

.brand h1 { font-size: 20px; font-weight: 800; letter-spacing: -0.3px; }
.brand-sub { font-size: 12px; color: var(--text-soft); font-weight: 500; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.sync-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
}

.family-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.15s ease;
}
.family-pill:active { transform: scale(0.95); }
.family-pill #familyPillName {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Selección de familia ---------- */
.family-state { padding-top: 40px; }

.family-list {
  display: grid;
  gap: 10px;
  margin-bottom: 22px;
}

.family-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.15s ease, border-color 0.2s ease;
}
.family-chip:active { transform: scale(0.97); border-color: var(--accent); }
.family-chip .family-chip-icon {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  font-size: 18px;
  border-radius: 12px;
  background: var(--accent-soft);
}

.family-none {
  font-size: 13.5px;
  color: var(--text-soft);
  padding: 14px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

.family-create {
  display: grid;
  gap: 10px;
  text-align: left;
}

.family-create input {
  width: 100%;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.family-create input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.family-actions {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.family-lock {
  margin-left: auto;
  font-size: 14px;
  opacity: 0.6;
}

.pin-input {
  text-align: center;
  letter-spacing: 8px;
  font-size: 22px !important;
  font-weight: 800 !important;
}

/* ---------- Evolución (gráfica de crecimiento) ---------- */
.growth-section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.growth-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.growth-title { font-size: 15px; font-weight: 800; }

.growth-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.growth-tab {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
  background: transparent;
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}
.growth-tab.active {
  color: #fff;
  background: linear-gradient(135deg, #8d7bff 0%, #6a58ec 100%);
}

.growth-chart { margin-bottom: 12px; }
.growth-svg { width: 100%; height: auto; display: block; }

.gc-grid { stroke: var(--border); stroke-width: 1; }
.gc-ylabel { font-size: 9px; fill: var(--text-soft); text-anchor: end; font-weight: 600; }
.gc-xlabel { font-size: 9px; fill: var(--text-soft); font-weight: 600; }
.gc-vlabel { font-size: 10px; font-weight: 800; text-anchor: middle; }
.gc-dot { stroke: var(--surface); stroke-width: 2; }

.growth-empty {
  text-align: center;
  font-size: 13px;
  color: var(--text-soft);
  padding: 22px 10px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

.measure-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.measure-form input {
  width: 100%;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.measure-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.measure-cancel { grid-column: 1 / -1; }

/* Lista de medidas */
.measure-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  max-height: 190px;
  overflow-y: auto;
}

.measure-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 8px 10px;
  font-size: 13px;
}
.measure-row.editing {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.measure-date {
  color: var(--text-soft);
  font-weight: 600;
  min-width: 78px;
  white-space: nowrap;
}

.measure-vals { font-weight: 700; flex: 1; }

.measure-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  font-family: var(--font);
  padding: 5px 7px;
  border-radius: 8px;
  opacity: 0.7;
}
.measure-btn:active { background: var(--accent-soft); opacity: 1; }
.measure-btn.danger-armed {
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  opacity: 1;
}

.entry-dot.growth { background: var(--ok-soft); }

/* ---------- Selector de niños ---------- */
.children-bar {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 2px 14px;
  scrollbar-width: none;
}
.children-bar::-webkit-scrollbar { display: none; }

.child-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px 8px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.15s ease, background 0.2s ease, color 0.2s ease;
}
.child-chip:active { transform: scale(0.96); }

.child-chip .chip-avatar {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  font-size: 16px;
  border-radius: 50%;
  background: var(--accent-soft);
}

.child-chip.active {
  background: linear-gradient(135deg, #8d7bff 0%, #6a58ec 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(106, 88, 236, 0.35);
}
.child-chip.active .chip-avatar { background: rgba(255, 255, 255, 0.22); }

.child-chip.add-chip {
  padding: 8px 16px;
  color: var(--accent);
  border-style: dashed;
  border-color: rgba(124, 108, 240, 0.45);
  background: transparent;
  box-shadow: none;
}

/* ---------- Estado vacío ---------- */
.empty-state {
  text-align: center;
  padding: 60px 24px;
}
.empty-emoji { font-size: 56px; margin-bottom: 14px; }
.empty-state h2 { font-size: 22px; font-weight: 800; margin-bottom: 8px; }
.empty-state p { color: var(--text-soft); font-size: 15px; margin-bottom: 22px; }

/* ---------- Tarjetas genéricas ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

/* ---------- Tarjetas de medicamento ---------- */
.med-cards {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
}

.med-card {
  position: relative;
  overflow: hidden;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.med-card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 5px;
}
.med-card.apiretal::before { background: var(--apiretal-grad); }
.med-card.dalsy::before { background: var(--dalsy-grad); }

.med-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.med-icon {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 14px;
  font-size: 22px;
}
.med-card.apiretal .med-icon { background: var(--apiretal-soft); }
.med-card.dalsy .med-icon { background: var(--dalsy-soft); }

.med-name { font-size: 18px; font-weight: 800; letter-spacing: -0.2px; }
.med-compound { font-size: 12px; color: var(--text-soft); font-weight: 500; }

.med-count {
  margin-left: auto;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-soft);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 5px 10px;
  white-space: nowrap;
}
.med-count.maxed { color: var(--danger); background: var(--danger-soft); }

.med-status {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
}

.ring { position: relative; width: 86px; height: 86px; flex: 0 0 auto; }
.ring svg { transform: rotate(-90deg); }
.ring .ring-bg { stroke: var(--surface-2); }
.ring .ring-fg {
  transition: stroke-dashoffset 0.6s ease;
  stroke-linecap: round;
}
.med-card.apiretal .ring-fg { stroke: var(--apiretal); }
.med-card.dalsy .ring-fg { stroke: var(--dalsy); }
.ring.ready .ring-fg { stroke: var(--ok); }

.ring-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 26px;
}

.med-state-text { min-width: 0; }

.status-pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 11px;
  border-radius: 999px;
  margin-bottom: 6px;
}
.status-pill.ok { color: var(--ok); background: var(--ok-soft); }
.status-pill.wait { color: var(--danger); background: var(--danger-soft); }

.status-big { font-size: 21px; font-weight: 800; letter-spacing: -0.3px; line-height: 1.2; }
.status-detail { font-size: 13px; color: var(--text-soft); margin-top: 4px; }

.med-btn {
  width: 100%;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.2s ease, opacity 0.2s ease;
}
.med-btn:active { transform: scale(0.98); }
.med-card.apiretal .med-btn { background: var(--apiretal-grad); box-shadow: 0 6px 16px rgba(233, 58, 114, 0.30); }
.med-card.dalsy .med-btn { background: var(--dalsy-grad); box-shadow: 0 6px 16px rgba(239, 133, 6, 0.30); }
.med-btn.waiting { filter: saturate(0.25) brightness(0.9); box-shadow: none; }

/* ---------- Tarjeta temperatura ---------- */
.temp-card { padding: 14px 18px; margin-bottom: 16px; }

.temp-row { display: flex; align-items: center; gap: 12px; }

.temp-icon {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  font-size: 20px;
  border-radius: 13px;
  background: var(--accent-soft);
}

.temp-info { display: flex; flex-direction: column; min-width: 0; }
.temp-label { font-size: 12px; color: var(--text-soft); font-weight: 500; }
.temp-value { font-size: 17px; font-weight: 800; }
.temp-value .fever { color: var(--danger); }
.temp-info .temp-when { font-size: 11px; color: var(--text-soft); }
.temp-row .btn { margin-left: auto; }

.alternate-hint {
  font-size: 12.5px;
  color: var(--text-soft);
  text-align: center;
  padding: 0 10px;
  margin-bottom: 24px;
}

/* ---------- Historial ---------- */
.section-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.2px;
  margin-bottom: 12px;
}

.history-day {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-soft);
  margin: 18px 4px 8px;
}
.history-day:first-child { margin-top: 0; }

.history-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-soft);
}

.entry-dot {
  width: 38px; height: 38px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 12px;
  font-size: 18px;
}
.entry-dot.apiretal { background: var(--apiretal-soft); }
.entry-dot.dalsy { background: var(--dalsy-soft); }
.entry-dot.temp { background: var(--accent-soft); }

.entry-main { min-width: 0; flex: 1; }
.entry-title { font-size: 14px; font-weight: 700; }
.entry-title .entry-temp-badge {
  font-weight: 700;
  font-size: 12px;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: 999px;
  padding: 2px 8px;
  margin-left: 6px;
}
.entry-meta { font-size: 12px; color: var(--text-soft); }

.entry-time { font-size: 13px; font-weight: 700; color: var(--text-soft); white-space: nowrap; }

.entry-delete {
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-size: 16px;
  padding: 6px;
  cursor: pointer;
  border-radius: 8px;
  opacity: 0.55;
}
.entry-delete:active { background: var(--danger-soft); color: var(--danger); opacity: 1; }

.history-empty {
  text-align: center;
  color: var(--text-soft);
  font-size: 14px;
  padding: 26px 10px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

/* ---------- Botones ---------- */
.btn {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, #8d7bff 0%, #6a58ec 100%);
  box-shadow: 0 6px 16px rgba(106, 88, 236, 0.35);
}

.btn-ghost {
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.btn-danger { color: var(--danger); background: var(--danger-soft); }

/* ---------- Hojas modales ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 12, 40, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 40;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.sheet-backdrop.show { opacity: 1; }

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translate(-50%, 105%);
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: 26px 26px 0 0;
  padding: 10px 22px calc(env(safe-area-inset-bottom, 0px) + 22px);
  z-index: 50;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.25);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0.25, 1);
  max-height: 88dvh;
  overflow-y: auto;
}
.sheet.show { transform: translate(-50%, 0); }

.sheet-handle {
  width: 42px; height: 5px;
  border-radius: 999px;
  background: var(--border);
  margin: 4px auto 16px;
}

.sheet-title { font-size: 19px; font-weight: 800; letter-spacing: -0.2px; }
.sheet-sub { font-size: 13px; color: var(--text-soft); margin: 4px 0 16px; }

.sheet-confirm { text-align: center; }
.confirm-icon { font-size: 40px; margin-bottom: 8px; }
.sheet-confirm .sheet-sub { margin-bottom: 20px; }

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-hint { font-size: 12px; color: var(--text-soft); margin-top: 6px; }
.field-hint strong { color: var(--accent); }

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.sheet-actions .btn { flex: 1; }
.sheet-actions .btn-danger { flex: 0 0 auto; }

/* ---------- Selector de emoji ---------- */
.emoji-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.emoji-option {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  font-size: 22px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s ease, background 0.2s ease;
}
.emoji-option:active { transform: scale(0.92); }
.emoji-option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 60;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Pie ---------- */
.disclaimer {
  font-size: 11.5px;
  color: var(--text-soft);
  text-align: center;
  line-height: 1.55;
  margin-top: 30px;
  padding: 0 8px;
  opacity: 0.8;
}
.disclaimer a { color: var(--accent); font-weight: 600; }

/* ---------- Animación de entrada ---------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.med-card, .temp-card, .history-entry { animation: rise 0.3s ease both; }
