/* =====================================================================
   CISAM · Salud Ocupacional — SISTEMA VISUAL COMPARTIDO
   ---------------------------------------------------------------------
   Única hoja de estilos global de la aplicación autenticada.
   Orden:
     1. Tokens (colores, tipografía, espaciado, bordes, sombras, estados)
     2. Base
     3. Layout de la aplicación (menú lateral, cabecera, contenido)
     4. Componentes (botones, campos, tarjetas, tablas, filtros,
        paginación, pestañas, modales, avisos, archivos, estados)
     5. Utilidades mínimas
   Las hojas por pantalla (public/css/paginas/*.css) solo contienen
   necesidades propias y no redefinen tokens ni componentes.
   Identidad: azul petróleo y verde del logotipo CISAM.
   ===================================================================== */

@font-face { font-family: "Inter"; font-weight: 400; font-display: swap; src: url("/vendor/fonts/inter-latin-400-normal-55WT6UWF.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 500; font-display: swap; src: url("/vendor/fonts/inter-latin-500-normal-W62DVTXI.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 600; font-display: swap; src: url("/vendor/fonts/inter-latin-600-normal-R6Y2SZCR.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 700; font-display: swap; src: url("/vendor/fonts/inter-latin-700-normal-PQ7JFZQA.woff2") format("woff2"); }

/* 1. TOKENS ============================================================ */
:root {
  /* Marca CISAM */
  --c-brand-50: #eaf5f9;
  --c-brand-100: #cfe8f1;
  --c-brand-200: #9fd0e2;
  --c-brand-500: #1f7fa3;
  --c-brand-600: #186a8a;
  --c-brand-700: #135570;
  --c-brand-900: #0b3345;
  --c-accent-50: #e8f7ee;
  --c-accent-500: #0e9a4b;
  --c-accent-600: #0b7f3d;

  /* Neutros */
  --c-bg: #f3f6f8;
  --c-surface: #ffffff;
  --c-surface-2: #f8fafb;
  --c-border: #dde3e8;
  --c-border-strong: #c3ccd4;
  --c-text: #14212b;
  --c-text-2: #3d4b56;
  --c-muted: #5f6d78;
  --c-disabled: #9aa6b0;

  /* Estados */
  --c-info: #1f7fa3;      --c-info-bg: #eaf5f9;      --c-info-border: #9fd0e2;
  --c-success: #0b7f3d;   --c-success-bg: #e8f7ee;   --c-success-border: #9fdcb7;
  --c-warning: #9a5b00;   --c-warning-bg: #fff5e0;   --c-warning-border: #f3cf85;
  --c-danger: #b42318;    --c-danger-bg: #fdecea;    --c-danger-border: #f4b4ad;

  /* Tipografía */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-md: 0.875rem;
  --fs-base: 0.9375rem;
  --fs-lg: 1.0625rem;
  --fs-xl: 1.25rem;
  --fs-2xl: 1.5rem;
  --lh: 1.5;

  /* Espaciado (escala de 4px) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;

  /* Bordes y sombras */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-pill: 999px;
  --sh-1: 0 1px 2px rgba(16, 33, 43, 0.06);
  --sh-2: 0 4px 14px rgba(16, 33, 43, 0.08);
  --sh-3: 0 18px 44px rgba(16, 33, 43, 0.18);
  --focus: 0 0 0 3px rgba(31, 127, 163, 0.35);

  /* Layout */
  --sidebar-w: 264px;
  --topbar-h: 60px;
  --content-max: 1480px;
  --z-sidebar: 40;
  --z-topbar: 30;
  --z-overlay: 50;
  --z-modal: 60;
  --z-toast: 70;
}

/* 2. BASE ============================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh);
  color: var(--c-text);
  background: var(--c-bg);
}
h1, h2, h3, h4 { margin: 0 0 var(--sp-2); line-height: 1.25; color: var(--c-text); font-weight: 700; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-base); }
p { margin: 0 0 var(--sp-3); }
a { color: var(--c-brand-600); }
a:hover { color: var(--c-brand-700); }
img { max-width: 100%; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
[hidden], .hidden, .is-hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: var(--sp-2); top: -48px; z-index: var(--z-toast); background: var(--c-brand-700); color: #fff; padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm); }
.skip-link:focus { top: var(--sp-2); color: #fff; }

/* 3. LAYOUT ============================================================ */
.app { display: flex; min-height: 100vh; }

.app-sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--c-brand-900); color: #dbe9ef;
  display: flex; flex-direction: column; z-index: var(--z-sidebar);
}
.app-brand { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid rgba(255,255,255,.08); text-decoration: none; }
.app-brand img { height: 40px; width: auto; max-width: 112px; object-fit: contain; background: #fff; border-radius: var(--r-sm); padding: 4px 6px; }
.app-brand-text { display: flex; flex-direction: column; color: #fff; line-height: 1.2; }
.app-brand-text strong { font-size: var(--fs-md); letter-spacing: .02em; }
.app-brand-text span { font-size: var(--fs-xs); color: #9fc6d6; }

.app-nav { flex: 1; overflow-y: auto; padding: var(--sp-3) var(--sp-3) var(--sp-6); }
.app-nav-group { margin-top: var(--sp-4); }
.app-nav-group:first-child { margin-top: 0; }
.app-nav-title { font-size: 0.6875rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #7fa9bb; padding: 0 var(--sp-3) var(--sp-1); }
.app-nav-link {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 9px var(--sp-3); margin: 1px 0; border-radius: var(--r-md);
  color: #dbe9ef; text-decoration: none; font-size: var(--fs-md); font-weight: 500;
}
.app-nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.app-nav-link[aria-current="page"] { background: var(--c-brand-600); color: #fff; font-weight: 600; }
.app-nav-link svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: .9; }
.app-sidebar-foot { padding: var(--sp-3) var(--sp-5); font-size: var(--fs-xs); color: #7fa9bb; border-top: 1px solid rgba(255,255,255,.08); }

.app-main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }

.app-topbar {
  position: sticky; top: 0; z-index: var(--z-topbar);
  height: var(--topbar-h); display: flex; align-items: center; gap: var(--sp-3);
  padding: 0 var(--sp-6); background: var(--c-surface); border-bottom: 1px solid var(--c-border);
}
.app-topbar-title { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--sp-2); }
.app-topbar-title .crumb { color: var(--c-muted); font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-topbar-actions { display: flex; align-items: center; gap: var(--sp-2); }
.icon-btn.app-menu-toggle { display: none; }

.app-user { display: flex; align-items: center; gap: var(--sp-2); padding: 4px var(--sp-2) 4px 4px; border-radius: var(--r-pill); border: 1px solid var(--c-border); background: var(--c-surface); cursor: pointer; font: inherit; color: var(--c-text); }
.app-user:hover { border-color: var(--c-border-strong); }
.app-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--c-brand-100); color: var(--c-brand-700); display: grid; place-items: center; font-weight: 700; font-size: var(--fs-sm); overflow: hidden; }
.app-avatar img { width: 100%; height: 100%; object-fit: cover; }
.app-user-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; text-align: left; }
.app-user-text strong { font-size: var(--fs-sm); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-user-text span { font-size: var(--fs-xs); color: var(--c-muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.app-content { flex: 1; width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--sp-6); }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-5); }
.page-head-text { min-width: 0; }
.page-head h1 { margin: 0; font-size: var(--fs-2xl); }
.page-head p { margin: var(--sp-1) 0 0; color: var(--c-muted); font-size: var(--fs-md); }
.page-back { display: inline-flex; align-items: center; gap: var(--sp-1); font-size: var(--fs-sm); color: var(--c-muted); text-decoration: none; margin-bottom: var(--sp-2); }
.page-back:hover { color: var(--c-brand-600); }
.page-back svg { width: 16px; height: 16px; }
.page-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }

.app-overlay { display: none; }

/* Menú desplegable (perfil, notificaciones) */
.dropdown { position: relative; }
.dropdown-panel {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 240px; max-width: min(92vw, 360px);
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg);
  box-shadow: var(--sh-3); z-index: var(--z-overlay); overflow: hidden;
}
.dropdown-head { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--c-border); font-weight: 600; font-size: var(--fs-md); }
.dropdown-item { display: flex; align-items: center; gap: var(--sp-2); width: 100%; padding: 10px var(--sp-4); background: none; border: 0; font: inherit; font-size: var(--fs-md); color: var(--c-text); text-align: left; text-decoration: none; cursor: pointer; }
.dropdown-item:hover, .dropdown-item:focus-visible { background: var(--c-surface-2); color: var(--c-text); }
.dropdown-item.is-danger { color: var(--c-danger); }
.dropdown-item svg { width: 18px; height: 18px; flex: 0 0 18px; }
.dropdown-list { max-height: 340px; overflow-y: auto; }

.icon-btn {
  position: relative; display: inline-grid; place-items: center; width: 38px; height: 38px;
  border-radius: var(--r-pill); border: 1px solid var(--c-border); background: var(--c-surface);
  color: var(--c-text-2); cursor: pointer; padding: 0;
}
.icon-btn:hover { background: var(--c-surface-2); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn .count { position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-pill); background: var(--c-danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }

/* 4. COMPONENTES ======================================================= */

/* Botones ------------------------------------------------------------- */
.btn, .cisam-btn {
  --btn-bg: var(--c-surface); --btn-fg: var(--c-text); --btn-bd: var(--c-border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 38px; padding: 0 var(--sp-4); border-radius: var(--r-md);
  border: 1px solid var(--btn-bd); background: var(--btn-bg); color: var(--btn-fg);
  font: inherit; font-size: var(--fs-md); font-weight: 600; line-height: 1; text-decoration: none;
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--c-surface-2); color: var(--btn-fg); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-primary, .btn.primary, .btn-primario, .btn-prim, .cisam-btn-primary { --btn-bg: var(--c-brand-600); --btn-fg: #fff; --btn-bd: var(--c-brand-600); }
.btn-primary:hover, .btn.primary:hover, .btn-primario:hover, .btn-prim:hover { background: var(--c-brand-700); border-color: var(--c-brand-700); color: #fff; }
.btn-success { --btn-bg: var(--c-accent-600); --btn-fg: #fff; --btn-bd: var(--c-accent-600); }
.btn-success:hover { background: #096c34; color: #fff; }
.btn-danger, .btn.danger { --btn-bg: var(--c-danger); --btn-fg: #fff; --btn-bd: var(--c-danger); }
.btn-danger:hover, .btn.danger:hover { background: #962017; color: #fff; }
.btn-warning { --btn-bg: var(--c-warning-bg); --btn-fg: var(--c-warning); --btn-bd: var(--c-warning-border); }
.btn-warning:hover { filter: brightness(.97); }
.btn-success-soft { --btn-bg: var(--c-success-bg); --btn-fg: var(--c-success); --btn-bd: var(--c-success-border); }
.btn-secondary, .btn.secondary, .btn-sec, .btn-secundario, .btn-outline, .btn-light, .btn-ghost, .cisam-btn-ghost { --btn-bg: var(--c-surface); --btn-fg: var(--c-text-2); --btn-bd: var(--c-border-strong); }
.btn-link { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--c-brand-600); padding: 0 var(--sp-2); }
.btn-sm, .btn-small, .btn-mini, .mini-btn, .link-sm { min-height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.btn-group, .btn-row, .actions, .acciones, .actions-row, .row-actions, .co-actions, .top-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }
.acciones { justify-content: flex-end; }

/* Campos -------------------------------------------------------------- */
.field, .form-group, .campo, .co-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .form-group > label, .form-label, .label, .campo > label { font-size: var(--fs-sm); font-weight: 600; color: var(--c-text-2); }
.required::after, label.required::after { content: " *"; color: var(--c-danger); }
.input, .form-input, .form-select, .field input, .field select, .field textarea,
.form-group input, .form-group select, .form-group textarea,
input[type="text"], input[type="email"], input[type="number"], input[type="date"], input[type="datetime-local"],
input[type="time"], input[type="search"], input[type="tel"], input[type="password"], input[type="url"], input[type="month"],
select, textarea {
  width: 100%; min-height: 38px; padding: 8px var(--sp-3);
  border: 1px solid var(--c-border-strong); border-radius: var(--r-md);
  background: var(--c-surface); color: var(--c-text); font: inherit; font-size: var(--fs-md);
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--c-brand-500); box-shadow: var(--focus); }
input[readonly], input:disabled, select:disabled, textarea:disabled, textarea[readonly] { background: var(--c-surface-2); color: var(--c-muted); }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--c-danger); }
.field-error { color: var(--c-danger); font-size: var(--fs-sm); }
.hint, .help-text, .form-hint { font-size: var(--fs-sm); color: var(--c-muted); }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; accent-color: var(--c-brand-600); }
.check, .check-item, .chk { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-md); color: var(--c-text-2); cursor: pointer; }
.form-grid, .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--sp-4); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-4); }
.form-row { display: flex; gap: var(--sp-4); flex-wrap: wrap; }
.form-row > * { flex: 1 1 200px; }
fieldset { border: 1px solid var(--c-border); border-radius: var(--r-lg); padding: var(--sp-4); margin: 0 0 var(--sp-4); }
legend { padding: 0 var(--sp-2); font-weight: 600; font-size: var(--fs-md); }

/* Selector con búsqueda / multiselección (usado por multiselect.js) */
.select-search { position: relative; }

/* Tarjetas ------------------------------------------------------------ */
.card, .cisam-card, .panel, .co-alert-card, .meta-card, .info-box, .miniCard {
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg);
  box-shadow: var(--sh-1); padding: var(--sp-5); min-width: 0;
}
.card + .card { margin-top: var(--sp-4); }
.card-header, .panel-header, .section-header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.card-title, .panel-title, .section-title { font-size: var(--fs-lg); font-weight: 700; color: var(--c-text); margin: 0; }
.card-subtitle, .subtitle, .sub { color: var(--c-muted); font-size: var(--fs-md); margin: 0; }
.card > .card-title:first-child { margin-bottom: var(--sp-4); }
.card-body, .panel-body { min-width: 0; }
.card-footer { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-5); padding-top: var(--sp-4); border-top: 1px solid var(--c-border); }
.section-title { margin: var(--sp-5) 0 var(--sp-3); font-size: var(--fs-base); }
.divider, hr { border: 0; border-top: 1px solid var(--c-border); margin: var(--sp-5) 0; }

/* Indicadores (KPI) */
.stats, .summary-grid, .kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-5); }
.stat, .stat-card, .kpi, .summary-card {
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg);
  padding: var(--sp-4); box-shadow: var(--sh-1); min-width: 0;
  display: flex; flex-direction: column; gap: var(--sp-1);
}
.stat-label, .kpi-label { font-size: var(--fs-sm); color: var(--c-muted); font-weight: 500; }
.stat-value, .kpi-value { font-size: 1.625rem; font-weight: 700; color: var(--c-text); line-height: 1.2; font-variant-numeric: tabular-nums; }

/* Tablas -------------------------------------------------------------- */
.table-wrap, .table-wrapper, .cisam-table-wrap {
  width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--c-border); border-radius: var(--r-lg); background: var(--c-surface);
}
.table, .cisam-table, .table-wrap table, .table-wrapper table {
  width: 100%; border-collapse: collapse; font-size: var(--fs-md);
}
.table th, .table-wrap th, .table-wrapper th, .cisam-table th {
  position: sticky; top: 0; background: var(--c-surface-2); color: var(--c-text-2);
  font-weight: 600; font-size: var(--fs-sm); text-align: left; padding: 10px var(--sp-3);
  border-bottom: 1px solid var(--c-border); white-space: nowrap;
}
.table td, .table-wrap td, .table-wrapper td, .cisam-table td { padding: 10px var(--sp-3); border-bottom: 1px solid var(--c-border); vertical-align: middle; }
.table tbody tr:last-child td, .table-wrap tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover, .table-wrap tbody tr:hover { background: #f7fbfc; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Filtros y barra de herramientas */
.toolbar, .filters, .filtros {
  display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: flex-end;
  margin-bottom: var(--sp-4);
}
.toolbar .field, .filters .field { flex: 1 1 180px; }
.filter-push { margin-left: auto; }
.search { position: relative; }

/* Paginación */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; margin-top: var(--sp-4); font-size: var(--fs-sm); color: var(--c-muted); }
.pagination-controls { display: flex; gap: var(--sp-1); }

/* Pestañas */
.tabs { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--c-border); margin-bottom: var(--sp-4); overflow-x: auto; }
.tab, .tabs [role="tab"] {
  appearance: none; border: 0; background: none; font: inherit; font-size: var(--fs-md); font-weight: 600;
  color: var(--c-muted); padding: 10px var(--sp-4); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--c-text); }
.tab.active, .tab[aria-selected="true"], .tabs [role="tab"][aria-selected="true"] { color: var(--c-brand-600); border-bottom-color: var(--c-brand-600); }

/* Insignias y estados de expediente */
.badge, .pill, .tag, .badge-estado, .topPill {
  --b-bg: var(--c-surface-2); --b-fg: var(--c-text-2); --b-bd: var(--c-border);
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--r-pill);
  background: var(--b-bg); color: var(--b-fg); border: 1px solid var(--b-bd);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.6; white-space: nowrap;
}
.badge.info, .pill.info, .badge.blue { --b-bg: var(--c-info-bg); --b-fg: var(--c-info); --b-bd: var(--c-info-border); }
.badge.success, .badge.ok, .badge.green, .pill.success { --b-bg: var(--c-success-bg); --b-fg: var(--c-success); --b-bd: var(--c-success-border); }
.badge.warning, .badge.warn, .pill.warning { --b-bg: var(--c-warning-bg); --b-fg: var(--c-warning); --b-bd: var(--c-warning-border); }
.badge.danger, .badge.red, .pill.danger { --b-bg: var(--c-danger-bg); --b-fg: var(--c-danger); --b-bd: var(--c-danger-border); }
/* Estados de expediente: data-estado="PENDIENTE" etc. (ver cisam-estados.js) */
.estado { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; border: 1px solid var(--c-border); background: var(--c-surface-2); color: var(--c-text-2); }
.estado[data-estado="PENDIENTE"], .estado[data-estado="AGENDADO"], .estado[data-estado="EN_PROCESO"] { background: var(--c-warning-bg); color: var(--c-warning); border-color: var(--c-warning-border); }
.estado[data-estado="COMPLETO"], .estado[data-estado="COMPLETADO"], .estado[data-estado="HABILITADO"], .estado[data-estado="FINALIZADO"], .estado[data-estado="APROBADO"] { background: var(--c-success-bg); color: var(--c-success); border-color: var(--c-success-border); }
.estado[data-estado="CANCELADO"], .estado[data-estado="RECHAZADO"], .estado[data-estado="NO_ASISTIO"], .estado[data-estado="ELIMINADO"] { background: var(--c-danger-bg); color: var(--c-danger); border-color: var(--c-danger-border); }
.estado[data-estado="EN_REVISION"], .estado[data-estado="TOMADO"], .estado[data-estado="CONFIRMADO"], .estado[data-estado="EN_SALA"], .estado[data-estado="ATENDIENDOSE"] { background: var(--c-info-bg); color: var(--c-info); border-color: var(--c-info-border); }

/* Estados de expediente como clase (badge-estado + variante). Mismo
   significado de color que .estado[data-estado]. */
.badge-estado.badge-pendiente, .estado-pendiente, .estado-standby { --b-bg: var(--c-warning-bg); --b-fg: var(--c-warning); --b-bd: var(--c-warning-border); }
.badge-estado.badge-proceso, .estado-agendado, .estado-atendiendose { --b-bg: var(--c-info-bg); --b-fg: var(--c-info); --b-bd: var(--c-info-border); }
.badge-estado.badge-ok, .estado-completo, .estado-habilitado { --b-bg: var(--c-success-bg); --b-fg: var(--c-success); --b-bd: var(--c-success-border); }
.badge-estado.badge-entregar, .estado-por-entregar { --b-bg: var(--c-brand-50); --b-fg: var(--c-brand-700); --b-bd: var(--c-brand-200); }
.badge-estado.badge-standby { --b-bg: var(--c-surface-2); --b-fg: var(--c-text-2); --b-bd: var(--c-border-strong); }
.badge-estado.badge-cancelado, .badge-estado.badge-vencido, .estado-cancelado, .estado-vencido, .estado-no-asistio, .estado-eliminado, .estado-rechazado { --b-bg: var(--c-danger-bg); --b-fg: var(--c-danger); --b-bd: var(--c-danger-border); }
.badge-soft { --b-bg: var(--c-surface-2); --b-fg: var(--c-text-2); --b-bd: var(--c-border); display: inline-flex; align-items: center; padding: 2px 10px; border-radius: var(--r-pill); background: var(--b-bg); color: var(--b-fg); border: 1px solid var(--b-bd); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; }
.badge-soft.badge-soft-ok { --b-bg: var(--c-success-bg); --b-fg: var(--c-success); --b-bd: var(--c-success-border); }
.badge-soft.badge-soft-warn { --b-bg: var(--c-warning-bg); --b-fg: var(--c-warning); --b-bd: var(--c-warning-border); }
.badge-soft.badge-soft-danger { --b-bg: var(--c-danger-bg); --b-fg: var(--c-danger); --b-bd: var(--c-danger-border); }
/* Botón con forma de insignia (p. ej. seguimiento pendiente / cargado) */
button.badge, button.badge-soft { cursor: pointer; font: inherit; font-size: var(--fs-xs); font-weight: 600; }
button.badge:hover, button.badge-soft:hover { filter: brightness(.97); }
button.badge:focus-visible, button.badge-soft:focus-visible { outline: none; box-shadow: var(--focus); }
/* Resalte temporal de una fila (enlace profundo ?expedienteId=) */
tr.is-destacado td { background: var(--c-brand-50); box-shadow: inset 0 1px 0 var(--c-brand-500), inset 0 -1px 0 var(--c-brand-500); }
/* Bloque de mensaje / nota (texto largo con saltos de línea) */
.nota { background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: var(--r-md); padding: var(--sp-3) var(--sp-4); white-space: pre-wrap; font-size: var(--fs-md); }
.nota + .nota { margin-top: var(--sp-2); }
.nota-titulo { font-weight: 700; margin: 0 0 2px; }
.nota-meta { font-size: var(--fs-xs); color: var(--c-muted); margin: 0 0 var(--sp-2); }
.nota-respuesta { margin-top: var(--sp-2); padding-top: var(--sp-2); border-top: 1px solid var(--c-border); color: var(--c-success); }
.nota-pendiente { margin-top: var(--sp-2); color: var(--c-danger); font-weight: 600; }

/* Avisos */
.alert, .notice, .note-box, .msg {
  display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md); border: 1px solid var(--c-info-border); background: var(--c-info-bg); color: var(--c-text);
  font-size: var(--fs-md); margin-bottom: var(--sp-4);
}
.alert-success, .msg.success, .msg.ok { border-color: var(--c-success-border); background: var(--c-success-bg); }
.alert-warning, .msg.warning { border-color: var(--c-warning-border); background: var(--c-warning-bg); }
.alert-danger, .alert-error, .msg.error, .msg.danger { border-color: var(--c-danger-border); background: var(--c-danger-bg); }
.msg:empty { display: none; }

/* Notificaciones emergentes */
.toasts { position: fixed; right: var(--sp-5); bottom: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); z-index: var(--z-toast); max-width: min(92vw, 380px); }
.toast { background: var(--c-text); color: #fff; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); box-shadow: var(--sh-3); font-size: var(--fs-md); }
.toast.is-error { background: var(--c-danger); }
.toast.is-success { background: var(--c-accent-600); }

/* Estados de carga, vacío y error */
.state, .empty, .empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: var(--sp-8) var(--sp-4); color: var(--c-muted); text-align: center; font-size: var(--fs-md);
}
.state-error { color: var(--c-danger); }
.state .spinner, .spinner {
  width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--c-brand-100); border-top-color: var(--c-brand-600);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.is-loading .stat-value, .skeleton { color: transparent !important; background: linear-gradient(90deg, #eef2f4 25%, #f7f9fa 50%, #eef2f4 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--r-sm); }
@keyframes shimmer { to { background-position: -200% 0; } }
[aria-busy="true"] { cursor: progress; }

/* Modales (accesibles: role="dialog" aria-modal="true") */
.modal-backdrop, .modal-overlay {
  position: fixed; inset: 0; background: rgba(11, 33, 45, .5); z-index: var(--z-modal);
  display: flex; align-items: center; justify-content: center; padding: var(--sp-4);
}
.modal-backdrop.hidden, .modal-overlay.hidden { display: none; }
.modal, [role="dialog"].modal {
  background: var(--c-surface); border-radius: var(--r-lg); box-shadow: var(--sh-3);
  width: min(640px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; overflow: hidden;
}
.modal.modal-lg { width: min(960px, 100%); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--c-border); }
.modal-header h2, .modal-header h3 { margin: 0; font-size: var(--fs-lg); }
.modal-body { padding: var(--sp-5); overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--c-border); background: var(--c-surface-2); }
body.modal-open { overflow: hidden; }

/* Carga de archivos */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: var(--sp-6); border: 2px dashed var(--c-border-strong); border-radius: var(--r-lg);
  background: var(--c-surface-2); color: var(--c-muted); text-align: center; cursor: pointer;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--c-brand-500); background: var(--c-brand-50); color: var(--c-brand-700); }
.file-list { list-style: none; margin: var(--sp-3) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.file-item { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-2) var(--sp-3); border: 1px solid var(--c-border); border-radius: var(--r-md); font-size: var(--fs-md); }
input[type="file"] { font: inherit; font-size: var(--fs-sm); max-width: 100%; }

/* Listas de datos (definición) */
.data-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--sp-3) var(--sp-5); margin: 0; }
.data-list dt, .info-label, .data-label, .k { font-size: var(--fs-xs); color: var(--c-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.data-list dd, .info-value, .data-value, .v { margin: 2px 0 0; font-size: var(--fs-md); color: var(--c-text); word-break: break-word; }

/* Chat flotante (widget global de la cabecera) */
.chat-widget { position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: var(--z-overlay); }
.chat-toggle { width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--c-brand-600); color: #fff; box-shadow: var(--sh-3); cursor: pointer; display: grid; place-items: center; }
.chat-toggle.has-new { background: var(--c-danger); }
.chat-toggle svg { width: 24px; height: 24px; }
.chat-window { position: absolute; right: 0; bottom: 64px; width: min(92vw, 380px); height: min(70vh, 520px); background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-lg); box-shadow: var(--sh-3); display: flex; flex-direction: column; overflow: hidden; }
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--c-border); font-weight: 600; }
.chat-body { flex: 1; display: grid; grid-template-columns: 136px 1fr; min-height: 0; }
.chat-threads { border-right: 1px solid var(--c-border); overflow-y: auto; }
.chat-thread { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--c-border); padding: var(--sp-2) var(--sp-3); font: inherit; font-size: var(--fs-sm); cursor: pointer; }
.chat-thread[aria-current="true"] { background: var(--c-brand-50); }
.chat-thread small { display: block; color: var(--c-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-thread .count { float: right; background: var(--c-danger); color: #fff; border-radius: var(--r-pill); padding: 0 6px; font-size: 11px; }
.chat-messages { display: flex; flex-direction: column; min-height: 0; }
.chat-list { flex: 1; overflow-y: auto; padding: var(--sp-2); background: var(--c-surface-2); }
.chat-msg { max-width: 80%; margin: var(--sp-1) 0; padding: var(--sp-2) var(--sp-3); border-radius: var(--r-md); background: var(--c-surface); border: 1px solid var(--c-border); font-size: var(--fs-sm); white-space: pre-wrap; word-break: break-word; }
.chat-msg.is-mine { margin-left: auto; background: var(--c-accent-50); border-color: var(--c-success-border); }
.chat-msg .who { display: block; font-size: 11px; font-weight: 700; color: var(--c-brand-600); }
.chat-msg time { display: block; text-align: right; font-size: 10px; color: var(--c-muted); }
.chat-compose { display: flex; gap: var(--sp-2); padding: var(--sp-2); border-top: 1px solid var(--c-border); }
.chat-compose textarea { min-height: 38px; height: 38px; }

/* Página de acceso denegado / error */
.page-status { max-width: 520px; margin: var(--sp-10) auto; text-align: center; }
.page-status h1 { font-size: var(--fs-xl); }

/* 5. UTILIDADES ======================================================== */
.muted, .text-muted, .small, small { color: var(--c-muted); }
.small, small { font-size: var(--fs-sm); }
.mono { font-family: var(--font-mono); }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: var(--sp-4); }
.row-flex { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.text-right { text-align: right; }
.w-100 { width: 100%; }

/* ADAPTABLE ============================================================ */
@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .app-sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--sh-3); }
  body.nav-open .app-sidebar { transform: none; }
  body.nav-open .app-overlay { display: block; position: fixed; inset: 0; background: rgba(11,33,45,.45); z-index: calc(var(--z-sidebar) - 1); }
  .app-main { margin-left: 0; }
  .icon-btn.app-menu-toggle { display: inline-grid; }
  .app-topbar { padding: 0 var(--sp-3); }
  .app-content { padding: var(--sp-4) var(--sp-3); }
  .app-user-text { display: none; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .page-head h1 { font-size: var(--fs-xl); }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }
  .card, .panel { padding: var(--sp-4); }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 92vh; }
  .chat-body { grid-template-columns: 1fr; }
  .chat-threads { max-height: 120px; border-right: 0; border-bottom: 1px solid var(--c-border); }
  /* Tablas: desplazamiento horizontal dentro de su contenedor, nunca de la página */
  .table-wrap, .table-wrapper { border-radius: var(--r-md); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* IMPRESIÓN: nunca se imprime la estructura de la aplicación */
@media print {
  .app-sidebar, .app-topbar, .chat-widget, .toasts, .no-print, .page-actions { display: none !important; }
  .app-main { margin: 0 !important; }
  .app-content { padding: 0 !important; max-width: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #bbb; }
}

/* Tarjetas dispuestas en rejilla: sin margen de apilado */
.grid > .card, .grid-2 > .card, .grid-3 > .card, .grid-4 > .card, .form-grid > .card { margin-top: 0; }

/* Botones de acción con ícono (public/js/cisam-iconos.js) y su rótulo */
.btn.btn-icono { width: 30px; min-width: 30px; height: 30px; min-height: 30px; padding: 0; justify-content: center; gap: 0; flex-shrink: 0; }
.btn.btn-sm.btn-icono { width: 28px; min-width: 28px; height: 28px; min-height: 28px; }
.btn.btn-icono svg { width: 15px; height: 15px; display: block; }
.cisam-tip {
  position: fixed; z-index: 3000; max-width: 240px; padding: 4px 8px; border-radius: var(--r-sm);
  background: #1f2937; color: #fff; font-size: 12px; font-weight: 600; line-height: 1.3;
  pointer-events: none; box-shadow: 0 2px 8px rgba(0,0,0,.25); white-space: nowrap;
}
.cisam-tip[hidden] { display: none; }

/* ---------- Dictamen del certificado (panel lateral, /js/dictamen-certificado.js) ---------- */
.dictamen-panel {
  position: fixed; z-index: 900; right: 16px; top: calc(var(--topbar-h, 60px) + 12px); bottom: 88px;
  width: min(380px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: var(--sp-2);
  padding: var(--sp-4); background: var(--c-surface); color: var(--c-text);
  border: 1px solid var(--c-border-strong); border-radius: var(--r-lg); box-shadow: var(--sh-3);
}
.dictamen-panel[hidden] { display: none; }
.dictamen-cab { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.dictamen-cab h2 { margin: 0; font-size: var(--fs-md); }
.dictamen-ayuda { margin: 0; color: var(--c-muted); font-size: var(--fs-sm); line-height: 1.4; }
.dictamen-panel textarea {
  flex: 1; min-height: 160px; width: 100%; box-sizing: border-box; resize: none; padding: var(--sp-3);
  border: 1px solid var(--c-border-strong); border-radius: var(--r-md); background: var(--c-surface); color: var(--c-text);
  font: inherit; line-height: 1.45;
}
.dictamen-panel textarea:focus-visible { outline: 2px solid var(--c-brand-500); outline-offset: 1px; }
.dictamen-panel textarea[readonly] { background: var(--c-surface-2); }
.dictamen-pie { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.dictamen-estado { font-size: var(--fs-xs); color: var(--c-muted); }
.dictamen-estado[data-tipo="ok"] { color: var(--c-success); }
.dictamen-estado[data-tipo="error"] { color: var(--c-danger); }
.dictamen-estado[data-tipo="pendiente"] { color: var(--c-warning); }
/* Deja libre la parte del formulario que queda debajo del panel. */
@media (min-width: 1200px) { body.con-dictamen .app-main { padding-right: 396px; } }
@media (max-width: 700px) {
  .dictamen-panel { top: auto; bottom: 0; right: 0; left: 0; width: auto; height: 55vh; border-radius: 12px 12px 0 0; }
}
