:root {
  --bg: #f5f5f7;
  --bg-elevated: rgba(255, 255, 255, 0.85);
  --card: #ffffff;
  --card-hover: #f8f8fa;
  --text: #1d1d1f;
  --text-muted: #6e6e73;
  --text-soft: #86868b;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --border: #d2d2d7;
  --input-bg: #fafafa;
  --input-bg-focus: #ffffff;
  --table-head: #f5f5f7;
  --row-hover: #f5f5f7;
  --radius: 18px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
  --modal-overlay: rgba(0, 0, 0, 0.4);
  --loading-overlay: rgba(255, 255, 255, 0.7);
  --error-bg: #ffebeb;
  --error-text: #c41e1e;
  --badge-soft-bg: #e8f1ff;
  --badge-soft-text: #0071e3;
  --btn-secondary-bg: #f5f5f7;
  --btn-secondary-hover: #e8e8ed;
  --header-blur: blur(20px);
  --transition: 0.25s ease;

  /* Estados */
  --estado-por-asignar-bg: #ebebed;
  --estado-por-asignar-fg: #6e6e73;
  --estado-en-proceso-bg: #d6ebff;
  --estado-en-proceso-fg: #0071e3;
  --estado-en-revision-bg: #ffe8c2;
  --estado-en-revision-fg: #c77c00;
  --estado-completo-bg: #d4f5de;
  --estado-completo-fg: #1a7a3a;
  --estado-vb-bg: #f3e8ff;
  --estado-vb-fg: #7c3aed;
}

[data-theme="dark"] {
  --bg: #0b0d12;
  --bg-elevated: rgba(20, 24, 32, 0.92);
  --card: #1a1f2b;
  --card-hover: #222836;
  --text: #f0f2f5;
  --text-muted: #8b93a7;
  --text-soft: #6b7388;
  --accent: #3b9eff;
  --accent-hover: #5cb0ff;
  --border: rgba(255, 255, 255, 0.1);
  --input-bg: #141820;
  --input-bg-focus: #1a1f2b;
  --table-head: #141820;
  --row-hover: #222836;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --modal-overlay: rgba(0, 0, 0, 0.65);
  --loading-overlay: rgba(11, 13, 18, 0.75);
  --error-bg: #3a1a1a;
  --error-text: #ff8a8a;
  --badge-soft-bg: rgba(59, 158, 255, 0.15);
  --badge-soft-text: #5cb0ff;
  --btn-secondary-bg: #141820;
  --btn-secondary-hover: #222836;

  --estado-por-asignar-bg: #2a2e38;
  --estado-por-asignar-fg: #a0a4b0;
  --estado-en-proceso-bg: #1a2f4a;
  --estado-en-proceso-fg: #5cb0ff;
  --estado-en-revision-bg: #3a2e1a;
  --estado-en-revision-fg: #f0b040;
  --estado-completo-bg: #1a3a28;
  --estado-completo-fg: #4ade80;
  --estado-vb-bg: #2a1f3a;
  --estado-vb-fg: #c4a0ff;
}

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

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

/* ========== INTRO ========== */
#intro {
  position: fixed;
  inset: 0;
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.8s ease, visibility 0.8s ease;
}
#intro.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
#intro-logo {
  width: min(280px, 55vw);
  height: auto;
  opacity: 0;
  transition: opacity 1.6s ease;
}
#intro-logo.visible {
  opacity: 1;
}

/* ========== Header ========== */
.header {
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  backdrop-filter: var(--header-blur);
  -webkit-backdrop-filter: var(--header-blur);
  border-bottom: 1px solid var(--border);
  padding: 16px 0;
  display: flex;
  justify-content: center;
  z-index: 100;
  transition: background var(--transition), border-color var(--transition);
}

.logo { height: 48px; object-fit: contain; }

.header-main { padding: 12px 24px; }
.header-inner {
  width: 100%;
  max-width: none; /* escritorio: usar todo el ancho disponible */
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.logo-small {
  height: 36px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 auto;
}
.header-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* Buscador en header */
.header-search {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  min-width: 180px;
  max-width: 280px;
  flex: 1 1 200px;
}
.header-search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  pointer-events: none;
  flex-shrink: 0;
}
.header-search-input {
  width: 100%;
  padding: 9px 32px 9px 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
  min-width: 0;
}
.header-search-input::placeholder {
  color: var(--text-muted);
  opacity: 0.85;
}
.header-search-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--input-bg-focus);
}
.header-search-clear {
  position: absolute;
  right: 6px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.header-search-clear:hover {
  background: var(--btn-secondary-hover);
  color: var(--text);
}
.header-search-clear[hidden] { display: none !important; }

.user-box {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  font-size: 13px;
}
.user-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  min-width: 0;
}
.user-box > span,
.user-box .user-name-row > #userName { font-weight: 600; color: var(--text); }
.user-box .chat-unread-dots { font-weight: 400; }
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

/* Theme toggle */
.theme-btn {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform 0.15s;
  flex-shrink: 0;
}
.theme-btn:hover {
  background: var(--card-hover);
  transform: scale(1.05);
}
.theme-btn svg { width: 20px; height: 20px; }

/* Start screen */
#start-screen {
  display: none;
  min-height: 100vh;
  flex-direction: column;
}
#start-screen.visible {
  display: flex;
}

.main-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  min-height: calc(100vh - 80px);
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 48px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  border: 1px solid var(--border);
  transition: background var(--transition), box-shadow var(--transition);
}
.app-title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
}
.app-subtitle {
  font-size: 14px;
  color: var(--text-muted);
}
.spacer { height: 16px; }

/* Buttons */
.btn {
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 14px 20px;
}
.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}
.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--btn-secondary-hover); }
.btn.full { width: 100%; }
.btn-small {
  padding: 8px 14px;
  font-size: 13px;
  border-radius: 10px;
  background: var(--btn-secondary-bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-small:hover { background: var(--btn-secondary-hover); }

/* Filters */
.filters-bar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: flex-end;
  transition: background var(--transition), border-color var(--transition);
}
.filters-bar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto; /* empuja controles de widgets a la derecha */
  flex-shrink: 0;
  order: 99;
}
.filters-mobile-toggle {
  display: none; /* solo móvil */
}
.btn-filters-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--btn-secondary-bg);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.btn-filters-menu:hover {
  background: var(--btn-secondary-hover);
}
.btn-filters-menu .icon-hamburger {
  flex-shrink: 0;
  color: var(--text);
}
.btn-filters-menu .filters-menu-label {
  flex-shrink: 0;
}
.btn-filters-menu .icon-chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform var(--transition);
  margin-left: 4px;
}
.filters-bar.is-open .btn-filters-menu .icon-chevron {
  transform: rotate(180deg);
}
.filters-bar-body {
  display: contents; /* los filtros participan en el flex de .filters-bar */
}
.filter-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.filter-item label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.filter-item select,
.filter-item input[type="date"],
.filter-item input[type="week"] {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: var(--input-bg);
  color: var(--text);
  min-width: 160px;
  transition: border-color var(--transition), background var(--transition);
}
.filter-item select:focus,
.filter-item input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--input-bg-focus);
}

/* Content */
.content {
  display: grid;
  /* Listado más ancho; widgets fijos a la derecha */
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px; /* espacio entre Listado y widgets */
  /* Márgenes izq/der del mismo tamaño que el gap (24px) */
  padding: 24px;
  max-width: none;
  width: 100%;
  margin: 0 auto;
  align-items: start;
  box-sizing: border-box;
}

.table-card, .widget-card, .chart-card, .anim-card, .calendar-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  border: 1px solid var(--border);
  transition: background var(--transition), box-shadow var(--transition), opacity var(--transition);
}


/* FAB móvil widgets (oculto en escritorio) */
.widgets-fab {
  display: none;
}
.widgets-mobile-sheet-head {
  display: none;
}

.sidebar-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 88px;
  /* Limitar altura al viewport para poder hacer scroll interno */
  max-height: calc(100vh - 100px);
  min-height: 0;
  overflow: hidden;
}

.widgets-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 0;
  flex-shrink: 0;
}
.widgets-toolbar-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}
.widgets-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

/* Control de escala de widgets */
.widgets-scale-control {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.widgets-scale-value {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 34px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.widgets-scale-control input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 72px;
  height: 4px;
  border-radius: 999px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}
.widgets-scale-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--card);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  cursor: pointer;
}
.widgets-scale-control input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--card);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
  cursor: pointer;
}
.widgets-scale-control input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: var(--border);
}

.widgets-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  /* Escala de módulos (controlada por JS / localStorage) */
  zoom: var(--widgets-scale, 1);
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.widgets-container::-webkit-scrollbar {
  width: 6px;
}
.widgets-container::-webkit-scrollbar-track {
  background: transparent;
}
.widgets-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}
.widgets-container::-webkit-scrollbar-thumb:hover {
  background: var(--text-soft);
}

.widget-card[hidden],
.widget-card.is-hidden {
  display: none !important;
}

.widget-hide-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--btn-secondary-bg);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}
.widget-hide-btn:hover {
  background: var(--btn-secondary-hover);
  color: var(--text);
}

.widgets-config-hint {
  font-size: 14px;
  color: var(--text-muted);
  margin: -8px 0 16px;
  line-height: 1.45;
}
.widgets-config-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
}
.widget-config-item {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--input-bg);
}
.widget-config-main {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.widget-config-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex-shrink: 0;
  margin-top: 2px;
}
.widget-config-item label {
  flex: 1;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}
.widget-config-item .widget-config-desc {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 2px;
}
.widget-config-scale {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 30px;
}
.widget-config-scale-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.widget-config-scale input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 4px;
  accent-color: var(--accent);
  cursor: pointer;
}
.widget-config-scale-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  min-width: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.widget-card {
  /* Escala final = global × individual (asignada en JS vía zoom) */
  transform-origin: top center;
}

/* Animación estado destacado — fondo transparente para respetar el GIF */
.anim-box {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  max-height: 280px;
  overflow: hidden;
  background: transparent;
  border-radius: 12px;
}

.anim-box img {
  max-width: 100%;
  max-height: 260px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  background: transparent;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 8px;
  min-width: 0;
}
.section-head h2 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
  min-width: 0;
}
.badge {
  background: var(--accent);
  color: white;
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 999px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.badge-soft {
  background: var(--badge-soft-bg);
  color: var(--badge-soft-text);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
  vertical-align: middle;
  line-height: 1.3;
}
.widget-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1 1 auto;
  justify-content: flex-end;
  overflow: hidden;
}
.widget-head-actions .badge-soft {
  flex: 1 1 auto;
  min-width: 0;
  text-align: right;
}
.widget-card,
.chart-card,
.anim-card,
.calendar-card {
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
}

/* Widget Calendario (minicalendario filtro por semana) */
.calendar-card .mini-cal-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.calendar-card .mini-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.calendar-card .mini-head h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}
.calendar-card .mini-nav {
  display: flex;
  gap: 2px;
}
.calendar-card .cal-nav {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.calendar-card .cal-nav:hover {
  background: var(--btn-secondary-hover);
  color: var(--text);
}
.calendar-card .mini-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
  text-align: center;
}
.calendar-card .mini-dow {
  font-size: 11px;
  color: var(--text-muted);
  padding: 4px 0;
  font-weight: 600;
}
.calendar-card .mini-day {
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  height: 32px;
  border-radius: 16px;
  cursor: pointer;
  position: relative;
  transition: background var(--transition), color var(--transition);
}
.calendar-card .mini-day.other {
  color: var(--text-soft);
  opacity: 0.55;
}
.calendar-card .mini-day.inweek {
  background: var(--badge-soft-bg);
  border-radius: 0;
  color: var(--badge-soft-text);
}
.calendar-card .mini-day.inweek:first-of-type,
.calendar-card .mini-day:hover {
  /* hover handled below */
}
.calendar-card .mini-day:hover {
  background: var(--btn-secondary-hover);
  color: var(--text);
}
.calendar-card .mini-day.today {
  background: var(--accent);
  color: #fff;
  border-radius: 16px;
  font-weight: 600;
}
.calendar-card .mini-day.today.inweek {
  background: var(--accent);
  color: #fff;
}
.calendar-card .mini-day.marked::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 3px;
  width: 5px;
  height: 5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: #ffb800;
}
.calendar-card .mini-day.today.marked::after {
  background: #fff;
}
.calendar-card .mini-cal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.calendar-card .mini-cal-actions .btn {
  flex: 1 1 auto;
  min-width: 0;
}

/* Table */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th {
  text-align: left;
  padding: 12px 14px;
  background: var(--table-head);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
td {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
tbody tr {
  cursor: pointer;
  transition: background 0.15s;
}
tbody tr:hover { background: var(--row-hover); }

/* Desktop-only columns (hidden on mobile portrait) */
.col-desktop { }

.estado-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.estado-por-asignar { background: var(--estado-por-asignar-bg); color: var(--estado-por-asignar-fg); }
.estado-en-proceso  { background: var(--estado-en-proceso-bg); color: var(--estado-en-proceso-fg); }
.estado-en-revision { background: var(--estado-en-revision-bg); color: var(--estado-en-revision-fg); }
.estado-completo    { background: var(--estado-completo-bg); color: var(--estado-completo-fg); }
.estado-vb-presidencia { background: var(--estado-vb-bg); color: var(--estado-vb-fg); }

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-soft);
  font-size: 15px;
}

/* Chart */
.chart-box {
  position: relative;
  height: 260px;
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  backdrop-filter: blur(8px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.modal.active { display: flex; }

.modal-content {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  padding: 36px 40px;
  width: 100%;
  max-width: 440px;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
  color: var(--text);
  border: 1px solid var(--border);
}
.modal-large { max-width: 720px; }

.close-btn {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  font-size: 28px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 4px 8px;
}
.close-btn:hover { color: var(--text); }

.modal-content h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 24px;
  color: var(--text);
}

.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 6px;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
}

input, textarea, select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--input-bg);
  color: var(--text);
  transition: border 0.2s, background 0.2s;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--input-bg-focus);
}
textarea { resize: vertical; min-height: 100px; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.error-msg {
  background: var(--error-bg);
  color: var(--error-text);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 16px;
}

/* Detail */
.detalle-grid {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 10px 16px;
  font-size: 14.5px;
}
.detalle-label { font-weight: 600; color: var(--text-muted); }
.detalle-desc {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.detalle-desc h4 {
  font-size: 13px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 8px;
}

/* Loading */
.loading {
  position: fixed;
  inset: 0;
  background: var(--loading-overlay);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive tablet */
@media (max-width: 1000px) {
  .content {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .sidebar-right {
    position: static;
    max-height: none;
    overflow: visible;
  }
  .widgets-container {
    max-height: min(60vh, 520px);
    overflow-y: auto;
  }
}

/* Responsive mobile */
@media (max-width: 768px) {
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  .header-main { padding: 10px 12px; }
  .header-inner {
    gap: 8px;
    flex-wrap: wrap;
  }
  /* Logo + título siempre en la misma fila */
  .header-brand {
    flex: 1 1 auto;
    min-width: 0;
    max-width: calc(100% - 48px);
  }
  .header-title {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .logo-small { height: 28px; }
  .header-actions {
    width: 100%;
    gap: 8px;
  }
  .header-actions .btn {
    flex: 1;
    padding: 10px 10px;
    font-size: 12px;
  }
  .user-box {
    width: 100%;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding-top: 2px;
  }

  /* Buscador a ancho completo, centrado, debajo de los botones principales */
  .header-search {
    order: 3;
    flex: 1 1 100%;
    max-width: 100%;
    min-width: 0;
    width: 100%;
    margin: 2px auto 0;
  }
  .header-search-input {
    font-size: 14px;
    padding: 10px 34px 10px 36px;
    text-align: left;
  }
  .header-actions .btn {
    order: 1;
  }
  .header-actions .theme-toggle {
    order: 2;
  }
  .header-actions .user-box {
    order: 4;
  }


  .filters-bar {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 12px;
    gap: 0;
  }
  .filters-bar-header {
    width: 100%;
    margin-left: 0;
    order: 0;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
  }
  .filters-mobile-toggle {
    display: block;
    flex: 0 1 auto;
    min-width: 0;
  }
  .btn-filters-menu {
    width: auto;
    max-width: 100%;
  }
  /* Controles de widgets a la derecha del botón Menú */
  .filters-bar-header .widgets-toolbar {
    flex: 1 1 auto;
    justify-content: flex-end;
    min-width: 0;
  }
  .filters-bar-header .widgets-toolbar-label {
    display: none; /* en móvil basta con escala + botón */
  }
  /* Cerrado por defecto en móvil: solo la fila Menú + widgets */
  .filters-bar-body {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding-top: 10px;
    width: 100%;
  }
  .filters-bar.is-open .filters-bar-body {
    display: flex;
  }
  .filter-item select,
  .filter-item input[type="date"] {
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }
  .filters-bar-body .filter-item .btn {
    width: 100%;
  }

  .content {
    padding: 12px 12px;
    gap: 12px;
    /* espacio inferior para la barra fija de widgets */
    /* padding inferior: FAB o panel (ver body.widgets-mobile-open) */
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    max-width: 100%;
    overflow-x: hidden;
  }

  .table-card {
    padding: 12px;
    border-radius: 14px;
    max-width: 100%;
    overflow: hidden;
  }

  /* Solo Título, Tipo de Trabajo y Estado en vertical móvil */
  .col-desktop {
    display: none !important;
  }

  .table-wrap {
    overflow-x: hidden;
    max-width: 100%;
  }
  table {
    font-size: 12px;
    table-layout: fixed;
    width: 100%;
    max-width: 100%;
  }
  th, td {
    padding: 8px 6px;
    vertical-align: middle;
  }
  /* Distribución de columnas móviles */
  #tablaSolicitudes th:nth-child(2),
  #tablaSolicitudes td:nth-child(2) {
    width: 42%;
  }
  #tablaSolicitudes th:nth-child(3),
  #tablaSolicitudes td:nth-child(3) {
    width: 30%;
  }
  #tablaSolicitudes th:nth-child(5),
  #tablaSolicitudes td:nth-child(5) {
    width: 28%;
  }
  /* Truncar textos largos (título, tipo) */
  #tablaSolicitudes td:nth-child(2),
  #tablaSolicitudes td:nth-child(3) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 0; /* fuerza ellipsis con table-layout:fixed */
  }
  .estado-badge {
    font-size: 10px;
    padding: 3px 6px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
  }

  /* FAB: mostrar widgets (replegado por defecto) */
  .widgets-fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 95;
    padding: 10px 16px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    cursor: pointer;
    font-family: inherit;
    max-width: calc(100vw - 24px);
  }
  .widgets-fab:active {
    transform: translateX(-50%) scale(0.98);
  }
  .widgets-fab-icon {
    flex-shrink: 0;
    opacity: 0.9;
  }
  .widgets-fab-label {
    white-space: nowrap;
  }
  /* Cuando el panel está abierto, el FAB pasa a "ocultar" o se esconde */
  body.widgets-mobile-open .widgets-fab {
    display: none;
  }

  .widgets-mobile-sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 2px 2px 8px;
    flex-shrink: 0;
  }
  .widgets-mobile-sheet-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
  }

  /* Panel de widgets: oculto por defecto en móvil */
  .sidebar-right {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 90;
    top: auto;
    order: unset;
    gap: 0;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    background: var(--bg-elevated);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.18);
    max-height: 75vh;
    overflow: hidden;
    transform: translateY(110%);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.28s ease, opacity 0.2s ease;
  }
  body.widgets-mobile-open .sidebar-right {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }
  /* Padding del contenido: solo reservar espacio del FAB cuando está replegado */
  .content {
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)) !important;
  }
  body.widgets-mobile-open .content {
    padding-bottom: calc(var(--widgets-bar-h, 180px) + 16px) !important;
  }
  .widgets-scale-control input[type="range"] {
    width: 56px;
  }
  .widgets-scale-value {
    font-size: 10px;
    min-width: 30px;
  }
  .filters-bar-header .widgets-toolbar .btn-small {
    padding: 6px 10px;
    font-size: 11px;
  }
  /* Una columna: cada widget a ancho completo (evita aplastar altura) */
  .widgets-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: calc(75vh - 52px);
    min-height: 0;
    padding-right: 2px;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
  }
  /* Contenido completo visible; el scroll es del contenedor */
  .widget-card {
    padding: 12px;
    border-radius: 12px;
    box-shadow: none;
    margin: 0;
    max-height: none;
    overflow: visible;
    height: auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
  }
  .widget-card .section-head {
    margin-bottom: 8px;
    gap: 4px;
    flex-shrink: 0;
  }
  .widget-card .section-head h2 {
    font-size: 13px;
  }
  .badge-soft {
    font-size: 10px;
    padding: 2px 6px;
  }
  .widget-hide-btn {
    width: 22px;
    height: 22px;
    font-size: 14px;
    flex-shrink: 0;
  }
  /* Altura suficiente para dona + leyenda y animación completa */
  .chart-box,
  .anim-box {
    height: 240px;
    min-height: 240px;
    max-height: none;
    flex: 0 0 auto;
  }
  .anim-box {
    overflow: hidden;
  }
  .anim-box img {
    max-height: 100%;
    max-width: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
  }
  .calendar-card {
    display: block;
    overflow: visible;
  }
  .calendar-card .mini-day {
    height: 30px;
    font-size: 13px;
  }
  .calendar-card .mini-cal-actions {
    margin-top: 6px;
  }
  .calendar-card .mini-cal-actions .btn {
    font-size: 12px;
    padding: 6px 8px;
  }

  .modal-content { padding: 24px 18px; }
  .detalle-grid {
    grid-template-columns: 1fr;
    gap: 4px 0;
  }
  .detalle-label { margin-top: 8px; }
}

/* Si no hay widgets visibles */
body.widgets-bar-empty .content {
  padding-bottom: calc(var(--widgets-bar-h, 56px) + 12px) !important;
}
body.widgets-bar-empty .widgets-container {
  display: none;
}
/* Toolbar de widgets vive en la barra de menú/filtros; se puede ocultar el aside vacío en móvil */
body.widgets-bar-empty .sidebar-right {
  /* desktop: aside puede quedar vacío sin toolbar interno */
}

@media (max-width: 380px) {
  .header-title { font-size: 13px; }
}

/* Landscape móvil */
@media (max-width: 768px) and (orientation: landscape) {
  .col-desktop {
    display: none !important; /* seguir compacto en landscape estrecho */
  }
  .sidebar-right {
    max-height: 70vh;
  }
  .widgets-container {
    max-height: calc(70vh - 48px);
  }
  .chart-box,
  .anim-box {
    height: 200px;
    min-height: 200px;
    max-height: none;
  }
  .content {
    padding-bottom: calc(var(--widgets-bar-h, 140px) + 12px);
  }
}


/* Barra inferior ocultable cuando no hay widgets activos */
@media (max-width: 768px) {
  body.widgets-bar-empty .sidebar-right {
    display: none;
  }
  body.widgets-bar-empty .content {
    padding-bottom: 16px !important;
  }
}


/* ===== Stats widget modes ===== */
.stats-mode-bar {
  display: flex;
  gap: 6px;
  margin: -4px 0 10px;
  flex-wrap: wrap;
}
.stats-mode-btn {
  flex: 1;
  min-width: 36px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--btn-secondary-bg);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.stats-mode-btn:hover {
  background: var(--btn-secondary-hover);
  color: var(--text);
}
.stats-mode-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.stats-percent-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  gap: 14px;
  padding: 8px 4px 4px;
}
.stats-percent-view[hidden] { display: none !important; }
.stats-percent-main {
  text-align: center;
}
.stats-percent-value {
  font-size: 2.6rem;
  font-weight: 700;
  line-height: 1.05;
  color: var(--accent);
  letter-spacing: -0.03em;
}
.stats-percent-name {
  margin-top: 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stats-percent-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stats-percent-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 3px 6px;
  border-radius: 6px;
  background: var(--input-bg);
}
.stats-percent-row strong {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 768px) {
  .stats-mode-btn { height: 28px; font-size: 12px; min-width: 28px; }
  .stats-percent-view { min-height: 120px; gap: 8px; }
  .stats-percent-value { font-size: 1.8rem; }
  .stats-percent-name { font-size: 0.7rem; }
  .stats-percent-row { font-size: 0.65rem; }
  .form-actions {
    flex-wrap: wrap;
  }
  .form-actions .btn {
    flex: 1 1 auto;
  }
}


/* Termómetro: widget más bajo */
.chart-box-compact {
  height: 120px !important;
  min-height: 100px !important;
  max-height: 130px !important;
}
#widget-stats.stats-mode-thermo .chart-box {
  height: 120px;
  min-height: 100px;
}
@media (max-width: 768px) {
  .chart-box-compact,
  #widget-stats.stats-mode-thermo .chart-box {
    height: 96px !important;
    min-height: 88px !important;
    max-height: 100px !important;
  }
}


/* Diálogo app (reemplazo de alert/confirm nativos) */
.modal-dialog {
  max-width: 420px;
  text-align: center;
  padding: 28px 28px 24px;
}
.dialog-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}
.dialog-icon:empty { display: none; }
.dialog-icon.dialog-info {
  background: var(--badge-soft-bg);
  color: var(--accent);
}
.dialog-icon.dialog-success {
  background: var(--estado-completo-bg, #d4f5de);
  color: var(--estado-completo-fg, #1a7a3a);
}
.dialog-icon.dialog-error {
  background: var(--error-bg, #ffebeb);
  color: var(--error-text, #c41e1e);
}
.dialog-icon.dialog-confirm {
  background: #fff3cd;
  color: #9a6b00;
}
[data-theme="dark"] .dialog-icon.dialog-confirm {
  background: #3a2e1a;
  color: #f0b040;
}
.modal-dialog h2 {
  margin-bottom: 10px;
  font-size: 18px;
}
.dialog-message {
  color: var(--text-muted);
  font-size: 14.5px;
  line-height: 1.5;
  margin: 0 0 22px;
  white-space: pre-wrap;
  word-break: break-word;
}
.dialog-actions {
  justify-content: center;
  border-top: none;
  padding-top: 0;
  margin-top: 0;
  gap: 10px;
}
.dialog-actions .btn {
  min-width: 110px;
}
.dialog-actions .btn-danger-dialog {
  background: #ff3b30;
  color: #fff;
}
.dialog-actions .btn-danger-dialog:hover {
  background: #e0352b;
}
#modalDialog {
  z-index: 400;
}


/* Widget Unidades no Disponibles */
.disponibilidad-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.disp-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: 10px;
  min-height: 48px;
}
.disp-empty {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 16px 8px;
  margin: 0;
}
.disp-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  font-size: 13px;
}
.disp-item-main {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.disp-item-name {
  font-weight: 600;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.disp-item-period {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.disp-badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.disp-badge-no-disponible { background: #ebebed; color: #6e6e73; }
.disp-badge-vacaciones { background: #d6ebff; color: #0071e3; }
.disp-badge-incapacitado { background: #ffe8c2; color: #c77c00; }
.disp-badge-tiempo-compensatorio { background: #f3e8ff; color: #7c3aed; }
.disp-badge-en-gira { background: #d4f5de; color: #1a7a3a; }
[data-theme="dark"] .disp-badge-no-disponible { background: #2a2e38; color: #a0a4b0; }
[data-theme="dark"] .disp-badge-vacaciones { background: #1a2f4a; color: #5cb0ff; }
[data-theme="dark"] .disp-badge-incapacitado { background: #3a2e1a; color: #f0b040; }
[data-theme="dark"] .disp-badge-tiempo-compensatorio { background: #2a1f3a; color: #c4a0ff; }
[data-theme="dark"] .disp-badge-en-gira { background: #1a3a28; color: #4ade80; }

.disp-widget-actions {
  margin-top: auto;
  padding-top: 4px;
}
.disp-widget-actions .btn.full { width: 100%; }

.disp-edit-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: min(50vh, 420px);
  overflow-y: auto;
  margin-bottom: 8px;
  padding-right: 4px;
}
.disp-edit-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--input-bg);
}
.disp-edit-top {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.disp-edit-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.disp-edit-top select {
  width: auto;
  min-width: 160px;
  max-width: 52%;
  flex-shrink: 0;
  padding: 8px 10px;
  font-size: 13px;
}
.disp-edit-dates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.disp-edit-dates[hidden] {
  display: none !important;
}
.disp-date-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.disp-date-field label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
}
.disp-date-field input[type="date"] {
  width: 100%;
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card, var(--input-bg-focus, #fff));
  color: var(--text);
  font-family: inherit;
}
.disp-date-field input[type="date"]:focus {
  outline: none;
  border-color: var(--accent);
}

@media (max-width: 768px) {
  .disp-list { max-height: 140px; }
  .disp-edit-top {
    flex-wrap: wrap;
  }
  .disp-edit-top select {
    width: 100%;
    max-width: 100%;
  }
  .disp-edit-dates {
    grid-template-columns: 1fr;
  }
  .disp-item { font-size: 12px; padding: 6px 8px; }
  .disp-badge { font-size: 10px; }
}

/* URL OneDrive row */
.url-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.url-row input {
  flex: 1;
  min-width: 0;
}
.url-row .btn {
  flex-shrink: 0;
  white-space: nowrap;
}
.help-url {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-soft);
}

/* ========== BOTÓN ENGRANAJE (estilo gráfico) ========== */
.btn-icon-gear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 10px;
  min-width: 36px;
}
.btn-icon-gear svg {
  display: block;
}
.filter-item-style {
  align-self: flex-end;
}

/* ========== MODAL ESTILOS GRÁFICOS ========== */
.style-options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0 12px;
}
.style-option {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
  font-family: inherit;
}
.style-option:hover {
  background: var(--card-hover);
  border-color: var(--accent);
}
.style-option.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent);
  background: var(--badge-soft-bg);
}
.style-option-swatch {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: linear-gradient(135deg, #f5f5f7 0%, #0071e3 100%);
}
.style-swatch-original {
  background: linear-gradient(135deg, #f5f5f7 0%, #ffffff 40%, #0071e3 100%);
}
.style-swatch-patria {
  background: linear-gradient(135deg, #ffffff 0%, #0057b8 45%, #d21034 100%);
}
.style-swatch-cintarosada {
  background: linear-gradient(135deg, #fff8f8 0%, #ffffff 35%, #c41e1e 100%);
}
.style-swatch-oceano {
  background: linear-gradient(135deg, #e8f4fc 0%, #5ba3d9 50%, #0a4d68 100%);
}
.style-swatch-forestal {
  background: linear-gradient(135deg, #e8f5e9 0%, #52b788 45%, #1b4332 100%);
}
.style-option-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.style-option-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
}
.style-option-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.35;
}
.style-options-note {
  font-size: 12px;
  color: var(--text-soft);
  margin: 0 0 8px;
  min-height: 1.2em;
}

/* ========== SKINS (estilos gráficos) ========== */
/* Combinan con data-theme light/dark. ORIGINAL = variables por defecto (sin overrides). */

/* ----- PATRIA (fiestas patrias: azul, rojo, blanco) ----- */
[data-skin="patria"] {
  --bg: #f4f7fb;
  --bg-elevated: rgba(255, 255, 255, 0.92);
  --card: #ffffff;
  --card-hover: #f0f5fb;
  --text: #0a1628;
  --text-muted: #4a5a72;
  --text-soft: #6b7c94;
  --accent: #0057b8;
  --accent-hover: #004494;
  --border: #c5d4e8;
  --input-bg: #f7fafd;
  --input-bg-focus: #ffffff;
  --table-head: #e8f0fa;
  --row-hover: #eef4fb;
  --shadow: 0 4px 24px rgba(0, 50, 120, 0.1);
  --modal-overlay: rgba(10, 30, 60, 0.45);
  --loading-overlay: rgba(244, 247, 251, 0.75);
  --error-bg: #fde8ec;
  --error-text: #b01030;
  --badge-soft-bg: #e3eef9;
  --badge-soft-text: #0057b8;
  --btn-secondary-bg: #eef3f9;
  --btn-secondary-hover: #dde7f3;
  --estado-por-asignar-bg: #e8ecf2;
  --estado-por-asignar-fg: #4a5a72;
  --estado-en-proceso-bg: #d6e8f8;
  --estado-en-proceso-fg: #0057b8;
  --estado-en-revision-bg: #fde8c8;
  --estado-en-revision-fg: #b45309;
  --estado-completo-bg: #d4f0e0;
  --estado-completo-fg: #0d6b3a;
  --estado-vb-bg: #fce4e8;
  --estado-vb-fg: #c41e3a;
}

[data-skin="patria"][data-theme="dark"] {
  --bg: #0a1424;
  --bg-elevated: rgba(16, 28, 48, 0.95);
  --card: #121e32;
  --card-hover: #1a2a44;
  --text: #eef3fa;
  --text-muted: #8fa3bf;
  --text-soft: #6b82a0;
  --accent: #3b9eff;
  --accent-hover: #5cb0ff;
  --border: rgba(100, 140, 200, 0.2);
  --input-bg: #0e1a2c;
  --input-bg-focus: #121e32;
  --table-head: #0e1a2c;
  --row-hover: #1a2a44;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  --modal-overlay: rgba(0, 8, 20, 0.7);
  --loading-overlay: rgba(10, 20, 36, 0.8);
  --error-bg: #3a1820;
  --error-text: #ff8a9a;
  --badge-soft-bg: rgba(59, 158, 255, 0.18);
  --badge-soft-text: #5cb0ff;
  --btn-secondary-bg: #0e1a2c;
  --btn-secondary-hover: #1a2a44;
  --estado-por-asignar-bg: #1e2a3c;
  --estado-por-asignar-fg: #8fa3bf;
  --estado-en-proceso-bg: #153050;
  --estado-en-proceso-fg: #5cb0ff;
  --estado-en-revision-bg: #3a2e18;
  --estado-en-revision-fg: #f0b040;
  --estado-completo-bg: #143528;
  --estado-completo-fg: #4ade80;
  --estado-vb-bg: #3a1a24;
  --estado-vb-fg: #ff7a90;
}

/* ----- CINTA ROSADA (blanco y rojo, sin verde) ----- */
[data-skin="cintarosada"] {
  --bg: #faf6f6;
  --bg-elevated: rgba(255, 255, 255, 0.94);
  --card: #ffffff;
  --card-hover: #fdf5f5;
  --text: #1a1010;
  --text-muted: #6b5050;
  --text-soft: #8a6a6a;
  --accent: #c41e1e;
  --accent-hover: #a01818;
  --border: #e8d0d0;
  --input-bg: #fffafa;
  --input-bg-focus: #ffffff;
  --table-head: #f8eeee;
  --row-hover: #fdf5f5;
  --shadow: 0 4px 24px rgba(120, 20, 20, 0.08);
  --modal-overlay: rgba(40, 10, 10, 0.4);
  --loading-overlay: rgba(250, 246, 246, 0.75);
  --error-bg: #fde8e8;
  --error-text: #a01010;
  --badge-soft-bg: #fce8e8;
  --badge-soft-text: #c41e1e;
  --btn-secondary-bg: #f8f0f0;
  --btn-secondary-hover: #f0e0e0;
  --estado-por-asignar-bg: #f0e8e8;
  --estado-por-asignar-fg: #6b5050;
  --estado-en-proceso-bg: #fce0e0;
  --estado-en-proceso-fg: #c41e1e;
  --estado-en-revision-bg: #ffe8c8;
  --estado-en-revision-fg: #b45309;
  --estado-completo-bg: #f0e0e0;
  --estado-completo-fg: #8b2020;
  --estado-vb-bg: #f8e0e8;
  --estado-vb-fg: #9b1b4a;
}

[data-skin="cintarosada"][data-theme="dark"] {
  --bg: #1a0c0c;
  --bg-elevated: rgba(36, 18, 18, 0.95);
  --card: #241414;
  --card-hover: #321c1c;
  --text: #f8eeee;
  --text-muted: #c0a0a0;
  --text-soft: #9a7878;
  --accent: #e84848;
  --accent-hover: #ff6a6a;
  --border: rgba(220, 120, 120, 0.22);
  --input-bg: #1e1010;
  --input-bg-focus: #241414;
  --table-head: #1e1010;
  --row-hover: #321c1c;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
  --modal-overlay: rgba(20, 0, 0, 0.7);
  --loading-overlay: rgba(26, 12, 12, 0.8);
  --error-bg: #3a1818;
  --error-text: #ff9a9a;
  --badge-soft-bg: rgba(232, 72, 72, 0.2);
  --badge-soft-text: #ff7a7a;
  --btn-secondary-bg: #1e1010;
  --btn-secondary-hover: #321c1c;
  --estado-por-asignar-bg: #2a1c1c;
  --estado-por-asignar-fg: #c0a0a0;
  --estado-en-proceso-bg: #3a2020;
  --estado-en-proceso-fg: #ff7a7a;
  --estado-en-revision-bg: #3a2e18;
  --estado-en-revision-fg: #f0b040;
  --estado-completo-bg: #2a1818;
  --estado-completo-fg: #e8a0a0;
  --estado-vb-bg: #2a1420;
  --estado-vb-fg: #f0a0c0;
}

/* ----- OCÉANO (Discovery-like, azules claros / océano) ----- */
[data-skin="oceano"] {
  --bg: #eef6fb;
  --bg-elevated: rgba(255, 255, 255, 0.9);
  --card: #f5fafd;
  --card-hover: #f2f8fc;
  --text: #0c2438;
  --text-muted: #4a6a82;
  --text-soft: #6a8aa2;
  --accent: #0a6e9c;
  --accent-hover: #085a80;
  --border: #b8d4e8;
  --input-bg: #f5fafd;
  --input-bg-focus: #ffffff;
  --table-head: #e4f0f8;
  --row-hover: #d9edf9;
  --shadow: 0 4px 24px rgba(10, 80, 120, 0.1);
  --modal-overlay: rgba(8, 40, 60, 0.4);
  --loading-overlay: rgba(238, 246, 251, 0.75);
  --error-bg: #fde8e8;
  --error-text: #b01020;
  --badge-soft-bg: #d8eef8;
  --badge-soft-text: #0a6e9c;
  --btn-secondary-bg: #e4f0f8;
  --btn-secondary-hover: #d0e4f0;
  --estado-por-asignar-bg: #e0eaf2;
  --estado-por-asignar-fg: #4a6a82;
  --estado-en-proceso-bg: #cce8f5;
  --estado-en-proceso-fg: #0a6e9c;
  --estado-en-revision-bg: #ffe8c8;
  --estado-en-revision-fg: #b45309;
  --estado-completo-bg: #d0eee0;
  --estado-completo-fg: #0d6b4a;
  --estado-vb-bg: #e0e8f8;
  --estado-vb-fg: #3a5a9c;
}

[data-skin="oceano"][data-theme="dark"] {
  --bg: #061820;
  --bg-elevated: rgba(10, 32, 44, 0.95);
  --card: #0d2a41;
  --card-hover: #1e4664;
  --text: #e4f2f8;
  --text-muted: #7aa0b4;
  --text-soft: #5a8094;
  --accent: #3db8e8;
  --accent-hover: #1c4260;
  --border: rgba(80, 160, 200, 0.2);
  --input-bg: #0a1e28;
  --input-bg-focus: #0c2430;
  --table-head: #0a1e28;
  --row-hover: #1c4260;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  --modal-overlay: rgba(0, 12, 20, 0.7);
  --loading-overlay: rgba(6, 24, 32, 0.8);
  --error-bg: #3a1818;
  --error-text: #ff8a8a;
  --badge-soft-bg: rgba(61, 184, 232, 0.18);
  --badge-soft-text: #5cc8f0;
  --btn-secondary-bg: #0a1e28;
  --btn-secondary-hover: #143040;
  --estado-por-asignar-bg: #1a2e38;
  --estado-por-asignar-fg: #7aa0b4;
  --estado-en-proceso-bg: #123848;
  --estado-en-proceso-fg: #5cc8f0;
  --estado-en-revision-bg: #3a2e18;
  --estado-en-revision-fg: #f0b040;
  --estado-completo-bg: #143828;
  --estado-completo-fg: #4adea0;
  --estado-vb-bg: #1a2840;
  --estado-vb-fg: #80a0e0;
}

/* ====================== CHAT WIDGET ====================== */
.chat-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: none;
  overflow: hidden;
}
.chat-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.chat-tab {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--btn-secondary-bg);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.chat-tab.active {
  background: var(--primary, #0071e3);
  color: #fff;
  border-color: transparent;
}
.chat-peer-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
}
.chat-peer-wrap select {
  flex: 1;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 12px;
}
.chat-admin-actions {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.chat-btn-danger {
  color: #ff3b30 !important;
  border-color: rgba(255, 59, 48, 0.35) !important;
}
.chat-messages {
  flex: 1 1 auto;
  min-height: 160px;
  /* Altura fija del panel: no crece con más mensajes; se navega con scroll */
  height: 240px;
  max-height: 240px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg, #f5f5f7);
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
  scrollbar-gutter: stable;
}
.chat-messages::-webkit-scrollbar {
  width: 8px;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 12px;
}
.chat-bubble {
  max-width: 92%;
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1.35;
  word-break: break-word;
}
.chat-bubble.mine {
  align-self: flex-end;
  background: var(--primary, #0071e3);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-bubble.theirs {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.chat-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 10px;
  opacity: 0.85;
  margin-bottom: 3px;
}
.chat-bubble.mine .chat-meta { color: rgba(255,255,255,0.9); }
.chat-link {
  color: inherit;
  text-decoration: underline;
  font-weight: 600;
}
.chat-bubble.mine .chat-link { color: #fff; }
.chat-link-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
  padding: 8px;
  border: 1px dashed var(--border);
  border-radius: 10px;
}
.chat-link-panel input {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 12px;
}
.chat-compose {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  padding-top: 2px;
}
.chat-link-panel {
  flex-shrink: 0;
}
.chat-compose input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 13px;
}
.chat-attach {
  flex-shrink: 0;
  min-width: 36px;
}


/* Indicadores de mensajes sin leer junto al nombre de usuario */
.user-name-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.chat-unread-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.chat-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 0 2px var(--card, #fff);
}
.chat-dot[hidden] {
  display: none !important;
}
.chat-dot-dm {
  background: #0071e3; /* azul = privado */
}
.chat-dot-group {
  background: #ff3b30; /* rojo = grupo */
}

.chat-bubble {
  position: relative;
}
.chat-del-btn {
  position: static;
  border: none;
  background: transparent;
  color: inherit;
  opacity: 0.85;
  cursor: pointer;
  font-size: 15px;
  font-weight: 800;
  line-height: 1;
  padding: 0 0 0 10px;
  margin-left: 6px;
  flex-shrink: 0;
  -webkit-text-stroke: 0.4px currentColor;
}
.chat-del-btn:hover { opacity: 1; }
.chat-bubble.mine .chat-del-btn { color: #fff; }
.chat-meta {
  align-items: center;
}
.chat-meta-right {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
  padding-left: 10px;
  flex-shrink: 0;
}
/* dots más visibles */
.chat-dot {
  width: 10px !important;
  height: 10px !important;
  flex-shrink: 0;
}
.chat-dot-dm {
  background: #0071e3 !important;
}
.chat-dot-group {
  background: #ff3b30 !important;
}


/* Botón CHAT en barra (antes de Widgets) */
.btn-chat-open {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--btn-secondary-bg);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition);
}
.btn-chat-open:hover {
  background: var(--btn-secondary-hover);
}
.chat-btn-unread {
  position: absolute;
  top: 2px;
  right: 2px;
  display: inline-flex;
  gap: 2px;
  pointer-events: none;
}
.chat-btn-unread .chat-dot {
  width: 8px !important;
  height: 8px !important;
  box-shadow: 0 0 0 1px var(--card, #fff);
}

/* FAB chat móvil (derecha) */
.chat-fab {
  display: none;
}
@media (max-width: 768px) {
  .chat-fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    z-index: 96;
    width: 52px;
    height: 52px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    cursor: pointer;
  }
  .chat-fab:active {
    transform: scale(0.96);
  }
  .chat-fab-unread {
    position: absolute;
    top: 6px;
    right: 6px;
    display: inline-flex;
    gap: 2px;
    pointer-events: none;
  }
  .chat-fab-unread .chat-dot {
    width: 8px !important;
    height: 8px !important;
  }
  /* En móvil el botón de la barra también puede mostrarse; el FAB es el principal */
  .filters-bar-header .btn-chat-open {
    display: none;
  }
}

/* Modal CHAT ampliado */
.modal-chat {
  max-width: 560px;
  width: min(560px, 100%);
  display: flex;
  flex-direction: column;
  max-height: min(90vh, 720px);
  padding-bottom: 20px;
}
.chat-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  padding-right: 28px;
}
.chat-modal-head h2 {
  margin: 0;
}
.modal-chat .chat-messages {
  height: min(42vh, 360px);
  max-height: min(42vh, 360px);
  min-height: 200px;
}
@media (max-width: 768px) {
  .modal-chat {
    max-width: calc(100vw - 24px);
    max-height: 88vh;
  }
  .modal-chat .chat-messages {
    height: 40vh;
    max-height: 40vh;
  }
}


/* ===== Configuración del Sitio (adminx) + Banner de aviso ===== */
.site-config-section {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.site-config-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--text);
}
.site-config-item {
  margin: 12px 0 8px;
}
.site-config-check {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}
.site-config-check input[type="checkbox"] {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  accent-color: var(--primary, #0071e3);
}
.site-config-check span {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.site-config-check small {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
  line-height: 1.35;
}
.site-config-check code {
  font-size: 11px;
}
.site-config-actions {
  margin-top: 8px;
  margin-bottom: 4px;
  justify-content: flex-start;
}

.modal-banner-aviso {
  max-width: min(560px, 94vw);
  padding: 20px 20px 18px;
  text-align: center;
}
.banner-aviso-img-wrap {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg, #f5f5f7);
  border: 1px solid var(--border);
  margin-bottom: 16px;
}
.banner-aviso-img-wrap img {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(70vh, 520px);
  object-fit: contain;
}
.banner-aviso-actions {
  margin: 0;
}


/* ===== Avatar usuario (header) ===== */
.user-box {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: flex-end;
  gap: 10px !important;
}
.user-box .user-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  min-width: 0;
}
.user-box .user-name-row {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.user-box .btn-link {
  flex-shrink: 0;
  align-self: flex-end;
}
.user-avatar-btn {
  border: none;
  padding: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
  flex-shrink: 0;
  line-height: 0;
}
.user-avatar-img {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  background: var(--bg);
  display: block;
}
.user-avatar-btn:hover .user-avatar-img {
  border-color: var(--primary, #0071e3);
}

/* ===== Chat estilo WhatsApp (usa variables del tema) ===== */
.wa-chat.modal-chat {
  max-width: min(480px, 96vw);
  padding: 0 0 12px;
  overflow: hidden;
}
.wa-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 44px 12px 16px;
  background: var(--bg-elevated, var(--card));
  border-bottom: 1px solid var(--border);
}
.wa-header-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.wa-header-avatar img,
#waHeaderAvatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  background: var(--bg);
  display: block;
}
.wa-header-text {
  min-width: 0;
}
.wa-header-text h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wa-header-sub {
  font-size: 12px;
  color: var(--text-muted);
}
.wa-header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.wa-tabs {
  padding: 8px 12px 0;
  margin-bottom: 0;
}
.wa-contacts-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  flex-wrap: wrap;
}
.wa-btn-contacts {
  font-weight: 600;
}
.wa-active-peer {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 13px;
  font-weight: 600;
}
.wa-active-peer img {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}
.wa-messages.chat-messages {
  margin: 0 0 8px;
  border-radius: 0;
  border-left: none;
  border-right: none;
  height: min(46vh, 380px);
  max-height: min(46vh, 380px);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--bg) 92%, var(--primary, #0071e3) 8%), var(--bg));
  padding: 12px 10px 16px;
}
.wa-messages .chat-bubble {
  max-width: 78%;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
  border-radius: 10px;
  padding: 6px 10px 4px;
}
.wa-messages .chat-bubble.mine {
  background: color-mix(in srgb, var(--primary, #0071e3) 82%, #fff 18%);
  color: #fff;
  border: none;
  border-top-right-radius: 3px;
}
.wa-messages .chat-bubble.theirs {
  background: var(--card);
  border: 1px solid var(--border);
  border-top-left-radius: 3px;
}
.wa-messages .chat-meta {
  font-size: 11px;
  margin-bottom: 2px;
}
.wa-messages .chat-meta .chat-from-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.wa-messages .chat-meta img.chat-msg-avatar {
  display: none;
}
.wa-messages .chat-text {
  font-size: 14px;
  line-height: 1.35;
}
.wa-compose.chat-compose {
  padding: 6px 12px 4px;
  gap: 8px;
}
.wa-compose input[type="text"] {
  border-radius: 22px;
  padding: 10px 14px;
}
.wa-send {
  border-radius: 50% !important;
  width: 40px;
  height: 40px;
  padding: 0 !important;
  min-width: 40px;
}

/* Lista de contactos */
.modal-contacts {
  max-width: min(400px, 94vw);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  padding: 16px 0 12px;
}
.wa-contacts-head {
  padding: 0 20px 8px;
}
.wa-contacts-head h2 {
  margin: 0 0 4px;
}
.wa-contacts-list {
  overflow-y: auto;
  max-height: min(60vh, 480px);
  padding: 4px 0;
}
.wa-contact-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 20px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: background 0.15s ease;
}
.wa-contact-row:hover {
  background: color-mix(in srgb, var(--primary, #0071e3) 10%, transparent);
}
.wa-contact-row img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.wa-contact-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.wa-contact-name {
  font-weight: 600;
  font-size: 15px;
}
.wa-contact-hint {
  font-size: 12px;
  color: var(--text-muted);
}
.wa-contact-unread {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #0071e3;
  flex-shrink: 0;
}

/* Selector de avatar */
.modal-avatar-picker {
  max-width: min(420px, 94vw);
}
.avatar-picker-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin: 12px 0 8px;
}
.avatar-pick-btn {
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  background: var(--card);
  cursor: pointer;
  line-height: 0;
  transition: border-color 0.15s ease, transform 0.12s ease;
}
.avatar-pick-btn img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}
.avatar-pick-btn:hover {
  border-color: var(--primary, #0071e3);
  transform: scale(1.04);
}
.avatar-pick-btn.is-selected {
  border-color: var(--primary, #0071e3);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary, #0071e3) 35%, transparent);
}
@media (max-width: 480px) {
  .avatar-picker-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* user-box: avatar izquierda, nombre+cerrar sesión en columna */
.header-actions .user-box,
.user-box {
  flex-direction: row !important;
  align-items: center !important;
}
.user-box .user-meta {
  display: flex !important;
  flex-direction: column !important;
  align-items: flex-end !important;
}
@media (max-width: 768px) {
  .header-actions .user-box,
  .user-box {
    flex-direction: row !important;
    align-items: center !important;
    flex-wrap: nowrap;
  }
  .user-avatar-img {
    width: 30px;
    height: 30px;
  }
}

#chatTesterActions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
#chatBtnCloseDmTester {
  font-weight: 700;
}


/* ----- FORESTAL (verdes de bosque) ----- */
[data-skin="forestal"] {
  --bg: #f1f6f0;
  --bg-elevated: rgba(255, 255, 255, 0.94);
  --card: #ffffff;
  --card-hover: #e8f2e6;
  --text: #14291e;
  --text-muted: #4a6b58;
  --text-soft: #6d8f7a;
  --accent: #2d6a4f;
  --accent-hover: #1b4332;
  --primary: #40916c;
  --border: rgba(45, 106, 79, 0.18);
  --input-bg: #f7fbf6;
  --input-bg-focus: #eef7ec;
  --table-head: #e4f0e2;
  --row-hover: #eaf5e8;
  --shadow: 0 8px 28px rgba(27, 67, 50, 0.12);
  --modal-overlay: rgba(20, 40, 28, 0.45);
  --loading-overlay: rgba(241, 246, 240, 0.85);
  --error-bg: #fde8e8;
  --error-text: #b42318;
  --badge-soft-bg: rgba(64, 145, 108, 0.16);
  --badge-soft-text: #1b4332;
  --btn-secondary-bg: #e8f2e6;
  --btn-secondary-hover: #d5ead1;
  --estado-por-asignar-bg: #e8eeea;
  --estado-por-asignar-fg: #4a6b58;
  --estado-en-proceso-bg: #d8f0e4;
  --estado-en-proceso-fg: #1b4332;
  --estado-en-revision-bg: #fff3d6;
  --estado-en-revision-fg: #8a5a00;
  --estado-completo-bg: #d4edda;
  --estado-completo-fg: #1b4332;
  --estado-vb-bg: #dcefe6;
  --estado-vb-fg: #2d6a4f;
}

[data-skin="forestal"][data-theme="dark"] {
  --bg: #0c1a14;
  --bg-elevated: rgba(14, 32, 24, 0.95);
  --card: #13241b;
  --card-hover: #1a3326;
  --text: #e6f4ea;
  --text-muted: #8fb89c;
  --text-soft: #6a9478;
  --accent: #52b788;
  --accent-hover: #40916c;
  --primary: #74c69d;
  --border: rgba(82, 183, 136, 0.2);
  --input-bg: #0f1f17;
  --input-bg-focus: #152a1e;
  --table-head: #0f1f17;
  --row-hover: #1a3326;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  --modal-overlay: rgba(6, 16, 12, 0.72);
  --loading-overlay: rgba(12, 26, 20, 0.82);
  --error-bg: #3a1818;
  --error-text: #ff8a8a;
  --badge-soft-bg: rgba(82, 183, 136, 0.18);
  --badge-soft-text: #95d5b2;
  --btn-secondary-bg: #0f1f17;
  --btn-secondary-hover: #1a3326;
  --estado-por-asignar-bg: #1a2a22;
  --estado-por-asignar-fg: #8fb89c;
  --estado-en-proceso-bg: #143528;
  --estado-en-proceso-fg: #74c69d;
  --estado-en-revision-bg: #3a2e14;
  --estado-en-revision-fg: #f0b040;
  --estado-completo-bg: #143528;
  --estado-completo-fg: #74c69d;
  --estado-vb-bg: #1a3328;
  --estado-vb-fg: #95d5b2;
}

/* Puntos de no leído más visibles */
.chat-dot {
  width: 9px !important;
  height: 9px !important;
  border-radius: 50%;
  flex-shrink: 0;
}
.chat-unread-dots {
  display: inline-flex !important;
  align-items: center;
  gap: 4px;
  min-height: 10px;
}
.btn-chat-open.has-unread,
.chat-fab.has-unread {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent, #0071e3) 35%, transparent);
}


/* Filas de mensaje: avatar al lado (más grande), burbuja aparte */
.chat-messages,
.wa-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
}
.chat-row.theirs {
  align-self: flex-start;
  flex-direction: row;
  justify-content: flex-start;
}
.chat-row.mine {
  align-self: flex-end;
  flex-direction: row;
  justify-content: flex-end;
}
.chat-row .chat-msg-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--border);
  background: var(--card);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.chat-row .chat-bubble {
  max-width: min(78%, calc(100% - 52px));
  margin: 0;
}
.chat-row.mine .chat-bubble {
  align-self: auto;
}
.chat-row.theirs .chat-bubble {
  align-self: auto;
}
.wa-messages .chat-meta img.chat-msg-avatar {
  display: none; /* ya no va dentro del meta */
}

.banner-upload-block {
  margin: 12px 0 4px 30px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
}
.banner-upload-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}
.banner-upload-block input[type="file"] {
  display: block;
  width: 100%;
  font-size: 13px;
  margin-bottom: 6px;
}
.banner-upload-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0 0 10px;
  line-height: 1.35;
}
.banner-upload-preview-wrap {
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg);
  min-height: 0;
}
.banner-upload-preview-wrap img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: contain;
}
.banner-upload-preview-wrap img[hidden] {
  display: none !important;
}
.banner-upload-actions {
  margin-top: 8px;
}

/* Vista Productividad (tester) */
.main-list-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}
.main-list-title-row h2 {
  margin: 0;
}
.btn-toggle-productividad {
  font-weight: 700;
  white-space: nowrap;
}
.productividad-view {
  padding: 8px 4px 16px;
}
.productividad-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 14px;
}
.productividad-bars {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.prod-row {
  display: grid;
  grid-template-columns: minmax(140px, 200px) 1fr auto;
  align-items: center;
  gap: 12px;
}
.prod-user {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.prod-user img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}
.prod-user-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.prod-bar-track {
  height: 22px;
  border-radius: 11px;
  background: color-mix(in srgb, var(--border) 55%, transparent);
  overflow: hidden;
  min-width: 0;
}
.prod-bar-fill {
  height: 100%;
  border-radius: 11px;
  background: linear-gradient(90deg, var(--primary, #40916c), var(--accent, #2d6a4f));
  min-width: 0;
  transition: width 0.35s ease;
}
.prod-bar-stack {
  display: flex;
  flex-direction: row;
  height: 100%;
  border-radius: 11px;
  overflow: hidden;
  min-width: 4px;
  transition: width 0.35s ease;
}
.prod-bar-seg {
  display: block;
  height: 100%;
  min-width: 0;
}
.prod-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-bottom: 14px;
  font-size: 11px;
  color: var(--text-muted);
}
.prod-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.prod-legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}
.prod-count {
  font-weight: 700;
  font-size: 14px;
  min-width: 2ch;
  text-align: right;
  color: var(--text);
}
.productividad-chart-canvas {
  display: none !important;
}
.productividad-trend-block {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}
.productividad-trend-title {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.productividad-trend-hint {
  margin: 0 0 14px;
  font-size: 12px;
  color: var(--text-muted);
}
.productividad-trend-chart-wrap {
  position: relative;
  width: 100%;
  height: min(340px, 48vh);
  min-height: 240px;
}
.productividad-trend-chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}
@media (max-width: 640px) {
  .prod-row {
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
  }
  .prod-user {
    grid-column: 1 / -1;
  }
}


/* Burbujas de chat del usuario tester */
.chat-bubble.from-tester,
.wa-messages .chat-bubble.from-tester {
  background: #62a586 !important;
  color: #fff !important;
  border-color: transparent !important;
}
.chat-bubble.from-tester .chat-meta,
.chat-bubble.from-tester .chat-link,
.chat-bubble.from-tester .chat-del-btn {
  color: rgba(255, 255, 255, 0.95) !important;
}
[data-skin="forestal"] .chat-bubble.from-tester,
[data-skin="forestal"] .wa-messages .chat-bubble.from-tester {
  background: #b7cd02 !important;
  color: #1a2a08 !important;
}
[data-skin="forestal"] .chat-bubble.from-tester .chat-meta,
[data-skin="forestal"] .chat-bubble.from-tester .chat-link,
[data-skin="forestal"] .chat-bubble.from-tester .chat-del-btn {
  color: rgba(26, 42, 8, 0.9) !important;
}

.btn-tester-see-all.is-active {
  background: var(--accent, #2d6a4f);
  color: #fff;
  border-color: transparent;
  font-weight: 700;
}

/* Panel de emojis del chat */
.chat-emoji-panel {
  display: none;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 10px;
  margin: 0 10px 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  max-height: 140px;
  overflow-y: auto;
}
.chat-emoji-panel.is-open {
  display: flex !important;
}
.chat-emoji-panel button.chat-emoji-item {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1.2;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chat-emoji-panel button.chat-emoji-item:hover {
  background: var(--badge-soft-bg, rgba(0,0,0,0.06));
}
.chat-emoji-btn {
  flex-shrink: 0;
  font-size: 16px;
  min-width: 36px;
}

/* Aprobación en listado */
.btn-aprobacion {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  white-space: nowrap;
}
.btn-aprobacion.is-ok {
  background: color-mix(in srgb, #30d158 22%, transparent);
  color: var(--estado-completo-fg, #1b4332);
  border-color: transparent;
}
.btn-aprobacion.is-pending {
  background: color-mix(in srgb, #ff9f0a 20%, transparent);
  color: #8a5a00;
  border-color: transparent;
}
.btn-aprobacion.is-correcciones {
  background: color-mix(in srgb, #ff9f0a 35%, transparent);
  color: #7a4500;
  border-color: transparent;
  font-weight: 800;
}
.modal-aprobacion { max-width: 520px; }

/* Modal aprobación multi-muestra */
.modal-aprobacion { max-width: 560px; }
.ap-items-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: min(60vh, 520px);
  overflow-y: auto;
  padding-right: 4px;
}
.ap-item-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--card);
}
.ap-item-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.ap-item-card-head strong {
  font-size: 13px;
}
.ap-item-status {
  font-size: 11px;
  color: var(--text-muted);
}
.ap-item-card .form-group { margin-bottom: 8px; }
.ap-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.ap-item-actions .btn {
  font-size: 11px;
  padding: 5px 8px;
  font-weight: 700;
}
.ap-add-item-wrap {
  display: flex;
  justify-content: center;
  margin-top: 12px;
}
.btn-ap-add {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
}

/* Ocultar columna Aprobación (global) */
html.hide-aprobacion-col .col-aprobacion,
html.hide-aprobacion-col .td-aprobacion {
  display: none !important;
}
