﻿:root {
  /* Paleta tomada del logo "Upright Medical Group":
     azul marino del emblema (#152369) y cian del texto (#00aeef) */
  --bg: #f3f5fa;
  --card: #ffffff;
  --ink: #1a2233;
  --muted: #6b7280;
  --line: #e3e7ef;
  --primary: #162977;
  --primary-dark: #0f1c56;
  --accent: #00aeef;
  --accent-dark: #0093c9;
  --danger: #c0392b;
  --success: #1e8e5a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  /* Zonas seguras de iPhone (notch / home indicator) */
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%; /* evita el zoom de texto en iOS al rotar */
}

/* Ninguna imagen debe desbordar su contenedor (clave en móvil) */
img {
  max-width: 100%;
  height: auto;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* --- Topbar (blanca, para que el logo se lea correctamente) --- */
.topbar {
  background: #fff;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 2px rgba(21, 35, 105, 0.06);
  padding-top: env(safe-area-inset-top, 0px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 max(20px, var(--safe-l)) 0 max(20px, var(--safe-r));
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; text-decoration: none; }
.brand img { height: 38px; width: auto; display: block; }
.nav { display: flex; gap: 20px; flex: 1; }
.nav a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 8px 2px;
  border-bottom: 2px solid transparent;
}
.nav a:hover, .nav a:active { color: var(--accent); border-bottom-color: var(--accent); }
.user-box { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 0.9rem; color: var(--muted); }
/* Botón hamburguesa: oculto en escritorio, visible en móvil */
.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  color: var(--primary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nav-toggle:active { background: var(--bg); }

/* --- Layout --- */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px max(20px, var(--safe-l)) calc(60px + var(--safe-b)) max(20px, var(--safe-r));
}
.page-head { margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 1.5rem; }
.page-head.with-back { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.footer {
  text-align: center; color: var(--muted); font-size: 0.85rem;
  padding: 20px 20px calc(20px + var(--safe-b));
}

/* --- Cards --- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}
.card-title { margin: 0 0 14px; font-size: 1.05rem; }
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px;
}
.card-head .card-title { margin: 0; }
.count { font-size: 0.85rem; }
/* Formularios de crear/editar (egreso, usuario, catálogos): centrados y
   un poco más anchos para que la rejilla de 2 columnas respire. */
.form-card { max-width: 620px; margin-left: auto; margin-right: auto; }
.sep { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }

/* --- Forms --- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  align-items: end;
}
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; min-width: 0; }
.field span { color: var(--muted); font-weight: 500; }
/* --- Interruptor (activo / inactivo) --- */
.switch {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  min-height: 44px; /* objetivo táctil */
  -webkit-tap-highlight-color: transparent;
}
/* El checkbox real se oculta, pero sigue siendo accesible por teclado */
.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-track {
  position: relative;
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: #c3cad9;
  flex-shrink: 0;
  transition: background 0.18s ease;
}
.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.3);
  transition: transform 0.18s ease;
}
.switch input:checked + .switch-track { background: var(--success); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(22px); }
.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.switch-text { font-weight: 600; font-size: 0.92rem; }
/* El texto cambia según el estado, sin necesidad de JavaScript */
.switch-text .on { display: none; color: var(--success); }
.switch-text .off { color: var(--muted); }
.switch input:checked ~ .switch-text .on { display: inline; }
.switch input:checked ~ .switch-text .off { display: none; }

input, select, button {
  font-family: inherit;
}
/* OJO: se excluyen checkbox y radio. La regla lleva `appearance: none`, que
   les borraría la palomita y dejaría un cuadro vacío imposible de interpretar. */
input:not([type="checkbox"]):not([type="radio"]), select {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  /* 16px evita que Safari en iOS haga zoom automático al enfocar el campo */
  font-size: 16px;
  background: #fff;
  color: var(--ink);
  width: 100%;
  min-width: 0;
  appearance: none;
  -webkit-appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7280' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
input:focus, select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: var(--primary);
}
/* Campos bloqueados (p. ej. el Tag del alta de pacientes): se ven no editables */
input[readonly] {
  background: var(--bg, #f3f4f6);
  color: var(--muted);
  cursor: not-allowed;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 11px 16px;
  min-height: 44px; /* objetivo táctil recomendado por Apple */
  border: 1px solid transparent;
  border-radius: 9px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
  background: #eef1f5;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(0.97); }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 7px 12px; min-height: 38px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.inline { display: inline; }

/* --- Search bar --- */
.search-fields {
  display: grid;
  grid-template-columns: 2fr 1fr auto;
  gap: 14px;
  align-items: end;
}
.users-filters { grid-template-columns: 2fr 1fr 1fr auto; }
/* Filtro de invoices: nombre, DOB, desde, hasta, acciones */
.invoice-filters { grid-template-columns: 1.6fr 1fr 1fr 1fr auto; }
/* Filtros de egresos: varias columnas que se acomodan solas */
.filters-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.filters-grid .search-actions { grid-column: 1 / -1; }

/* --- Panel de filtros colapsable (invoices, egresos, usuarios) --- */
.filter-panel { padding: 0; overflow: hidden; }
.filter-toggle {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  font-weight: 600;
  color: var(--primary);
  user-select: none;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}
.filter-toggle::-webkit-details-marker { display: none; } /* quita el triángulo nativo */
.filter-toggle::marker { content: ''; }
.filter-toggle:hover { color: var(--accent); }
.filter-toggle .chevron { margin-left: auto; transition: transform 0.18s ease; }
.filter-panel[open] .filter-toggle { border-bottom: 1px solid var(--line); }
.filter-panel[open] .filter-toggle .chevron { transform: rotate(180deg); }
.filter-panel > form { padding: 16px 18px; }
.filter-badge {
  background: var(--accent); color: #fff;
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.03em; padding: 2px 8px; border-radius: 999px;
}
.filter-note { margin-top: 12px; }
.search-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* --- Paginado --- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.pagination-info { color: var(--muted); font-size: 0.9rem; }
.pagination-controls { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-disabled {
  opacity: 0.45;
  cursor: default;
  pointer-events: none;
}

/* Selector de orden para móvil (oculto en escritorio) */
.mobile-sort { display: none; }

/* --- Tables --- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
.table th {
  font-size: 0.75rem; text-transform: uppercase;
  letter-spacing: 0.03em; color: var(--muted);
}
.table tbody tr:hover { background: #f8fafc; }
.text-right { text-align: right; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 0.88rem; }
/* Descripciones de items: respetan los saltos de línea del texto original */
.desc { white-space: pre-line; overflow-wrap: anywhere; }
.actions { white-space: nowrap; }
.actions > * { margin-left: 6px; }

/* Encabezados ordenables */
.sort-link {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  padding: 4px 0;
}
.sort-link:hover, .sort-link.is-active { color: var(--primary); }
.sort-link .arrow { font-size: 0.7em; }

/* --- Detail --- */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.meta { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }

/* --- Badges / status --- */
.badge {
  display: inline-block;
  font-size: 0.72rem; text-transform: uppercase; padding: 3px 9px;
  border-radius: 999px; font-weight: 700; letter-spacing: 0.03em;
}
.badge-admin { background: #fde68a; color: #92400e; }
.badge-nurse { background: #bfdbfe; color: #1e3a8a; }
.badge-frontdesk { background: #c7f0dd; color: #0f5132; }

/* Matriz de permisos */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 18px; }
.perm-item { min-height: 40px; }
.perm-caps { grid-column: 1 / -1; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.perm-caps-label { font-weight: 700; margin-bottom: 8px; }
.perm-caps-list { display: flex; flex-wrap: wrap; gap: 8px 18px; }

/* Resultados de búsqueda de paciente */
.match-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.match-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.match-row:has(input:checked) { border-color: var(--primary); background: #f5f8ff; }
.match-row input { width: 18px; height: 18px; flex-shrink: 0; }
.match-info { display: flex; flex-direction: column; gap: 2px; }
.match-info .muted { font-size: 0.85rem; }
.pill-form select { min-width: 130px; }

/* Selector de país + teléfono */
.phone-field { position: relative; display: flex; gap: 8px; align-items: stretch; }
.phone-field input[type="tel"] { flex: 1; }
.pc-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 0 12px; min-height: 46px;
  border: 1px solid var(--line); border-radius: 9px; background: #fff;
  cursor: pointer; white-space: nowrap; color: var(--ink);
}
.pc-toggle:hover { border-color: var(--primary); }
.pc-toggle .pc-flag { font-size: 1.2rem; line-height: 1; }
.pc-toggle .pc-dial { font-weight: 600; font-size: 0.95rem; }
.pc-toggle .pc-caret { color: var(--muted); font-size: 0.75rem; }
.pc-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 30;
  width: min(340px, 92vw);
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 28px rgba(16, 24, 40, 0.18); padding: 8px;
}
.pc-list { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow-y: auto; }
.pc-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 8px;
  border-radius: 8px; cursor: pointer; font-size: 0.92rem;
}
.pc-item:hover { background: var(--bg); }
.pc-item.is-sel { background: #f5f8ff; }
.pc-item .pc-flag { font-size: 1.15rem; line-height: 1; }
.pc-item .pc-name { flex: 1; }
.pc-item .pc-dial { color: var(--muted); }
.status {
  display: inline-block;
  font-size: 0.8rem; padding: 3px 10px; border-radius: 999px;
  background: #e5e7eb; color: #374151;
}
.status-paid, .status-active { background: #d1fae5; color: #065f46; }
.status-unpaid, .status-inactive, .status-void { background: #fee2e2; color: #991b1b; }
.status-draft, .status-sent { background: #dbeafe; color: #1e40af; }

/* --- Alerts / misc --- */
.alert { padding: 12px 16px; border-radius: 9px; margin-bottom: 18px; font-size: 0.9rem; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.note { color: var(--muted); font-size: 0.82rem; margin-top: 10px; }
.muted { color: var(--muted); }

/* --- Editor de horarios --- */
.schedule-editor { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.schedule-row {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.schedule-row:last-child { border-bottom: 0; }
.schedule-day { min-width: 190px; }
.schedule-day-name { font-weight: 600; font-size: 0.95rem; }
.schedule-times { display: flex; gap: 14px; flex: 1; }
.schedule-times .field { flex: 1; max-width: 150px; }
/* Los días apagados se ven atenuados, pero siguen siendo editables */
.schedule-row:has(input[type="checkbox"]:not(:checked)) .schedule-times { opacity: 0.45; }
.custom-schedule { border-left: 3px solid var(--accent); padding-left: 14px; margin: 4px 0 8px; }

.alert-info {
  background: #e0f2fe; color: #075985; border: 1px solid #bae6fd;
}
.alert-info a { color: inherit; font-weight: 600; }

/* --- Modal de fin de horario --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: #fff;
  border-radius: var(--radius);
  padding: 26px 24px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.28);
}
.modal-icon { font-size: 2.4rem; line-height: 1; margin-bottom: 8px; }
.modal h2 { margin: 0 0 10px; font-size: 1.2rem; }
.modal p { margin: 0 0 20px; color: var(--muted); font-size: 0.94rem; }
.modal-actions { display: flex; flex-direction: column; gap: 10px; }

/* Modal con formulario (completar datos del paciente) */
.modal-wide { max-width: 560px; }
.modal-form { text-align: left; max-height: 90vh; overflow-y: auto; }
.modal-form .modal-icon { margin-bottom: 4px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.modal-head h2 { margin: 0; }
.modal-sub { margin: 6px 0 16px; color: var(--muted); font-size: 0.94rem; }
.modal-close {
  font-size: 1.6rem; line-height: 1; color: var(--muted); text-decoration: none;
  padding: 0 6px; border-radius: 8px;
}
.modal-close:hover { background: var(--bg, #f3f4f6); color: var(--ink); }
/* Campo con dato faltante: se resalta para guiar al frontdesk */
.field.is-missing input { border-color: var(--accent, #00aeef); background: #f0fbff; }
.field.is-missing > span:first-child::after { content: ' — falta'; color: var(--accent, #00aeef); font-weight: 600; }

/* Aviso de tiempo adicional */
.grace-banner {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(16px + var(--safe-b));
  background: #92400e;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.25);
  z-index: 90;
}
.grace-banner[hidden] { display: none; }

/* --- Pantalla de fuera de horario --- */
.out-of-hours { max-width: 460px; text-align: center; }
.oh-icon { font-size: 2.6rem; margin-bottom: 6px; }
.oh-message { color: var(--muted); }
.oh-schedule { text-align: left; margin: 20px 0; }
.oh-schedule h2 { font-size: 0.8rem; text-transform: uppercase; color: var(--muted); letter-spacing: 0.04em; }
.oh-table td { padding: 8px 0; }
.oh-table tr.is-today { font-weight: 700; }
.oh-today {
  background: var(--accent); color: #fff; font-size: 0.68rem;
  padding: 1px 7px; border-radius: 999px; margin-left: 6px;
  text-transform: uppercase; font-weight: 700;
}

/* --- Sub-navegación (módulo de egresos) --- */
.subnav {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.subnav a {
  padding: 9px 14px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.92rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.subnav a:hover { color: var(--primary); }
.subnav a.is-active { color: var(--primary); border-bottom-color: var(--primary); }

/* --- Chips (salas de un servicio) y casillas tipo chip --- */
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg, #eef2ff);
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 600;
}
.check-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.check-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  min-height: 44px;
}
.check-chip:hover { border-color: var(--primary); }
.check-chip input { width: auto; margin: 0; }
.check-chip:has(input:checked) {
  border-color: var(--primary);
  background: var(--bg, #eef2ff);
  color: var(--primary);
}

/* --- Cola de turnos (tablero por sala, reactivo) --- */
.queue-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip-filter {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 999px; text-decoration: none;
  color: var(--ink); font-weight: 600; font-size: 0.9rem; min-height: 40px;
}
.chip-filter .c { background: var(--bg, #eef2ff); color: var(--primary); border-radius: 999px; padding: 0 8px; font-size: 0.8rem; }
.chip-filter:hover { border-color: var(--primary); }
.chip-filter.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }
.chip-filter.is-active .c { background: rgba(255, 255, 255, 0.25); color: #fff; }

.room-board { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.room-col { padding: 14px; }
.room-col-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.room-col-head h2 { margin: 0; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }

.turn-card { border: 1px solid var(--line); border-left-width: 5px; border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
/* Color por tiempo en cola (umbrales configurables): 🟢 0–Y · 🟡 Y–R · 🔴 ≥R */
.turn-card.wait-green { border-left-color: #16a34a; }
.turn-card.wait-yellow { border-left-color: #d97706; background: #fffbeb; }
.turn-card.wait-red { border-left-color: #dc2626; background: #fef2f2; }
.turn-card.is-current { box-shadow: 0 0 0 2px rgba(22, 41, 119, 0.35); }
.turn-wait { font-size: 0.82rem; font-weight: 600; margin-left: auto; white-space: nowrap; }
.turn-main { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.turn-ticket { font-weight: 700; color: var(--primary); }
.turn-name { font-weight: 600; }
.turn-service { font-size: 0.85rem; }
.turn-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; align-items: center; }
.turn-resp { font-size: 0.82rem; }
.triage-pass { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.triage-pass select { width: auto; min-width: 150px; min-height: 36px; padding: 6px 28px 6px 10px; }
.triage-note { width: auto; min-width: 200px; flex: 1 1 200px; min-height: 36px; padding: 6px 10px; }
.turn-note {
  margin-top: 8px; padding: 8px 10px; border-radius: 8px;
  background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
  font-size: 0.88rem; overflow-wrap: anywhere;
}
.empty.small { padding: 10px; font-size: 0.9rem; }

.seg { display: flex; gap: 14px; flex-wrap: wrap; }
.seg label { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.modal-form textarea { width: 100%; }

/* Comprobante en el formulario de egreso */
.doc-current {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 12px; background: var(--bg); border-radius: 9px;
}
.doc-remove { display: inline-flex; align-items: center; gap: 6px; font-size: 0.88rem; color: var(--muted); }
.doc-remove input { width: 18px; height: 18px; }
textarea {
  padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 16px; font-family: inherit; color: var(--ink); width: 100%;
  resize: vertical; min-height: 72px;
}
textarea:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.table tfoot td { border-top: 2px solid var(--line); border-bottom: 0; }

/* Enlace con solo un ícono (p. ej. ver comprobante) */
.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--primary);
  transition: color 0.15s ease, background 0.15s ease;
}
.icon-link:hover, .icon-link:focus-visible {
  color: var(--accent);
  background: var(--bg);
}
.icon-link svg { display: block; }

/* --- Dashboard --- */
.dash-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.dash-sub { margin: 2px 0 0; font-size: 0.9rem; }
.dash-range { font-size: 0.82rem; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.kpi { min-width: 0; }
.kpi-label { font-size: 0.82rem; color: var(--muted); margin: 0; }
.kpi-value { font-size: 1.6rem; font-weight: 700; margin: 6px 0 0; color: var(--ink); letter-spacing: -0.01em; overflow-wrap: anywhere; }
.kpi-value.is-pos { color: var(--success); }
.kpi-value.is-neg { color: var(--danger); }
.kpi-value.is-warn { color: #b45309; }
.kpi-foot { font-size: 0.78rem; color: var(--muted); margin: 4px 0 0; }

.dash-card { padding: 18px; min-width: 0; }
.chart-box { position: relative; width: 100%; overflow: hidden; }
.dash-head > div { min-width: 0; }
.dash-sub { overflow-wrap: anywhere; }
.dash-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 18px; }

.chart-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; }
.chart-legend .dot { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chart-legend .dash { width: 12px; height: 2px; display: inline-block; }

/* Métodos de pago */
.paymethods td { vertical-align: middle; }
.paymethods .pm-name { font-weight: 500; white-space: nowrap; }
.paymethods .pm-pct { width: 48px; }
.pm-bar-cell { width: 45%; }
.pm-bar {
  display: block;
  height: 8px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
}
.pm-bar > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

/* Invoices por cobrar: marca de vencido */
.due-overdue { color: var(--danger); font-weight: 600; }
.due-tag {
  display: inline-block; font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  background: #fee2e2; color: #991b1b; padding: 1px 7px; border-radius: 999px; margin-left: 4px;
}

/* --- Login --- */
.login-wrap { display: flex; justify-content: center; padding-top: 5vh; }
.login-card { width: 100%; max-width: 390px; }
/* El logo es horizontal (~3.7:1); "Upright" se forma con el emblema + el texto,
   por eso NO debe partirse en dos líneas. */
.login-logo { display: block; width: 260px; max-width: 88%; height: auto; margin: 2px auto 18px; }
.login-title { margin: 0 0 4px; text-align: center; font-size: 1.15rem; }
.login-sub { margin: 0 0 22px; text-align: center; color: var(--muted); font-size: 0.9rem; }

/* --- Error page --- */
.error-page { display: flex; justify-content: center; padding-top: 5vh; }
.error-page .card { max-width: 460px; text-align: center; }
.error-code { font-size: 3rem; font-weight: 800; color: var(--primary); }

/* ==========================================================
   MÓVIL / TABLET  (iPhone, iPad en vertical)
   ========================================================== */
@media (max-width: 860px) {
  .detail-grid { grid-template-columns: 1fr; }
  .search-fields, .users-filters, .invoice-filters { grid-template-columns: 1fr; }
  .search-actions .btn { flex: 1; }
  .pagination { flex-direction: column; align-items: stretch; }
  .pagination-controls { justify-content: space-between; }
  .pagination-controls .btn { flex: 1; }
}

/* Menú hamburguesa: hasta 900px (cubre iPhone e iPad en vertical, donde los
   6 enlaces de admin ya no caben en una fila). El resto del layout móvil
   (tablas apiladas, etc.) sigue en 640px. */
@media (max-width: 900px) {
  .topbar-inner { min-height: 54px; padding-top: 8px; padding-bottom: 8px; gap: 10px; }
  .brand img { height: 30px; }
  .nav-toggle { display: inline-flex; }

  /* Menú y datos de usuario ocultos hasta abrir el hamburguesa.
     flex: 0 0 100% es clave: el .nav base trae flex:1 (basis 0), que impediría
     saltar a su propia línea; aquí lo forzamos a ancho completo. */
  .nav, .user-box { display: none; width: 100%; flex: 0 0 100%; }
  .nav {
    order: 4;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    border-top: 1px solid var(--line);
    margin-top: 4px;
    padding-top: 4px;
  }
  .nav a { padding: 13px 6px; border-bottom: none; border-radius: 8px; }
  .nav a:hover, .nav a:active { border-bottom-color: transparent; background: var(--bg); }
  .user-box {
    order: 5;
    justify-content: space-between;
    border-top: 1px solid var(--line);
    margin-top: 4px;
    padding-top: 10px;
  }
  .user-name { font-size: 0.85rem; }

  /* Al marcar la casilla, se despliegan */
  .nav-cb:checked ~ .nav,
  .nav-cb:checked ~ .user-box { display: flex; }
}

@media (max-width: 640px) {
  .container { padding-top: 16px; }
  .page-head h1 { font-size: 1.25rem; }

  /* Mostrar el selector de orden */
  .mobile-sort { display: block; }

  /* Tablas apiladas: cada fila se convierte en una tarjeta */
  .table.stacked { border-collapse: separate; border-spacing: 0; }
  .table.stacked thead { display: none; }
  .table.stacked tbody, .table.stacked tr, .table.stacked td { display: block; width: 100%; }
  .table.stacked tr {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 6px 12px;
    margin-bottom: 12px;
    background: #fff;
  }
  .table.stacked tr:last-child { margin-bottom: 0; }
  .table.stacked td {
    border: 0;
    border-bottom: 1px solid #f1f3f5;
    padding: 9px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    text-align: right;
  }
  .table.stacked td:last-child { border-bottom: 0; }
  /* Etiqueta de la columna a la izquierda */
  .table.stacked td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 600;
    text-align: left;
    flex-shrink: 0;
  }
  .table.stacked td[data-label=""]::before { content: none; }
  .table.stacked td[data-label=""] { justify-content: stretch; }
  .table.stacked td[data-label=""] .btn { width: 100%; }

  /* Acciones en columna dentro de la tarjeta */
  .actions { white-space: normal; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
  .actions > * { margin-left: 0; }

  .meta { grid-template-columns: 1fr; gap: 2px; }
  .meta dt { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.03em; }
  .meta dd { margin-bottom: 10px; }

  .form-card { max-width: none; }
  .form-actions .btn { flex: 1; }

  /* Horarios: cada día en bloque, entrada y salida lado a lado */
  .schedule-row { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px 0; }
  .schedule-day { min-width: 0; }
  .schedule-times .field { max-width: none; }

  /* Dashboard: 2 KPIs por fila (minmax(0,..) evita el desbordamiento), gráficas
     a una columna y el subtítulo de rango en su propia línea. */
  .dash-head { flex-direction: column; align-items: stretch; }
  .dash-range { display: block; margin-top: 2px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 13px; }
  .kpi-value { font-size: 1.3rem; }
  .dash-charts { grid-template-columns: 1fr; }
  .chart-legend { gap: 12px; }
  .paymethods .pm-bar-cell { display: none; } /* la barra estorba en móvil */
}

/* Modo standalone (instalada como PWA en iOS/Android) */
@media all and (display-mode: standalone) {
  .footer { padding-bottom: calc(28px + var(--safe-b)); }
}

/* --- Monitor de turnos (sala de espera / TV) — paleta de la app --- */
.monitor-body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--ink); }
/* Barra de controles OCULTA por defecto (no ocupa espacio): se desliza desde
   arriba al pasar el mouse por el borde superior o sobre ella, y se esconde al
   quitarlo. Así el monitor gana toda esa altura. */
.monitor-hot { position: fixed; top: 0; left: 0; right: 0; height: 22px; z-index: 49; }
.monitor-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 6px max(16px, var(--safe-l)); background: #fff;
  border-bottom: 1px solid var(--line); box-shadow: 0 2px 8px rgba(21, 35, 105, 0.15);
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  transform: translateY(-100%); transition: transform 0.25s ease;
}
.monitor-hot:hover + .monitor-toolbar, .monitor-toolbar:hover { transform: translateY(0); }
.monitor-toolbar .btn { min-height: 36px; padding: 6px 12px; } /* barra compacta (kiosco) */
.monitor-toolbar-info strong { font-size: 1.05rem; display: block; color: var(--primary); }
.monitor-toolbar-info small { color: var(--muted); font-size: 0.85rem; }
.monitor-toolbar-actions { display: flex; gap: 10px; flex-wrap: wrap; }
#sound-btn.is-on { background: var(--success); color: #fff; border-color: var(--success); }
/* Enfocado a TV/escritorio: usa casi todo el ancho y la tipografía ESCALA con el
   tamaño de la pantalla (clamp), para leerse de lejos en una sala de espera. */
.monitor-screen { max-width: 1800px; margin: 0 auto; padding: clamp(10px, 1.1vw, 20px) max(16px, var(--safe-l)) calc(24px + var(--safe-b)); }
/* Encabezado compacto: logo + título a la izquierda y el reloj a la derecha, en
   UNA sola fila, para no robar alto (el monitor no hace scroll). */
/* logo (izq) · título (centrado) · reloj (der) — las columnas 1fr laterales igualan
   y dejan el título perfectamente centrado sin importar el ancho de logo/reloj. */
.monitor-head {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: clamp(10px, 1.2vw, 20px);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: clamp(8px, 0.8vw, 14px) clamp(14px, 1.6vw, 26px);
  margin-bottom: clamp(8px, 0.9vw, 14px);
}
.monitor-logo { justify-self: start; height: clamp(36px, 3.4vw, 62px); width: auto; }
.monitor-head h1 { justify-self: center; text-align: center; margin: 0; color: var(--primary); font-size: clamp(1.4rem, 2.5vw, 2.6rem); }
.monitor-clock {
  justify-self: end; white-space: nowrap;
  font-size: clamp(1.3rem, 2.3vw, 2.4rem); font-weight: 700; color: var(--primary);
}
/* En pantallas muy chicas se apila para no encimarse. */
@media (max-width: 640px) {
  .monitor-head { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .monitor-logo, .monitor-head h1, .monitor-clock { justify-self: center; }
}
.monitor-legend {
  display: flex; justify-content: space-between; padding: 4px clamp(16px, 1.6vw, 28px) 10px;
  color: var(--muted); font-weight: 600; font-size: clamp(0.9rem, 1.2vw, 1.3rem);
}
.monitor-rooms { display: grid; grid-template-columns: repeat(2, 1fr); gap: clamp(10px, 1vw, 16px); }
.monitor-room {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: clamp(12px, 1.2vw, 22px) clamp(18px, 1.7vw, 32px);
}
.mr-name { font-size: clamp(1.3rem, 2.1vw, 2.6rem); font-weight: 600; color: var(--primary); display: flex; align-items: center; gap: 10px; }
.mr-ticket { font-size: clamp(1.4rem, 2.2vw, 2.8rem); font-weight: 700; color: var(--muted); letter-spacing: 1px; white-space: nowrap; }
.monitor-room.has-turn { border-left-color: var(--accent); background: #f0fbff; }
.monitor-room.has-turn .mr-ticket { color: var(--primary); font-size: clamp(1.7rem, 2.7vw, 3.4rem); }
/* Fila de medios ARRIBA (TV a la izquierda + carrusel de publicidad a la derecha)
   y el tablero de consultorios debajo. */
.monitor-main { display: flex; flex-direction: column; gap: clamp(10px, 1vw, 18px); }
.monitor-board-area { min-width: 0; }
.monitor-media { display: flex; gap: clamp(16px, 2vw, 40px); justify-content: center; align-items: flex-start; }
/* Con TV + publicidad: dos columnas a todo el ancho (alineadas con los consultorios). */
.monitor-media.two { display: grid; grid-template-columns: repeat(2, 1fr); gap: clamp(12px, 1.4vw, 24px); }
.monitor-tv, .monitor-ads { min-width: 0; width: 100%; max-width: clamp(360px, 46vw, 720px); }
.monitor-media.two .monitor-tv, .monitor-media.two .monitor-ads { max-width: none; }
.monitor-tv-frame, .monitor-ads-frame {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  max-height: 36vh; /* tope para no empujar los consultorios fuera de pantalla */
  background: #000; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.monitor-tv-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.tv-media { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; } /* video HLS/IPTV */
/* Carrusel de publicidad: capas apiladas con fundido. */
/* `contain`: muestra la imagen/video COMPLETO sin recortar (bordes negros si la
   proporción no es 16:9). Así no importa el tamaño original del anuncio. */
.ad-slide { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity 0.6s ease; }
.ad-slide.is-on { opacity: 1; }
/* Miniaturas de publicidad en la config */
.ad-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 14px; }
.ad-item { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.ad-thumb { width: 100%; aspect-ratio: 16 / 9; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; background: #000; }
.ad-badge { font-size: 0.8rem; color: var(--muted); }
.ad-order { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.ad-order input { width: 76px; text-align: center; }
/* Buscador de canales IPTV: lista de resultados que se despliega bajo el input */
.iptv-field { position: relative; }
.iptv-results {
  list-style: none; margin: 4px 0 0; padding: 0;
  position: absolute; left: 0; right: 0; top: 100%; z-index: 20;
  border: 1px solid var(--line); border-radius: 9px; max-height: 300px; overflow: auto;
  background: #fff; box-shadow: var(--shadow);
}
.iptv-results li { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid var(--line); font-size: 0.92rem; }
.iptv-results li:last-child { border-bottom: 0; }
.iptv-results li:hover { background: var(--bg, #f3f4f6); }

/* Pantallas chicas: TV y publicidad se apilan; tablero a una columna. */
@media (max-width: 900px) { .monitor-media { flex-direction: column; align-items: stretch; } .monitor-tv, .monitor-ads { max-width: none; } }
@media (max-width: 820px) { .monitor-rooms { grid-template-columns: 1fr; } }
