/* ==========================================================================
   MATRON UI FRAMEWORK v2.0
   Sistema de diseño congruente, responsivo y moderno.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
  /* --- PALETA DE COLORES (Slate & Blue) --- */
  /* Neutros (Slate) */
  --slate-50: #f8fafc;
  --slate-100: #f1f5f9;
  --slate-200: #e2e8f0;
  --slate-300: #cbd5e1;
  --slate-400: #94a3b8;
  --slate-500: #64748b;
  --slate-600: #475569;
  --slate-700: #334155;
  --slate-800: #1e293b;
  --slate-900: #0f172a;
  --slate-950: #020617;

  /* Primario (Blue/Sky) */
  --primary-50: #f0f9ff;
  --primary-100: #e0f2fe;
  --primary-200: #bae6fd;
  --primary-300: #7dd3fc;
  --primary-400: #38bdf8;
  --primary-500: #0ea5e9;
  --primary-600: #0284c7;
  --primary-700: #0369a1;
  --primary-800: #075985;
  --primary-900: #0c4a6e;

  /* Semánticos (Estado) */
  --success-bg: #ecfdf5; --success-text: #059669; --success-border: #a7f3d0;
  --warning-bg: #fffbeb; --warning-text: #d97706; --warning-border: #fde68a;
  --danger-bg: #fef2f2; --danger-text: #dc2626; --danger-border: #fecaca;
  --info-bg: #eff6ff; --info-text: #2563eb; --info-border: #bfdbfe;

  /* --- VARIABLES DE TEMA --- */
  --color-bg: var(--slate-100);
  --color-bg-subtle: var(--slate-50);
  --color-surface: #ffffff;
  --color-surface-hover: var(--slate-50);
  
  --color-text: var(--slate-900);
  --color-text-secondary: var(--slate-600);
  --color-text-muted: var(--slate-400);
  --color-text-inverse: #ffffff;

  --color-border: var(--slate-200);
  --color-border-hover: var(--slate-300);
  --color-border-focus: var(--primary-500);

  --color-primary: var(--primary-600);
  --color-primary-hover: var(--primary-700);
  --color-primary-subtle: var(--primary-50);
  --color-primary-text: var(--primary-700);

  /* --- TIPOGRAFÍA --- */
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --text-xs: 0.75rem;   /* 12px */
  --text-sm: 0.875rem;  /* 14px */
  --text-base: 1rem;    /* 16px */
  --text-lg: 1.125rem;  /* 18px */
  --text-xl: 1.25rem;   /* 20px */
  --text-2xl: 1.5rem;   /* 24px */
  
  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;

  /* --- ESPACIADO & RADIOS --- */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  /* --- SOMBRAS (Elevación) --- */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);

  /* --- LAYOUT --- */
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --container-max: 1280px;

  /* --- TRANSICIONES --- */
  --transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   RESET & BASE
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  scroll-behavior: smooth;
  max-width: 100%;
  overflow-x: hidden;
}
/* Firefox / Chromium recientes: barra fina; Chrome/Safari antiguos usan ::-webkit-scrollbar abajo */
@supports (scrollbar-width: thin) {
  html {
    scrollbar-width: thin;
    scrollbar-color: var(--slate-300) transparent;
  }
}
html::-webkit-scrollbar { width: 6px; }
html::-webkit-scrollbar-track { background: transparent; }
html::-webkit-scrollbar-thumb { background: var(--slate-300); border-radius: 99px; }
html::-webkit-scrollbar-thumb:hover { background: var(--slate-400); }

body {
  font-family: var(--font-sans);
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  overflow-x: hidden;
}

a { color: var(--color-primary); text-decoration: none; transition: var(--transition-base); }
a:hover { color: var(--color-primary-hover); }

img, svg, video { display: block; max-width: 100%; height: auto; }

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

.app-with-sidebar {
  display: flex;
  flex: 1;
  position: relative;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* --- Topbar --- */
.topbar {
  height: var(--topbar-height);
  background: var(--slate-900);
  color: var(--color-text-inverse);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 130;
  box-shadow: var(--shadow-md);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.025em;
}
.topbar__brand a { color: inherit; }
.topbar__brand-icon { width: 32px; height: 32px; color: var(--primary-400); }

.topbar__actions { display: flex; align-items: center; gap: 0.75rem; }
.topbar__user { display: flex; align-items: center; gap: 0.75rem; }
.topbar__user-info { text-align: right; line-height: 1.2; }
.topbar__user-name { display: block; font-weight: 600; font-size: 0.9rem; }
.topbar__user-role { display: block; font-size: 0.75rem; color: var(--slate-400); }

.topbar__menu-btn {
  display: none; /* Desktop hidden */
  background: transparent;
  border: none;
  color: white;
  padding: 0.5rem;
  cursor: pointer;
}
.topbar__menu-btn .feather { width: 24px; height: 24px; }

/* Topbar: contexto, búsqueda, notificaciones (evita style="" para CSP) */
.topbar__badge-ellipsis {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  vertical-align: middle;
}
.topbar__context-form {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
}
.topbar__context-select {
  width: 220px;
  height: 32px;
  padding: 0 0.5rem;
  font-size: 0.8rem;
}
.topbar__context-select--narrow {
  width: 180px;
}
.topbar__context-submit {
  height: 32px;
}
#open-command-palette {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
#open-command-palette .feather {
  width: 18px;
  height: 18px;
}
.cmd-palette__kbd {
  display: none;
}
.topbar__notif-wrapper {
  position: relative;
}
#topbar-notifications-btn {
  position: relative;
  z-index: 1;
}
#topbar-notifications-btn .feather {
  width: 18px;
  height: 18px;
  pointer-events: none;
}
#topbar-notifications-badge {
  margin-left: 4px;
  min-width: 16px;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  pointer-events: none;
}
#topbar-notifications-badge.topbar__notif-badge--hidden {
  display: none;
}
#topbar-notifications-badge.topbar__notif-badge--visible {
  display: inline-flex;
}
#topbar-notifications-panel {
  position: absolute;
  right: 0;
  top: 110%;
  width: 380px;
  max-width: min(92vw, 380px);
  max-height: 360px;
  overflow-y: auto;
  overflow-x: hidden;
  display: none;
  z-index: 50;
}
#topbar-notifications-panel.is-open {
  display: block;
}
.topbar__notif-mark-form {
  margin-left: auto;
}
.topbar__notif-mark-form .btn {
  font-size: 0.8rem;
}
.topbar__avatar-img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--primary-100);
}
.topbar__avatar-btn .feather[data-feather="chevron-down"] {
  width: 14px;
  height: 14px;
  opacity: 0.7;
}
.topbar__avatar-dropdown__item--danger {
  color: var(--danger-text);
}
/* Lista de notificaciones (render JS) */
.topbar-notif-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.topbar-notif-item {
  padding: 6px 0;
  border-bottom: 1px solid var(--color-border);
}
.topbar-notif-item:last-child {
  border-bottom: none;
}
.topbar-notif-title {
  font-size: 0.9rem;
}
.topbar-notif-title--unread {
  font-weight: 600;
}
.topbar-notif-title--read {
  opacity: 0.7;
}
.topbar-notif-msg,
.topbar-notif-date {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}
.topbar-notif-date {
  margin-top: 2px;
}

/* --- Sidebar --- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 40;
  transition: transform var(--transition-base);
}
@supports (scrollbar-width: thin) {
  .sidebar {
    scrollbar-width: thin;
    scrollbar-color: var(--slate-200) transparent;
  }
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--slate-200); border-radius: 99px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: var(--slate-300); }

/* Mini-perfil de usuario en el sidebar */
.sidebar__user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1rem 0.875rem;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 0.25rem;
  min-width: 0;
}
.sidebar__user-avatar {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary-100);
  color: var(--primary-700);
  font-size: 0.85rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  letter-spacing: 0;
}
.sidebar__user-info { min-width: 0; flex: 1; }
.sidebar__user-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
.sidebar__user-role {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.sidebar__search {
  padding: 0.75rem 1rem 0;
}
.sidebar__search-input {
  position: relative;
  display: flex;
  align-items: center;
}
.sidebar__search-icon {
  width: 15px !important;
  height: 15px !important;
  position: absolute;
  left: 0.6rem;
  color: var(--color-text-muted);
  pointer-events: none;
}
.sidebar__search-control {
  padding-left: 1.7rem;
  font-size: 0.78rem;
  border-radius: 999px;
}
.sidebar__nav { padding: 0.625rem 0.75rem 1rem; display: flex; flex-direction: column; gap: 0.125rem; }
.sidebar__nav--with-search { padding-top: 0.5rem; }

.sidebar__link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.575rem 0.75rem;
  color: var(--color-text-secondary);
  font-weight: 500;
  font-size: 0.875rem;
  border-radius: var(--radius-md);
  transition: background 0.15s ease, color 0.15s ease;
  position: relative;
  border-left: 3px solid transparent;
}
.sidebar__link:hover {
  background-color: var(--slate-100);
  color: var(--color-text);
  border-left-color: var(--slate-300);
}
.sidebar__link.active {
  background-color: var(--primary-50);
  color: var(--color-primary);
  font-weight: 600;
  border-left-color: var(--color-primary);
}
.sidebar__link .feather {
  width: 1.1rem;
  height: 1.1rem;
  stroke-width: 2px;
  flex-shrink: 0;
  opacity: 0.75;
  transition: opacity 0.15s;
}
.sidebar__link:hover .feather,
.sidebar__link.active .feather { opacity: 1; }

/* Links anidados (dentro de grupos) */
.sidebar__link--nested {
  font-size: 0.85rem;
  padding-left: 2.25rem;
  border-left: none;
  position: relative;
}
.sidebar__link--nested::before {
  content: '';
  position: absolute;
  left: 1.1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--slate-300);
  transition: background 0.15s;
}
.sidebar__link--nested:hover::before { background: var(--slate-500); }
.sidebar__link--nested.active::before { background: var(--color-primary); }
.sidebar__link--nested.active {
  background-color: var(--primary-50);
  color: var(--color-primary);
  font-weight: 600;
}

/* Grupos del sidebar (Acordeón) */
.sidebar__group { margin-top: 0.25rem; }
.sidebar__group-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--slate-400);
  font-weight: 700;
  cursor: pointer;
  border-radius: var(--radius-sm);
  -webkit-user-select: none;
  user-select: none;
  list-style: none;
  transition: color 0.15s;
}
.sidebar__group-header:hover { color: var(--slate-600); }
.sidebar__group-header--active { color: var(--primary-600); }

/* Sidebar AJAX progressive loading */
#main-content.is-loading-ajax {
  position: relative;
}
.sidebar-ajax-loading {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 1rem;
  text-align: center;
  color: var(--color-text-muted);
  background: var(--color-bg);
  z-index: 5;
}
.sidebar__group-icon {
  width: 0.85rem !important;
  height: 0.85rem !important;
  stroke-width: 2.5px;
  transition: transform 0.2s ease;
  flex-shrink: 0;
  margin-left: auto;
  order: 1;
}
.sidebar__group[open] > summary .sidebar__group-icon { transform: rotate(180deg); }
.sidebar__group-header > span:not(.feather) { order: 0; }
.sidebar__group-body { display: flex; flex-direction: column; gap: 0.125rem; padding-bottom: 0.25rem; }

/* Botón cerrar sidebar (móvil) */
.sidebar__close {
  display: none;
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: var(--slate-100);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: var(--radius-full);
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  z-index: 10;
}
.sidebar__close:hover { background: var(--slate-200); color: var(--color-text); }
.sidebar__close .feather { width: 14px; height: 14px; stroke-width: 2.5px; }

/* --- Main Content --- */
.main-content {
  flex: 1;
  padding: 2rem;
  max-width: 100%;
  overflow-x: hidden;
  overflow-wrap: break-word;
  word-break: break-word;
}

.main-content__inner {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

/* ==========================================================================
   COMPONENTES
   ========================================================================== */

/* --- Botones --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition-base);
  line-height: 1.5;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn .feather { width: 1.125rem; height: 1.125rem; }

/* Variantes */
.btn-primary {
  background-color: var(--color-primary);
  color: white;
  border-color: transparent;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) { background-color: var(--color-primary-hover); box-shadow: var(--shadow-md); }

.btn-secondary {
  background-color: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover:not(:disabled) { background-color: var(--slate-50); border-color: var(--color-border-hover); }

.btn-ghost {
  background-color: transparent;
  color: var(--color-text-secondary);
}
.btn-ghost:hover:not(:disabled) { background-color: var(--slate-100); color: var(--color-text); }
.btn-ghost-light { background: transparent; color: white; }
.btn-ghost-light:hover { background: rgba(255,255,255,0.1); }

.btn-danger {
  background-color: var(--danger-bg);
  color: var(--danger-text);
  border-color: transparent;
}
.btn-danger:hover:not(:disabled) { background-color: #fee2e2; border-color: var(--danger-border); }

.btn-link { padding: 0; background: none; color: var(--color-primary); text-decoration: underline; }
.btn-link:hover { color: var(--color-primary-hover); }

/* Tamaños */
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-icon { padding: 0.5rem; aspect-ratio: 1/1; }

/* --- Tarjetas (Cards) --- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 1.5rem;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.card:hover { box-shadow: var(--shadow-md); border-color: var(--slate-300); }
.card__header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--slate-50);
}
.card__header span {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--color-text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.8rem;
}
.card__body { padding: 1.5rem; }
.card__footer { padding: 1rem 1.5rem; background: var(--slate-50); border-top: 1px solid var(--color-border); }

/* --- Formularios --- */
.form-group { margin-bottom: 1.25rem; }
.form-label { display: block; margin-bottom: 0.375rem; font-weight: 500; font-size: 0.875rem; color: var(--color-text); }
.form-control {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--color-text);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: var(--transition-base);
}
.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-control::placeholder { color: var(--color-text-muted); }
.form-hint { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 0.25rem; }
.form-error { font-size: 0.8rem; color: var(--danger-text); margin-top: 0.25rem; }

/* Select wrapper */
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e"); background-repeat: no-repeat; background-position: right 0.75rem center; background-size: 16px 12px; padding-right: 2.5rem; }

/* File input — styled button */
input[type="file"].form-control { padding: 0; border: none; background: none; }
input[type="file"].form-control::file-selector-button {
  padding: 0.5rem 1rem; margin-right: 0.75rem;
  font-family: inherit; font-size: 0.8125rem; font-weight: 500; line-height: 1.5;
  color: #fff; background: #1e3a5f; border: 1.5px solid #1e3a5f; border-radius: 6px;
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
input[type="file"].form-control::file-selector-button:hover { background: #15304f; border-color: #15304f; }
input[type="file"].form-control:disabled::file-selector-button { opacity: 0.5; cursor: not-allowed; }

/* --- Tablas --- */
.tabla-responsive {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
}
.tabla {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  white-space: nowrap;
}
.tabla thead th {
  background-color: var(--slate-50);
  color: var(--slate-500);
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}
.tabla tbody td {
  padding: 0.7rem 1rem;
  color: var(--color-text);
  border-bottom: 1px solid var(--slate-100);
  vertical-align: middle;
  transition: background 0.1s;
}
.tabla tbody tr:nth-child(even) td { background-color: var(--slate-50); }
.tabla tbody tr:last-child td { border-bottom: none; }
.tabla tbody tr:hover td {
  background-color: var(--primary-50) !important;
  color: var(--color-text);
}
/* Botones compactos dentro de tablas */
.tabla .btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.78rem;
  border-radius: var(--radius-sm);
}
.tabla .btn-ghost {
  color: var(--slate-500);
}
.tabla .btn-ghost:hover {
  color: var(--color-primary);
  background: var(--primary-50);
}
/* Empty state de tabla */
.tabla-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-muted);
}
.tabla-empty .feather {
  width: 2.5rem;
  height: 2.5rem;
  margin: 0 auto 0.75rem;
  opacity: 0.3;
  display: block;
}
.tabla-empty p { font-size: 0.9rem; }

/* --- Badges / Chips --- */
.badge, .chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  line-height: 1.4;
  border: 1px solid transparent;
  letter-spacing: 0.02em;
}
.badge--primary, .chip--primary { background: var(--primary-100); color: var(--primary-700); border-color: var(--primary-200); }
.badge--success, .chip--success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }
.badge--warning, .chip--warning { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.badge--danger,  .chip--danger  { background: var(--danger-bg); color: var(--danger-text); border-color: var(--danger-border); }
.badge--secondary, .chip--secondary { background: var(--slate-100); color: var(--slate-600); border-color: var(--slate-200); }
.badge--info,    .chip--info    { background: var(--info-bg); color: var(--info-text); border-color: var(--info-border); }
/* Dot indicator en badge */
.badge::before, .chip::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
  flex-shrink: 0;
  display: none;
}
.badge--dot::before, .chip--dot::before { display: block; }

/* --- Alertas --- */
.alert {
  padding: 1rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  display: flex;
  gap: 0.75rem;
  font-size: 0.9rem;
  border: 1px solid transparent;
}
.alert-success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }
.alert-danger { background: var(--danger-bg); color: var(--danger-text); border-color: var(--danger-border); }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.alert-info { background: var(--info-bg); color: var(--info-text); border-color: var(--info-border); }
.impersonation-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}
.impersonation-banner__origin {
  font-size: 0.85rem;
}
.impersonation-banner__form {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

/* --- Dialog nativo (<dialog> element) --- */
dialog.modal-dialog {
  position: fixed;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  margin: 0 !important;
  width: 90%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--color-surface);
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  padding: 0;
  z-index: 9999;
}
dialog.modal-dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

/* --- Modal overlay (pantalla completa centrada) --- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.55);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
  max-width: none;
  border-radius: 0;
  transform: none;
}
.modal-overlay .modal__content {
  margin: auto;
  max-width: 540px;
  width: 100%;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

/* --- Modales --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s;
}
.modal-backdrop.is-visible { opacity: 1; visibility: visible; }

.modal {
  background: var(--color-surface);
  width: 100%;
  max-width: 500px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  transform: scale(0.95);
  transition: transform 0.2s;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-backdrop.is-visible .modal { transform: scale(1); }
.modal__header { padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--color-border); display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 1.1rem; }

/* --- MatronConfirm / MatronAlert (JS dialogs) --- */
.matron-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
.matron-modal-backdrop.is-visible { opacity: 1; visibility: visible; }
.matron-modal {
  background: var(--color-surface);
  width: 100%;
  max-width: 440px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  padding: 1.75rem 1.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  transform: scale(0.94);
  transition: transform 0.2s ease;
  text-align: center;
}
.matron-modal-backdrop.is-visible .matron-modal { transform: scale(1); }
.matron-modal__icon { font-size: 2rem; margin-bottom: 0.25rem; line-height: 1; }
.matron-modal__icon .feather { width: 2rem; height: 2rem; }
.matron-modal__icon--warning .feather { color: #d97706; }
.matron-modal__icon--danger  .feather { color: #dc2626; }
.matron-modal__icon--success .feather { color: #059669; }
.matron-modal__icon--info    .feather { color: #0284c7; }
.matron-modal__title   { font-size: 1.1rem; font-weight: 700; margin: 0; color: var(--color-text); }
.matron-modal__message { font-size: 0.9rem; color: var(--color-text-muted); margin: 0.25rem 0 0.75rem; }
.matron-modal__footer  { display: flex; gap: 0.75rem; justify-content: center; margin-top: 0.5rem; flex-wrap: wrap; }
@media (max-width: 480px) {
  .matron-modal { padding: 1.25rem; }
  .matron-modal__footer .btn { flex: 1; justify-content: center; }
}
.modal__body { padding: 1.5rem; overflow-y: auto; }
.modal__footer { padding: 1rem 1.5rem; background: var(--slate-50); border-top: 1px solid var(--color-border); display: flex; justify-content: flex-end; gap: 0.75rem; }
.modal__close { background: transparent; border: none; cursor: pointer; color: var(--color-text-muted); }
.modal__close:hover { color: var(--color-text); }

/* --- Toast --- */
.toast-container {
  position: fixed;
  top: 5rem;
  right: 1.5rem;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  padding: 1rem 1.25rem;
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 280px;
  pointer-events: auto;
  animation: toastIn 0.35s var(--transition-base);
}
@keyframes toastIn { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }
.toast.toast-success { border-left: 4px solid var(--success-text); }
.toast.toast-danger { border-left: 4px solid var(--danger-text); }
.toast.toast-warning { border-left: 4px solid var(--warning-text); }

/* --- Breadcrumbs --- */
.breadcrumb { margin-bottom: 1.25rem; }
.breadcrumb__list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  list-style: none;
  padding: 0;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  align-items: center;
}
.breadcrumb__item { display: flex; align-items: center; gap: 0.25rem; }
.breadcrumb__link {
  color: var(--slate-400);
  font-weight: 500;
  padding: 0.1rem 0.25rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}
.breadcrumb__link:hover { color: var(--color-primary); background: var(--primary-50); }
.breadcrumb__item:last-child .breadcrumb__link,
.breadcrumb__item:last-child span[aria-current] {
  color: var(--color-text);
  font-weight: 600;
}
.breadcrumb__sep { opacity: 0.35; color: var(--slate-400); }
.breadcrumb__sep .feather { width: 12px; height: 12px; }

/* --- Page Header --- */
.page-header {
  margin-bottom: 1.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.page-header__title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--color-text);
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-bottom: 0.25rem;
}
.page-header__desc {
  color: var(--color-text-muted);
  font-size: 0.875rem;
  font-weight: 400;
}
/* Empty state reutilizable */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3.5rem 2rem;
  text-align: center;
  color: var(--color-text-muted);
}
.empty-state .feather {
  width: 3rem;
  height: 3rem;
  margin-bottom: 1rem;
  opacity: 0.25;
  display: block;
}
.empty-state__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 0.375rem;
}
.empty-state__desc { font-size: 0.875rem; }

/* --- Kanban --- */
.kanban-board { display: flex; gap: 1rem; overflow-x: auto; padding-bottom: 1rem; min-height: 500px; }
.kanban-column { flex: 0 0 300px; background: var(--slate-100); border-radius: var(--radius-lg); border: 1px solid var(--color-border); display: flex; flex-direction: column; }
.kanban-column__header { padding: 1rem; font-weight: 700; border-bottom: 1px solid var(--color-border); display: flex; justify-content: space-between; align-items: center; }
.kanban-column__count { background: var(--color-surface); padding: 0.1rem 0.5rem; border-radius: var(--radius-full); font-size: 0.75rem; }
.kanban-column__cards { padding: 0.75rem; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.75rem; }
.kanban-card { background: var(--color-surface); padding: 1rem; border-radius: var(--radius-md); box-shadow: var(--shadow-sm); border: 1px solid var(--color-border); cursor: default; transition: var(--transition-base); position: relative; }
.kanban-card:hover { box-shadow: var(--shadow-md); border-color: var(--color-border-hover); }
.kanban-card__title { font-weight: 600; margin-bottom: 0.25rem; }
.kanban-card__title-link { display: block; font-weight: 600; margin-bottom: 0.25rem; color: var(--color-text); text-decoration: none; }
.kanban-card__title-link:hover { color: var(--color-primary); text-decoration: underline; }
.kanban-card__desc { font-size: 0.8rem; color: var(--color-text-secondary); margin-bottom: 0.5rem; }
.kanban-card__meta { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.kanban-card__link { background: none; border: none; padding: 0; margin: 0; cursor: pointer; color: var(--color-primary); font-size: 0.85rem; font-weight: 500; text-decoration: underline; display: inline-block; }
.kanban-card__link:hover { color: var(--color-primary-dark, var(--color-primary)); text-decoration: none; }
.kanban-drag-handle { position: absolute; top: 0.5rem; right: 0.5rem; cursor: grab; color: var(--color-text-muted); font-size: 1rem; line-height: 1; -webkit-user-select: none; user-select: none; padding: 2px 4px; border-radius: 3px; }
.kanban-drag-handle:hover { background: var(--color-bg); color: var(--color-text); }
.kanban-card { position: relative; }
.kanban-subcolumn { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.kanban-subcolumn__header { padding: 0.5rem 0.75rem; font-size: 0.8rem; font-weight: 600; border-bottom: 1px solid var(--color-border); display: flex; justify-content: space-between; align-items: center; background: var(--color-surface); }
.kanban-subcolumn__title { color: var(--color-text); }
.kanban-subcolumn__count { background: var(--color-surface); padding: 0.1rem 0.4rem; border-radius: var(--radius-full); font-size: 0.7rem; color: var(--color-text-muted); }
.kanban-subcolumn__cards { padding: 0.5rem; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 0.5rem; }

/* --- Auth Pages --- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--slate-900); padding: 1rem; }
.auth-card { width: 100%; max-width: 420px; background: var(--color-surface); padding: 2.5rem; border-radius: var(--radius-xl); box-shadow: var(--shadow-xl); }
.auth-card__logo { margin-bottom: 1.5rem; color: var(--color-primary); }
.auth-card__title { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.5rem; }
.auth-card__subtitle { color: var(--color-text-secondary); margin-bottom: 2rem; }

/* --- Business Model Canvas --- */
.canvas-modelo-negocio { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1rem; margin-bottom: 2rem; }
@media (max-width: 1024px) { .canvas-modelo-negocio { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 768px) { .canvas-modelo-negocio { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .canvas-modelo-negocio { grid-template-columns: 1fr; } }
.canvas-cell { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: 1rem; display: flex; flex-direction: column; }
.canvas-label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: var(--color-text-muted); margin-bottom: 0.5rem; }
.canvas-textarea { flex: 1; border: 1px solid var(--color-border); background: var(--slate-50); border-radius: var(--radius-md); padding: 0.5rem; width: 100%; min-height: 100px; }

/* --- FABs (Ayuda/Búsqueda) --- */
.fab {
  position: fixed;
  bottom: 1.25rem;
  height: 48px;
  min-width: 48px;
  padding: 0 1.1rem;
  border-radius: 999px;
  color: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18), 0 1px 4px rgba(0,0,0,0.1);
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  z-index: 120;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  font-weight: 600;
  transition: box-shadow 0.18s ease, transform 0.18s ease, background 0.18s ease;
  white-space: nowrap;
}
.fab:hover, .fab:focus-visible {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.22), 0 2px 6px rgba(0,0,0,0.12);
  outline: none;
}
.fab:active { transform: translateY(0); box-shadow: 0 2px 8px rgba(0,0,0,0.16); }
.fab .feather { width: 19px; height: 19px; flex-shrink: 0; pointer-events: none; }
.fab__label { font-size: 0.82rem; font-weight: 600; letter-spacing: 0.01em; }
.fab--help { right: 1.25rem; left: auto; background: var(--color-primary); }
.fab--help:hover { background: #1d4ed8; }
.fab--search { left: 1.25rem; right: auto; background: #0891b2; }
.fab--search:hover { background: #0e7490; }
/* Speed-dial trigger — hidden on desktop */
.fab--trigger { display: none; }
/* Speed-dial backdrop */
.fab-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 118;
}
@media (max-width: 768px) {
  .fab { height: 46px; padding: 0 0.95rem; bottom: 1.1rem; }
}
/* ── Speed dial mobile (≤640px) ─────────────────────── */
@media (max-width: 640px) {
  /* Trigger button */
  .fab--trigger {
    display: inline-flex;
    right: 1rem;
    left: auto;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    width: 52px;
    height: 52px;
    min-width: 52px;
    padding: 0;
    background: linear-gradient(135deg, #0369a1 0%, #7c3aed 100%);
    box-shadow: 0 4px 20px rgba(3,105,161,0.45), 0 2px 6px rgba(0,0,0,0.15);
    z-index: 122;
    transition: transform 0.22s cubic-bezier(.34,1.56,.64,1), box-shadow 0.18s;
  }
  .fab--trigger:hover, .fab--trigger:focus-visible {
    transform: scale(1.08);
    box-shadow: 0 8px 28px rgba(3,105,161,0.5), 0 2px 8px rgba(0,0,0,0.18);
  }
  /* Trigger icon rotates 45° → × when open */
  .fab--trigger .fab--trigger__icon {
    transition: transform 0.25s cubic-bezier(.34,1.56,.64,1);
  }
.fab--trigger__icon-lg {
  width: 22px !important;
  height: 22px !important;
  pointer-events: none;
}
  body.fab-dial-open .fab--trigger .fab--trigger__icon {
    transform: rotate(45deg);
  }
  /* Sub-FABs: positioned above trigger, initially hidden */
  .fab--help,
  .fab--search {
    right: 1rem;
    left: auto;
    width: auto;
    height: 44px;
    min-width: 44px;
    padding: 0 0.9rem;
    gap: 0.4rem;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px) + 64px);
    opacity: 0;
    pointer-events: none;
    transform: translateY(14px) scale(0.88);
    transition: opacity 0.2s ease, transform 0.22s cubic-bezier(.34,1.56,.64,1);
    z-index: 121;
  }
  .fab--search {
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px) + 118px);
    transition-delay: 0.04s;
  }
  /* Show sub-FABs when open */
  body.fab-dial-open .fab--help,
  body.fab-dial-open .fab--search {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
  }
  body.fab-dial-open .fab--search {
    transition-delay: 0s;
  }
  body.fab-dial-open .fab--help {
    transition-delay: 0.05s;
  }
  /* Labels visible inside speed dial */
  .fab__label { display: inline; font-size: 0.8rem; }
  /* Backdrop: blurred semi-transparent overlay */
  .fab-backdrop {
    display: block;
    background: rgba(0,0,0,0);
    -webkit-backdrop-filter: blur(0px);
    backdrop-filter: blur(0px);
    pointer-events: none;
    transition: background 0.2s, backdrop-filter 0.2s;
    z-index: 119;
  }
  body.fab-dial-open .fab-backdrop {
    background: rgba(15,23,42,0.3);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    pointer-events: auto;
  }
}

/* --- Command Palette --- */
.command-palette {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border: none;
  padding: 0;
  margin: 0;
  background: transparent;
  z-index: 210;
}
.command-palette:not([open]) { display: none !important; }
.command-palette__backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.6); }
.command-palette__content {
  position: relative;
  width: min(92vw, 520px);
  margin: 12vh auto 0;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: 1rem;
}
.command-palette__input-wrap { display: flex; align-items: center; gap: 0.75rem; border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: 0.75rem 1rem; }
.command-palette__input { flex: 1; border: none; outline: none; background: transparent; color: var(--color-text); }
.command-palette__results { max-height: 280px; overflow-y: auto; margin-top: 0.75rem; border: 1px solid var(--color-border); border-radius: var(--radius-md); }
.command-palette__results:empty { display: none; }
.command-palette__group-title { font-size: 0.75rem; font-weight: 700; color: var(--color-text-muted); padding: 0.35rem 0.75rem; text-transform: uppercase; }
.command-palette__item { display: block; padding: 0.5rem 0.75rem; color: var(--color-text); }
.command-palette__item:hover { background: var(--slate-100); }
.command-palette__hint { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 0.75rem; }

/* --- Chat Help --- */
.chat-help {
  position: fixed;
  inset: 0;
  z-index: 220;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border: none;
  margin: 0;
  padding: 0;
  background: transparent;
}
.chat-help:not([open]) { display: none !important; }
.chat-help__backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.5); }
.chat-help__content {
  position: absolute;
  right: 0;
  bottom: 0;
  width: min(100%, 400px);
  max-height: 88vh;
  background: var(--color-surface);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 32px rgba(0,0,0,0.18), 0 -1px 6px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-help__header {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.875rem 1rem;
  background: var(--color-primary);
  color: #fff;
  flex-shrink: 0;
}
.chat-help__header-icon {
  width: 18px !important;
  height: 18px !important;
  flex-shrink: 0;
}
.chat-help__header-body { flex: 1; display: flex; flex-direction: column; gap: 0.05rem; min-width: 0; }
.chat-help__header-title { font-size: 0.9rem; font-weight: 700; line-height: 1.2; }
.chat-help__header-hint { font-size: 0.68rem; font-weight: 400; opacity: 0.78; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-help__close {
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 6px;
  color: #fff;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s;
}
.chat-help__close:hover { background: rgba(255,255,255,0.28); }
.chat-help__close-icon {
  width: 16px !important;
  height: 16px !important;
}
.chat-help__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 140px;
}
.chat-help__msg {
  max-width: 88%;
  padding: 0.6rem 0.9rem;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
}
.chat-help__msg--user {
  align-self: flex-end;
  background: var(--color-primary);
  color: #fff;
  border-bottom-right-radius: 3px;
}
.chat-help__msg--bot {
  align-self: flex-start;
  background: var(--slate-100);
  color: var(--color-text);
  border-bottom-left-radius: 3px;
}
.chat-help__form {
  display: flex;
  gap: 0.5rem;
  padding: 0.875rem 1rem;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}
.chat-help__input {
  flex: 1;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.85rem;
  font-size: 0.875rem;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-help__input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.15);
}
.chat-help__submit { flex-shrink: 0; }
@media (max-width: 480px) {
  .chat-help__content { width: 100%; border-radius: 16px 16px 0 0; max-height: 92vh; }
  .chat-help__messages { min-height: 180px; }
}

/* --- Chat (chat.php) --- */
.chat-container {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: calc(100vh - 130px);
  min-height: 480px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.chat-sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--color-border);
  background: var(--color-bg);
  overflow: hidden;
}
.chat-sidebar__header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-shrink: 0;
}
.chat-sidebar__title {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.chat-sidebar__actions {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}
.chat-sidebar__actions .btn.active,
.chat-sidebar__actions .btn-ghost.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem 0;
}
.chat-list__empty {
  padding: 1.25rem 1rem;
  font-size: 0.875rem;
  text-align: center;
}
.chat-list-item {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0.6rem 1rem;
  background: none;
  border: none;
  border-left: 3px solid transparent;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.chat-list-item:hover { background: var(--slate-50, #f8fafc); }
.chat-list-item--active {
  background: var(--primary-50, #eff6ff);
  border-left-color: var(--color-primary);
}
.chat-list-item--archived { opacity: 0.65; }
.chat-list-item__name {
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.chat-list-item__preview {
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.1rem;
}
.chat-list-item__unread {
  margin-left: auto;
  background: var(--color-primary);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0 0.4rem;
  line-height: 1.4rem;
  min-width: 1.4rem;
  text-align: center;
  flex-shrink: 0;
}
.chat-list-item__archived { font-size: 0.65rem; background: var(--slate-200); color: var(--slate-600); border-radius: 3px; padding: 0.05rem 0.3rem; }
.chat-list-item__group-badge { font-size: 0.65rem; background: var(--primary-100); color: var(--primary-700); border-radius: 3px; padding: 0.05rem 0.3rem; }
.chat-main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--color-bg);
}
.chat-main__placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: var(--color-text-muted);
  padding: 2rem;
  text-align: center;
}
.chat-placeholder__icon { opacity: 0.2; color: var(--color-primary); }
.chat-placeholder__text { font-size: 1rem; font-weight: 500; margin: 0; color: var(--color-text); }
.chat-placeholder__hint { font-size: 0.875rem; margin: 0; }
.chat-conversation { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-conversation__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}
.chat-conversation__back { display: none; }
.chat-conversation__header-info { flex: 1; min-width: 0; }
.chat-conversation__name { font-size: 0.925rem; font-weight: 700; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-conversation__email { font-size: 0.78rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--color-text-muted); }
.chat-conversation__header-actions { display: flex; gap: 0.3rem; flex-shrink: 0; }
.chat-conversation__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.chat-msg { display: flex; }
.chat-msg--mine { justify-content: flex-end; }
.chat-msg--theirs { justify-content: flex-start; }
.chat-msg__bubble {
  max-width: 72%;
  padding: 0.5rem 0.85rem;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.5;
}
.chat-msg--mine .chat-msg__bubble { background: var(--color-primary); color: #fff; border-bottom-right-radius: 3px; }
.chat-msg--theirs .chat-msg__bubble { background: var(--slate-100); color: var(--color-text); border-bottom-left-radius: 3px; }
.chat-msg__body { margin: 0; word-break: break-word; }
.chat-msg__time { display: block; font-size: 0.68rem; opacity: 0.6; margin-top: 0.2rem; text-align: right; }
.chat-msg__audit { display: block; font-size: 0.65rem; opacity: 0.45; }
.chat-msg__audio audio { max-width: 200px; display: block; }
.chat-msg__video video { max-width: 240px; border-radius: 8px; display: block; }
.chat-msg__img img { max-width: 240px; border-radius: 8px; display: block; }
.chat-msg__doc { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.82rem; text-decoration: underline; }
.chat-conversation__form { flex-shrink: 0; border-top: 1px solid var(--color-border); background: var(--color-surface); }
.chat-input__file-hidden { display: none; }
.chat-input__wrap { padding: 0.625rem 0.75rem; }
.chat-emoji-panel {
  display: none;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.5rem;
  margin-bottom: 0.4rem;
}
.chat-emoji-panel--open { display: block; }
.chat-emoji-panel__grid { display: flex; flex-wrap: wrap; gap: 0.2rem; }
.chat-emoji-btn { background: none; border: none; font-size: 1.1rem; cursor: pointer; padding: 0.15rem; border-radius: 4px; line-height: 1; }
.chat-emoji-btn:hover { background: var(--slate-100); }
.chat-input__row { display: flex; align-items: flex-end; gap: 0.35rem; }
.chat-input__body {
  flex: 1;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem;
  font-family: inherit;
  font-size: 0.875rem;
  resize: none;
  line-height: 1.5;
  background: var(--color-bg);
  color: var(--color-text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-input__body:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(59,130,246,0.15); }
.chat-input__hint { font-size: 0.75rem; margin: 0.1rem 0 0; padding: 0 0.75rem 0.5rem; color: var(--color-text-muted); }
.chat-btn-recording { color: var(--color-danger,#ef4444) !important; animation: chat-pulse 1s infinite; }
@keyframes chat-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
.chat-panel-nueva {
  position: fixed;
  top: 0;
  right: -400px;
  width: min(380px, 100vw);
  height: 100%;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: -4px 0 32px rgba(0,0,0,0.14);
  z-index: 300;
  display: flex;
  flex-direction: column;
  transition: right 0.25s ease;
  overflow: hidden;
}
.chat-panel-nueva--open { right: 0; }
.chat-panel-nueva__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-primary);
  color: #fff;
  flex-shrink: 0;
}
.chat-panel-nueva__header h3 { margin: 0; font-size: 0.95rem; font-weight: 700; display: inline-flex; align-items: center; gap: 0.4rem; }
.chat-panel-nueva__header .btn-ghost { color: rgba(255,255,255,0.85); }
.chat-panel-nueva__header .btn-ghost:hover { background: rgba(255,255,255,0.15); color: #fff; }
.chat-panel-nueva__search {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.chat-panel-grupo__form {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.chat-resultados-usuarios { flex: 1; overflow-y: auto; padding: 0.4rem 0; }
.chat-user-item {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 0.55rem 1rem;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
}
.chat-user-item:hover { background: var(--slate-50, #f8fafc); }
.chat-user-item--selected { background: var(--primary-50, #eff6ff); }
.chat-user-item__name { font-size: 0.875rem; font-weight: 600; }
.chat-user-item__meta { font-size: 0.78rem; color: var(--color-text-muted); }
.chat-grupo-seleccionados { display: flex; flex-wrap: wrap; gap: 0.35rem; min-height: 1.5rem; padding: 0.25rem 0; }
.chat-grupo-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: var(--primary-100);
  color: var(--primary-700);
  border-radius: 999px;
  padding: 0.15rem 0.5rem 0.15rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 500;
}
.chat-grupo-chip-remove { background: none; border: none; cursor: pointer; font-size: 0.85rem; padding: 0; line-height: 1; color: var(--primary-600); }
.chat-panel-nueva__backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.4);
  z-index: 299;
}
.chat-panel-nueva__backdrop[aria-hidden="false"] { display: block; }
@media (max-width: 768px) {
  .chat-container {
    grid-template-columns: 1fr;
    height: calc(100vh - 100px);
    border-radius: var(--radius-md);
  }
  .chat-main { display: none; }
  body.chat-mobile-show-conversation .chat-sidebar { display: none; }
  body.chat-mobile-show-conversation .chat-main { display: flex; }
  .chat-conversation__back { display: inline-flex; }
  .chat-msg__bubble { max-width: 85%; }
}
@media (max-width: 480px) {
  .chat-container {
    height: calc(100vh - 80px);
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  .chat-sidebar__header { padding: 0.5rem 0.75rem; }
  .chat-sidebar__actions { gap: 0.2rem; }
  .chat-sidebar__actions .btn { font-size: 0.75rem; padding: 0.3rem 0.55rem; }
  .chat-msg__bubble { max-width: 92%; }
  .chat-panel-nueva { width: 100vw; }
}

/* --- Footer --- */
.site-footer {
  margin-top: auto;
  width: 100%;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 0.9rem 1rem calc(0.9rem + env(safe-area-inset-bottom, 0px));
}
.site-footer__inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.9rem;
  color: var(--color-text-muted);
  font-size: 0.86rem;
}
.site-footer__copy { margin: 0; flex: 1 1 420px; min-width: 260px; }
.site-footer__link { color: var(--color-text-secondary); }
.site-footer__link:hover { color: var(--color-primary); }
.site-footer__link + .site-footer__link { margin-left: 0.75rem; }

/* ==========================================================================
   UTILIDADES & GRID
   ========================================================================== */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.text-muted { color: var(--color-text-muted); }
.text-danger { color: var(--danger-text); }
.text-success { color: var(--success-text); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-bold { font-weight: 700; }
.w-full { width: 100%; }

/* Grid System Responsivo */
.grid-2, .grid-3, .grid-4 { display: grid; gap: 1.5rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* Reportes KPIs Grid */
.reportes-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
}
.reportes-kpi { background: var(--color-surface); padding: 1.5rem; border-radius: var(--radius-lg); border: 1px solid var(--color-border); box-shadow: var(--shadow-sm); }
.reportes-kpi__valor { font-size: 1.75rem; font-weight: 800; color: var(--color-text); line-height: 1; margin-bottom: 0.25rem; }
.reportes-kpi__etiqueta { font-size: 0.875rem; color: var(--color-text-muted); font-weight: 500; }
.quick-access {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Progress Bar */
.progress-bar-wrap { margin-bottom: 0.5rem; }
.progress-bar__label { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 0.25rem; color: var(--color-text-secondary); }
.progress-bar { width: 100%; height: 8px; background: var(--slate-200); border-radius: var(--radius-full); overflow: hidden; appearance: none; }
.progress-bar::-webkit-progress-bar { background: var(--slate-200); border-radius: var(--radius-full); }
.progress-bar::-webkit-progress-value { background: var(--color-primary); border-radius: var(--radius-full); }
.progress-bar::-moz-progress-bar { background: var(--color-primary); border-radius: var(--radius-full); }

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */
@media (max-width: 1024px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  :root { --sidebar-width: 0px; --topbar-height: 56px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .topbar { padding: 0 0.5rem; overflow: visible; }
  .topbar__brand { min-width: 0; flex: 0 1 auto; }
  .topbar__brand a:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100px; display: inline-block; }
  .topbar__user { min-width: 0; flex: 1; justify-content: flex-end; gap: 0.35rem; flex-wrap: nowrap; overflow: visible; }
  .topbar__context-form, .topbar__user > .badge { display: none !important; }
  .topbar__avatar-btn .feather[data-feather="chevron-down"] { display: none; }
  .topbar__avatar-btn > * { pointer-events: none; }
  .topbar__avatar-dropdown { right: -0.5rem; min-width: 200px; z-index: 9000; }
  .topbar__avatar-dropdown > * { pointer-events: auto; }
  .topbar__notif-wrapper { z-index: 9090; }
  #topbar-notifications-panel { z-index: 9100; }
  .topbar__avatar-btn, #topbar-notifications-btn, #open-command-palette {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
    position: relative;
    z-index: 9050;
    pointer-events: auto;
  }
  .cmd-palette__kbd { display: none !important; }
  .topbar__menu-btn { 
    display: flex !important; 
    flex: 0 0 44px;
    align-items: center; 
    justify-content: center;
    width: 44px; 
    height: 44px; 
    position: relative;
    z-index: 200;
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  .topbar__menu-btn .feather { pointer-events: none; }
  /* Touch targets mínimos 40px */
  .btn-icon { min-width: 40px; min-height: 40px; }
  .topbar .btn { min-width: 40px; min-height: 40px; }
  .main-content { padding: 1rem; }
  .card__header { flex-wrap: wrap; }
  .card__body { padding: 1rem; }
  .card__footer { padding: 0.875rem 1rem; }

  /* Page header: stack título y acciones verticalmente */
  .page-header { flex-direction: column; align-items: flex-start; gap: 0.75rem; padding-bottom: 1rem; margin-bottom: 1.25rem; }
  .page-header__title { font-size: 1.25rem; }
  .page-header__actions { width: 100%; display: flex; flex-wrap: wrap; gap: 0.5rem; }
  .page-header__actions .btn { flex: 1 1 auto; justify-content: center; min-width: 120px; }

  /* Breadcrumb compacto */
  .breadcrumb { margin-bottom: 0.875rem; }
  .breadcrumb__list { font-size: 0.78rem; gap: 0.15rem; }
  .breadcrumb__link { padding: 0.1rem 0.2rem; }

  /* Alerts */
  .alert { padding: 0.75rem 1rem; font-size: 0.875rem; }

  /* Tabla responsive forzada */
  .tabla-responsive { border-radius: var(--radius-md); }
  .tabla thead th { font-size: 0.68rem; padding: 0.6rem 0.75rem; }
  .tabla tbody td { padding: 0.6rem 0.75rem; font-size: 0.84rem; }

  /* Botones en mobile */
  .btn { font-size: 0.875rem; }
  .btn,
  .btn-sm,
  .form-control,
  .form-select,
  select.form-control,
  textarea.form-control {
    min-height: 44px;
  }
  /* Evitar taps finos en tablas */
  .tabla .btn-sm { min-height: 40px; }
  .flex.gap-2, .flex.gap-3 { flex-wrap: wrap; }
  
  .sidebar {
    position: fixed;
    width: min(300px, 92vw);
    left: 0;
    top: 0;
    height: 100vh;
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
    z-index: 170;
    touch-action: pan-y;
  }
  .sidebar__close {
    display: flex !important;
  }
  .sidebar__user {
    padding-top: 1.25rem;
    padding-right: 2.5rem; /* espacio para el botón X */
  }
  .sidebar__nav { padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px)); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  
  /* Overlay para sidebar móvil */
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    top: 0; /* Cover full screen including topbar if needed, or topbar-height if we want topbar visible */
    background: rgba(15, 23, 42, 0.5);
    z-index: 160;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
  }
  body.sidebar-open .sidebar-overlay,
  .sidebar-overlay[aria-hidden="false"] {
    opacity: 1;
    visibility: visible;
  }
  .fab--help { display: inline-flex; }
  .fab--search { display: inline-flex; }
  .site-footer {
    padding: 0.8rem 0.85rem calc(0.8rem + env(safe-area-inset-bottom, 0px));
  }
  .site-footer__inner {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    font-size: 0.82rem;
  }
  .site-footer__copy {
    min-width: 0;
    flex: 1 1 auto;
  }
  .site-footer__link + .site-footer__link { margin-left: 0.5rem; }
  /* Notification panel mobile fix */
  #topbar-notifications-panel { left: 0.5rem !important; right: 0.5rem !important; width: auto !important; max-width: none !important; }
  .quick-access {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    overflow-y: hidden;
    touch-action: pan-x;
    overscroll-behavior-x: contain;
    padding-bottom: 0.25rem;
  }
  .quick-access .btn {
    flex: 0 0 auto;
    white-space: nowrap;
  }
}

@media (max-width: 480px) {
  .topbar { padding: 0 0.35rem; gap: 0.2rem; }
  .topbar__brand a:last-child { max-width: 70px; font-size: 1rem; }
  .topbar__user { gap: 0.15rem; }
  .topbar__actions { gap: 0.15rem; }
  #enable-push-btn { display: none !important; }
  .main-content { padding: 0.75rem; }
  .card__body { padding: 0.875rem; }
  .card__header { padding: 0.75rem 0.875rem; }

  .page-header__title { font-size: 1.1rem; }
  .page-header__desc { font-size: 0.82rem; }

  .tabla-responsive { margin-left: -0.75rem; margin-right: -0.75rem; border-radius: 0; border-left: none; border-right: none; }
  .tabla thead th { font-size: 0.65rem; padding: 0.5rem 0.6rem; }
  .tabla tbody td { padding: 0.5rem 0.6rem; font-size: 0.8rem; }
  .tabla .btn-sm { padding: 0.2rem 0.45rem; font-size: 0.72rem; }

  .btn { padding: 0.55rem 1rem; font-size: 0.84rem; }
  .btn-sm { padding: 0.3rem 0.65rem; font-size: 0.78rem; }

  .form-control { font-size: 16px; padding: 0.45rem 0.65rem; }
  .form-label { font-size: 0.82rem; }

  .breadcrumb__list { font-size: 0.74rem; }
  .alert { font-size: 0.82rem; padding: 0.65rem 0.875rem; }
  .badge, .chip { font-size: 0.7rem; }

  /* Footer stacking */
  .site-footer__inner { flex-direction: column; align-items: center; text-align: center; font-size: 0.78rem; }
  .site-footer__copy { text-align: center; min-width: 0; }
  .site-footer__link + .site-footer__link { margin-left: 0.4rem; }
}

@media (min-width: 769px) {
  .fab--search { display: inline-flex; left: 1rem; bottom: 1rem; }
  .fab--help { display: inline-flex; bottom: 1rem; right: 1rem; }
}

/* ==========================================================================
   DARK MODE
   ========================================================================== */
html.theme-dark {
  --slate-50: #0f172a;
  --slate-100: #1e293b;
  --slate-200: #334155;
  --slate-300: #475569;
  --slate-400: #94a3b8;
  --slate-500: #94a3b8;
  --slate-600: #cbd5e1;
  --slate-700: #e2e8f0;
  --slate-800: #f1f5f9;
  --slate-900: #f8fafc;
  --slate-950: #ffffff;

  --color-bg: #0c1222;
  --color-bg-subtle: #111827;
  --color-surface: #1e293b;
  --color-surface-hover: #263348;

  --color-text: #f1f5f9;
  --color-text-secondary: #cbd5e1;
  --color-text-muted: #64748b;
  --color-text-inverse: #0f172a;

  --color-border: #334155;
  --color-border-hover: #475569;
  --color-border-focus: var(--primary-400);

  --color-primary: var(--primary-400);
  --color-primary-hover: var(--primary-300);
  --color-primary-subtle: rgba(56,189,248,0.1);
  --color-primary-text: var(--primary-300);

  --primary-50: rgba(56,189,248,0.08);
  --primary-100: rgba(56,189,248,0.12);
  --primary-700: #38bdf8;

  --success-bg: rgba(5,150,105,0.12); --success-text: #34d399; --success-border: rgba(5,150,105,0.3);
  --warning-bg: rgba(217,119,6,0.12); --warning-text: #fbbf24; --warning-border: rgba(217,119,6,0.3);
  --danger-bg: rgba(220,38,38,0.12); --danger-text: #f87171; --danger-border: rgba(220,38,38,0.3);
  --info-bg: rgba(37,99,235,0.12); --info-text: #60a5fa; --info-border: rgba(37,99,235,0.3);

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.2);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.2);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.3), 0 8px 10px -6px rgb(0 0 0 / 0.2);

  color-scheme: dark;
}
html.theme-dark body { background-color: var(--color-bg); color: var(--color-text); }
html.theme-dark .topbar { background: #0a0f1a; }
html.theme-dark .sidebar { background: var(--color-surface); border-right-color: var(--color-border); }
html.theme-dark .card { background: var(--color-surface); border-color: var(--color-border); }
html.theme-dark .card:hover { border-color: var(--color-border-hover); }
html.theme-dark .card__header { background: #161f2e; }
html.theme-dark .tabla thead th { background: #161f2e; color: var(--color-text-muted); }
html.theme-dark .tabla tbody td { border-bottom-color: var(--color-border); }
html.theme-dark .tabla tbody tr:nth-child(even) td { background: rgba(255,255,255,0.02); }
html.theme-dark .tabla tbody tr:hover td { background: var(--color-primary-subtle) !important; }
html.theme-dark .form-control { background: #111827; border-color: var(--color-border); color: var(--color-text); }
html.theme-dark .form-control:focus { border-color: var(--primary-400); box-shadow: 0 0 0 3px rgba(56,189,248,0.15); }
html.theme-dark select.form-control { background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%2394a3b8' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e"); }
html.theme-dark input[type="file"].form-control { color: var(--color-text); }
html.theme-dark input[type="file"].form-control::file-selector-button { background: #2d4a6f; border-color: #2d4a6f; }
html.theme-dark input[type="file"].form-control::file-selector-button:hover { background: #1e3a5f; border-color: #1e3a5f; }
html.theme-dark .btn-primary { background: var(--primary-500); }
html.theme-dark .btn-primary:hover:not(:disabled) { background: var(--primary-400); }
html.theme-dark .btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
html.theme-dark .btn-ghost:hover:not(:disabled) { background: rgba(255,255,255,0.06); color: var(--color-text); }
html.theme-dark .modal, html.theme-dark .matron-modal { background: var(--color-surface); }
html.theme-dark .modal__footer, html.theme-dark .card__footer { background: #161f2e; border-top-color: var(--color-border); }
html.theme-dark .kanban-column { background: #111827; }
html.theme-dark .kanban-card { background: var(--color-surface); border-color: var(--color-border); }
html.theme-dark .auth-page { background: #050810; }
html.theme-dark .auth-card { background: var(--color-surface); }
html.theme-dark .site-footer { background: var(--color-surface); border-top-color: var(--color-border); }
html.theme-dark .sidebar__link:hover { background: rgba(255,255,255,0.05); }
html.theme-dark .sidebar__link.active { background: var(--color-primary-subtle); }
html.theme-dark .toast { background: var(--color-surface); border-color: var(--color-border); }
html.theme-dark .command-palette__content { background: var(--color-surface); }
html.theme-dark .chat-help__content { background: var(--color-surface); }
html.theme-dark img { opacity: 0.92; }

/* Auto dark mode preference (when no explicit class) */
@media (prefers-color-scheme: dark) {
  html:not(.theme-light):not(.theme-dark) {
    --color-bg: #0c1222;
    --color-bg-subtle: #111827;
    --color-surface: #1e293b;
    --color-surface-hover: #263348;
    --color-text: #f1f5f9;
    --color-text-secondary: #cbd5e1;
    --color-text-muted: #64748b;
    --color-text-inverse: #0f172a;
    --color-border: #334155;
    --color-border-hover: #475569;
    color-scheme: dark;
  }
}

/* Theme toggle icon visibility */
html.theme-dark .theme-icon-light { display: inline-block !important; }
html.theme-dark .theme-icon-dark { display: none !important; }
html:not(.theme-dark) .theme-icon-light { display: none !important; }
html:not(.theme-dark) .theme-icon-dark { display: inline-block !important; }

/* ==========================================================================
   ACCIONES EN TABLAS
   ========================================================================== */
.form-accion-inline { display: inline-flex; margin: 0; padding: 0; }
td.acciones > div { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; }
td.acciones .btn-icon { padding: 4px; min-width: 28px; min-height: 28px; }

/* ==========================================================================
   ESTADOS DE COLORES (Legacy support)
   ========================================================================== */
.estado-icon--activo { color: var(--success-text); }
.estado-icon--inactivo { color: var(--danger-text); }
.estado-icon--pendiente { color: var(--warning-text); }
.estado-icon--vigente { color: var(--success-text); }
.estado-icon--vencida { color: var(--warning-text); }
.estado-icon--cancelada { color: var(--danger-text); }
.estado-icon--pagado { color: var(--success-text); }
.estado-icon--vencido { color: var(--danger-text); }
