:root {
  /* Marca — navy (estructura y confianza) */
  --navy-900: #0E1B2E;
  --navy-700: #1B2B48;
  --navy-500: #2E4468;
  /* Marca — teal (accion y lo vivo) */
  --teal-700: #2F7573;
  --teal-600: #3E8E8C;
  --teal-500: #55A8A6;
  --teal-300: #93C9C6;
  --teal-100: #D9EBE9;
  --teal-50:  #EFF6F5;

  /* Acento (mapeado a la escala teal) */
  --accent: #55A8A6;         /* teal 500 — rellenos, botones, isotipo */
  --accent-hover: #3E8E8C;   /* teal 600 — hover de boton, estados activos */
  --accent-light: #D9EBE9;   /* teal 100 — fondos suaves, chips, nav activo */
  --accent-dark: #2F7573;    /* teal 700 — TEXTO y links (pasa AA en blanco) */

  /* Neutros */
  --bg: #F6F8F8;             /* papel */
  --surface: #FFFFFF;
  --surface-muted: #F1F4F5;
  --border: #E1E7E8;         /* linea */
  --border-soft: #EAF0F0;
  --text: #0E1B2E;           /* navy 900 */
  --text-muted: #65757E;     /* gris texto */
  --text-soft: #98A6AC;

  /* Semanticos clinicos (el color comunica estado, nunca decora) */
  --success-bg: #E6F3EE;
  --success-text: #2E8B6E;   /* confirmado */
  --warn-bg: #FBF1DC;
  --warn-text: #B9820F;      /* pendiente */
  --danger-bg: #FAE9E7;
  --danger-text: #C0392F;    /* alerta clinica */
  --info-bg: #E7F0F5;
  --info-text: #3B7EA1;      /* informativo */

  /* Tipografia */
  --font-display: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 26px;
  --shadow-xs: 0 1px 2px rgba(16, 30, 54, 0.04);
  --shadow-sm: 0 2px 10px rgba(16, 30, 54, 0.05);
  --shadow-md: 0 10px 28px rgba(16, 30, 54, 0.09);
  --shadow-lg: 0 22px 56px rgba(16, 30, 54, 0.16);
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  background: var(--bg);
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-dark); text-decoration: none; transition: color 0.15s ease; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* Titulos en la familia display (Poppins). Nunca en parrafos. */
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.01em; }

/* --- Marca --- */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
}
a.brand:hover .brand-name { color: var(--accent); }

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--navy-900);
  color: var(--teal-500);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
}

.brand-mark svg { width: 20px; height: 20px; }

.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.02em;
}
.brand-name i { font-style: normal; color: var(--teal-600); }

/* --- Formularios --- */

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin: 14px 0 6px;
  color: var(--text-muted);
}

input,
textarea,
select {
  width: 100%;
  box-sizing: border-box;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

input::placeholder { color: var(--text-soft); }

/* --- Botones --- */

button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

button:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover { background: var(--accent-hover); box-shadow: var(--shadow-sm); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-muted); border-color: #cbd5e1; }

.btn-danger-ghost {
  background: transparent;
  color: var(--danger-text);
  border: 1px solid var(--border);
}
.btn-danger-ghost:hover { background: var(--danger-bg); border-color: #f3c6c1; }

.btn-whatsapp {
  background: #25d366;
  color: #fff;
  border: 1px solid #25d366;
}
.btn-whatsapp:hover { background: #1ebe5b; border-color: #1ebe5b; box-shadow: var(--shadow-sm); }
.btn-whatsapp svg { fill: currentColor; }

.btn-icon {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 8px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover { background: var(--surface-muted); color: var(--text); }
.btn-icon svg { width: 18px; height: 18px; }

.btn-sm { padding: 7px 12px; font-size: 12.5px; display: inline-flex; align-items: center; gap: 6px; }
.btn-sm svg { width: 15px; height: 15px; flex-shrink: 0; }

/* --- Tarjetas --- */

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

/* --- Mensajes --- */

.error {
  color: var(--danger-text);
  font-size: 13px;
  margin-top: 10px;
  min-height: 16px;
}

.info {
  color: var(--success-text);
  font-size: 13px;
  margin-top: 10px;
  min-height: 16px;
}

/* --- Badges --- */

.badge {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.badge.linked { background: var(--success-bg); color: var(--success-text); }
.badge.unlinked { background: var(--warn-bg); color: var(--warn-text); }
.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* --- Estados de cita --- */

.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.status-pendiente { background: var(--warn-text); }
.status-dot.status-confirmada { background: var(--success-text); }
.status-dot.status-asistio { background: var(--accent); }
.status-dot.status-cancelada { background: var(--danger-text); }
.status-dot.status-no_asistio { background: var(--text-soft); }

/* Seccion generica dentro de un modal (separada por una linea arriba),
   usada por "Agregar a tu calendario" y por el historial de citas del paciente. */
.modal-section { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.modal-section-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 8px; }

/* Item de lista de citas reusable (panel "Proximas citas" del calendario,
   historial de citas en la ficha de paciente). */
.upcoming-empty { text-align: center; padding: 22px 8px; color: var(--text-muted); font-size: 13px; }
.upcoming-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  transition: background 0.15s ease;
  text-align: left;
  width: 100%;
}
.upcoming-item:hover { background: var(--surface-muted); }
.upcoming-date {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  background: var(--accent-light);
  color: var(--accent-dark);
  flex-shrink: 0;
  line-height: 1.1;
}
.upcoming-date .day { font-family: var(--font-display); font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.upcoming-date .month { font-size: 9px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.upcoming-info { min-width: 0; flex: 1; }
.upcoming-info .title { font-family: var(--font-display); font-size: 13px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upcoming-info .time { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upcoming-item .status-dot { margin-left: 4px; }

/* Item de la tarjeta de recordatorios del calendario (hoy y manana) */
.reminder-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
  background: transparent;
}
.reminder-item .reminder-info { min-width: 0; flex: 1; }
.reminder-item .reminder-name { font-family: var(--font-display); font-size: 13px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reminder-item .reminder-when { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reminder-item.is-sent { opacity: 0.6; }
.reminder-item.is-sent .reminder-name { text-decoration: line-through; }
.reminder-wa-btn {
  flex-shrink: 0;
  padding: 7px;
  border-radius: var(--radius-sm);
  background: #25d366;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.reminder-wa-btn:hover { background: #1ebe5b; box-shadow: var(--shadow-sm); }
.reminder-wa-btn svg { width: 16px; height: 16px; fill: currentColor; }
.reminder-item.is-sent .reminder-wa-btn { background: var(--text-soft); }

.history-group + .history-group { margin-top: 10px; }
.history-group-label { font-size: 11px; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.03em; margin: 0 0 4px 8px; }
.history-group .upcoming-item { cursor: default; }
.history-group .upcoming-item:hover { background: transparent; }
#patient-history-list { max-height: 220px; overflow-y: auto; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.status-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-badge.status-pendiente { background: var(--warn-bg); color: var(--warn-text); }
.status-badge.status-confirmada { background: var(--success-bg); color: var(--success-text); }
.status-badge.status-asistio { background: var(--accent-light); color: var(--accent-dark); }
.status-badge.status-cancelada { background: var(--danger-bg); color: var(--danger-text); }
.status-badge.status-no_asistio { background: var(--surface-muted); color: var(--text-muted); }

/* --- Chip de usuario --- */

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px 4px 4px;
  border-radius: 999px;
  background: var(--surface-muted);
  border: 1px solid var(--border-soft);
}

.avatar-circle {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--navy-900);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
}

.user-chip span:last-child {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

/* --- Cabecera de la app (calendario / pacientes) --- */

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 10px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-left { display: flex; align-items: center; flex-wrap: wrap; row-gap: 8px; }
.header-actions { display: flex; align-items: center; gap: 10px; font-size: 13px; flex-wrap: wrap; }

.header-nav { display: flex; align-items: center; gap: 4px; margin-left: 20px; }
.header-nav a {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.header-nav a:hover { background: var(--surface-muted); color: var(--text); text-decoration: none; }
.header-nav a.active { background: var(--accent-light); color: var(--accent-dark); }

/* --- Menu desplegable del usuario --- */

.user-menu { position: relative; }
.user-chip { cursor: pointer; }
.user-chip:hover { background: var(--border-soft); }
.user-chip .chevron { width: 14px; height: 14px; color: var(--text-muted); transition: transform 0.15s ease; }
.user-chip[aria-expanded="true"] .chevron { transform: rotate(180deg); }

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 6px;
  z-index: 20;
}
.dropdown-menu.open { display: block; }
.dropdown-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; padding: 10px 8px 12px 12px; border-bottom: 1px solid var(--border-soft); margin-bottom: 6px; }
.dropdown-header .name { font-size: 13px; font-weight: 600; color: var(--text); }
.dropdown-header .email { font-size: 12px; color: var(--text-muted); margin-top: 2px; word-break: break-all; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text);
  text-align: left;
  border-radius: var(--radius-sm);
  background: transparent;
}
.dropdown-item:hover { background: var(--surface-muted); }
.dropdown-item svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--text-muted); }
.dropdown-item span:not(.badge) { white-space: nowrap; }
.dropdown-item .badge { margin-left: auto; }
.dropdown-item.danger { color: var(--danger-text); }
.dropdown-item.danger svg { color: var(--danger-text); }

.dropdown-tz { padding: 6px 12px 10px; border-top: 1px solid var(--border-soft); margin-top: 4px; }
.dropdown-tz label { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-muted); margin: 8px 0 6px; }
.dropdown-tz label svg { width: 15px; height: 15px; flex-shrink: 0; }
.dropdown-tz select { font-size: 13px; padding: 8px 10px; }

@media (max-width: 640px) {
  header { padding: 12px 16px; justify-content: center; }
  .header-left { width: 100%; justify-content: center; }
  .header-nav { margin-left: 0; }
  .header-actions { width: 100%; justify-content: center; }
}

/* --- Modales --- */

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 45, 0.45);
  backdrop-filter: blur(2px);
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.modal-backdrop.open { display: flex; opacity: 1; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 26px;
  width: 340px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: scale(0.96) translateY(6px);
  transition: transform 0.15s ease;
}
.modal-backdrop.open .modal { transform: scale(1) translateY(0); }

.modal h2 {
  margin: 0 0 18px;
  font-size: 16px;
  font-weight: 600;
}

.modal label { display: block; font-size: 13px; margin: 10px 0 4px; color: var(--text-muted); }
.modal-actions { display: flex; justify-content: space-between; margin-top: 22px; gap: 8px; }
.modal-actions .right { display: flex; gap: 8px; }
.form-error { color: var(--danger-text); font-size: 12px; margin-top: 8px; min-height: 14px; }

.modal-lg { width: 520px; max-width: calc(100vw - 32px); }
.form-row { display: grid; gap: 10px; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 1.2fr 1fr 1fr; }
.form-row label { margin-top: 0; }
@media (max-width: 520px) {
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
}

#link-code-box { text-align: center; }
#link-code-box p { font-size: 13px; color: var(--text-muted); line-height: 1.5; margin: 0 0 4px; }
#link-code-box .code {
  font-size: 26px;
  letter-spacing: 5px;
  font-weight: 700;
  margin: 10px 0;
  color: var(--accent);
}
#link-qr {
  display: block;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 8px;
  background: #fff;
  margin: 12px auto;
}

/* --- Shell de autenticacion (login / registro / recuperar contrasena) --- */

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.auth-shell {
  width: 100%;
  max-width: 960px;
  min-height: 560px;
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.auth-brand-panel {
  background: linear-gradient(165deg, var(--navy-700) 0%, var(--navy-900) 100%);
  color: #fff;
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.auth-brand-panel::after {
  content: '';
  position: absolute;
  width: 480px;
  height: 480px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  right: -180px;
  bottom: -200px;
}

.auth-brand-panel .brand-mark {
  background: rgba(255, 255, 255, 0.10);
  color: var(--teal-300);
}

.auth-brand-panel .brand-name {
  color: #fff;
  font-size: 16px;
}

.auth-brand-copy {
  position: relative;
  max-width: 380px;
}

.auth-brand-copy h1 {
  font-size: 30px;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 14px;
}

.auth-brand-copy p {
  font-size: 14px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.82);
  margin: 0;
}

.auth-features {
  list-style: none;
  margin: 28px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
}

.auth-features li {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.92);
}

.auth-features li svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.auth-brand-foot {
  position: relative;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
}

.auth-form-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: var(--surface);
}

.auth-form-panel .card {
  padding: 40px 36px;
  width: 100%;
  max-width: 360px;
  box-shadow: none;
}

.auth-form-panel .brand { display: none; }

@media (max-width: 860px) {
  .auth-page { padding: 0; }
  .auth-shell { grid-template-columns: 1fr; min-height: 100vh; border-radius: 0; box-shadow: none; }
  .auth-brand-panel { display: none; }
  .auth-form-panel .brand { display: flex; margin-bottom: 24px; }
  .auth-form-panel .card { border: none; padding: 8px 4px; }
}
