﻿: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); }

/* Grupos desplegables de la topbar (Atención / Dashboard / Configuración):
   <details> nativo, sin JS — mismo patrón que .filter-panel. */
.nav-group { position: relative; }
.nav-group summary {
  list-style: none;
  cursor: pointer;
  color: var(--primary);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 8px 18px 8px 2px;
  border-bottom: 2px solid transparent;
  -webkit-tap-highlight-color: transparent;
}
.nav-group summary::-webkit-details-marker { display: none; }
.nav-group summary::after {
  content: '';
  position: absolute;
  right: 3px;
  top: 15px;
  width: 6px;
  height: 6px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s;
}
.nav-group:hover summary, .nav-group[open] summary { color: var(--accent); border-bottom-color: var(--accent); }
.nav-group[open] summary::after { transform: rotate(-135deg); }
.nav-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 190px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  flex-direction: column;
  z-index: 30;
}
.nav-dropdown a { padding: 9px 10px; border-radius: 7px; border-bottom: none !important; }
.nav-dropdown a:hover, .nav-dropdown a:active { background: var(--bg); }

.user-box { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 0.9rem; color: var(--muted); }

/* En escritorio todo va en UNA sola fila: la barra no envuelve, el bloque de
   usuario no se encoge y el menú cede espacio (puede achicarse). */
@media (min-width: 901px) {
  .topbar-inner { flex-wrap: nowrap; }
  .user-box { flex-shrink: 0; }
  .nav { min-width: 0; }
}
/* 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); }
/* Botón deshabilitado (atributo `disabled`): look apagado y sin interacción,
   para que se vea que no está disponible (ej.: "Terminar" sin responsable). */
.btn:disabled,
.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
  transform: none;
  box-shadow: none;
}
.btn:disabled:hover,
.btn[disabled]:hover { filter: none; }
.btn:disabled:active,
.btn[disabled]:active { transform: none; }
.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; }

/* --- Gestión de cobranza (dashboard: por cobrar) --- */
.collection-cell { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.coll-flags { display: inline-flex; gap: 4px; align-items: center; }
.coll-chip { font-size: 0.85rem; opacity: 0.85; }
.modal.modal-wide { max-width: 620px; width: 94%; text-align: left; }
.coll-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; margin: 14px 0; }
.coll-check { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.coll-check input { width: auto; }
.coll-notes-title { margin: 6px 0; font-size: 1rem; }
.note-thread-box { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: var(--bg); }
.coll-note-input { display: flex; gap: 8px; margin-top: 8px; }
.coll-note-input input { flex: 1; min-width: 0; }
@media (max-width: 560px) { .coll-grid { grid-template-columns: 1fr; } }

/* --- Dashboard Ventas IV: barra por producto --- */
.prod-name { font-weight: 600; }
.prod-bar { height: 6px; background: var(--bg); border-radius: 999px; margin-top: 5px; overflow: hidden; max-width: 340px; }
.prod-bar span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }

/* --- Tables --- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Celda "Detalle" del historial de inventario: varias líneas compactas para no
   necesitar scroll horizontal con tantos campos. */
.detail-cell { font-size: 0.85rem; }
.detail-cell div { line-height: 1.45; white-space: nowrap; }
.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; }

/* --- Switcher de idioma: una bandera + desplegable (topbar) --- */
.lang-menu { position: relative; display: inline-flex; }
.lang-current {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 5px; border-radius: 7px; border: 1px solid var(--line);
  background: var(--card); line-height: 0; -webkit-tap-highlight-color: transparent;
}
.lang-current::-webkit-details-marker { display: none; }
.lang-current::after {
  content: ''; width: 5px; height: 5px; border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin: -2px 2px 0 1px;
  transition: transform 0.15s;
}
.lang-menu[open] .lang-current::after { transform: rotate(-135deg); margin-top: 2px; }
.lang-current .flag, .lang-opt .flag { display: inline-flex; line-height: 0; }
.lang-current .flag svg, .lang-opt .flag svg { display: block; border-radius: 2px; }
.lang-dropdown {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 150px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; gap: 2px; z-index: 30;
}
.lang-opt {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 7px;
  text-decoration: none; color: var(--ink); font-size: 0.9rem; font-weight: 600;
}
.lang-opt:hover { background: var(--bg); }
.lang-opt.is-active { background: var(--bg); color: var(--accent); }

/* --- 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;
  /* Fallback para roles personalizados (sin color propio). */
  background: #e5e7eb; color: #374151; margin: 2px 2px 0 0;
}
.badge-admin { background: #fde68a; color: #92400e; }
.badge-nurse { background: #bfdbfe; color: #1e3a8a; }
.badge-frontdesk { background: #c7f0dd; color: #0f5132; }
.badge-oma { background: #ddd6fe; color: #5b21b6; }
.badge-monitor { background: #fbcfe8; color: #9d174d; }

/* Roles: selección multi-rol (usuarios) y gestión de roles (/permisos) */
.roles-field { border: 1px solid var(--border, #e5e7eb); border-radius: 10px; padding: 10px 12px; }
.roles-field legend { font-weight: 600; padding: 0 6px; }
.roles-checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.role-check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.role-check input { width: auto; }
/* Gestión de roles en /permisos: píldoras con borrado integrado */
.roles-hint { margin: 4px 0 0; }
.roles-list { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0 18px; }
.role-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 4px; border-radius: 999px;
  background: var(--surface-2, #f3f4f6); border: 1px solid var(--border, #e5e7eb);
}
.role-pill .badge { margin: 0; }
.role-pill-lock { font-size: 0.8rem; opacity: 0.7; padding-right: 6px; }
.role-pill-x {
  border: none; cursor: pointer; padding: 0; margin: 0;
  width: 20px; height: 20px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; line-height: 1;
  background: rgba(0, 0, 0, 0.12); color: inherit;
  transition: background 0.15s, color 0.15s;
}
.role-pill-x:hover, .role-pill-x:focus-visible { background: #dc2626; color: #fff; }
.role-create { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.role-create input { flex: 1 1 280px; min-width: 0; }

/* 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; }

/* --- Grupos retraíbles en /permisos (Turnos, Financiero, Inventario...) --- */
.perm-group { margin-bottom: 12px; border: 1px solid var(--line); border-radius: var(--radius); }
.perm-group:last-of-type { margin-bottom: 0; }
.perm-group-toggle { padding: 12px 16px; min-height: 44px; }
.perm-count { background: var(--line); color: var(--muted); }
.perm-group-body { padding: 14px 16px; }
.perm-loose { margin-top: 14px; }

/* Barra fija de "Guardar permisos": la página de /permisos es larga (varios
   roles, cada uno con varias pestañas), así que el botón queda siempre a la
   vista en vez de perderse al final — se probó que sin esto era fácil marcar
   una casilla y nunca llegar a guardar. */
.perm-save-bar {
  position: sticky;
  bottom: 0;
  z-index: 15;
  margin-top: 16px;
  padding: 12px 18px calc(12px + var(--safe-b));
  background: var(--card);
  border-top: 1px solid var(--line);
  box-shadow: 0 -2px 10px rgba(21, 35, 105, 0.08);
  display: flex;
  justify-content: flex-end;
}

/* 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; }
/* Filtro por sala (una sola columna): ocupa TODO el ancho y sus tarjetas fluyen en
   grid horizontal, envolviendo al llegar al borde (aprovecha el espacio, menos scroll).
   Con `auto-fill minmax(280px,1fr)` en pantallas angostas (móvil) cae a UNA columna,
   respetando la vista vertical apilada. En "Todos" (sin .is-single) no cambia nada. */
.room-board.is-single { grid-template-columns: 1fr; }
.room-board.is-single .room-col-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 8px;
  align-items: start;
}
.room-board.is-single .turn-card { margin-bottom: 0; }
/* Turnos enlazados (grupo/familia): chip distintivo + borde izquierdo punteado. */
.chip-group { background: #eef2ff; color: #3730a3; border: 1px solid #c7d2fe; white-space: nowrap; }
.turn-card.is-grouped { border-left-style: dashed; }
/* Lista de turnos del modal de enlazar (scrollable). */
.link-list { max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.link-row { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.link-row.is-base { background: #eef2ff; border-color: #c7d2fe; }
.link-row input:disabled + .match-info { opacity: 0.55; }
.link-svc { margin-top: 6px; width: 100%; }

/* Notas del turno (mini-chat) */
.turn-notes-line { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
/* Facturación desde el turno */
.btn-invoice { background: #ecfdf5; border: 1px solid #a7f3d0; color: #047857; }
.btn-invoice-view { background: #eef2ff; border: 1px solid #c7d2fe; color: #3730a3; }
.invoice-modal { max-width: 720px; }
.invoice-items { width: 100%; }
.invoice-items th, .invoice-items td { padding: 6px 8px; vertical-align: middle; }
.invoice-items input.inv-amount, .invoice-items input.inv-qty { width: 92px; }
.invoice-total-line { display: flex; justify-content: space-between; align-items: center; padding: 8px 4px 0; margin-bottom: 12px; font-size: 1.05rem; }
.invoice-total-line strong { color: var(--primary); font-size: 1.15rem; }
#invoice-prod-results { position: static; margin: 4px 0 12px; max-height: 220px; }
/* En móvil, la tabla de items se apila (patrón .table.stacked): sin scroll lateral. */
@media (max-width: 640px) {
  .invoice-items input.inv-amount, .invoice-items input.inv-qty { width: 120px; }
  .invoice-items .inv-remove { width: 100%; }
}
.btn-notes { background: transparent; border: 1px solid var(--line); color: var(--primary); }
.notes-modal { max-width: 540px; }
.notes-body { max-height: 46vh; overflow-y: auto; margin-bottom: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: #fafbfc; }
.note-thread { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.note-msg { border-radius: 10px; padding: 8px 10px; background: #fff; border: 1px solid var(--line); }
.note-msg.is-mine { background: #eef2ff; border-color: #c7d2fe; }
.note-head { display: flex; justify-content: space-between; gap: 10px; font-size: 0.8rem; margin-bottom: 2px; }
.note-author { font-weight: 700; color: var(--primary); }
.note-body { white-space: pre-wrap; word-break: break-word; }
.note-empty { padding: 16px; text-align: center; }
/* Turnos EN ESPERA DE CONTRATO (no entran a la cola hasta validar la firma) */
.room-col.is-contract { border-left: 6px solid #d97706; background: #fffbeb; }
.contract-note { color: #b45309; margin: 0 0 8px; font-size: 0.85rem; }
.status.status-contract { background: #fef3c7; color: #92400e; }
/* Modal de resultado de validar contrato (verde éxito / ámbar no-firmado) */
.contract-result .modal-icon { font-size: 2.4rem; }
.contract-result.is-ok h2 { color: var(--success); }
.contract-result.is-fail h2 { color: #b45309; }
.contract-result.is-loading h2 { color: var(--muted); }
.contract-result.is-ok { border-top: 4px solid var(--success); }
.contract-result.is-fail { border-top: 4px solid #d97706; }
/* Botón con notas SIN LEER: azul eléctrico con halo cian pulsante (muy notorio) +
   badge amarillo. */
.btn-notes.has-unread { border-color: #1d4ed8; color: #fff; background: #2563eb; font-weight: 800; animation: notesPulse 1.1s ease-in-out infinite; }
.btn-notes.has-unread:hover { filter: brightness(1.06); }
.notes-dot { display: inline-flex; align-items: center; justify-content: center; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: #fde047; color: #1e3a8a; font-size: 0.74rem; font-weight: 800; margin-left: 5px; }
@keyframes notesPulse {
  0%   { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.75), 0 0 6px rgba(37, 99, 235, 0.5); }
  50%  { box-shadow: 0 0 0 7px rgba(56, 189, 248, 0), 0 0 18px rgba(56, 189, 248, 0.95); }
  100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0), 0 0 6px rgba(37, 99, 235, 0.5); }
}

.turn-card { position: relative; border: 1px solid var(--line); border-left-width: 5px; border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
/* Marca de paciente moroso: ícono 💰 en la esquina superior + borde ámbar. */
.turn-card.is-debtor { border-color: #f0b429; box-shadow: 0 0 0 1px rgba(240, 180, 41, 0.35); }
.turn-debtor {
  position: absolute; top: 4px; right: 6px; z-index: 1; line-height: 1;
  font-size: 1.15rem; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.15));
}
/* Badge de deuda en la lista de resultados de búsqueda. */
.debtor-badge {
  display: inline-block; margin-left: 6px; font-size: 0.78rem; font-weight: 700;
  color: #92400e; background: #fde68a; border-radius: 999px; padding: 1px 8px; white-space: nowrap;
}
/* Turno VIP (urgencia): borde dorado + pill "⭐ VIP" en la esquina superior. Entra
   de primero en la cola (ver turnModel: ORDER BY vip DESC). */
.turn-card.is-vip { border-color: #d4a017; box-shadow: 0 0 0 1px rgba(212, 160, 23, 0.4); }
.turn-vip {
  position: absolute; top: 4px; right: 6px; z-index: 2; line-height: 1;
  font-size: 0.72rem; font-weight: 800; letter-spacing: 0.03em;
  color: #7a5c00; background: #ffe08a; border: 1px solid #e6b800;
  border-radius: 999px; padding: 2px 8px; white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}
/* Si además es moroso, corre el 💰 a la izquierda del pill VIP para no encimarse. */
.turn-card.is-vip .turn-debtor { right: 58px; }
/* Toggle VIP en los formularios de creación de turno. */
.vip-toggle {
  display: flex; align-items: flex-start; gap: 10px; cursor: pointer;
  margin: 14px 0; padding: 12px 14px; border-radius: 10px;
  border: 1px solid #e6b800; background: #fffbeb;
}
.vip-toggle input { margin-top: 3px; width: 18px; height: 18px; accent-color: #d4a017; flex: none; }
.vip-toggle-text { display: flex; flex-direction: column; gap: 2px; }
.vip-toggle-text strong { color: #7a5c00; }
.vip-toggle-text small { color: var(--muted); font-size: 0.8rem; }
/* 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); }

  /* Los desplegables se aplanan a acordeón (mismo <details>, sin posicionar
     el panel en absoluto: ya está apilado dentro del menú del hamburguesa). */
  .nav-group summary { padding: 13px 6px; border-radius: 8px; }
  .nav-group summary::after { top: 19px; }
  .nav-group:hover summary, .nav-group[open] summary { border-bottom-color: transparent; background: var(--bg); }
  .nav-dropdown {
    position: static;
    margin-top: 2px;
    padding: 2px 2px 2px 16px;
    background: transparent;
    border: none;
    box-shadow: none;
  }

  .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; color: var(--ink);
  /* Fondo azul de la sala de espera (degradado radial: azul medio arriba-centro
     que se oscurece a azul marino en los bordes). */
  background: radial-gradient(125% 120% at 50% 20%, #2c6fd4 0%, #143f8b 52%, #0a2a63 100%) fixed, #0a2a63;
}
/* 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.
   El monitor NUNCA hace scroll: ocupa exactamente la altura del viewport y el
   tablero se auto-escala (JS `fitBoard`) para caber sin importar cuántos turnos haya. */
.monitor-body { overflow: hidden; }
.monitor-screen {
  height: 100vh; height: 100dvh; box-sizing: border-box;
  display: flex; flex-direction: column; overflow: hidden;
  max-width: 1800px; margin: 0 auto; padding: clamp(10px, 1.1vw, 20px) max(16px, var(--safe-l)) calc(16px + 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(8px, 1vw, 16px);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: clamp(3px, 0.4vw, 8px) clamp(12px, 1.4vw, 22px);
  margin-bottom: clamp(6px, 0.7vw, 10px);
}
.monitor-logo { justify-self: start; height: clamp(26px, 2.3vw, 42px); width: auto; }
.monitor-head h1 { justify-self: center; text-align: center; margin: 0; color: var(--primary); font-size: clamp(1.1rem, 1.9vw, 2rem); }
.monitor-clock {
  justify-self: end; white-space: nowrap;
  font-size: clamp(1rem, 1.7vw, 1.8rem); 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: rgba(255, 255, 255, 0.92); 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); }
/* Varias unidades en atención por sala (capacidad >1); los enlazados en una pill. */
.mr-units { display: flex; flex-direction: column; align-items: flex-end; gap: clamp(3px, 0.5vw, 10px); text-align: right; min-width: 0; }
.mr-unit { font-size: clamp(1.3rem, 2.1vw, 2.9rem); font-weight: 700; color: var(--muted); letter-spacing: 0.5px; display: inline-flex; align-items: center; gap: 8px; }
.monitor-room.has-turn .mr-unit { color: var(--primary); }
.mr-unit.is-grouped { background: #eef2ff; color: #3730a3; border-radius: 10px; padding: 2px clamp(8px, 0.8vw, 14px); }
.mr-link { font-size: 0.75em; }
/* Fila de medios ARRIBA (TV a la izquierda + carrusel de publicidad a la derecha)
   y el tablero de consultorios debajo. */
.monitor-head { flex: 0 0 auto; }
.monitor-main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: clamp(10px, 1vw, 18px); }
.monitor-media { flex: 0 0 auto; }
/* El tablero ocupa el alto restante; #monitor-board se escala (JS) para caber. */
.monitor-board-area { flex: 1 1 auto; min-height: 0; min-width: 0; overflow: hidden; }
#monitor-board { transform-origin: top center; }
/* TV horizontal (ancha) a la izquierda + carrusel de publicidad VERTICAL (angosto) a
   la derecha, ambos con la MISMA altura (`--media-h`). La mayoría de anuncios son
   cuadrados/verticales, por eso el panel de publicidad es vertical (menos bordes). */
.monitor-media { --media-h: clamp(240px, 48vh, 640px); display: flex; gap: clamp(16px, 2vw, 40px); justify-content: center; align-items: flex-start; }
.monitor-tv, .monitor-ads { min-width: 0; }
.monitor-tv-frame, .monitor-ads-frame {
  position: relative; height: var(--media-h);
  background: #000; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.monitor-tv-frame  { aspect-ratio: 16 / 9; width: auto; max-width: 100%; } /* TV horizontal */
.monitor-ads-frame { aspect-ratio: 4 / 5;  width: auto; }                  /* Publicidad VERTICAL */
.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); }
/* Lista de reproducción de TV (config del monitor) */
.tv-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.tv-item { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.tv-url { flex: 1 1 260px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.85rem; color: var(--muted); }
.tv-order { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.tv-order input { width: 76px; text-align: center; }
.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; } }

/* ============================================================
   Inventario (ver docs/modulos/inventario.md)
   ============================================================ */
/* Variante para grupos de campos donde cada uno trae su propio texto de
   ayuda de distinto largo (ej. formulario de insumo): alinea las etiquetas
   arriba en vez de alinear los inputs abajo, para que no se vea "corrido". */
.form-grid-top { align-items: start; }
.text-danger { color: var(--danger); font-weight: 600; }
.text-success { color: var(--success); font-weight: 600; }
.is-reverted { opacity: 0.5; }

/* Lista de notas de diagnóstico (dashboard de Turnos, solo admin). */
.insight-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.insight-item {
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 0.9rem; line-height: 1.45; color: var(--ink);
  padding: 10px 12px; border-radius: 8px; background: var(--bg);
}
.insight-item .dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; flex-shrink: 0; background: var(--muted); }
.insight-item.tone-warn .dot { background: #f59e0b; }
.insight-item.tone-good .dot { background: var(--success); }
.insight-item.tone-info .dot { background: var(--accent); }
.status-soon { background: #fef3c7; color: #92400e; }

/* --- Filas dinámicas de la receta de un procedimiento --- */
.ingredient-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.ingredient-row .field { flex: 1; min-width: 180px; margin: 0; }
.ingredient-row .ingredient-qty-field { flex: 0 0 110px; min-width: 90px; }

/* --- Movimiento de inventario: varias líneas (un ticket con varios productos) --- */
.restock-line {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px;
  padding: 10px 0; border-bottom: 1px dashed var(--line);
}
.restock-line .line-item { flex: 1 1 220px; min-width: 0; margin: 0; }
.restock-line .line-field { margin: 0; flex: 0 0 auto; }
.restock-line .line-field span { font-size: 0.78rem; }
.restock-line .line-qty { width: 90px; }
.restock-line .line-field input[type="date"] { width: 160px; }
.restock-line .line-field input[type="number"] { width: 110px; }
.restock-line .line-remove { flex: 0 0 auto; }
.restock-line .line-hint { flex-basis: 100%; margin-top: 2px; }

/* --- Combobox buscable (elegir insumo: en la receta de un procedimiento y
   en "Agregar insumo") --- */
.combobox { position: relative; }
.combobox-input.is-invalid { border-color: var(--danger); }
.combobox-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 9px;
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow-y: auto;
}
.combobox-option { padding: 9px 12px; cursor: pointer; font-size: 0.9rem; }
.combobox-option:hover { background: var(--bg); }
.combobox-empty { padding: 9px 12px; color: var(--muted); font-size: 0.85rem; }

/* --- Cuadrícula visual con foto (listado de insumos) --- */
.inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.inventory-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.inventory-photo {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.inventory-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.inventory-photo-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted);
}
.inventory-status { position: absolute; top: 8px; right: 8px; }
.inventory-body { padding: 14px 16px 4px; flex: 1; }
.inventory-name { margin: 0 0 8px; font-size: 1.02rem; }
.inventory-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.inventory-exp { font-size: 0.86rem; color: var(--muted); margin-bottom: 8px; }
.inventory-desc { margin: 0 0 10px; font-size: 0.88rem; color: var(--ink); white-space: pre-line; }
.inventory-actions {
  display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line);
}
.inventory-current-photo img {
  max-width: 220px; max-height: 160px; border-radius: 9px; display: block; margin-bottom: 8px;
  object-fit: cover;
}

/* --- Resumen de inventario --- */
/* Variantes de urgencia, reusando la barra .pm-bar de "métodos de pago". */
.pm-bar.is-ok > span { background: var(--success); }
.pm-bar.is-low > span { background: #f59e0b; }
.pm-bar.is-critical > span { background: var(--danger); }
.pm-bar.is-unknown > span { background: var(--muted); }
.stock-table td { vertical-align: middle; }
.stock-name { font-weight: 500; }
/* .pm-bar-cell trae width:45% para la tabla de métodos de pago (2 columnas);
   aquí hay 6 columnas, así que se limita a un ancho fijo razonable. */
.stock-table .pm-bar-cell { width: 90px; }
