/* Reset y Estilos Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* El [hidden] del navegador viene de su hoja por defecto, asi que lo tumba
   cualquier regla nuestra que fije display —.se-campo es flex, y el campo de
   afiliado se quedaba en pantalla con el atributo puesto—. Aqui se restaura,
   para que poner y quitar `hidden` desde JS signifique siempre lo mismo. */
[hidden] { display: none !important; }

html, body {
  width: 100%;
  height: 100%;
  font-family: var(--font-family);
  background-color: var(--slate-900);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

/* Scrollbar Personalizado */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--slate-300);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--slate-400);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  outline: none;
  transition: all var(--transition-fast);
}

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text-main);
  outline: none;
}

/* Shell Principal de la Aplicación */
#app-root {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  background: radial-gradient(circle at 10% 20%, #1e293b 0%, #0f172a 90%);
}

/* Modo Dispositivo: Contenedor Móvil Simulado en Escritorio o Pantalla Completa */
.device-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.device-wrapper.mode-patient {
  max-width: 480px;
  height: 100%;
  max-height: 940px;
  background: var(--bg-app);
  border-radius: 36px;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.5), 0 0 0 12px #1e293b, 0 0 0 14px #334155;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
}

@media (max-width: 640px) {
  .device-wrapper.mode-patient {
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
    box-shadow: none;
  }
}

.device-wrapper.mode-admin {
  width: 96%;
  max-width: 1440px;
  height: 92%;
  max-height: 900px;
  background: var(--bg-surface);
  border-radius: 16px;
  box-shadow: 0 30px 70px -10px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Botones y Componentes Estándar */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

.btn-primary {
  background: var(--primary-600);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(2, 132, 199, 0.2);
}
.btn-primary:hover {
  background: var(--primary-700);
  transform: translateY(-1px);
}
.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--slate-100);
  color: var(--slate-700);
}
.btn-secondary:hover {
  background: var(--slate-200);
  color: var(--slate-900);
}

.btn-accent {
  /* El relleno es el 700 y no el 600 porque el texto va en blanco: sobre el
     600 daba 3.77, por debajo del 4.5 de WCAG AA. Es el boton de WhatsApp de
     la ficha del medico, entre otros. */
  background: var(--accent-700);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(4, 120, 87, 0.25);
}
.btn-accent:hover {
  background: var(--accent-800);
}

.btn-danger {
  background: var(--danger-50);
  color: var(--danger-600);
}
.btn-danger:hover {
  background: var(--danger-500);
  color: #ffffff;
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--slate-100);
  color: var(--slate-700);
}
.btn-icon:hover {
  background: var(--slate-200);
  color: var(--slate-900);
}

/* Badges / Etiquetas */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
}
.badge-primary {
  background: var(--primary-50);
  color: var(--primary-700);
}
.badge-success {
  background: var(--accent-50);
  color: var(--accent-700);
}
.badge-warning {
  background: var(--warning-50);
  color: var(--warning-600);
}
.badge-neutral {
  background: var(--slate-100);
  color: var(--slate-700);
}

/* Switcher Flotante de Vista (Móvil Paciente <-> macOS Admin) */
.view-mode-switcher {
  position: fixed;
  top: 14px;
  right: 18px;
  z-index: 9999;
  display: flex;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  padding: 4px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: var(--shadow-xl);
}

.switcher-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  color: var(--slate-500);
}

.switcher-btn.active {
  background: var(--primary-600);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.4);
}

/* Modales y Capas de Superposición */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  animation: fadeIn 0.2s ease-out;
}

@media (min-width: 641px) {
  .modal-overlay {
    align-items: center;
  }
}

.bottom-sheet {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  background: var(--bg-surface);
  border-radius: 28px 28px 0 0;
  overflow-y: auto;
  padding: 24px;
  box-shadow: var(--shadow-sheet);
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
}

@media (min-width: 641px) {
  .bottom-sheet {
    border-radius: 24px;
    max-height: 85vh;
  }

  /* Una hoja con un catalogo dentro necesita mas de 480px. Con ese ancho, la
     rejilla de estudios se quedaba en 211 y no cabia mas de una tarjeta por
     fila --justo lo que se queria evitar--.
     Es un modificador y no un cambio de `.bottom-sheet`: las demas hojas
     enseñan un formulario o una confirmacion, y ahi 480 es el ancho que hace
     que se lean de un vistazo. */
  .bottom-sheet.hoja-ancha { max-width: 760px; }
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--slate-300);
  border-radius: 2px;
  margin: 0 auto 16px auto;
}

/* Notificación Toast */
.toast-container {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: var(--slate-900);
  color: #ffffff;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-xl);
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* En pantallas pequeñas el marco de "ventana macOS" del panel admin solo
   resta espacio útil: se ocupa todo el alto y ancho disponibles. */
@media (max-width: 1024px) {
  .device-wrapper.mode-admin {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
    box-shadow: none;
  }
}

/* A partir de 768px la vista de paciente deja de ser un teléfono dibujado en
   medio de la pantalla y pasa a ocuparla como una web normal. El marco del
   dispositivo tenía sentido para enseñar la app; para usarla, estorba. */
@media (min-width: 768px) {
  .device-wrapper.mode-patient {
    max-width: 100%;
    max-height: none;
    height: 100%;
    border-radius: 0;
    box-shadow: none;
    background: var(--bg-app);
    align-items: stretch;
    overflow-y: auto;
  }
}

/* --- Campana de avisos (centro y médico) ------------------------------ */
.av-hueco { position: relative; display: inline-flex; }
.av-campana {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-md);
  background: transparent; border: 1px solid transparent;
  color: var(--slate-500); cursor: pointer;
}
.av-campana:hover { background: var(--slate-100); color: var(--slate-700); }
.av-campana:focus-visible { outline: 2px solid var(--primary-500); outline-offset: 1px; }
.av-campana.con-avisos { color: var(--primary-600); }
.av-punto {
  position: absolute; top: 3px; right: 3px; min-width: 17px; height: 17px;
  padding: 0 3px; border-radius: 999px; background: var(--danger-600); color: #fff;
  font-size: 12px; font-weight: 800; line-height: 17px; text-align: center;
}
.av-panel {
  position: absolute; top: calc(100% + 7px); right: 0; z-index: 400;
  width: min(330px, calc(100vw - 28px));
  background: var(--bg-surface); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  max-height: min(70vh, 460px); overflow-y: auto;
}
.av-cab {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 11px 14px; border-bottom: 1px solid var(--border-color);
  position: sticky; top: 0; background: var(--bg-surface);
}
.av-cab strong { font-size: 13px; font-weight: 800; color: var(--slate-900); }
.av-todos {
  background: none; border: 0; cursor: pointer;
  font-size: 12px; font-weight: 700; color: var(--primary-600); padding: 4px;
}
.av-todos:hover { text-decoration: underline; }
.av-lista { list-style: none; margin: 0; padding: 0; }
.av-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 11px 14px; border-bottom: 1px solid var(--border-color-subtle, #f1f5f9);
  cursor: pointer;
}
.av-item:last-child { border-bottom: none; }
.av-item:hover { background: var(--slate-50); }
.av-item:focus-visible { outline: 2px solid var(--primary-500); outline-offset: -2px; }
.av-item.sin-leer { background: var(--primary-50); }
.av-item.sin-leer:hover { background: var(--primary-100, #e0f2fe); }
.av-titulo { font-size: 12.5px; font-weight: 700; color: var(--slate-900); }
.av-item.sin-leer .av-titulo::before {
  content: ''; display: inline-block; width: 6px; height: 6px;
  border-radius: 50%; background: var(--primary-600); margin-right: 6px;
  vertical-align: middle;
}
.av-texto { font-size: 12px; color: var(--slate-600); overflow-wrap: anywhere; }
.av-cuando { font-size: 12px; color: var(--slate-500); }
.av-nada { font-size: 12.5px; color: var(--slate-500); text-align: center; padding: 26px 14px; }


/* =====================================================================
 * ANCHOS DE CAMPO REUTILIZABLES  ·  JEA-221
 * =====================================================================
 *
 * EL PROBLEMA
 * -----------
 * Los campos ocupaban el 100% del ancho aunque el dato fuera corto. Un
 * telefono de nueve digitos en una caja de mil pixeles no se lee mejor: se lee
 * peor, porque el ojo tiene que recorrer una linea vacia para llegar al
 * siguiente campo. Y la pagina se hace el doble de larga de lo necesario.
 *
 * COMO FUNCIONA
 * -------------
 * Se envuelve un grupo de campos en `.campos` y a cada uno se le da una talla.
 * Las tallas no son porcentajes fijos sino PROPORCIONES: reparten el espacio
 * sobrante despues de que cada campo tenga su minimo.
 *
 *     <div class="campos">
 *       <label class="campo-lg"><span>Razon social</span><input …></label>
 *       <label class="campo-sm"><span>RNC</span><input …></label>
 *     </div>
 *
 * POR QUE PROPORCIONES Y NO PORCENTAJES
 * -------------------------------------
 * Con porcentajes hay que elegir el punto de ruptura a mano y acertar. Con
 * `flex-basis` mas proporcion, cada campo pide un minimo legible (180px) y el
 * resto se reparte; cuando ya no caben, se van bajando de linea SOLOS. El
 * corte a 768px que hay abajo es una red de seguridad, no el mecanismo.
 *
 * Eso importa en una pantalla partida o una ventana a medio ancho, que es
 * donde los disenos por porcentaje se rompen y nadie lo ve porque solo se
 * prueba a los anchos de siempre.
 *
 * NOMBRES EN CASTELLANO
 * ---------------------
 * El ticket sugeria `field-*`. Aqui todo se llama en castellano --`sol-fila`,
 * `centro-tarjeta`, `cat-marca`-- y mezclar los dos idiomas en el mismo
 * archivo cuesta mas de lo que ahorra.
 */

.campos {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-start;
}

/* Cada campo pide 180px como minimo legible y crece segun su talla. */
.campos > * {
  flex: 2 1 180px;
  min-width: 0;   /* sin esto un valor largo ensancha el campo y rompe la fila */
}

.campo-xs   { flex-grow: 1; }
.campo-sm   { flex-grow: 2; }
.campo-md   { flex-grow: 3; }
.campo-lg   { flex-grow: 5; }
.campo-full { flex: 1 1 100%; }

/* Un campo corto de verdad --un codigo, un numero-- no necesita 180 de base. */
.campo-xs, .campo-sm { flex-basis: 120px; }

/* Un campo corto no se estira aunque vaya solo en su fila.
 *
 * `flex-grow` reparte lo que sobra, pero si no hay con quien repartir el campo
 * se lo queda todo: un "Anos de experiencia" ocupando mil pixeles. El tope lo
 * evita sin necesidad de ponerle un ancho suelto a cada uno.
 *
 * Va en `ch` --unidades de caracter-- y no en pixeles: lo que limita es cuanto
 * texto entra, y eso lo dice la fuente, no la pantalla.
 *
 * Solo por encima del corte: en movil todos van a ancho completo, y un tope
 * ahi los dejaria a media anchura en una pantalla que ya va justa. */
@media (min-width: 769px) {
  .campo-xs { max-width: 14ch; }
  .campo-sm { max-width: 26ch; }
}

@media (max-width: 768px) {
  .campos > * { flex: 1 1 100%; }
}
