/* =========================================================
   Clínica Del Sagrario — Base / Design tokens
   Ver design-system/clinica-del-sagrario/MASTER.md
   ========================================================= */
@import url('https://fonts.googleapis.com/css2?family=Figtree:wght@500;600;700;800&family=Noto+Sans:wght@400;500;600&display=swap');

:root {
  /* Marca */
  --primary: #1B2A9E;
  --primary-700: #15207A;
  --primary-800: #101863;
  --primary-100: #DDE3FB;
  --primary-50: #EEF1FD;
  --accent: #D92D2A;
  --accent-700: #B42320;
  --accent-50: #FDECEC;

  /* Superficies y texto */
  --bg: #F6F8FC;
  --surface: #FFFFFF;
  --surface-2: #F1F4F9;
  --text: #0F172A;
  --text-muted: #475569;
  --text-subtle: #64748B;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;

  /* Semánticos */
  --success: #047857; --success-50: #ECFDF5;
  --warning: #B45309; --warning-50: #FFFBEB;
  --info: #0369A1;    --info-50: #F0F9FF;
  --danger: #C62828;  --danger-50: #FEF2F2;
  --neutral: #475569; --neutral-50: #F1F5F9;
  --violet: #6D28D9;  --violet-50: #F5F3FF;

  /* Tipografía */
  --font-head: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-body: 'Noto Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;

  /* Espaciado (4pt) */
  --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px;
  --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px; --s-16: 64px; --s-20: 80px;

  /* Radios y sombras (una sola escala) */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 24px; --r-full: 999px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, .07), 0 2px 4px rgba(15, 23, 42, .04);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, .12), 0 4px 12px rgba(15, 23, 42, .06);

  /* Movimiento */
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --dur-fast: 150ms; --dur: 220ms;

  /* Capas */
  --z-sticky: 20; --z-drawer: 40; --z-modal: 100; --z-toast: 1000;

  --ring: 0 0 0 3px rgba(27, 42, 158, .35);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
img { height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); text-underline-offset: 3px; }
h1, h2, h3, h4 {
  font-family: var(--font-head);
  line-height: 1.2;
  margin: 0 0 var(--s-3);
  color: var(--text);
  text-wrap: balance;
}
p { margin: 0 0 var(--s-4); }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--primary-100); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------- Utilidades ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: var(--s-4); top: -60px; z-index: var(--z-toast); background: var(--primary); color: #fff; padding: var(--s-2) var(--s-4); border-radius: var(--r-sm); font-weight: 600; transition: top var(--dur-fast); }
.skip-link:focus { top: var(--s-4); }
.container { width: 100%; max-width: 1200px; margin-inline: auto; padding-inline: var(--s-4); }
@media (min-width: 768px) { .container { padding-inline: var(--s-8); } }
.tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.stack > * + * { margin-top: var(--s-4); }
.row { display: flex; align-items: center; gap: var(--s-3); }
.hidden { display: none !important; }

/* ---------- Iconos ---------- */
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }
.icon-xl { width: 28px; height: 28px; }

/* ---------- Botones ---------- */
.btn {
  --btn-bg: var(--surface); --btn-fg: var(--text); --btn-bd: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 44px; padding: 0 var(--s-5);
  border: 1px solid var(--btn-bd); border-radius: var(--r-sm);
  background: var(--btn-bg); color: var(--btn-fg);
  font-family: var(--font-head); font-weight: 600; font-size: 15px; line-height: 1;
  text-decoration: none; white-space: nowrap;
  transition: background-color var(--dur-fast), border-color var(--dur-fast), box-shadow var(--dur-fast), transform var(--dur-fast);
  touch-action: manipulation;
}
.btn:hover { --btn-bg: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; }
.btn-primary { --btn-bg: var(--primary); --btn-fg: #fff; --btn-bd: var(--primary); }
.btn-primary:hover { --btn-bg: var(--primary-700); --btn-bd: var(--primary-700); }
.btn-secondary { --btn-bg: var(--surface); --btn-fg: var(--primary); --btn-bd: var(--primary-100); }
.btn-secondary:hover { --btn-bg: var(--primary-50); }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--text-muted); }
.btn-ghost:hover { --btn-bg: var(--surface-2); --btn-fg: var(--text); }
.btn-danger { --btn-bg: var(--surface); --btn-fg: var(--danger); --btn-bd: #F5C2C2; }
.btn-danger:hover { --btn-bg: var(--danger-50); }
.btn-danger-solid { --btn-bg: var(--danger); --btn-fg: #fff; --btn-bd: var(--danger); }
.btn-danger-solid:hover { --btn-bg: #A61F1F; }
.btn-white { --btn-bg: #fff; --btn-fg: var(--primary); --btn-bd: #fff; }
.btn-white:hover { --btn-bg: var(--primary-50); }
.btn-sm { min-height: 36px; padding: 0 var(--s-3); font-size: 14px; }
.btn-lg { min-height: 52px; padding: 0 var(--s-6); font-size: 16px; border-radius: var(--r-md); }
.btn-block { width: 100%; }
.btn-icon { min-width: 44px; padding: 0; }
.btn-icon.btn-sm { min-width: 36px; }
.btn .spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label { font-weight: 600; font-size: 14px; color: var(--text); }
.req { color: var(--danger); margin-left: 2px; }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); font-size: 16px;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.textarea { min-height: 96px; resize: vertical; }
.select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-subtle); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.help { font-size: 13px; color: var(--text-muted); }
.error-msg { font-size: 13px; color: var(--danger); display: flex; gap: 6px; align-items: center; font-weight: 500; }
.error-msg:empty { display: none; }
.check { display: flex; gap: var(--s-3); align-items: flex-start; font-size: 14px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--primary); flex: none; cursor: pointer; }
.input-icon { position: relative; }
.input-icon .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-subtle); pointer-events: none; }
.input-icon .input { padding-left: 40px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; }

/* ---------- Tarjetas / chips ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }

.chip {
  --chip-fg: var(--neutral); --chip-bg: var(--neutral-50);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px; border-radius: var(--r-full);
  background: var(--chip-bg); color: var(--chip-fg);
  font-size: 13px; font-weight: 600; line-height: 1.4; white-space: nowrap;
}
.chip .icon { width: 14px; height: 14px; }
.tone-warning { --chip-fg: var(--warning); --chip-bg: var(--warning-50); }
.tone-primary { --chip-fg: var(--primary); --chip-bg: var(--primary-50); }
.tone-info    { --chip-fg: var(--violet); --chip-bg: var(--violet-50); }
.tone-success { --chip-fg: var(--success); --chip-bg: var(--success-50); }
.tone-neutral { --chip-fg: var(--neutral); --chip-bg: var(--neutral-50); }
.tone-danger  { --chip-fg: var(--danger); --chip-bg: var(--danger-50); }

.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--primary-50); color: var(--primary);
  font-family: var(--font-head); font-weight: 700; font-size: 14px;
}

/* ---------- Toasts ---------- */
.toasts[popover] { margin: 0; inset: auto var(--s-4) var(--s-4) auto; padding: 0; border: 0; background: transparent; overflow: visible; }
.toasts { position: fixed; z-index: var(--z-toast); right: var(--s-4); bottom: var(--s-4); display: flex; flex-direction: column; gap: var(--s-2); max-width: min(380px, calc(100vw - 32px)); }
.toast { display: flex; gap: var(--s-3); align-items: flex-start; padding: var(--s-3) var(--s-4); background: var(--text); color: #fff; border-radius: var(--r-md); box-shadow: var(--shadow-lg); font-size: 14px; animation: toast-in var(--dur) var(--ease-out); }
.toast .icon { margin-top: 1px; }
.toast-success .icon { color: #6EE7B7; }
.toast-error .icon { color: #FCA5A5; }
.toast button { margin-left: auto; background: none; border: 0; color: #C7D2FE; font-weight: 600; padding: 0 0 0 var(--s-2); text-decoration: underline; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Dialog / Drawer ---------- */
dialog { border: 0; padding: 0; color: var(--text); background: var(--surface); }
dialog::backdrop { background: rgba(15, 23, 42, .55); }
.modal { overflow: auto; width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); }
.modal[open] { animation: modal-in var(--dur) var(--ease-out); }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); padding: var(--s-5) var(--s-6); border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 20px; margin: 0; }
.modal-body { padding: var(--s-6); overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s-3); padding: var(--s-4) var(--s-6); border-top: 1px solid var(--border); background: var(--surface-2); }
.modal-sm { width: min(420px, calc(100vw - 32px)); }

.drawer { margin: 0 0 0 auto; max-width: 100vw; height: 100dvh; max-height: 100dvh; width: min(480px, 100vw); display: none; flex-direction: column; box-shadow: var(--shadow-lg); }
.drawer[open] { display: flex; animation: drawer-in var(--dur) var(--ease-out); }
@keyframes drawer-in { from { transform: translateX(32px); opacity: 0; } }
.drawer .modal-body { flex: 1; }

/* Aviso cuando no responde el servidor */
.load-error { display: flex; flex-direction: column; align-items: center; gap: var(--s-3); padding: var(--s-8) var(--s-4); text-align: center; color: var(--text-muted); }
.load-error .icon { width: 32px; height: 32px; color: var(--danger); }
.load-error strong { color: var(--text); font-size: 18px; }

/* Etiqueta del modo debug (?debug=1) */
.debug-badge { position: fixed; left: 8px; bottom: 8px; z-index: 2147483647; background: #D92D2A; color: #fff; font: 600 11px/1 system-ui, sans-serif; letter-spacing: .06em; padding: 5px 8px; border-radius: 4px; pointer-events: none; opacity: .85; }
