/* ============================================================
   CalendarioMedico — base.css (v4)
   Reset, componentes y layout público.
   Requiere tokens.css cargado antes.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

img { max-width: 100%; display: block; }
a { color: var(--brand); text-underline-offset: 3px; }

h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.15; text-wrap: balance; }
h1 { font-family: var(--display); font-size: clamp(34px, 5.2vw, 58px); font-weight: 700; letter-spacing: -.025em; line-height: 1.04; }
h2 { font-family: var(--display); font-size: clamp(24px, 3.2vw, 34px); font-weight: 600; letter-spacing: -.02em; }
h3 { font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
h4 { font-size: 14px; font-weight: 600; }
p  { margin: 0 0 12px; max-width: 68ch; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-s); }

.container { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.hide { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* Etiqueta superior de sección */
.eyebrow {
  display: inline-block; font-size: 11.5px; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
  margin-bottom: var(--s3);
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(16px) saturate(1.6);
  -webkit-backdrop-filter: blur(16px) saturate(1.6);
  border-bottom: 1px solid var(--line);
}
.topbar-in { display: flex; align-items: center; gap: var(--s3); min-height: 68px; }
.logo {
  display: flex; align-items: center; gap: 9px;
  font-size: 16.5px; font-weight: 650; letter-spacing: -.02em;
  color: var(--ink); text-decoration: none; margin-right: auto;
}
.logo svg { color: var(--brand); flex: none; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  font: inherit; font-size: 14px; font-weight: 550; letter-spacing: -.005em;
  border-radius: var(--r-m); border: 1px solid transparent;
  padding: 10px 18px; cursor: pointer; text-decoration: none;
  transition: background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease, transform .1s ease;
  white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:not(:disabled):active { transform: translateY(.5px); }

.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-pac { background: var(--pac); color: #fff; }
:root[data-theme="dark"] .btn-pac { color: #062B28; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-pac { color: #062B28; } }
.btn-pac:hover:not(:disabled) { background: var(--pac-hover); }
.btn-ghost { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); border-color: var(--muted); }
.btn-plano { background: transparent; color: var(--ink-2); }
.btn-plano:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-lg { padding: 13px 24px; font-size: 15px; border-radius: var(--r-m); }
.btn-sm { padding: 7px 13px; font-size: 13px; }
.btn-icon {
  padding: 8px; border-radius: var(--r-m); cursor: pointer; line-height: 0;
  background: transparent; color: var(--muted); border: 1px solid transparent;
  font: inherit; font-size: 12.5px; font-weight: 600;
  transition: background .14s, color .14s;
}
.btn-icon:hover { color: var(--ink); background: var(--surface-2); }

/* ---------- Campos ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--s4); }
.field label { font-size: 13px; font-weight: 550; color: var(--ink-2); }
.input, select.input, textarea.input {
  font: inherit; font-size: 14.5px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r-m); padding: 10px 13px; width: 100%;
  transition: border-color .14s, box-shadow .14s;
}
.input:hover { border-color: var(--muted); }
.input:focus-visible { border-color: var(--brand); box-shadow: var(--focus); }
.input::placeholder { color: color-mix(in srgb, var(--muted) 75%, transparent); }
.field .err { font-size: 12.5px; color: var(--bad); display: none; }
.field.invalid .input { border-color: var(--bad); }
.field.invalid .err { display: block; }

/* Campo de fecha con formato de preferencia (botón + picker nativo oculto) */
.campo-fecha { position: relative; }
.campo-fecha-btn { display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left; cursor: pointer; line-height: 1.3; }
.campo-fecha-btn .cf-txt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.campo-fecha-btn.sin-fecha .cf-txt { color: color-mix(in srgb, var(--muted) 75%, transparent); }
.campo-fecha-btn svg { flex: none; color: var(--muted); }
.campo-fecha-nativo { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; pointer-events: none; border: 0; padding: 0; margin: 0; }

/* Campo de teléfono: código de país + número */
.campo-tel { display: flex; gap: 6px; }
.campo-tel .campo-tel-lada { width: auto; flex: none; padding-left: 10px; padding-right: 6px; font-variant-numeric: tabular-nums; }
.campo-tel .campo-tel-num { flex: 1; min-width: 0; }
.hint { font-size: 12.5px; color: var(--muted); }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-l); padding: var(--s5);
}
.card-link { text-decoration: none; color: inherit; display: block; transition: border-color .16s, box-shadow .16s, transform .16s; }
.card-link:hover { border-color: var(--line-2); box-shadow: var(--shadow-2); transform: translateY(-2px); }

/* ---------- Chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 550; letter-spacing: -.005em;
  border-radius: 999px; padding: 3px 10px; white-space: nowrap;
}
.chip svg { flex: none; }
.chip-ok    { color: var(--ok);    background: var(--ok-soft); }
.chip-warn  { color: var(--warn);  background: var(--warn-soft); }
.chip-bad   { color: var(--bad);   background: var(--bad-soft); }
.chip-brand { color: var(--brand); background: var(--brand-soft); }
.chip-pac   { color: var(--pac);   background: var(--pac-soft); }
.chip-muted { color: var(--muted); background: var(--surface-2); }

/* ---------- Avatar ---------- */
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface-3); color: var(--ink-2);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13.5px; object-fit: cover; flex: none;
  letter-spacing: -.01em;
}

/* ---------- Toasts ---------- */
#toasts {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: var(--s2); align-items: center;
}
.toast {
  background: var(--ink); color: var(--bg);
  font-size: 13.5px; font-weight: 500;
  border-radius: var(--r-m); padding: 11px 18px; box-shadow: var(--shadow-3);
  max-width: min(90vw, 460px);
}
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok  { background: var(--ok);  color: #fff; }

/* ---------- Diálogo ---------- */
dialog.dlg {
  border: 1px solid var(--line); border-radius: var(--r-l);
  background: var(--surface); color: var(--ink);
  padding: var(--s5); max-width: min(92vw, 440px); width: 100%;
  box-shadow: var(--shadow-3);
}
dialog.dlg::backdrop { background: rgba(16,14,20,.5); backdrop-filter: blur(4px); }
dialog.dlg h3 { margin-bottom: 4px; font-size: 17px; }
dialog.dlg .dlg-sub { color: var(--muted); font-size: 13.5px; margin-bottom: var(--s4); }
dialog.dlg .dlg-acciones { display: flex; gap: var(--s2); justify-content: flex-end; margin-top: var(--s5); }
.dlg-opcion {
  display: flex; align-items: center; gap: var(--s2);
  border: 1px solid var(--line-2); border-radius: var(--r-m);
  padding: 10px 13px; margin-bottom: 6px; cursor: pointer; font-size: 14px;
  transition: border-color .14s, background .14s;
}
.dlg-opcion:hover { border-color: var(--muted); }
.dlg-opcion:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }

/* ---------- Vacíos ---------- */
.vacio {
  text-align: center; padding: var(--s8) var(--s5); color: var(--muted);
  border: 1px dashed var(--line-2); border-radius: var(--r-l); background: var(--surface);
}
.vacio b { color: var(--ink); display: block; margin-bottom: 6px; }

/* ---------- Skeleton ---------- */
.skel {
  border-radius: var(--r-m);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: skel 1.4s ease infinite;
}
@keyframes skel { from { background-position: 100% 50%; } to { background-position: 0 50%; } }

/* ============================================================
   Panel lateral de captura (altas y ediciones fuera de
   las listas y tablas)
   ============================================================ */
.panel-velo {
  position: fixed; inset: 0; background: rgba(16,14,20,.45);
  backdrop-filter: blur(3px); z-index: 60;
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.panel-velo.abierto { opacity: 1; pointer-events: auto; }
.panel {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(480px, 100vw);
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: var(--shadow-3); z-index: 61;
  transform: translateX(100%); transition: transform .24s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column;
}
.panel.abierto { transform: translateX(0); }
.panel-cab {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); flex: none;
}
.panel-cab h3 { margin: 0; font-size: 16px; }
.panel-cab .cerrar { margin-left: auto; }
.panel-cuerpo { padding: var(--s5); overflow-y: auto; flex: 1; }
.panel-pie {
  display: flex; gap: var(--s2); justify-content: flex-end;
  padding: var(--s4) var(--s5); border-top: 1px solid var(--line); flex: none;
  background: var(--surface);
}
@media (max-width: 560px) { .panel { width: 100vw; } }

/* ============================================================
   Selector con búsqueda (catálogos)
   La lista tiene exactamente el ancho del control.
   ============================================================ */
.sel-busca { position: relative; width: 100%; }
.sel-busca .sel-btn {
  display: flex; align-items: center; gap: var(--s2); width: 100%;
  font: inherit; font-size: 14.5px; color: var(--ink); text-align: left;
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r-m); padding: 10px 13px; cursor: pointer;
  transition: border-color .14s, box-shadow .14s;
}
.sel-busca .sel-btn:hover { border-color: var(--muted); }
.sel-busca.abierto .sel-btn { border-color: var(--brand); box-shadow: var(--focus); }
.sel-busca .sel-btn .val { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sel-busca .sel-btn .val.sin-valor { color: color-mix(in srgb, var(--muted) 75%, transparent); }
.sel-busca .sel-btn svg { flex: none; color: var(--muted); transition: transform .15s; }
.sel-busca.abierto .sel-btn svg { transform: rotate(180deg); }

.sel-lista {
  position: absolute; top: calc(100% + 4px); left: 0;
  width: 100%;                      /* mismo ancho que el control */
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r-m); box-shadow: var(--shadow-3);
  z-index: 70; display: none; overflow: hidden;
}
.sel-busca.abierto .sel-lista { display: block; }
.sel-lista .sel-campo { padding: var(--s2); border-bottom: 1px solid var(--line); }
.sel-lista .sel-campo input {
  width: 100%; font: inherit; font-size: 14px; color: var(--ink);
  background: var(--surface-2); border: 1px solid transparent;
  border-radius: var(--r-s); padding: 8px 11px;
}
.sel-lista .sel-campo input:focus-visible { border-color: var(--brand); box-shadow: none; outline: none; }
.sel-opciones { max-height: 260px; overflow-y: auto; padding: 4px; }
.sel-op {
  display: block; width: 100%; text-align: left;
  font: inherit; font-size: 14px; color: var(--ink);
  background: transparent; border: none; border-radius: var(--r-s);
  padding: 8px 11px; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sel-op:hover, .sel-op.marcado { background: var(--surface-2); }
.sel-op.sel { color: var(--brand); font-weight: 550; background: var(--brand-soft); }
.sel-vacio { padding: 14px 12px; font-size: 13.5px; color: var(--muted); text-align: center; }

/* ============================================================
   PORTADA
   ============================================================ */
.hero { padding: var(--s8) 0 var(--s7); }
.hero-grid { display: grid; grid-template-columns: 1.05fr .95fr; gap: var(--s8); align-items: center; }
@media (max-width: 900px) { .hero-grid { grid-template-columns: 1fr; gap: var(--s6); } }
.hero h1 { margin-bottom: var(--s4); }
.hero h1 em { font-style: italic; color: var(--brand); }
.hero .lede { font-size: 17.5px; color: var(--ink-2); max-width: 46ch; margin-bottom: var(--s5); line-height: 1.55; }

/* Buscador principal */
.buscador-hero {
  display: flex; gap: 6px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line-2);
  border-radius: var(--r-l); box-shadow: var(--shadow-2);
  max-width: 520px;
}
.buscador-hero .input {
  border: none; background: transparent; box-shadow: none;
  font-size: 15px; padding: 11px 12px;
}
.buscador-hero .input:focus-visible { box-shadow: none; }
.buscador-hero .btn { flex: none; }

.hero .apoyo { margin-top: var(--s4); font-size: 13.5px; color: var(--muted); display: flex; gap: var(--s4); flex-wrap: wrap; }
.hero .apoyo span { display: inline-flex; align-items: center; gap: 6px; }
.hero .apoyo svg { color: var(--ok); flex: none; }

/* Tarjeta visual del hero: agenda de ejemplo */
/* Vista previa ILUSTRATIVA (no interactiva): no debe competir con los
   CTA reales ni parecer que se puede tocar. */
.hero-visual {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-xl); padding: var(--s5);
  box-shadow: var(--shadow-3);
  pointer-events: none; user-select: none;
}
.hv-cab { display: flex; align-items: center; gap: var(--s3); padding-bottom: var(--s4); border-bottom: 1px solid var(--line); }
.hv-cab .avatar { width: 44px; height: 44px; background: var(--brand-soft); color: var(--brand); }
.hv-cab b { display: block; font-size: 14.5px; }
.hv-cab span { font-size: 12.5px; color: var(--muted); }
.hv-dia { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; margin: var(--s4) 0 var(--s3); }
.hv-slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); }
.hv-slot {
  text-align: center; font-size: 13.5px; font-weight: 550;
  padding: 9px 4px; border-radius: var(--r-m);
  border: 1px solid var(--line-2); color: var(--ink-2); background: var(--surface);
  font-variant-numeric: tabular-nums; cursor: default;
}
/* Horario "elegido" en la muestra: chip suave (estado de selección),
   NO el sólido del botón primario, para que no parezca un CTA real. */
.hv-slot.on {
  background: var(--brand-soft); border-color: var(--brand);
  color: var(--brand); font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--brand);
}
.hv-pie { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--line); font-size: 12.5px; color: var(--muted); }

/* Secciones */
.seccion { padding: var(--s8) 0; }
.seccion-cab { max-width: 60ch; margin-bottom: var(--s6); }
.seccion-cab p { color: var(--ink-2); font-size: 16px; }

/* Doble puerta por perfil */
.puertas { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
@media (max-width: 760px) { .puertas { grid-template-columns: 1fr; } }
.puerta {
  display: block; text-decoration: none; color: inherit;
  border: 1px solid var(--line); border-radius: var(--r-l);
  padding: var(--s5); background: var(--surface);
  transition: border-color .16s, box-shadow .16s, transform .16s;
}
.puerta:hover { border-color: var(--line-2); box-shadow: var(--shadow-2); transform: translateY(-2px); }
.puerta .ic {
  width: 40px; height: 40px; border-radius: var(--r-m);
  display: flex; align-items: center; justify-content: center; margin-bottom: var(--s4);
  background: var(--surface-2); color: var(--ink-2);
}
.puerta-pac .ic { background: var(--pac-soft); color: var(--pac); }
.puerta-med .ic { background: var(--brand-soft); color: var(--brand); }
.puerta h3 { font-size: 18px; margin-bottom: 4px; }
.puerta p { font-size: 14px; color: var(--muted); margin-bottom: var(--s4); }
.puerta .ir { font-size: 14px; font-weight: 550; display: inline-flex; align-items: center; gap: 6px; }
.puerta-pac .ir { color: var(--pac); }
.puerta-med .ir { color: var(--brand); }

/* Pasos numerados */
.pasos { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s6); }
@media (max-width: 800px) { .pasos { grid-template-columns: 1fr; gap: var(--s5); } }
.paso { border-top: 2px solid var(--ink); padding-top: var(--s4); }
.paso .n { font-family: var(--display); font-size: 13px; font-weight: 600; color: var(--muted); display: block; margin-bottom: var(--s2); }
.paso h3 { margin-bottom: 6px; }
.paso p { font-size: 14px; color: var(--muted); margin: 0; }

/* ---------- Footer ---------- */
footer.pie {
  border-top: 1px solid var(--line); margin-top: var(--s8);
  padding: var(--s6) 0; font-size: 13px; color: var(--muted);
}
footer.pie .container { display: flex; gap: var(--s5); flex-wrap: wrap; align-items: center; }
footer.pie a { color: var(--muted); text-decoration: none; }
footer.pie a:hover { color: var(--ink); }
footer.pie .der { margin-left: auto; }

/* ---------- Auth ---------- */
.auth-wrap { max-width: 420px; margin: var(--s8) auto; padding: 0 24px; }
.auth-wrap .card { padding: var(--s6); }
.auth-wrap h2 { font-size: 24px; margin-bottom: 4px; }
.auth-alt { text-align: center; margin-top: var(--s4); font-size: 13.5px; color: var(--muted); }

/* app-main legado (páginas públicas simples) */
.app-main { padding: var(--s6) 0 var(--s8); }
