/* ================================================================
   MediMap SpA — Panel de Operador
   Mockup estático de alta fidelidad (1920×1080)
   CSS3 nativo: Variables, Grid, Flexbox
   ================================================================ */


/* ----------------------------------------------------------------
   1. RESET BÁSICO Y VARIABLES GLOBALES
   ---------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* --- Paleta base --- */
  --color-bg-app:        #f4f6f8;
  --color-bg-panel:      #ffffff;
  --color-bg-subtle:     #eef1f5;
  --color-border:        #dde3ea;
  --color-border-light:  #e8ecf1;
  --color-text-primary:  #1a2332;
  --color-text-secondary:#5a6578;
  --color-text-muted:    #8b95a5;

  /* --- Marca / Salud --- */
  --color-brand:         #0d6e8a;
  --color-brand-light:   #e6f4f8;
  --color-brand-dark:    #0a5568;
  --color-teal:          #14a89a;
  --color-teal-hover:    #119688;
  --color-teal-light:    #d4f5f1;

  /* --- Estados de riesgo (cola) --- */
  --color-critical:      #dc3545;
  --color-critical-bg:   #fff5f5;
  --color-critical-border:#fecaca;

  --color-active:        #e67e22;
  --color-active-bg:     #fff8f0;
  --color-active-border: #fed7aa;

  --color-automated:     #22a06b;
  --color-automated-bg:  #f0fdf6;
  --color-automated-border:#a7f3d0;

  --color-archived:      #8b95a5;
  --color-archived-bg:   #f0f2f5;
  --color-archived-border:#d1d5db;

  /* --- Chat --- */
  --color-chat-incoming: #e9ecef;
  --color-chat-bot:      #dcf8c6;
  --color-chat-support:  #d1ecf9;
  --color-chat-outgoing-text: #1a2332;

  /* --- Legal / Seguridad --- */
  --color-legal-bg:      #e8f5e9;
  --color-legal-border:  #a5d6a7;
  --color-legal-text:    #2e7d32;

  /* --- Alertas --- */
  --color-alert:         #c0392b;
  --color-alert-bg:      #fdecea;

  /* --- RAG / IA --- */
  --color-rag-bg:        #ebf3fc;
  --color-rag-border:    #b3d4f5;
  --color-rag-accent:    #2563eb;

  /* --- Accesos directos --- */
  --color-portal:        #1e3a5f;
  --color-portal-hover:  #162d4a;
  --color-jira:          #2c3e50;
  --color-jira-hover:    #1a252f;
  --color-jira-text:     #f1c40f;

  /* --- Tipografía --- */
  --font-family:         system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-size-xs:        0.6875rem;   /* 11px */
  --font-size-sm:        0.8125rem;   /* 13px */
  --font-size-base:      0.875rem;    /* 14px */
  --font-size-md:        1rem;        /* 16px */
  --font-size-lg:        1.125rem;    /* 18px */

  /* --- Espaciado --- */
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  12px;
  --space-lg:  16px;
  --space-xl:  24px;

  /* --- Bordes y sombras --- */
  --radius-sm:   6px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-full: 9999px;
  --shadow-sm:   0 1px 3px rgba(26, 35, 50, 0.06);
  --shadow-md:   0 2px 8px rgba(26, 35, 50, 0.08);
  --shadow-lg:   0 4px 16px rgba(26, 35, 50, 0.10);

  /* --- Layout fijo 1920×1080 --- */
  --navbar-height: 56px;
  --column-gap:    12px;
  --panel-padding: 16px;
}


/* ----------------------------------------------------------------
   2. BASE GLOBAL
   ---------------------------------------------------------------- */

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100%;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--color-text-primary);
  background-color: #c8cdd4;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
}

/* Accesibilidad: texto oculto visualmente */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}


/* ----------------------------------------------------------------
   3. APP SHELL — Contenedor 1920×1080 sin scroll global
   ---------------------------------------------------------------- */

.app-shell {
  position: relative;
  width: min(1920px, 100vw);
  height: min(1080px, 100vh);
  height: min(1080px, 100dvh);
  max-width: 1920px;
  max-height: 1080px;
  background-color: var(--color-bg-app);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}


/* ----------------------------------------------------------------
   4. NAVBAR — Barra superior
   ---------------------------------------------------------------- */

.navbar {
  position: relative;
  z-index: 500;
  height: var(--navbar-height);
  min-height: var(--navbar-height);
  background-color: var(--color-bg-panel);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-xl);
  gap: var(--space-xl);
  flex-shrink: 0;
  overflow: visible;
}

/* Logo y título */
.navbar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.navbar__logo {
  height: 25px;
  width: auto;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
}

.navbar__title {
  font-size: var(--font-size-md);
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
}

/* Navegación principal */
.navbar__nav {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
}

.navbar__nav-item {
  padding: var(--space-sm) var(--space-md);
  border: none;
  border-radius: var(--radius-md);
  background: none;
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, color 0.15s;
}

.navbar__nav-item:hover {
  background-color: var(--color-bg-subtle);
  color: var(--color-text-primary);
}

.navbar__nav-item--active {
  background-color: var(--color-brand-light);
  color: var(--color-brand-dark);
}

.navbar__nav-item--active:hover {
  background-color: var(--color-brand-light);
  color: var(--color-brand-dark);
}

/* Acciones derecha: notificaciones + perfil */
.navbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-shrink: 0;
}

/* Toggle IA en navbar */
.navbar__ai-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-subtle);
}

.navbar__ai-toggle-info {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
  min-width: 0;
}

.navbar__ai-toggle-status {
  font-size: 10px;
  font-weight: 700;
  color: var(--color-teal);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.navbar__ai-toggle-action {
  font-size: 10px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.navbar__dropdown-wrap {
  position: relative;
  z-index: 501;
}

.navbar__notifications {
  position: relative;
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  transition: background-color 0.2s, color 0.2s;
}

.navbar__notifications--active {
  background-color: var(--color-brand-light);
  color: var(--color-brand);
}

.navbar__notifications svg {
  width: 22px;
  height: 22px;
}

.navbar__notifications:hover {
  background-color: var(--color-bg-subtle);
}

.navbar__notifications-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  background-color: var(--color-critical);
  color: #fff;
  font-size: var(--font-size-xs);
  font-weight: 700;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: transform 0.2s;
}

.navbar__notifications-badge--pulse {
  animation: badge-pulse 0.5s ease;
}

.navbar__notifications-badge--hidden {
  display: none;
}

@keyframes badge-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.25); }
}

.navbar__profile {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.navbar__profile--btn {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 4px 8px 4px 4px;
  border-radius: var(--radius-md);
  font-family: inherit;
  transition: background-color 0.2s;
}

.navbar__profile--btn:hover,
.navbar__profile--btn[aria-expanded="true"] {
  background-color: var(--color-bg-subtle);
}

.navbar__profile-chevron {
  width: 16px;
  height: 16px;
  color: var(--color-text-muted);
  flex-shrink: 0;
  transition: transform 0.2s;
}

.navbar__profile--btn[aria-expanded="true"] .navbar__profile-chevron {
  transform: rotate(180deg);
}

.navbar__avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-brand), var(--color-teal));
  color: #fff;
  font-weight: 700;
  font-size: var(--font-size-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.navbar__avatar--lg {
  width: 48px;
  height: 48px;
  font-size: var(--font-size-lg);
}

.navbar__profile-info {
  display: flex;
  flex-direction: column;
  line-height: 1.3;
  text-align: left;
}

.navbar__profile-name {
  font-weight: 600;
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
}

.navbar__profile-role {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

/* Dropdowns navbar */
.navbar-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 320px;
  background-color: var(--color-bg-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 502;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
  visibility: hidden;
}

.navbar-dropdown[hidden] {
  display: block !important;
  visibility: hidden;
  pointer-events: none;
}

.navbar-dropdown--open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  visibility: visible;
}

.navbar-dropdown--notifications {
  width: 360px;
}

.navbar-dropdown__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--color-border-light);
}

.navbar-dropdown__title {
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--color-text-primary);
}

.navbar-dropdown__action {
  border: none;
  background: none;
  font-family: inherit;
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-brand);
  cursor: pointer;
  padding: 4px 0;
}

.navbar-dropdown__action:hover {
  text-decoration: underline;
}

/* Lista de notificaciones */
.notifications-list {
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
}

.notification-item {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  border: none;
  border-bottom: 1px solid var(--color-border-light);
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.15s;
}

.notification-item:hover {
  background-color: var(--color-bg-subtle);
}

.notification-item--unread {
  background-color: var(--color-brand-light);
}

.notification-item--unread:hover {
  background-color: #dceef3;
}

.notification-item__dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  margin-top: 6px;
}

.notification-item__dot--critical  { background-color: var(--color-critical); }
.notification-item__dot--active    { background-color: var(--color-active); }
.notification-item__dot--automated { background-color: var(--color-automated); }

.notification-item__body {
  flex: 1;
  min-width: 0;
}

.notification-item__title {
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: 2px;
}

.notification-item__message {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  line-height: 1.4;
  margin-bottom: 4px;
}

.notification-item__meta {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  font-family: "Courier New", Courier, monospace;
}

.notifications-list__empty {
  padding: var(--space-xl);
  text-align: center;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

/* Panel perfil operador */
.navbar-dropdown--profile {
  width: 280px;
}

.profile-panel__header {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-lg);
  background: linear-gradient(135deg, var(--color-brand-light), var(--color-bg-subtle));
  border-bottom: 1px solid var(--color-border-light);
}

.profile-panel__name {
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--color-text-primary);
}

.profile-panel__email {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  margin: 2px 0 var(--space-xs);
}

.profile-panel__status {
  display: inline-block;
  font-size: var(--font-size-xs);
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.profile-panel__status--online {
  background-color: var(--color-automated-bg);
  color: var(--color-automated);
}

.profile-panel__status--away {
  background-color: var(--color-active-bg);
  color: var(--color-active);
}

.profile-panel__menu {
  list-style: none;
  padding: var(--space-sm) 0;
}

.profile-panel__item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-sm) var(--space-lg);
  border: none;
  background: none;
  font-family: inherit;
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  cursor: pointer;
  text-align: left;
  transition: background-color 0.15s;
}

.profile-panel__item:hover {
  background-color: var(--color-bg-subtle);
}

.profile-panel__item--danger {
  color: var(--color-critical);
}

.profile-panel__item-icon {
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.profile-panel__divider {
  height: 1px;
  background-color: var(--color-border-light);
  margin: var(--space-xs) 0;
}

.profile-panel__shift {
  padding: var(--space-sm) var(--space-lg) var(--space-md);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border-light);
}


/* ----------------------------------------------------------------
   4b. APP VIEWS — Navegación entre secciones
   ---------------------------------------------------------------- */

.app-views {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.app-view {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: none;
  flex-direction: column;
}

.app-view--active {
  display: flex;
}


/* ----------------------------------------------------------------
   4c. VISTAS SECUNDARIAS — Histórico y Trazabilidad
   ---------------------------------------------------------------- */

.secondary-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin: var(--column-gap);
  background-color: var(--color-bg-panel);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-light);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.secondary-view__header {
  flex-shrink: 0;
  padding: var(--panel-padding);
  border-bottom: 1px solid var(--color-border-light);
}

.secondary-view__title {
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--color-text-primary);
  margin: 0 0 var(--space-xs);
}

.secondary-view__subtitle {
  margin: 0;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.secondary-view__body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: var(--panel-padding);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.data-table th,
.data-table td {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  border-bottom: 1px solid var(--color-border-light);
}

.data-table th {
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  background-color: var(--color-bg-subtle);
  position: sticky;
  top: 0;
  z-index: 1;
}

.data-table tbody tr:hover {
  background-color: var(--color-bg-subtle);
}

.data-table__row--active {
  background-color: rgba(13, 110, 138, 0.06);
}

.data-table__id {
  font-family: "Courier New", Courier, monospace;
  font-weight: 700;
  color: var(--color-brand-dark);
}

.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill--resuelto {
  background-color: var(--color-automated-bg);
  color: var(--color-automated);
}

.status-pill--seguimiento {
  background-color: var(--color-brand-light);
  color: var(--color-brand-dark);
}

/* Toolbar — Histórico de Casos */
.secondary-view__header--historico {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-lg);
}

.secondary-view__header-main {
  min-width: 0;
}

.historico-results-count {
  flex-shrink: 0;
  margin: 0;
  padding: var(--space-xs) var(--space-md);
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--color-brand-dark);
  background-color: var(--color-brand-light);
  border: 1px solid rgba(13, 110, 138, 0.2);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.historico-toolbar {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: var(--space-lg);
  align-items: end;
  padding: var(--space-md) var(--panel-padding);
  border-bottom: 1px solid var(--color-border-light);
  background-color: var(--color-bg-subtle);
}

.historico-toolbar__search {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  min-width: 0;
}

.historico-toolbar__search-field {
  position: relative;
  display: flex;
  align-items: center;
}

.historico-toolbar__search-icon {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--color-text-muted);
  pointer-events: none;
}

.historico-toolbar__search-input {
  width: 100%;
  height: 36px;
  padding: 0 var(--space-md) 0 36px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-panel);
  font-family: inherit;
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.historico-toolbar__search-input::placeholder {
  color: var(--color-text-muted);
}

.historico-toolbar__search-input:focus {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px rgba(13, 110, 138, 0.12);
}

.historico-filter-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  min-width: 0;
}

.historico-filter-group__label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}

.historico-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.historico-filter {
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  background-color: var(--color-bg-panel);
  font-family: inherit;
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.historico-filter:hover {
  border-color: var(--color-brand);
  color: var(--color-brand-dark);
}

.historico-filter--active {
  background-color: var(--color-brand-light);
  border-color: var(--color-brand);
  color: var(--color-brand-dark);
}

.historico-filter--critical.historico-filter--active {
  background-color: var(--color-critical-bg);
  border-color: var(--color-critical-border);
  color: var(--color-critical);
}

.historico-filter--active-level.historico-filter--active {
  background-color: var(--color-active-bg);
  border-color: var(--color-active-border);
  color: var(--color-active);
}

.historico-filter--automated.historico-filter--active {
  background-color: var(--color-automated-bg);
  border-color: var(--color-automated-border);
  color: var(--color-automated);
}

.historico-toolbar__dates {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  min-width: 0;
}

.historico-toolbar__dates-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}

.historico-date-range {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-sm);
}

.historico-date-range__field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.historico-date-range__caption {
  font-size: 10px;
  color: var(--color-text-muted);
}

.historico-date-range__input {
  height: 36px;
  min-width: 140px;
  padding: 0 var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-panel);
  font-family: inherit;
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.historico-date-range__input:focus {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px rgba(13, 110, 138, 0.12);
}

.historico-date-range__sep {
  align-self: center;
  color: var(--color-text-muted);
  padding-bottom: 8px;
}

.historico-date-range__reset {
  height: 36px;
  padding: 0 var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-panel);
  font-family: inherit;
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-brand-dark);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s;
}

.historico-date-range__reset:hover {
  background-color: var(--color-brand-light);
  border-color: var(--color-brand);
}

.secondary-view__body--historico {
  padding: var(--panel-padding);
}

/* Tabla — Histórico de Casos */
.historico-table-wrap {
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background-color: var(--color-bg-panel);
  box-shadow: var(--shadow-sm);
}

.historico-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.historico-table th,
.historico-table td {
  padding: var(--space-md) var(--space-lg);
  text-align: left;
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
}

.historico-table th {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  background-color: var(--color-bg-subtle);
  position: sticky;
  top: 0;
  z-index: 1;
}

.historico-table tbody tr {
  transition: background-color 0.12s;
}

.historico-table tbody tr:hover {
  background-color: rgba(13, 110, 138, 0.04);
}

.historico-table tbody tr:last-child td {
  border-bottom: none;
}

.historico-table__row--active {
  background-color: rgba(13, 110, 138, 0.06);
}

.historico-table__row--active:hover {
  background-color: rgba(13, 110, 138, 0.09);
}

.historico-table__row--active td:first-child {
  box-shadow: inset 3px 0 0 var(--color-brand);
}

.historico-table__id {
  font-family: "Courier New", Courier, monospace;
  font-weight: 700;
  font-size: var(--font-size-xs);
  color: var(--color-brand-dark);
  white-space: nowrap;
}

.historico-table__patient {
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
}

.historico-table__type {
  color: var(--color-text-secondary);
  max-width: 320px;
  line-height: 1.4;
}

.historico-table__operator {
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.historico-table__date {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.historico-table__duration {
  text-align: right;
  font-size: var(--font-size-xs);
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.historico-table__col--duration {
  text-align: right;
}

.priority-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  border: 1px solid transparent;
}

.priority-pill--critical {
  background-color: var(--color-critical-bg);
  color: var(--color-critical);
  border-color: var(--color-critical-border);
}

.priority-pill--active {
  background-color: var(--color-active-bg);
  color: var(--color-active);
  border-color: var(--color-active-border);
}

.priority-pill--automated {
  background-color: var(--color-automated-bg);
  color: var(--color-automated);
  border-color: var(--color-automated-border);
}

.priority-pill--neutral {
  background-color: var(--color-bg-subtle);
  color: var(--color-text-muted);
  border-color: var(--color-border-light);
}

.historico-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  min-height: 240px;
  padding: var(--space-xl);
  text-align: center;
  color: var(--color-text-muted);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-lg);
  background-color: var(--color-bg-subtle);
}

.historico-empty__title {
  font-size: var(--font-size-md);
  font-weight: 700;
  color: var(--color-text-secondary);
  margin: 0;
}

.historico-empty__text {
  font-size: var(--font-size-sm);
  margin: 0;
  max-width: 420px;
  line-height: 1.5;
}

.audit-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.audit-entry {
  display: grid;
  grid-template-columns: 140px 1fr auto;
  gap: var(--space-md);
  align-items: start;
  padding: var(--space-md);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-panel);
}

.audit-entry:hover {
  border-color: var(--color-border);
  box-shadow: var(--shadow-sm);
}

.audit-entry__time {
  font-size: var(--font-size-xs);
  font-family: "Courier New", Courier, monospace;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.audit-entry__action {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-primary);
  margin: 0 0 2px;
}

.audit-entry__detail {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  margin: 0;
}

.audit-entry__case {
  font-size: var(--font-size-xs);
  font-family: "Courier New", Courier, monospace;
  font-weight: 700;
  color: var(--color-brand-dark);
  white-space: nowrap;
}

.audit-entry--sensitive {
  border-left: 3px solid var(--color-critical);
}

.audit-entry--system {
  border-left: 3px solid var(--color-brand);
}

.audit-entry--action {
  border-left: 3px solid var(--color-teal);
}


/* ----------------------------------------------------------------
   5. DASHBOARD — Grid de tres columnas (25% | 50% | 25%)
   ---------------------------------------------------------------- */

.dashboard {
  flex: 1;
  display: grid;
  grid-template-columns: 25% 50% 25%;
  gap: var(--column-gap);
  padding: var(--column-gap);
  min-height: 0; /* Permite que hijos flex/grid hagan scroll interno */
  overflow: hidden;
  transition: grid-template-columns 0.28s ease;
}

.dashboard--copilot-collapsed {
  grid-template-columns: 25% 1fr 44px;
}


/* ----------------------------------------------------------------
   6. COLUMNAS — Panel base compartido
   ---------------------------------------------------------------- */

.column {
  background-color: var(--color-bg-panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border-light);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.column__header {
  padding: var(--panel-padding) var(--panel-padding) var(--space-sm);
  flex-shrink: 0;
}

.column__title {
  font-size: var(--font-size-md);
  font-weight: 700;
  color: var(--color-text-primary);
}


/* ----------------------------------------------------------------
   7. COLA DE ATENCIÓN — Columna izquierda
   ---------------------------------------------------------------- */

.column--queue {
  overflow: hidden;
}

/* Buscador de la cola */
.queue-search {
  position: relative;
  display: flex;
  align-items: center;
  flex-shrink: 0;
  padding: 0 var(--panel-padding) var(--space-sm);
}

.queue-search__icon {
  position: absolute;
  left: calc(var(--panel-padding) + 10px);
  width: 14px;
  height: 14px;
  color: var(--color-text-muted);
  pointer-events: none;
}

.queue-search__input {
  width: 100%;
  height: 34px;
  padding: 0 var(--space-sm) 0 32px;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-subtle);
  font-family: inherit;
  font-size: var(--font-size-xs);
  color: var(--color-text-primary);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.queue-search__input::placeholder {
  color: var(--color-text-muted);
}

.queue-search__input:focus {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px rgba(13, 110, 138, 0.12);
  background-color: var(--color-bg-panel);
}

/* Filtros compactos por nivel de criticidad */
.queue-filters {
  display: flex;
  gap: 4px;
  padding: 0 var(--panel-padding) var(--space-sm);
  flex-shrink: 0;
}

.queue-filter {
  flex: 1;
  min-width: 0;
  padding: 5px 6px;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-full);
  background-color: var(--color-bg-subtle);
  color: var(--color-text-secondary);
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.queue-filter:hover {
  background-color: var(--color-bg-panel);
  border-color: var(--color-border);
}

.queue-filter--active {
  color: var(--color-text-primary);
  border-color: var(--color-brand);
  background-color: var(--color-brand-light);
  box-shadow: inset 0 0 0 1px rgba(13, 110, 138, 0.15);
}

.queue-filter--critical.queue-filter--active {
  border-color: var(--color-critical);
  background-color: var(--color-critical-bg);
  color: var(--color-critical);
}

.queue-filter--active-level.queue-filter--active {
  border-color: var(--color-active);
  background-color: var(--color-active-bg);
  color: var(--color-active);
}

.queue-filter--automated.queue-filter--active {
  border-color: var(--color-automated);
  background-color: var(--color-automated-bg);
  color: var(--color-automated);
}

/* Lista con scroll interno */
.queue-list {
  list-style: none;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 var(--panel-padding) var(--panel-padding);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

/* Tarjetas de la cola */
.queue-card {
  cursor: pointer;
}

.queue-card__inner {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-light);
  background-color: var(--color-bg-panel);
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.15s;
}

.queue-card:hover .queue-card__inner {
  box-shadow: var(--shadow-md);
}

.queue-card__body {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
}

.queue-card__avatar {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-xs);
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--color-brand) 0%, var(--color-brand-dark) 100%);
}

.queue-card--critical .queue-card__avatar {
  background: linear-gradient(135deg, #e55353 0%, var(--color-critical) 100%);
}

.queue-card--active .queue-card__avatar {
  background: linear-gradient(135deg, #f0a030 0%, var(--color-active) 100%);
}

.queue-card--automated .queue-card__avatar {
  background: linear-gradient(135deg, #3ecf8e 0%, var(--color-automated) 100%);
}

.queue-card__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.queue-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-xs);
}

.queue-card__name {
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.queue-card__phone {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.queue-card__rut {
  font-size: var(--font-size-xs);
  font-family: "Courier New", Courier, monospace;
  color: var(--color-text-muted);
}

.queue-card__rut--masked {
  letter-spacing: 0.02em;
  user-select: none;
}

.queue-card__badge {
  font-size: var(--font-size-xs);
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.queue-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-top: var(--space-xs);
  padding-top: var(--space-xs);
  border-top: 1px solid var(--color-border-light);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.queue-card__state {
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 10px;
  white-space: nowrap;
}

.queue-card__state--seguimiento {
  background-color: var(--color-brand-light);
  color: var(--color-brand-dark);
}

.queue-card__state--resuelto {
  background-color: var(--color-automated-bg);
  color: var(--color-automated);
}

/* --- Variantes de estado --- */

/* Alto — rojo */
.queue-card--critical .queue-card__inner {
  border-left: 4px solid var(--color-critical);
  background-color: var(--color-critical-bg);
}

.queue-card--critical .queue-card__badge--critical {
  background-color: var(--color-critical-bg);
  color: var(--color-critical);
  border: 1px solid var(--color-critical-border);
}

/* Medio — naranja */
.queue-card--active .queue-card__inner {
  border-left: 4px solid var(--color-active);
  background-color: var(--color-active-bg);
}

.queue-card--active .queue-card__badge--active {
  background-color: var(--color-active-bg);
  color: var(--color-active);
  border: 1px solid var(--color-active-border);
}

/* Seleccionada / activa (clase .active aplicada por script.js) */
.queue-card.active .queue-card__inner {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 2px rgba(13, 110, 138, 0.28), var(--shadow-md);
  transform: translateX(2px);
}

.queue-card.active.queue-card--critical .queue-card__inner {
  border-color: var(--color-critical);
  box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.22), var(--shadow-md);
}

.queue-card.active.queue-card--automated .queue-card__inner {
  border-color: var(--color-automated);
  box-shadow: 0 0 0 2px rgba(34, 160, 107, 0.22), var(--shadow-md);
}

/* Caso resuelto — atenuación visual */
.queue-card--resuelto .queue-card__inner {
  border-left-color: var(--color-archived);
  background-color: var(--color-archived-bg);
  opacity: 0.88;
}

/* Destello al navegar desde alerta */
.queue-card--highlight .queue-card__inner {
  animation: queue-highlight 1.2s ease;
}

@keyframes queue-highlight {
  0%, 100% { box-shadow: var(--shadow-md); }
  30%, 70%  { box-shadow: 0 0 0 3px rgba(13, 110, 138, 0.45), var(--shadow-lg); }
}

/* Bajo — verde */
.queue-card--automated .queue-card__inner {
  border-left: 4px solid var(--color-automated);
  background-color: var(--color-automated-bg);
}

.queue-card--automated .queue-card__badge--automated {
  background-color: var(--color-automated-bg);
  color: var(--color-automated);
  border: 1px solid var(--color-automated-border);
}


/* ----------------------------------------------------------------
   8. ÁREA DE TRABAJO — Columna central
   ---------------------------------------------------------------- */

.column--workspace {
  padding: 0;
  overflow: hidden;
}

.column--copilot {
  padding: 0;
  overflow: hidden;
  transition: width 0.28s ease;
}

.column--copilot--collapsed {
  cursor: pointer;
}

.column--copilot--collapsed .copilot-body {
  display: none;
}

.column--copilot--collapsed .copilot-header {
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-xs);
  border-bottom: none;
  height: 100%;
}

.column--copilot--collapsed .copilot-header__title {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: var(--font-size-xs);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  max-width: none;
  white-space: nowrap;
}

.column--copilot--collapsed .copilot-collapse-btn__icon {
  transform: rotate(180deg);
}

/* Cuerpo del workspace: vistas alternantes chat / portal */
.workspace-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: var(--panel-padding);
}

/* Grid superpuesto: chat + modal ficha clínica */
.workspace-views {
  flex: 1;
  display: grid;
  grid-template-areas: "panel";
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.workspace-views--portal-open {
  overflow: hidden;
}

.workspace-view {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Chat — vista base */
.workspace-view--chat {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
  transition: filter 0.32s ease;
}

.workspace-view--chat.workspace-view--behind-modal {
  pointer-events: none;
  filter: blur(3px);
}

/* Backdrop difuminado del modal ficha */
.portal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 15;
  background-color: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.32s ease, visibility 0.32s ease;
}

.portal-backdrop:not([hidden]) {
  opacity: 1;
  visibility: visible;
}

/* Modal ficha clínica */
.workspace-view--portal {
  position: absolute;
  inset: var(--space-md);
  z-index: 20;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(0.97) translateY(8px);
  transition:
    opacity 0.32s ease,
    transform 0.32s ease,
    visibility 0.32s ease;
}

.workspace-view--portal.workspace-view--active {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: scale(1) translateY(0);
}

/* Panel de chat con intervención manual fija al fondo */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 0;
}

.chat-scrollable {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  min-height: 0;
  padding-bottom: var(--space-sm);
}

/* Tarjeta del paciente — inicio del chat, acceso a ficha clínica */
.patient-card {
  flex-shrink: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-panel);
  position: relative;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.patient-card__identity {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex: 1;
  min-width: 0;
}

.patient-card__main {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  min-width: 0;
  flex: 1;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  border-radius: var(--radius-sm);
  transition: background-color 0.15s;
}

.patient-card__main:hover {
  background-color: var(--color-bg-subtle);
}

.patient-card__main:focus-visible {
  outline: 2px solid var(--color-brand);
  outline-offset: 2px;
}

.patient-card--ficha-open {
  border-color: var(--color-teal);
  box-shadow: inset 0 0 0 1px rgba(13, 148, 136, 0.2);
}

.patient-card--ficha-open .patient-card__main {
  background-color: rgba(13, 148, 136, 0.06);
}

.patient-card--loading .patient-card__main {
  opacity: 0.75;
  pointer-events: none;
}

.patient-card--loading .patient-card__avatar::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-top-color: transparent;
  border-radius: 50%;
  animation: patient-card-spin 0.7s linear infinite;
}

.patient-card--loading .patient-card__avatar {
  position: relative;
  opacity: 0.85;
}

@keyframes patient-card-spin {
  to { transform: rotate(360deg); }
}

.patient-card__avatar {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--color-brand) 0%, var(--color-brand-dark) 100%);
}

.patient-card--critical .patient-card__avatar {
  background: linear-gradient(135deg, #e55353 0%, var(--color-critical) 100%);
}

.patient-card--active .patient-card__avatar {
  background: linear-gradient(135deg, #f0a030 0%, var(--color-active) 100%);
}

.patient-card--automated .patient-card__avatar {
  background: linear-gradient(135deg, #3ecf8e 0%, var(--color-automated) 100%);
}

.patient-card__details {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.patient-card__name-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: var(--space-sm);
  min-width: 0;
}

.patient-card__name {
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.patient-card__phone {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.patient-card__phone::before {
  content: '·';
  margin-right: var(--space-sm);
  color: var(--color-text-muted);
}

.patient-card__rut-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.patient-card__rut-value {
  font-family: "Courier New", Courier, monospace;
  font-weight: 600;
  color: var(--color-text-secondary);
}

.patient-card__reveal-rut {
  padding: 1px 6px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background-color: var(--color-bg-subtle);
  color: var(--color-brand-dark);
  font-family: inherit;
  font-size: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s;
}

.patient-card__reveal-rut:hover {
  background-color: var(--color-brand-light);
}

.patient-card__actions {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex-shrink: 0;
}

.patient-card__attachments-wrap {
  position: relative;
  flex-shrink: 0;
}

.patient-card__attachments-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-subtle);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.patient-card__attachments-btn:hover,
.patient-card__attachments-btn[aria-expanded="true"] {
  background-color: var(--color-bg-panel);
  border-color: var(--color-brand);
  color: var(--color-brand-dark);
}

.patient-card__attachments-icon {
  width: 18px;
  height: 18px;
}

.patient-card__attachments-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: var(--radius-full);
  background-color: var(--color-brand);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.patient-card__attachments-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 25;
  width: min(300px, 78vw);
  padding: var(--space-sm);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-panel);
  box-shadow: var(--shadow-lg);
}

.patient-card__attachments-dropdown[hidden] {
  display: none;
}

.patient-card__attachments-title {
  margin: 0 0 var(--space-sm);
  padding: 0 var(--space-xs);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}

.patient-card__attachments-empty {
  margin: 0;
  padding: var(--space-sm) var(--space-xs);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

.patient-card__attachments-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  max-height: 220px;
  overflow-y: auto;
}

.patient-card__attachments-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  background-color: var(--color-bg-subtle);
}

.patient-card__attachments-file {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-width: 0;
}

.patient-card__attachments-file-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: var(--color-text-muted);
}

.patient-card__attachments-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.patient-card__attachments-name {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.patient-card__attachments-time {
  font-size: 10px;
  color: var(--color-text-muted);
}

.patient-card__attachments-status {
  flex-shrink: 0;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.patient-card__attachments-status--alert {
  background-color: var(--color-critical-bg);
  color: var(--color-critical);
}

.patient-card__attachments-status--pending {
  background-color: var(--color-active-bg);
  color: var(--color-active);
}

.patient-card__attachments-status--ok {
  background-color: var(--color-automated-bg);
  color: var(--color-automated);
}

.patient-card__jira-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-subtle);
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s, background-color 0.15s, border-color 0.15s;
}

.patient-card__jira-btn:hover {
  transform: translateY(-1px);
  background-color: var(--color-bg-panel);
  border-color: var(--color-border);
}

.patient-card__jira-icon {
  width: 22px;
  height: 22px;
  display: block;
}

.patient-card__consent-wrap {
  position: relative;
  flex-shrink: 0;
}

.patient-card__consent-lock {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--color-legal-border);
  border-radius: var(--radius-md);
  background-color: var(--color-legal-bg);
  color: var(--color-legal-text);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.patient-card__consent-lock:hover {
  background-color: #e8f5e9;
  border-color: var(--color-legal-text);
}

.patient-card__consent-lock[aria-expanded="true"] {
  background-color: var(--color-legal-text);
  color: #fff;
  border-color: var(--color-legal-text);
}

.patient-card__consent-lock-icon {
  width: 18px;
  height: 18px;
}

.patient-card__consent-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 20;
  width: min(280px, 70vw);
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-legal-border);
  border-radius: var(--radius-md);
  background-color: var(--color-legal-bg);
  box-shadow: var(--shadow-lg);
}

.patient-card__consent-popover[hidden] {
  display: none;
}

.patient-card__consent-title {
  margin: 0 0 4px;
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-legal-text);
}

.patient-card__consent-text {
  margin: 0;
  font-size: var(--font-size-xs);
  line-height: 1.45;
  color: var(--color-legal-text);
}

/* Área combinada chat + documento (legacy wrapper — scroll en .chat-scrollable) */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: var(--space-sm);
}

/* --- Línea de tiempo de chat --- */
.chat-timeline {
  flex-shrink: 0;
  min-height: 180px;
  max-height: none;
  overflow-y: visible;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  padding: var(--space-md);
  background-color: var(--color-bg-subtle);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-light);
}

.chat-message {
  display: flex;
  max-width: 78%;
}

.chat-message--incoming {
  align-self: flex-start;
}

.chat-message--outgoing {
  align-self: flex-end;
}

.chat-bubble {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-lg);
  position: relative;
  line-height: 1.45;
  font-size: var(--font-size-sm);
}

.chat-message--incoming .chat-bubble {
  background-color: var(--color-chat-incoming);
  border-bottom-left-radius: var(--radius-sm);
}

.chat-message--bot .chat-bubble {
  background-color: var(--color-chat-bot);
  border-bottom-right-radius: var(--radius-sm);
}

.chat-message--support .chat-bubble {
  background-color: var(--color-chat-support);
  border-bottom-right-radius: var(--radius-sm);
}

/* Mensaje de sistema (IA pausada) */
.chat-message--system {
  align-self: center;
  max-width: 92%;
}

.chat-bubble--system {
  background-color: #fff3cd;
  border: 1px solid #ffc107;
  color: #856404;
  text-align: center;
  font-size: var(--font-size-xs);
  font-weight: 600;
  border-radius: var(--radius-md);
}

.chat-bubble__time {
  display: block;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  text-align: right;
  margin-top: var(--space-xs);
}

/* Enmascaramiento de datos sensibles */
.masked-data {
  font-family: "Courier New", Courier, monospace;
  font-weight: 600;
  background-color: rgba(0, 0, 0, 0.06);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}

.btn-reveal {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: var(--space-sm);
  padding: 3px 10px;
  border: 1px solid var(--color-brand);
  border-radius: var(--radius-full);
  background-color: var(--color-brand-light);
  color: var(--color-brand);
  font-family: inherit;
  font-size: var(--font-size-xs);
  font-weight: 600;
  cursor: pointer;
  vertical-align: middle;
  transition: background-color 0.2s, color 0.2s;
}

.btn-reveal:hover {
  background-color: var(--color-brand);
  color: #fff;
}

.btn-reveal__icon {
  font-size: 0.85em;
}

/* Adjunto en chat */
.chat-attachment-preview {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
  padding: var(--space-sm);
  background-color: rgba(255, 255, 255, 0.6);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

.chat-attachment-preview__icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}


/* --- Visor de documentos --- */
.document-viewer {
  flex-shrink: 0;
  height: clamp(140px, 18vh, 200px);
  min-height: 140px;
}

.document-viewer__frame {
  position: relative;
  height: 100%;
  background-color: #fafafa;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Documento simulado (orden médica) */
.document-mock {
  width: 320px;
  height: 240px;
  background-color: #fff;
  border: 1px solid #ccc;
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  box-shadow: var(--shadow-sm);
  position: relative;
  font-size: var(--font-size-xs);
  color: var(--color-text-primary);
}

.document-mock__header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--color-border-light);
}

.document-mock__clinic-logo {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--color-brand-light), var(--color-brand));
}

.document-mock__clinic-info {
  display: flex;
  flex-direction: column;
}

.document-mock__clinic-name {
  font-weight: 700;
  font-size: var(--font-size-xs);
}

.document-mock__clinic-rut {
  color: var(--color-text-muted);
  font-size: 0.625rem;
}

.document-mock__title {
  text-align: center;
  font-size: var(--font-size-sm);
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-sm);
  color: var(--color-brand-dark);
}

.document-mock__fields {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.document-mock__row {
  display: flex;
  gap: var(--space-sm);
}

.document-mock__label {
  font-weight: 600;
  min-width: 72px;
  color: var(--color-text-secondary);
}

.document-mock__value--empty {
  color: var(--color-text-muted);
  font-style: italic;
}

.document-mock__row--highlight {
  background-color: #fff3cd;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  margin-top: 2px;
}

.document-mock__signature {
  margin-top: var(--space-md);
  text-align: center;
  font-size: 0.625rem;
  color: var(--color-text-muted);
}

.document-mock__signature-line {
  width: 120px;
  height: 1px;
  background-color: var(--color-text-primary);
  margin: 0 auto var(--space-xs);
}

/* Recuadro OCR simulado sobre campo diagnóstico */
.ocr-box {
  position: absolute;
  bottom: 72px;
  left: 88px;
  width: 130px;
  height: 18px;
  border: 2px dashed var(--color-alert);
  border-radius: 2px;
  background-color: rgba(192, 57, 43, 0.08);
  pointer-events: none;
}

/* Alerta flotante OCR */
.ocr-alert {
  position: absolute;
  top: 50%;
  right: 24px;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background-color: var(--color-alert-bg);
  border: 2px solid var(--color-alert);
  border-radius: var(--radius-md);
  color: var(--color-alert);
  font-weight: 800;
  font-size: var(--font-size-sm);
  letter-spacing: 0.04em;
  box-shadow: var(--shadow-lg);
  animation: pulse-alert 2s ease-in-out infinite;
}

.ocr-alert__icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

@keyframes pulse-alert {
  0%, 100% { box-shadow: var(--shadow-lg); }
  50%      { box-shadow: 0 4px 20px rgba(192, 57, 43, 0.35); }
}

/* Visor vacío o respondido */
.document-empty,
.document-responded {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  height: 100%;
  color: var(--color-text-muted);
  text-align: center;
  padding: var(--space-xl);
}

.document-empty__icon,
.document-responded__icon {
  width: 48px;
  height: 48px;
  opacity: 0.5;
}

.document-responded__icon {
  color: var(--color-automated);
  opacity: 1;
}

.document-responded__title {
  font-size: var(--font-size-md);
  font-weight: 700;
  color: var(--color-automated);
}

.document-responded__subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.document-viewer--responded .document-viewer__frame {
  background-color: var(--color-automated-bg);
  border-color: var(--color-automated-border);
}


/* --- Input de mensaje inferior --- */
.chat-input {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-md);
  flex-shrink: 0;
}

.chat-input__field {
  flex: 1;
  height: 44px;
  padding: 0 var(--space-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: var(--font-size-sm);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input__field:focus {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px rgba(13, 110, 138, 0.12);
}

.chat-input__send {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: var(--radius-full);
  background-color: var(--color-brand);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.2s, transform 0.15s;
}

.chat-input__send svg {
  width: 20px;
  height: 20px;
}

.chat-input__send:hover {
  background-color: var(--color-brand-dark);
  transform: scale(1.05);
}


/* ----------------------------------------------------------------
   8b. INTERVENCIÓN MANUAL — Tamara (textarea + barra de herramientas)
   ---------------------------------------------------------------- */

.manual-intervention {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-bg-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  z-index: 5;
}

/* Textarea + botón redondo de inserción (estilo WhatsApp) */
.manual-intervention__composer {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
}

.manual-intervention__textarea {
  flex: 1;
  min-height: 100px;
  max-height: 160px;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-subtle);
  font-family: inherit;
  font-size: var(--font-size-sm);
  line-height: 1.5;
  color: var(--color-text-primary);
  resize: none;
  outline: none;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.manual-intervention__send-round {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: var(--radius-full);
  background-color: var(--color-teal);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.manual-intervention__send-round svg {
  width: 20px;
  height: 20px;
}

.manual-intervention__send-round:hover:not(:disabled) {
  background-color: var(--color-teal-hover);
  transform: scale(1.06);
  box-shadow: var(--shadow-md);
}

.manual-intervention__send-round:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.manual-intervention__textarea::placeholder {
  color: var(--color-text-muted);
}

.manual-intervention__textarea:focus {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px rgba(13, 110, 138, 0.12), var(--shadow-sm);
  background-color: var(--color-bg-panel);
}

.manual-intervention__label {
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-brand-dark);
}

.manual-intervention__hint {
  font-size: var(--font-size-xs);
  color: var(--color-teal);
  font-weight: 600;
  font-style: italic;
  margin: 0;
}

.manual-intervention__hint--hidden {
  visibility: hidden;
  height: 0;
  margin: 0;
  overflow: hidden;
}

.bot-paused-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-sm);
  background-color: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-md);
}

.bot-paused-banner[hidden] {
  display: none;
}

.bot-paused-banner__text {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin: 0;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: #b45309;
}

.bot-paused-banner__icon {
  font-size: 1rem;
  line-height: 1;
}

.bot-paused-banner__btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  border: none;
  border-radius: var(--radius-md);
  background-color: var(--color-teal);
  color: #fff;
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.bot-paused-banner__btn-icon {
  width: 14px;
  height: 14px;
}

.bot-paused-banner__btn:hover {
  background-color: var(--color-teal-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.manual-intervention__toolbar {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.manual-intervention__btn {
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.manual-intervention__btn-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Enviar respuesta manual — Teal salud */
.manual-intervention__btn--send {
  background-color: var(--color-teal);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.manual-intervention__btn--send:hover:not(:disabled) {
  background-color: var(--color-teal-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* Editar y enviar sugerencia IA — Gris institucional */
.manual-intervention__btn--edit {
  background-color: var(--color-jira);
  color: #fff;
}

.manual-intervention__btn--edit:hover:not(:disabled) {
  background-color: var(--color-jira-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.manual-intervention__btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Scrollbar del área scrollable del chat */
.chat-scrollable {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.chat-scrollable::-webkit-scrollbar {
  width: 6px;
}

.chat-scrollable::-webkit-scrollbar-thumb {
  background-color: var(--color-border);
  border-radius: var(--radius-full);
}


/* ----------------------------------------------------------------
   9. COPILOTO DE IA — Columna derecha
   ---------------------------------------------------------------- */

.copilot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: var(--panel-padding);
  border-bottom: 1px solid var(--color-border-light);
  flex-shrink: 0;
}

.copilot-header__title {
  font-size: var(--font-size-md);
  font-weight: 700;
  line-height: 1.3;
}

.copilot-collapse-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
  background-color: var(--color-bg-subtle);
  color: var(--color-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.copilot-collapse-btn:hover {
  background-color: var(--color-brand-light);
  border-color: var(--color-brand);
  color: var(--color-brand-dark);
}

.copilot-collapse-btn__icon {
  width: 18px;
  height: 18px;
  transition: transform 0.28s ease;
}

/* Switch IA (navbar y reutilizable) */
.ai-toggle__switch {
  width: 52px;
  height: 28px;
  border: none;
  border-radius: var(--radius-full);
  background-color: #ccc;
  cursor: pointer;
  position: relative;
  transition: background-color 0.25s;
  padding: 0;
}

.ai-toggle__switch--active {
  background-color: var(--color-teal);
}

.ai-toggle__knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background-color: #fff;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  transition: transform 0.25s;
}

.ai-toggle__switch--active .ai-toggle__knob {
  transform: translateX(24px);
}

/* Cuerpo del copiloto con scroll interno */
.copilot-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--panel-padding);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}


/* --- Sugerencia RAG --- */
.rag-suggestion {
  background-color: var(--color-rag-bg);
  border: 1px solid var(--color-rag-border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  flex-shrink: 0;
}

.rag-suggestion__header {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.rag-suggestion__icon {
  width: 20px;
  height: 20px;
  color: var(--color-rag-accent);
}

.rag-suggestion__title {
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--color-rag-accent);
}

.rag-suggestion__source {
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  margin-bottom: var(--space-sm);
}

.rag-suggestion__source cite {
  font-style: normal;
  font-weight: 600;
  color: var(--color-text-secondary);
}

.rag-suggestion__draft {
  border-left: 3px solid var(--color-rag-accent);
  padding-left: var(--space-md);
  margin: 0;
  max-height: clamp(100px, 14vh, 160px);
  overflow-y: auto;
}

.rag-suggestion__draft p {
  font-size: var(--font-size-sm);
  line-height: 1.55;
  color: var(--color-text-primary);
}

.rag-suggestion__insert-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  margin-top: var(--space-md);
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px dashed var(--color-rag-accent);
  border-radius: var(--radius-md);
  background-color: rgba(37, 99, 235, 0.06);
  color: var(--color-rag-accent);
  font-family: inherit;
  font-size: var(--font-size-xs);
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}

.rag-suggestion__insert-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.rag-suggestion__insert-btn:hover:not(:disabled) {
  background-color: rgba(37, 99, 235, 0.12);
  border-color: var(--color-brand);
}

.rag-suggestion__insert-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* RAG deshabilitado cuando IA pausada */
.rag-suggestion--disabled {
  opacity: 0.45;
  pointer-events: none;
  filter: grayscale(0.4);
  transition: opacity 0.3s, filter 0.3s;
}


/* --- Botón de acción principal --- */
.btn-primary-action {
  width: 100%;
  flex-shrink: 0;
  padding: var(--space-sm) var(--space-md);
  border: none;
  border-radius: var(--radius-lg);
  background-color: var(--color-teal);
  color: #fff;
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: background-color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.btn-primary-action:hover {
  background-color: var(--color-teal-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.btn-primary-action:active {
  transform: translateY(0);
}

.btn-primary-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary-action:disabled:hover {
  background-color: var(--color-teal);
  transform: none;
  box-shadow: none;
}


/* --- Accesos directos --- */
.shortcuts {
  flex-shrink: 0;
}

.shortcuts__title {
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-md);
}

.shortcuts__list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.shortcut-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.15s;
  text-align: left;
}

.shortcut-btn__icon {
  font-size: var(--font-size-md);
  flex-shrink: 0;
}

/* Portal Web — azul institucional */
.shortcut-btn--portal {
  background-color: var(--color-portal);
  color: #fff;
  position: relative;
}

.shortcut-btn--portal:hover:not(:disabled) {
  background-color: var(--color-portal-hover);
  transform: translateX(2px);
}

/* Estado activo: ficha integrada abierta */
.shortcut-btn--portal-active {
  background-color: var(--color-teal);
  box-shadow: 0 0 0 2px rgba(20, 168, 154, 0.35);
}

.shortcut-btn--portal-active:hover:not(:disabled) {
  background-color: var(--color-teal-hover);
}

/* Indicador de carga al conectar API */
.shortcut-btn--loading {
  pointer-events: none;
  opacity: 0.85;
}

.shortcut-btn__loader {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: var(--radius-full);
  animation: portal-btn-spin 0.7s linear infinite;
  margin-left: auto;
  flex-shrink: 0;
}

.shortcut-btn--loading .shortcut-btn__loader {
  display: block;
}

.shortcut-btn--loading .shortcut-btn__icon {
  opacity: 0.5;
}

@keyframes portal-btn-spin {
  to { transform: rotate(360deg); }
}

/* Jira — gris oscuro con texto amarillo */
.shortcut-btn--jira {
  background-color: var(--color-jira);
  color: var(--color-jira-text);
}

.shortcut-btn--jira:hover {
  background-color: var(--color-jira-hover);
  transform: translateX(2px);
}


/* ----------------------------------------------------------------
   10. SCROLLBARS PERSONALIZADOS (WebKit + Firefox)
   ---------------------------------------------------------------- */

.queue-list,
.chat-timeline,
.copilot-body {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.queue-list::-webkit-scrollbar,
.chat-timeline::-webkit-scrollbar,
.copilot-body::-webkit-scrollbar {
  width: 6px;
}

.queue-list::-webkit-scrollbar-track,
.chat-timeline::-webkit-scrollbar-track,
.copilot-body::-webkit-scrollbar-track {
  background: transparent;
}

.queue-list::-webkit-scrollbar-thumb,
.chat-timeline::-webkit-scrollbar-thumb,
.copilot-body::-webkit-scrollbar-thumb {
  background-color: var(--color-border);
  border-radius: var(--radius-full);
}

.queue-list::-webkit-scrollbar-thumb:hover,
.chat-timeline::-webkit-scrollbar-thumb:hover,
.copilot-body::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-text-muted);
}


/* ----------------------------------------------------------------
   11. TOASTS — Notificaciones flotantes (script.js)
   ---------------------------------------------------------------- */

.toast-container {
  position: absolute;
  top: calc(var(--navbar-height) + 12px);
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
  max-width: 420px;
}

.toast {
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  font-weight: 600;
  line-height: 1.4;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateX(24px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: auto;
}

.toast--visible {
  opacity: 1;
  transform: translateX(0);
}

.toast--success {
  background-color: var(--color-automated);
  color: #fff;
  border-left: 4px solid #1a7a4c;
}

.toast--audit {
  background-color: #1a2332;
  color: #f4f6f8;
  border-left: 4px solid var(--color-brand);
}

.toast--info {
  background-color: var(--color-bg-panel);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
}


/* ----------------------------------------------------------------
   12. VISTA FICHA CLÍNICA — Secure-API integrada
   ---------------------------------------------------------------- */

.portal-secure-frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background-color: var(--color-bg-panel);
  border: 2px solid var(--color-brand);
  border-radius: var(--radius-lg);
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.22);
  overflow: hidden;
  position: relative;
}

/* Simula barra superior de iframe seguro con botón cerrar */
.portal-secure-frame__toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  padding: 6px var(--space-sm) 6px var(--space-lg);
  background: linear-gradient(90deg, var(--color-portal), var(--color-brand-dark));
  flex-shrink: 0;
}

.portal-secure-frame__url {
  font-size: var(--font-size-xs);
  font-family: "Courier New", Courier, monospace;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.portal-close-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 5px 12px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: var(--radius-sm);
  background-color: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-family: inherit;
  font-size: var(--font-size-xs);
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}

.portal-close-btn svg {
  width: 14px;
  height: 14px;
}

.portal-close-btn:hover {
  background-color: rgba(220, 53, 69, 0.85);
  border-color: rgba(255, 255, 255, 0.5);
}

.portal-close-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Banner de estado API OAuth2/TLS1.3 */
.portal-api-banner {
  flex-shrink: 0;
  padding: var(--space-sm) var(--space-lg);
  background-color: var(--color-brand-light);
  border-bottom: 1px solid var(--color-rag-border);
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-brand-dark);
  line-height: 1.45;
  font-family: "Courier New", Courier, monospace;
}

.portal-api-banner__token {
  display: block;
  margin-top: 2px;
  font-weight: 400;
  color: var(--color-text-muted);
  font-size: 0.625rem;
  word-break: break-all;
}

/* Overlay de carga API */
.portal-loading {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
}

.portal-loading[hidden] {
  display: none !important;
}

.portal-loading__spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-brand);
  border-radius: var(--radius-full);
  animation: portal-btn-spin 0.8s linear infinite;
}

/* Contenido clínico renderizado por JS */
.portal-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  padding-bottom: 72px;
  min-height: 0;
}

.portal-content[hidden] {
  display: none !important;
}

.portal-content__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--color-border-light);
}

.portal-content__patient-name {
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--color-text-primary);
}

.portal-content__patient-rut {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  font-family: "Courier New", Courier, monospace;
  margin-top: var(--space-xs);
}

.portal-content__case-ref {
  font-size: var(--font-size-xs);
  font-weight: 700;
  color: var(--color-brand);
  background-color: var(--color-brand-light);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

/* Tarjetas de resumen clínico */
.portal-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.portal-summary__card {
  padding: var(--space-md);
  background-color: var(--color-bg-subtle);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-md);
}

.portal-summary__label {
  display: block;
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-xs);
}

.portal-summary__value {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-primary);
  line-height: 1.4;
}

/* Secciones: historial y alertas */
.portal-section {
  margin-bottom: var(--space-xl);
}

.portal-section__title {
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--color-brand-dark);
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.portal-section__title svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* Tabla historial de consultas */
.portal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.portal-table th {
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  background-color: var(--color-portal);
  color: #fff;
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.portal-table th:first-child { border-radius: var(--radius-sm) 0 0 0; }
.portal-table th:last-child  { border-radius: 0 var(--radius-sm) 0 0; }

.portal-table td {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--color-border-light);
  color: var(--color-text-primary);
}

.portal-table tr:hover td {
  background-color: var(--color-bg-subtle);
}

.portal-table__estado--ok     { color: var(--color-automated); font-weight: 600; }
.portal-table__estado--warn   { color: var(--color-active); font-weight: 600; }
.portal-table__estado--alert  { color: var(--color-critical); font-weight: 600; }

/* Alertas Isapre */
.portal-alerts {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.portal-alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  line-height: 1.4;
  border-left: 4px solid;
}

.portal-alert--info {
  background-color: var(--color-rag-bg);
  border-left-color: var(--color-rag-accent);
  color: var(--color-text-primary);
}

.portal-alert--warning {
  background-color: var(--color-active-bg);
  border-left-color: var(--color-active);
  color: #7a4a0f;
}

.portal-alert--critical {
  background-color: var(--color-critical-bg);
  border-left-color: var(--color-critical);
  color: #922;
}

.portal-alert__icon {
  flex-shrink: 0;
  font-size: var(--font-size-md);
}

/* Botón flotante volver al chat */
.btn-back-chat {
  position: absolute;
  bottom: var(--space-lg);
  left: var(--space-lg);
  z-index: 10;
  padding: var(--space-sm) var(--space-lg);
  border: none;
  border-radius: var(--radius-full);
  background-color: var(--color-portal);
  color: #fff;
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: background-color 0.2s, transform 0.15s;
}

.btn-back-chat:hover {
  background-color: var(--color-portal-hover);
  transform: translateY(-2px);
}

/* Scrollbar del portal */
.portal-content {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

.portal-content::-webkit-scrollbar {
  width: 6px;
}

.portal-content::-webkit-scrollbar-thumb {
  background-color: var(--color-border);
  border-radius: var(--radius-full);
}

/* ================================================================
   MODAL — Toma de control manual (detener bot)
   ================================================================ */

.takeover-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
}

.takeover-modal[hidden] {
  display: none;
}

body.takeover-modal-open {
  overflow: hidden;
}

.takeover-modal__backdrop {
  position: absolute;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}

.takeover-modal__panel {
  position: relative;
  width: min(100%, 480px);
  padding: var(--space-xl);
  background-color: var(--color-bg-panel);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: takeover-modal-in 0.22s ease-out;
}

@keyframes takeover-modal-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.takeover-modal__icon {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background-color: var(--color-bg-subtle);
  border-radius: var(--radius-full);
}

.takeover-modal__title {
  margin: 0 0 var(--space-sm);
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-text-primary);
}

.takeover-modal__text {
  margin: 0 0 var(--space-md);
  font-size: var(--font-size-sm);
  line-height: 1.55;
  color: var(--color-text-secondary);
}

.takeover-modal__question {
  margin: 0 0 var(--space-lg);
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-primary);
}

.takeover-modal__actions {
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-sm);
}

@media (min-width: 480px) {
  .takeover-modal__actions {
    flex-direction: row;
    justify-content: flex-end;
  }
}

.takeover-modal__btn {
  flex: 1;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--font-size-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}

@media (min-width: 480px) {
  .takeover-modal__btn {
    flex: 0 1 auto;
  }
}

.takeover-modal__btn--cancel {
  border: 1px solid var(--color-border);
  background-color: var(--color-bg-subtle);
  color: var(--color-text-primary);
}

.takeover-modal__btn--cancel:hover {
  background-color: var(--color-bg-panel);
  border-color: var(--color-text-muted);
}

.takeover-modal__btn--confirm {
  border: none;
  background-color: var(--color-teal);
  color: #fff;
}

.takeover-modal__btn--confirm:hover {
  background-color: #0d9488;
}

.manual-intervention__textarea--bot-active {
  cursor: pointer;
  background-color: var(--color-bg-panel);
  color: var(--color-text-secondary);
}

.manual-intervention__textarea--bot-active:focus {
  border-color: var(--color-teal);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}
