:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #ccfbf1;
  --bg: #f4f7f7;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --warn: #b45309;
  --ok: #15803d;
  --wa: #25d366;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.loading { padding: 3rem; text-align: center; color: var(--muted); }

/* ---------- Botones y formularios ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: .55rem .9rem; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f8fafc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-outline { color: var(--danger); border-color: #fecaca; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: .35rem .6rem; font-size: .85rem; border-radius: 8px; }
.btn.big { padding: .85rem 1.2rem; font-size: 1.05rem; width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label { display: block; font-weight: 600; font-size: .85rem; margin: .75rem 0 .3rem; color: #334155; }
input, select, textarea {
  width: 100%; padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 10px;
  font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .75rem; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 .75rem; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.check input { width: auto; }
.error { color: var(--danger); font-size: .9rem; margin-top: .6rem; min-height: 1.2em; }
.notice { background: var(--primary-soft); color: var(--primary-dark); padding: .75rem 1rem; border-radius: 10px; margin: 1rem 0; font-weight: 600; }

/* ---------- Pantalla de acceso ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: linear-gradient(160deg, #0f766e, #134e4a); }
.auth-card { background: #fff; width: 100%; max-width: 420px; padding: 2rem; border-radius: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.auth-card .brand { text-align: center; margin-bottom: 1.25rem; }
.auth-card .brand .logo { font-size: 2.5rem; }
.tabs { display: flex; background: #f1f5f9; border-radius: 10px; padding: 4px; margin-bottom: .5rem; }
.tabs button { flex: 1; border: 0; background: transparent; padding: .5rem; border-radius: 8px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }

/* ---------- Estructura ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--primary); color: #fff;
  padding: .75rem 1rem; padding-top: calc(.75rem + env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.topbar .title { font-weight: 700; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .who { font-size: .8rem; opacity: .85; }
.topnav { display: flex; gap: .25rem; }
.topnav button { background: transparent; border: 0; color: #fff; opacity: .8; font: inherit; font-weight: 600; padding: .45rem .8rem; border-radius: 8px; cursor: pointer; }
.topnav button.active { background: rgba(255,255,255,.18); opacity: 1; }
main.content { max-width: 960px; margin: 0 auto; padding: 1rem 1rem 6rem; }
.bottomnav { display: none; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; flex-wrap: wrap; }

/* ---------- Agenda ---------- */
.next-banner {
  display: flex; gap: .9rem; align-items: center; background: linear-gradient(135deg, #0f766e, #0d9488);
  color: #fff; border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.next-banner .when { text-align: center; min-width: 64px; }
.next-banner .when .t { font-size: 1.4rem; font-weight: 800; }
.next-banner .when .d { font-size: .75rem; opacity: .85; }
.next-banner .lbl { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; opacity: .8; }
.next-banner .who { font-weight: 700; font-size: 1.05rem; }
.toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .75rem; }
.toolbar input[type=date], .toolbar select { width: auto; }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: .35rem; margin-bottom: 1rem; }
.week button {
  border: 1px solid var(--border); background: #fff; border-radius: 12px; padding: .45rem 0; cursor: pointer; font: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.week button .dw { font-size: .7rem; color: var(--muted); text-transform: uppercase; }
.week button .dn { font-weight: 700; font-size: 1.05rem; }
.week button .cnt { font-size: .7rem; color: var(--primary); font-weight: 700; min-height: 1em; }
.week button.sel { background: var(--primary); border-color: var(--primary); color: #fff; }
.week button.sel .dw, .week button.sel .cnt { color: #fff; }
.week button.today:not(.sel) { border-color: var(--primary); }
.week button.off { opacity: .45; }

.appt { display: flex; gap: .9rem; padding: .9rem; border-radius: 12px; border: 1px solid var(--border); background: #fff; margin-bottom: .6rem; border-left: 5px solid var(--primary); }
.appt.st-pendiente { border-left-color: #f59e0b; }
.appt.st-confirmada { border-left-color: var(--ok); }
.appt.st-cancelada { border-left-color: #cbd5e1; opacity: .6; }
.appt.st-completada { border-left-color: #64748b; }
.appt.st-no_asistio { border-left-color: var(--danger); }
.appt .time { min-width: 58px; font-weight: 800; font-size: 1.05rem; }
.appt .time small { display: block; font-weight: 500; color: var(--muted); font-size: .75rem; }
.appt .body { flex: 1; min-width: 0; }
.appt .pname { font-weight: 700; cursor: pointer; }
.appt .reason { color: #334155; }
.appt .meta { font-size: .8rem; color: var(--muted); display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .2rem; }
.appt .actions { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .6rem; }
.chip { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 700; }
.chip.pendiente { background: #fef3c7; color: var(--warn); }
.chip.confirmada { background: #dcfce7; color: var(--ok); }
.chip.cancelada { background: #f1f5f9; color: var(--muted); }
.chip.completada { background: #e2e8f0; color: #334155; }
.chip.no_asistio { background: #fee2e2; color: var(--danger); }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.empty .ico { font-size: 2.2rem; }

/* ---------- Pacientes ---------- */
.plist { list-style: none; margin: 0; padding: 0; }
.plist li { display: flex; align-items: center; gap: .75rem; padding: .75rem .25rem; border-bottom: 1px solid var(--border); cursor: pointer; }
.plist li:hover { background: #f8fafc; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-dark); display: grid; place-items: center; font-weight: 800; flex-shrink: 0; }
.plist .info { flex: 1; min-width: 0; }
.plist .info .n { font-weight: 600; }
.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: .5rem 0; border-bottom: 1px solid var(--border); font-size: .9rem; }

/* ---------- Horarios disponibles ---------- */
.slots { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .3rem; }
.slots button { border: 1px solid var(--border); background: #fff; padding: .45rem .7rem; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.slots button.sel { background: var(--primary); color: #fff; border-color: var(--primary); }
.search-results { border: 1px solid var(--border); border-radius: 10px; margin-top: .3rem; max-height: 200px; overflow: auto; background: #fff; }
.search-results div { padding: .55rem .7rem; cursor: pointer; border-bottom: 1px solid var(--border); }
.search-results div:hover { background: #f0fdfa; }
.selected-patient { display: flex; align-items: center; justify-content: space-between; background: #f0fdfa; border: 1px solid var(--primary-soft); padding: .55rem .7rem; border-radius: 10px; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 2rem 1rem; overflow: auto; }
.modal { background: #fff; width: 100%; max-width: 560px; border-radius: 18px; padding: 1.25rem; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .25rem; }
.modal-foot { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; flex-wrap: wrap; }
.x { border: 0; background: transparent; font-size: 1.5rem; cursor: pointer; color: var(--muted); line-height: 1; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: #0f172a; color: #fff; padding: .7rem 1.1rem; border-radius: 10px; z-index: 100; max-width: 90vw; box-shadow: var(--shadow); }
.toast.err { background: var(--danger); }

.days-picker { display: flex; gap: .3rem; flex-wrap: wrap; }
.days-picker label { margin: 0; display: flex; align-items: center; gap: .25rem; border: 1px solid var(--border); padding: .35rem .6rem; border-radius: 8px; font-weight: 600; cursor: pointer; }
.days-picker input { width: auto; }
table.users { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.users td, table.users th { padding: .5rem .35rem; border-bottom: 1px solid var(--border); text-align: left; }

/* ---------- Página pública del paciente ---------- */
body.public { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(160deg, #f0fdfa, #e2e8f0); }
.confirm-card { background: #fff; max-width: 440px; width: 100%; padding: 2rem 1.5rem; border-radius: 20px; box-shadow: 0 10px 40px rgba(15,23,42,.12); text-align: center; }
.brand-mark { font-size: 2.6rem; }
.appt-details { text-align: left; display: grid; grid-template-columns: auto 1fr; gap: .5rem 1rem; margin: 1.25rem 0; background: #f8fafc; padding: 1rem; border-radius: 12px; }
.appt-details dt { color: var(--muted); font-size: .85rem; }
.appt-details dd { margin: 0; font-weight: 600; }
.confirm-actions { display: grid; gap: .6rem; margin: 1rem 0; }

/* ---------- Celular ---------- */
@media (max-width: 720px) {
  .topnav { display: none; }
  .bottomnav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: #fff; border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .bottomnav button { flex: 1; border: 0; background: transparent; padding: .55rem 0 .6rem; font: inherit; font-size: .72rem; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; }
  .bottomnav button .i { font-size: 1.3rem; }
  .bottomnav button.active { color: var(--primary); font-weight: 700; }
  .fab { position: fixed; right: 1rem; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 21; border-radius: 999px; padding: .9rem 1.2rem; box-shadow: 0 8px 20px rgba(15,118,110,.4); }
  .hide-mobile { display: none; }
  .modal-bg { padding: 0; align-items: flex-end; }
  .modal { border-radius: 18px 18px 0 0; max-height: 94vh; overflow: auto; }
  .row3 { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 721px) { .fab { display: none; } }

/* ---------- Suscripción ---------- */
.sub-banner { display: flex; align-items: center; justify-content: space-between; gap: .75rem; max-width: 960px; margin: .75rem auto 0; padding: .6rem 1rem; border-radius: 12px; font-weight: 600; font-size: .9rem; width: calc(100% - 2rem); }
.sub-banner.info { background: #e0f2fe; color: #075985; }
.sub-banner.warn { background: #fef3c7; color: #92400e; }
.pay-box { white-space: pre-line; text-align: left; background: #f8fafc; border: 1px dashed var(--border); border-radius: 10px; padding: .75rem 1rem; margin: .75rem 0; font-size: .92rem; }
.chip.sub-prueba { background: #e0f2fe; color: #075985; }
.chip.sub-activo { background: #dcfce7; color: var(--ok); }
.chip.sub-gracia { background: #fef3c7; color: var(--warn); }
.chip.sub-vencido, .chip.sub-suspendido { background: #fee2e2; color: var(--danger); }

/* ---------- Privacidad ---------- */
.consent { display: flex; gap: .6rem; align-items: flex-start; text-align: left; font-weight: 500; font-size: .88rem; color: #334155; background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: .75rem; margin: 0; cursor: pointer; }
.consent input { width: auto; margin-top: .2rem; flex-shrink: 0; }
.notice-page { max-width: 720px; text-align: left; }
.notice-page h1, .notice-page .brand-mark { text-align: center; }
.notice-text { white-space: pre-line; font-size: .92rem; line-height: 1.6; color: #1e293b; }
.tag-warn { display: inline-block; font-size: .7rem; font-weight: 700; color: var(--warn); background: #fef3c7; padding: .05rem .45rem; border-radius: 999px; margin-left: .35rem; vertical-align: middle; }
.consent-box { border: 1px solid var(--border); border-radius: 10px; padding: .75rem; margin-top: .9rem; background: #f8fafc; }
.consent-box .check { margin: 0; }
.audit-list { list-style: none; padding: 0; margin: 0; font-size: .85rem; max-height: 60vh; overflow: auto; }
.audit-list li { padding: .45rem 0; border-bottom: 1px solid var(--border); }
.audit-list .when { color: var(--muted); font-size: .75rem; }

/* =====================================================================
   TEMA COLORIDO
   ===================================================================== */
:root {
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --primary-soft: #ccfbf1;
  --indigo: #6366f1;
  --pink: #ec4899;
  --orange: #f97316;
  --sky: #0ea5e9;
  --grad: linear-gradient(135deg, #14b8a6 0%, #3b82f6 55%, #6366f1 100%);
  --grad-warm: linear-gradient(135deg, #f97316 0%, #ec4899 100%);
  --bg: #f3f6fd;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(30, 41, 99, .05), 0 8px 24px rgba(30, 41, 99, .07);
}
body {
  background:
    radial-gradient(900px 500px at 100% -10%, rgba(99, 102, 241, .10), transparent 60%),
    radial-gradient(700px 400px at -10% 10%, rgba(20, 184, 166, .10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

/* Botones */
.btn { border-radius: 12px; transition: transform .08s ease, box-shadow .15s ease, background .15s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--grad); border: 0; box-shadow: 0 6px 16px rgba(59, 130, 246, .28); }
.btn.primary:hover { background: var(--grad); filter: brightness(1.06); }
.btn.wa { box-shadow: 0 4px 12px rgba(37, 211, 102, .3); }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(99, 102, 241, .18); border-color: var(--indigo); }

/* Barra superior */
.topbar { background: var(--grad); box-shadow: 0 6px 20px rgba(59, 130, 246, .25); }
.topnav button.active { background: rgba(255, 255, 255, .22); }

/* Tarjetas */
.card { border: 1px solid rgba(99, 102, 241, .08); }
.card h2 { display: flex; align-items: center; gap: .4rem; }

/* Próxima cita */
.next-banner { background: var(--grad-warm); box-shadow: 0 10px 28px rgba(236, 72, 153, .28); border-radius: 20px; position: relative; overflow: hidden; }
.next-banner::after { content: ''; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%; background: rgba(255, 255, 255, .12); }
.next-banner .when { background: rgba(255, 255, 255, .2); border-radius: 14px; padding: .4rem .6rem; }

/* Resumen del día */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; margin-bottom: 1rem; }
.stat { border-radius: 16px; padding: .75rem .85rem; color: #fff; position: relative; overflow: hidden; box-shadow: var(--shadow); }
.stat .n { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.stat .l { font-size: .78rem; opacity: .92; font-weight: 600; }
.stat .ico { position: absolute; right: .55rem; top: .45rem; font-size: 1.3rem; opacity: .85; }
.stat.s1 { background: linear-gradient(135deg, #6366f1, #8b5cf6); }
.stat.s2 { background: linear-gradient(135deg, #10b981, #14b8a6); }
.stat.s3 { background: linear-gradient(135deg, #f59e0b, #f97316); }
.stat.s4 { background: linear-gradient(135deg, #0ea5e9, #3b82f6); }

/* Semana */
.week button { border-radius: 14px; transition: transform .1s; }
.week button:hover { transform: translateY(-2px); }
.week button.sel { background: var(--grad); border-color: transparent; box-shadow: 0 6px 16px rgba(59, 130, 246, .3); }
.week button.today:not(.sel) { border: 2px solid var(--indigo); }
.week button .cnt { color: var(--indigo); }

/* Citas: fondo suave del color de su estado */
.appt { border-radius: 16px; border-left-width: 6px; transition: box-shadow .15s; }
.appt:hover { box-shadow: var(--shadow); }
.appt.st-pendiente { background: linear-gradient(90deg, #fffbeb, #fff 40%); }
.appt.st-confirmada { background: linear-gradient(90deg, #ecfdf5, #fff 40%); }
.appt.st-completada { background: linear-gradient(90deg, #f1f5f9, #fff 40%); }
.appt.st-no_asistio { background: linear-gradient(90deg, #fef2f2, #fff 40%); }
.appt .time { color: var(--indigo); }

/* Pacientes */
.plist li { border-radius: 12px; padding: .7rem .6rem; }
.avatar { color: #fff; font-size: .9rem; }

/* Navegación inferior en celular */
@media (max-width: 720px) {
  .bottomnav { box-shadow: 0 -6px 20px rgba(30, 41, 99, .08); border-top: 0; }
  .bottomnav button.active { color: var(--indigo); }
  .bottomnav button.active .i { transform: translateY(-2px) scale(1.1); }
  .fab { background: var(--grad-warm) !important; box-shadow: 0 10px 24px rgba(236, 72, 153, .4) !important; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* Pantalla de inicio */
.auth-wrap { background: linear-gradient(135deg, #0d9488 0%, #3b82f6 50%, #7c3aed 100%); position: relative; overflow: hidden; }
.auth-wrap::before, .auth-wrap::after { content: ''; position: absolute; border-radius: 50%; filter: blur(2px); }
.auth-wrap::before { width: 420px; height: 420px; background: rgba(236, 72, 153, .35); top: -120px; right: -100px; }
.auth-wrap::after { width: 360px; height: 360px; background: rgba(20, 184, 166, .35); bottom: -140px; left: -80px; }
.auth-split { position: relative; z-index: 1; display: grid; grid-template-columns: 1.1fr 1fr; gap: 2rem; align-items: center; max-width: 960px; width: 100%; }
.auth-hero { color: #fff; }
.auth-hero .badge { display: inline-block; background: rgba(255, 255, 255, .18); padding: .3rem .8rem; border-radius: 999px; font-weight: 700; font-size: .8rem; margin-bottom: 1rem; }
.auth-hero h1 { font-size: 2.5rem; line-height: 1.1; margin-bottom: .8rem; }
.auth-hero h1 span { background: linear-gradient(90deg, #fde68a, #fbcfe8); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-hero p { font-size: 1.05rem; opacity: .92; margin: 0 0 1.4rem; }
.feat { display: flex; gap: .75rem; align-items: center; background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .18); border-radius: 14px; padding: .65rem .85rem; margin-bottom: .55rem; backdrop-filter: blur(6px); }
.feat .fi { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 1.2rem; flex-shrink: 0; }
.feat strong { display: block; }
.feat small { opacity: .85; }
.auth-card { border-radius: 24px; }
.auth-card .brand .logo { display: inline-grid; place-items: center; width: 64px; height: 64px; border-radius: 20px; background: var(--grad); box-shadow: 0 10px 24px rgba(99, 102, 241, .35); font-size: 2rem; }
.tabs button.active { color: var(--indigo); }
@media (max-width: 820px) {
  .auth-split { grid-template-columns: 1fr; gap: 1.25rem; }
  .auth-hero { text-align: center; }
  .auth-hero h1 { font-size: 1.8rem; }
  .auth-hero .feats { display: none; }
  .auth-hero p { margin-bottom: 0; }
}

/* Chips más vivos */
.chip.pendiente { background: #fef3c7; color: #b45309; }
.chip.confirmada { background: #d1fae5; color: #047857; }
.chip.no_asistio { background: #fee2e2; color: #b91c1c; }
