/* ============================================================
   PROLED3D — Panel de administración · interfaz unificada (css/admin-v3.css)

   Se carga después de css/admin.css y de las hojas de cada módulo. Redefine los
   tokens (color, tipografía, espaciado) y unifica estructura, navegación, tarjetas,
   filtros, formularios, botones, tablas, estados, modales y gráficos. No cambia
   identificadores ni comportamiento: sólo presentación.

   Criterios: contraste AA, acento azul PROLED3D (#0088ff) reservado para acciones
   y selección, colores fuertes sólo para estados, cifras tabulares alineadas a la
   derecha, foco siempre visible.
   ============================================================ */

/* ── 1. Tokens ─────────────────────────────────────────────── */
:root {
  color-scheme: dark;
  --bg: #0a1118;
  --bg-elev: #101a24;
  --bg-elev-1: #101a24;
  --bg-elev-2: #152230;
  --bg-elev-3: #1c2c3d;
  --text: #edf3fa;
  --text-muted: #b3c2d1;
  --text-dim: #94a7b9;
  --accent: #3d9fff;
  --accent-2: #0073d9;
  --accent-solid: #0073d9;
  --accent-solid-hover: #0a84f0;
  --accent-dim: rgba(0, 136, 255, 0.16);
  --border: #2c3f52;
  --border-light: #213243;
  --chart-grid: #1f2e3d;
  --danger: #ff7b7b;
  --danger-dim: rgba(255, 123, 123, 0.14);
  --warning: #f2c768;
  --warning-dim: rgba(242, 199, 104, 0.14);
  --success: #62d59a;
  --success-dim: rgba(98, 213, 154, 0.14);
  --info: #7ab8f5;
  --info-dim: rgba(122, 184, 245, 0.14);
  --focus-ring: 0 0 0 3px rgba(61, 159, 255, 0.45);
  --shadow: 0 16px 40px rgba(0, 4, 10, 0.45);
  --shadow-sm: 0 1px 2px rgba(0, 4, 10, 0.3);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 248px;
  --topbar-h: 60px;
  --font: "Segoe UI", "Manrope", "Noto Sans", system-ui, sans-serif;
  /* Alias que usan las hojas de los módulos */
  --muted: var(--text-muted);
  --line: var(--border);
  --panel: var(--bg-elev);
  --panel2: var(--bg-elev-2);
  --amber: var(--warning);
  /* Escala de espaciado */
  --esp-1: 4px; --esp-2: 8px; --esp-3: 12px; --esp-4: 16px; --esp-5: 24px; --esp-6: 32px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f5f8;
  --bg-elev: #ffffff;
  --bg-elev-1: #ffffff;
  --bg-elev-2: #f5f7fa;
  --bg-elev-3: #e9eef3;
  --text: #0f1c28;
  --text-muted: #43566a;
  --text-dim: #586b7d;
  --accent: #0064c4;
  --accent-2: #00529f;
  --accent-solid: #0064c4;
  --accent-solid-hover: #00529f;
  --accent-dim: rgba(0, 100, 196, 0.1);
  --border: #cbd5de;
  --border-light: #e1e7ed;
  --chart-grid: #e6ebf0;
  --danger: #b3261e;
  --danger-dim: rgba(179, 38, 30, 0.09);
  --warning: #855600;
  --warning-dim: rgba(133, 86, 0, 0.1);
  --success: #17704a;
  --success-dim: rgba(23, 112, 74, 0.1);
  --info: #155f9b;
  --info-dim: rgba(21, 95, 155, 0.1);
  --focus-ring: 0 0 0 3px rgba(0, 100, 196, 0.3);
  --shadow: 0 16px 40px rgba(15, 28, 40, 0.16);
  --shadow-sm: 0 1px 2px rgba(15, 28, 40, 0.08);
}

/* ── 2. Base ───────────────────────────────────────────────── */
html, body { font-size: 14px; line-height: 1.5; }
body { background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
:root[data-theme="light"] body { background: var(--bg); }

.admin-saltar {
  position: fixed; left: 12px; top: -60px; z-index: 10000;
  padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--accent-solid); color: #fff; font-weight: 600; text-decoration: none;
}
.admin-saltar:focus { top: 12px; }

a:focus-visible, button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible,
summary:focus-visible, [tabindex="0"]:focus-visible, [tabindex="-1"]:focus-visible:not(main) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}
.admin-main:focus { outline: none; }

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

/* ── 3. Estructura ─────────────────────────────────────────── */
#adminApp { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); grid-template-rows: var(--topbar-h) minmax(0, 1fr); }

.admin-sidebar,
:root[data-theme="light"] .admin-sidebar { background: var(--bg-elev); border-right: 1px solid var(--border); }
.admin-sidebar-brand { padding: 16px 18px 14px; border-bottom: 1px solid var(--border-light); }
.admin-sidebar-brand .brand-logo { flex-direction: row; align-items: center; gap: 10px; }
.admin-sidebar-brand img { height: 22px; filter: none; }
.admin-sidebar-brand strong { font-size: 12px; font-weight: 600; letter-spacing: 0.02em; color: var(--text-muted); padding-left: 10px; border-left: 1px solid var(--border); }

.admin-nav { flex: 1; overflow-y: auto; padding: 10px 10px 16px; scrollbar-width: thin; }
.admin-nav-grupo { padding-bottom: 6px; }
.admin-nav-grupo + .admin-nav-grupo { margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--border-light); }
.admin-nav-section { padding: 6px 10px 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-dim); }
.admin-nav-btn {
  gap: 10px; min-height: 36px; padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 13.5px; font-weight: 500; text-decoration: none; line-height: 1.3;
}
a.admin-nav-btn { text-decoration: none; }
.admin-nav-btn .nav-icon { width: 16px; height: 16px; opacity: 0.75; }
.admin-nav-btn:hover { color: var(--text); background: var(--bg-elev-2); }
.admin-nav-btn.active { color: var(--accent); background: var(--accent-dim); font-weight: 700; }
:root[data-theme="light"] .admin-nav-btn.active { color: var(--accent-2); }
.admin-nav-btn.active::before { left: -10px; width: 4px; height: 22px; border-radius: 0 4px 4px 0; background: var(--accent); }
.admin-nav-badge { background: var(--bg-elev-3); color: var(--text); border: 1px solid var(--border); font-size: 11px; padding: 0 7px; min-width: 22px; font-variant-numeric: tabular-nums; }

.admin-sidebar-footer { padding: 12px 14px 14px; border-top: 1px solid var(--border-light); display: grid; grid-template-columns: 1fr auto; gap: 8px 10px; align-items: center; }
.admin-sidebar-user { grid-column: 1 / -1; margin: 0; min-width: 0; }
.admin-sidebar-user-info { min-width: 0; }
.admin-sidebar-user-info strong, .admin-sidebar-user-info small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-sidebar-user-info strong { font-size: 13px; }
.admin-sidebar-user-info small { font-size: 12px; color: var(--text-dim); }
.admin-badge-role { margin: 0; justify-self: start; font-size: 11px; background: var(--accent-dim); border-color: transparent; color: var(--accent); }
:root[data-theme="light"] .admin-badge-role { color: var(--accent-2); }
.admin-version { margin: 0; font-size: 12px; text-align: right; color: var(--text-dim); }
.btn-sidebar-back { grid-column: 1 / -1; justify-content: center; min-height: 36px; background: transparent; text-decoration: none; }
.btn-sidebar-back span { text-decoration: none; }

.admin-topbar,
:root[data-theme="light"] .admin-topbar { background: var(--bg-elev); border-bottom: 1px solid var(--border); padding: 0 24px; gap: 16px; min-height: var(--topbar-h); }
.admin-breadcrumb { margin: 0; gap: 8px; font-size: 13px; color: var(--text-dim); flex-wrap: wrap; }
.admin-breadcrumb a { color: var(--text-muted); text-decoration: none; }
.admin-breadcrumb a:hover { color: var(--accent); text-decoration: underline; }
.admin-breadcrumb #breadcrumbCurrent { color: var(--text); font-weight: 700; }
/* El título de la sección ya está en la página: en la barra queda sólo para lectores de pantalla. */
.admin-topbar-title h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.admin-topbar-title small:empty { display: none; }
.admin-topbar-title small { display: block; font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.admin-topbar-search { height: 38px; min-width: 260px; max-width: 340px; background: var(--bg-elev-2); border-color: var(--border); border-radius: var(--radius-sm); }
.admin-topbar-search:focus-within { border-color: var(--accent); box-shadow: var(--focus-ring); }
.admin-topbar .admin-topbar-search input[type="search"], .admin-topbar .admin-topbar-search input[type="search"]:focus-visible { border: 0; background: none; outline: none; box-shadow: none; min-height: 0; padding: 0; }

.admin-main { padding: 28px 32px 40px; background: var(--bg); scrollbar-width: thin; }
.admin-section { max-width: 1520px; margin-inline: auto; }
.admin-manual-refresh-note {
  display: block; max-width: 1520px; margin: 32px auto 0; padding: 12px 0 0; border: 0; border-top: 1px solid var(--border-light); border-radius: 0;
  background: none; color: var(--text-dim); font-size: 12px;
}

/* ── 4. Cabecera de sección ────────────────────────────────── */
.section-header, .beta-admin-cabecera, .pubadm-cabecera {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; margin-bottom: 20px;
}
.section-header h2, .beta-admin-cabecera h2, .pubadm-cabecera h2 { font-size: 24px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; color: var(--text); margin: 0; }
.section-header h2 small { font-size: 14px !important; font-weight: 500 !important; color: var(--text-dim) !important; margin-left: 6px; font-variant-numeric: tabular-nums; }
.section-header h3 { margin: 0; }
.section-header p, .beta-admin-cabecera p, .pubadm-cabecera p { margin: 4px 0 0; max-width: 78ch; color: var(--text-muted); font-size: 13px; }
.section-header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.admin-helper-text { color: var(--text-muted); font-size: 13px; line-height: 1.45; }
.admin-warning-text { color: var(--warning); }
button.enlace { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; min-height: 0; }

/* ── 5. Tarjetas y bloques ─────────────────────────────────── */
.block-card, .chart-card, .kpi-card, .export-card, .membership-card,
:root[data-theme="light"] .block-card, :root[data-theme="light"] .chart-card, :root[data-theme="light"] .kpi-card {
  background: var(--bg-elev); background-image: none;
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.block-card { padding: 20px; }
.block-card h3, .membership-card h3, .export-card h3 {
  font-size: 15px; font-weight: 700; color: var(--text); text-transform: none; letter-spacing: 0; margin: 0 0 12px;
}
.block-card-header { margin-bottom: 14px; }
.block-card-header h3 { margin-bottom: 2px; }
.block-card-header p { color: var(--text-muted); font-size: 13px; }

/* ── 6. Indicadores (KPI) ──────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 0; }
.kpi-card { position: relative; padding: 16px 18px; min-width: 0; transition: border-color 0.15s; }
.kpi-card:hover { transform: none; border-color: var(--border); }
.kpi-card::after { display: none; }
.kpi-label { font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: none; letter-spacing: 0; line-height: 1.3; }
.kpi-value {
  margin: 8px 0 4px; font-size: clamp(22px, 1.6vw + 8px, 30px); font-weight: 700; line-height: 1.1; color: var(--text);
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em; overflow-wrap: anywhere;
}
.kpi-sub { font-size: 12px; color: var(--text-dim); display: flex; align-items: baseline; gap: 5px; flex-wrap: wrap; }
.kpi-sub.positive { color: var(--success); }
.kpi-sub.negative { color: var(--danger); }
.kpi-sub.neutral { color: var(--text-dim); }
.kpi-delta-icon { font-size: 9px; }
.kpi-def { margin: 10px 0 0; font-size: 12px; line-height: 1.4; color: var(--text-dim); }
.kpi-def summary { display: inline-block; cursor: pointer; color: var(--text-muted); text-decoration: underline dotted; text-underline-offset: 3px; border-radius: 4px; }
.kpi-def summary:hover { color: var(--accent); }
.kpi-def p { margin: 6px 0 0; }

.kpi-grid-primary { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); margin-bottom: 0; }
.pulse-card { min-height: 0; border-top: 1px solid var(--border); }
.kpi-card.kpi-card--compacta, :root[data-theme="light"] .kpi-card.kpi-card--compacta {
  padding: 2px 0 2px 12px; border: 0; border-left: 3px solid var(--border); border-radius: 0; box-shadow: none; background: none;
}
.kpi-card.kpi-card--compacta.accent-info { border-left-color: var(--info); }
.kpi-card.kpi-card--compacta.accent-warning { border-left-color: var(--warning); }
.kpi-card--compacta .kpi-value { font-size: 22px; margin: 4px 0 2px; overflow-wrap: normal; white-space: nowrap; }
.kpi-grid--grupo { grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); gap: 14px 10px; }
.kpi-grid--dos { grid-template-columns: 1fr; }

/* ── 7. Inicio (Resumen) ───────────────────────────────────── */
#s-resumen { display: none; }
#s-resumen.active { display: grid; gap: 24px; }
#s-resumen > * { margin: 0 !important; min-width: 0; }
.admin-period-bar,
:root[data-theme="light"] .admin-period-bar {
  display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; padding: 14px 16px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.admin-period-bar label { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.data-freshness { margin-left: auto; align-self: center; font-size: 12px; color: var(--text-dim); text-align: right; }
.resumen-bloque { display: grid; gap: 12px; min-width: 0; }
.resumen-bloque-cab { display: flex; align-items: baseline; gap: 6px 12px; flex-wrap: wrap; }
.resumen-bloque-cab h3 { font-size: 17px; font-weight: 700; color: var(--text); margin: 0; }
.resumen-bloque-cab p { font-size: 13px; color: var(--text-dim); margin: 0; }
.resumen-grupos { display: grid; grid-template-columns: 5fr 5fr 2fr; gap: 12px; }
.resumen-grupo { padding: 16px; }
.resumen-grupo h4 { font-size: 13px; font-weight: 700; color: var(--text-muted); margin: 0 0 10px; }
.resumen-dos-columnas { display: grid; grid-template-columns: minmax(0, 3fr) minmax(280px, 2fr); gap: 16px; align-items: start; }
.resumen-atajos { display: grid; gap: 16px; }
.ultimo-evento { font-size: 14px; color: var(--text-muted); overflow-wrap: anywhere; }
.ultimo-evento small { display: block; margin-top: 2px; font-size: 12px; color: var(--text-dim) !important; }

.attention-card { margin: 0; }
.attention-grid { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.attention-item {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px; min-height: 0; padding: 12px 14px;
  background: var(--bg-elev-2); border: 1px solid var(--border); border-left-width: 4px; border-radius: var(--radius-sm); font-family: var(--font);
}
.attention-item span { grid-column: 1; font-size: 13px; font-weight: 600; color: var(--text); }
.attention-item strong { grid-column: 2; grid-row: 1 / 3; margin: 0; font-size: 24px; font-variant-numeric: tabular-nums; }
.attention-item small { grid-column: 1; font-size: 12px; }
.attention-item:hover { border-color: var(--accent); }
.attention-item.has-items { border-left-color: var(--warning); }
.attention-item.has-items small { color: var(--warning); font-weight: 700; }
.attention-item.has-items small::before { content: "▲ "; font-size: 9px; }
.attention-item.is-clear { border-left-color: var(--success); }
.attention-item.is-clear strong { color: var(--text-dim); }
.attention-item.is-clear small::before { content: "✓ "; color: var(--success); }

.ops-health-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; margin: 0; }
.ops-health-card, .ops-health-card.good, .ops-health-card.warning, .ops-health-card.danger {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; box-shadow: var(--shadow-sm);
}
.ops-health-card strong { font-size: 13px; color: var(--text); }
.ops-health-card small { font-size: 12px; color: var(--text-muted); }
.ops-health-dot { width: 10px; height: 10px; background: var(--text-dim); box-shadow: none; }
.ops-health-card.good .ops-health-dot { background: var(--success); box-shadow: 0 0 0 3px var(--success-dim); }
.ops-health-card.warning .ops-health-dot { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-dim); border-radius: 2px; }
.ops-health-card.danger .ops-health-dot { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-dim); border-radius: 0; transform: rotate(45deg); }
.secondary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; margin: 0 !important; }
.secondary-grid .block-card { padding: 14px 16px; }
.secondary-grid .block-card h3 { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }

.share3d-summary-card { padding: 20px; }
.share3d-summary-heading p, .share3d-summary-heading small { font-size: 13px; color: var(--text-dim); }
.share3d-summary-metrics { gap: 10px; }
.share3d-summary-metric { background: var(--bg-elev-2); border: 1px solid var(--border-light); border-radius: var(--radius-sm); padding: 12px 14px; }
.share3d-summary-metric span { font-size: 13px; color: var(--text-muted); }
.share3d-summary-metric strong { font-size: 22px; }
.share3d-summary-metric small { font-size: 12px; color: var(--text-dim); }

.admin-checklist { display: grid; grid-template-columns: 1fr; gap: 8px; }
.admin-check-item { background: var(--bg-elev-2); border: 1px solid var(--border-light); border-radius: var(--radius-sm); font-family: var(--font); }
.admin-check-item:hover { border-color: var(--accent); }
.admin-check-item strong { font-size: 13px; color: var(--text); }
.admin-check-item small { font-size: 12px; color: var(--text-muted); }
.admin-check-item span { color: var(--accent); font-variant-numeric: tabular-nums; }
.quick-actions-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.quick-actions-grid .btn { justify-content: center; }

.ranking-row { padding: 9px 0; border-bottom: 1px solid var(--border-light); }
.ranking-row:last-child { border-bottom: 0; }
.ranking-info { min-width: 0; }
.ranking-info strong, .ranking-info small { display: block; overflow-wrap: anywhere; }
.ranking-info small { font-size: 12px; color: var(--text-dim); }
.ranking-num { color: var(--text-dim); font-variant-numeric: tabular-nums; }
.ranking-num.top { color: var(--text); font-weight: 700; }
.ranking-val { color: var(--text); font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── 8. Filtros y formularios ──────────────────────────────── */
.filters-bar, .subscriptions-filters, .beta-admin-filtros, .support-admin-toolbar, .support-admin-workflow-controls {
  display: flex; align-items: flex-end; gap: 10px 12px; flex-wrap: wrap; margin-bottom: 16px; padding: 14px 16px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.filter-group { display: grid; gap: 4px; align-items: start; }
.filter-group:has(> label), .filter-group:has(input[type="checkbox"]) { align-self: center; }
.filter-label { font-size: 12px; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.filter-sep { display: none; }
.filters-bar > .filter-label { align-self: center; }
.filter-chips { margin: 0 0 16px; gap: 8px; }
.filter-chip { background: var(--bg-elev); border: 1px solid var(--border); color: var(--text-muted); font-weight: 600; font-size: 13px; padding: 6px 14px; min-height: 34px; }
.filter-chip:hover { border-color: var(--accent); color: var(--text); }
.filter-chip.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); font-weight: 700; }
:root[data-theme="light"] .filter-chip.active { color: var(--accent-2); }

input[type="text"], input[type="search"], input[type="date"], input[type="email"], input[type="number"], input[type="url"],
input[type="datetime-local"], input[type="time"], input[type="password"], input:not([type]), textarea, select {
  min-height: 36px; padding: 7px 10px; background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text); font-size: 13.5px; font-family: var(--font);
}
:root[data-theme="light"] :is(input[type="text"], input[type="search"], input[type="date"], input[type="email"], input[type="number"], input[type="url"], input:not([type]), textarea, select) { background: #fff; }
input:hover, textarea:hover, select:hover { border-color: var(--text-dim); }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
input:disabled, textarea:disabled, select:disabled { opacity: 0.6; cursor: not-allowed; }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; min-height: 0; accent-color: var(--accent-solid); flex-shrink: 0; }
select { padding-right: 28px; }
:root[data-theme="light"] select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%2343566a' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E"); }
input::placeholder, textarea::placeholder { color: var(--text-dim); opacity: 1; }
label { color: var(--text-muted); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
legend { padding: 0 6px; font-size: 13px; font-weight: 700; color: var(--text); }
.detail-field > span, .membership-inline-field > span, .modal-field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.detail-field small { font-size: 12px; color: var(--text-dim); }

/* ── 9. Botones ────────────────────────────────────────────── */
.btn {
  min-height: 36px; padding: 7px 14px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 13.5px; font-weight: 600; line-height: 1.2; justify-content: center; text-decoration: none;
  background: var(--bg-elev-2); border-color: var(--border); color: var(--text);
}
.btn:hover { border-color: var(--text-dim); }
.btn-primary, .btn.btn-primary { background: var(--accent-solid); border-color: var(--accent-solid); color: #fff; }
.btn-primary:hover, .btn.btn-primary:hover { background: var(--accent-solid-hover); border-color: var(--accent-solid-hover); }
.btn-secondary { background: var(--bg-elev); border-color: var(--border); color: var(--text); }
:root:not([data-theme="light"]) .btn-secondary { background: var(--bg-elev-2); }
.btn-secondary:hover { border-color: var(--accent); color: var(--text); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); padding: 7px 10px; }
.btn-ghost:hover { background: var(--bg-elev-2); border-color: transparent; color: var(--text); }
.btn-danger { background: var(--danger-dim); border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
:root:not([data-theme="light"]) .btn-danger:hover { color: #1a0505; }
.btn-warning { background: var(--warning-dim); border-color: var(--warning); color: var(--warning); }
.btn-warning:hover { background: var(--warning); color: #1c1300; }
:root[data-theme="light"] .btn-warning:hover { color: #fff; }
.btn-success { background: var(--success-dim); border-color: var(--success); color: var(--success); }
.btn-success:hover { background: var(--success); color: #04180e; }
:root[data-theme="light"] .btn-success:hover { color: #fff; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn-xs { min-height: 28px; padding: 3px 9px; font-size: 12px; }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-icon { min-width: 36px; padding: 6px; }

/* ── 10. Pestañas (todas las secciones comparten el mismo control) ── */
.subscriptions-tabs, .security-tabs, .support-admin-tabs, .asi-pestanas, .pubadm-pestanas {
  display: flex; align-items: stretch; gap: 2px; flex-wrap: wrap; margin: 0 0 16px; padding: 0;
  border: 0; border-bottom: 1px solid var(--border); background: none; border-radius: 0;
}
.subscriptions-tab, .security-tabs button, .support-admin-tabs button, .asi-pestanas .btn, .pubadm-pestana {
  min-height: 40px; padding: 8px 14px; margin: 0 0 -1px; border: 0; border-bottom: 3px solid transparent; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: none; color: var(--text-muted); font-family: var(--font); font-size: 13.5px; font-weight: 600; cursor: pointer; box-shadow: none;
}
.subscriptions-tab:hover, .security-tabs button:hover, .support-admin-tabs button:hover, .asi-pestanas .btn:hover, .pubadm-pestana:hover { color: var(--text); background: var(--bg-elev-2); }
.subscriptions-tab.active, .security-tabs button.active, .support-admin-tabs button.is-active, .asi-pestanas .btn[aria-selected="true"], .pubadm-pestana.activa {
  color: var(--accent); border-bottom-color: var(--accent); background: none; font-weight: 700;
}
:root[data-theme="light"] :is(.subscriptions-tab.active, .security-tabs button.active, .support-admin-tabs button.is-active, .asi-pestanas .btn[aria-selected="true"], .pubadm-pestana.activa) { color: var(--accent-2); }
.asi-separador { flex: 1; }
.pubadm-cabecera { display: grid; grid-template-columns: 1fr; }

/* ── 11. Tablas ────────────────────────────────────────────── */
.table-wrap, .admin-table-wrap, .beta-admin-tabla {
  overflow-x: auto; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); scrollbar-width: thin;
}
.block-card .table-wrap, .block-card .admin-table-wrap { box-shadow: none; }
.data-table, .admin-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table thead tr, .admin-table thead tr { background: var(--bg-elev-2); border-bottom: 1px solid var(--border); }
.data-table th, .admin-table th {
  position: sticky; top: 0; z-index: 1; padding: 10px 14px; background: var(--bg-elev-2);
  text-align: left; font-size: 12px; font-weight: 700; letter-spacing: 0.02em; text-transform: none; color: var(--text-muted); white-space: nowrap;
}
.data-table th[data-sortable="true"]:hover, .admin-table th[data-sortable="true"]:hover { color: var(--text); }
.data-table td, .admin-table td { padding: 10px 14px; border-bottom: 1px solid var(--border-light); color: var(--text); font-size: 13.5px; vertical-align: middle; }
.data-table tbody tr:hover, .admin-table tbody tr:hover { background: var(--bg-elev-2); }
.data-table tbody tr:last-child td, .admin-table tbody tr:last-child td { border-bottom: 0; }
.data-table .col-num, .admin-table .col-num, th.col-num, td.col-num { text-align: right; font-variant-numeric: tabular-nums; }
/* Valores largos: se leen completos en lugar de cortarse con puntos suspensivos. */
.data-table .col-email, .data-table .col-name { max-width: 280px; overflow: visible; text-overflow: clip; white-space: normal; overflow-wrap: anywhere; }
.data-table .col-date { font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.data-table .col-actions, .data-table td:has(> .btn):last-child, .admin-table td:has(> .btn):last-child { white-space: nowrap; }
.data-table td .btn + .btn, .admin-table td .btn + .btn { margin-left: 4px; }
.loading-spinner { color: var(--text-muted); }
.empty-state { color: var(--text-muted); font-size: 13.5px; }
.section-error-state {
  display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; margin-bottom: 16px; padding: 14px 16px; text-align: left;
  background: var(--danger-dim); border: 1px solid var(--danger); border-left-width: 4px; border-radius: var(--radius-sm); color: var(--text);
}
.section-error-state strong::before { content: "! "; color: var(--danger); font-weight: 800; }
.section-error-state span { color: var(--text-muted); flex: 1; min-width: 200px; }

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.pagination-info { font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.pagination-controls { display: flex; gap: 4px; flex-wrap: wrap; }
.page-btn { min-width: 36px; min-height: 36px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); font-family: var(--font); font-size: 13px; font-variant-numeric: tabular-nums; }
.page-btn:hover:not(:disabled) { border-color: var(--accent); }
.page-btn.active { background: var(--accent-solid); border-color: var(--accent-solid); color: #fff; font-weight: 700; }
.page-btn:disabled { opacity: 0.45; }

/* ── 12. Insignias de estado ───────────────────────────────── */
.badge { padding: 2px 9px; font-size: 12px; font-weight: 600; line-height: 1.5; border: 1px solid transparent; }
.membership-status-chip, .badge-membership-state { font-size: 12px; }

/* ── 13. Modales y panel de detalle ────────────────────────── */
.modal-overlay { background: rgba(4, 9, 14, 0.62); backdrop-filter: blur(2px); padding: 16px; }
.modal-box { width: min(480px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; padding: 24px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.modal-box h3 { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.modal-box p { font-size: 14px; color: var(--text-muted); margin-bottom: 16px; }
.modal-field { display: grid; gap: 4px; margin-bottom: 14px; }
.modal-field input, .modal-field select, .modal-field textarea { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
.detail-panel-backdrop { background: rgba(4, 9, 14, 0.55); }
.admin-detail-panel { background: var(--bg-elev); border-left: 1px solid var(--border); box-shadow: var(--shadow); }
.detail-panel-header { padding: 16px 20px; border-bottom: 1px solid var(--border); background: var(--bg-elev); }
.detail-panel-header h3 { font-size: 17px; font-weight: 700; }
.detail-panel-footer { border-top: 1px solid var(--border); background: var(--bg-elev-2); }
#toastContainer > div { font-size: 14px !important; border-radius: var(--radius-sm) !important; }

/* ── 14. Gráficos ──────────────────────────────────────────── */
.graficas-grupo { margin: 28px 0 12px; font-size: 17px; font-weight: 700; color: var(--text); }
.section-header + .graficas-grupo { margin-top: 0; }
.graficas-filtros { align-items: flex-end; padding: 12px 14px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.charts-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 16px; margin-bottom: 0; }
.charts-grid--dos { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.chart-card { display: flex; flex-direction: column; gap: 12px; padding: 20px; min-width: 0; }
.chart-card.wide { grid-column: 1 / -1; }
.grafico-cab { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px 20px; }
.grafico-cab > div:first-child { min-width: 0; }
.chart-card h3 { font-size: 16px; font-weight: 700; color: var(--text); text-transform: none; letter-spacing: 0; margin: 0; line-height: 1.3; }
.grafico-pregunta { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }
.grafico-sub { margin: 6px 0 0; font-size: 12px; font-weight: 600; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.grafico-cifra { flex-shrink: 0; text-align: right; }
.grafico-cifra strong { display: block; font-size: 24px; font-weight: 700; line-height: 1.1; color: var(--text); font-variant-numeric: tabular-nums; }
.grafico-cifra span { display: block; margin-top: 2px; font-size: 12px; color: var(--text-dim); max-width: 16ch; margin-left: auto; }
.grafico-lienzo { position: relative; width: 100%; height: 280px; }
.chart-card.wide .grafico-lienzo { height: 300px; }
.chart-card.tall .grafico-lienzo { height: 320px; }
.chart-card canvas, .chart-card.tall canvas { max-height: none; }
.grafico-nota, .chart-summary { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--text-muted); }
.chart-estado {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-height: 220px; padding: 20px;
  border: 1px dashed var(--border); border-radius: var(--radius-sm); background: var(--bg-elev-2); color: var(--text-muted); font-size: 13.5px; text-align: center;
}
.chart-estado-simbolo { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; border: 2px solid currentColor; font-size: 16px; font-weight: 800; }
.chart-estado--error { border-style: solid; border-color: var(--danger); background: var(--danger-dim); color: var(--text); }
.chart-estado--error .chart-estado-simbolo { color: var(--danger); }
.chart-estado-espera { width: 26px; height: 26px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
.chart-empty-state { display: none; }

.grafico-tabla { border-top: 1px solid var(--border-light); padding-top: 10px; }
.grafico-tabla summary { display: inline-block; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--accent); border-radius: 4px; }
.grafico-tabla summary:hover { text-decoration: underline; }
.grafico-tabla-marco { max-height: 260px; overflow: auto; margin-top: 10px; border: 1px solid var(--border-light); border-radius: var(--radius-sm); scrollbar-width: thin; }
.grafico-tabla table, .country-connection-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.grafico-tabla th, .country-connection-table th { position: sticky; top: 0; padding: 8px 12px; background: var(--bg-elev-2); text-align: left; font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: none; letter-spacing: 0; }
.grafico-tabla td, .country-connection-table td { padding: 7px 12px; border-top: 1px solid var(--border-light); color: var(--text); }
.grafico-tabla .col-num { text-align: right; font-variant-numeric: tabular-nums; }
.sin-dato { color: var(--text-dim); font-style: italic; }
.country-connection-table-wrap { border-color: var(--border-light); max-height: 420px; overflow: auto; }
.country-connection-table th:not(:first-child), .country-connection-table td:not(:first-child) { width: 180px; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.country-connection-table th:last-child, .country-connection-table td:last-child { width: 220px; }
.country-connection-table th.col-barra, .country-connection-table td.col-barra { width: 200px; }
.country-connection-table th.col-corta, .country-connection-table td.col-corta { width: 110px; }
.country-connection-table th.col-plan, .country-connection-table td.col-plan { width: 150px; }
.country-connection-table .plan-parte { display: inline-block; min-width: 52px; margin-left: 8px; color: var(--text-muted); }.tabla-barra { display: inline-block; width: 90px; height: 8px; margin-right: 10px; border-radius: 4px; background: var(--bg-elev-3); vertical-align: middle; overflow: hidden; }
.tabla-barra > span { display: block; height: 100%; border-radius: 4px; background: var(--accent-solid); }
.projection-note { margin-bottom: 16px; padding: 12px 14px; background: var(--info-dim); border: 1px solid var(--border); border-left: 4px solid var(--info); border-radius: var(--radius-sm); color: var(--text); font-size: 13.5px; }
.projection-note svg { color: var(--info); flex-shrink: 0; }

/* ── 15. Secciones secundarias ─────────────────────────────── */
.export-grid { gap: 16px; }
.export-card { padding: 20px; }
.export-card p { color: var(--text-muted); font-size: 13.5px; }
.dl-stats-grid { gap: 12px; margin-bottom: 16px; }
.online-card { background: var(--bg-elev-2); border: 1px solid var(--border-light); border-radius: var(--radius-sm); }
.membership-card { padding: 20px; }
.membership-card-header { gap: 12px 16px; flex-wrap: wrap; }
.premium-model-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.activity-filter-panel { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow-sm); }
.activity-filter-panel .filters-bar { margin: 12px 0 0; padding: 12px 0 0; border: 0; border-top: 1px solid var(--border-light); border-radius: 0; box-shadow: none; background: none; }
.activity-filter-header strong { font-size: 15px; }
.subscriptions-admin, .subscriptions-panel { min-width: 0; }
.subscriptions-filters input[type="search"] { flex: 1; min-width: 220px; }
.support-admin-mode-banner { border-radius: var(--radius-sm); font-size: 13.5px; }
.beta-admin-resumen > div, .support-admin-metrics > *, .pubadm-tarjeta { border-radius: var(--radius-sm); }
.beta-admin-nota { color: var(--text-muted); font-size: 13px; }
.initialization-save-row { gap: 12px; }

/* ── 16. Pantallas angostas ────────────────────────────────── */
@media (max-width: 1280px) {
  .resumen-grupos { grid-template-columns: 1fr 1fr; }
  .resumen-grupos > :last-child { grid-column: 1 / -1; }
  .resumen-dos-columnas { grid-template-columns: 1fr; }
  .resumen-atajos { grid-template-columns: 1fr 1fr; }
  .admin-checklist { grid-template-columns: 1fr; }
}
@media (max-width: 1100px) {
  .charts-grid--dos { grid-template-columns: 1fr; }
  .admin-main { padding: 24px 20px 32px; }
}
@media (max-width: 900px) {
  :root { --topbar-h: auto; }
  #adminApp { grid-template-columns: minmax(0, 1fr); }
  .admin-topbar { flex-wrap: wrap; padding: 10px 14px; gap: 10px; min-height: 56px; }
  .admin-topbar-title { order: 1; flex: 1; }
  .admin-mobile-menu-btn { order: 0; min-width: 44px; min-height: 44px; }
  .admin-topbar-actions { order: 2; }
  .admin-topbar-search { order: 3; flex: 1 1 100%; max-width: none; min-width: 0; height: 44px; }
  .admin-main { grid-column: 1; padding: 20px 14px 32px; }
  .admin-sidebar { width: min(300px, 86vw); box-shadow: var(--shadow); }
  .admin-nav-btn { min-height: 44px; }
  .resumen-grupos, .resumen-atajos { grid-template-columns: 1fr; }
  .section-header h2, .beta-admin-cabecera h2, .pubadm-cabecera h2 { font-size: 21px; }
  .data-freshness { width: 100%; margin-left: 0; text-align: left; }
  .graficas-filtros { width: 100%; }
}
@media (max-width: 640px) {
  .btn, .filter-chip, .page-btn, input:not([type="checkbox"]):not([type="radio"]), select { min-height: 44px; }
  .btn-xs { min-height: 36px; }
  .admin-topbar-actions .btn { padding-inline: 10px; }
  .kpi-grid, .kpi-grid-primary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi-card { padding: 12px; }
  .kpi-value { font-size: 22px; }
  .share3d-summary-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-period-bar > .btn { width: auto; }
  .kpi-grid--grupo { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .attention-grid, .quick-actions-grid { grid-template-columns: 1fr; }
  .filters-bar, .subscriptions-filters, .beta-admin-filtros, .graficas-filtros { display: grid; grid-template-columns: 1fr 1fr; align-items: end; }
  .filters-bar > *, .graficas-filtros > * { min-width: 0; }
  .filters-bar input:not([type="checkbox"]), .filters-bar select, .graficas-filtros input { width: 100% !important; }
  .filters-bar > .btn, .graficas-filtros > .btn { width: 100%; }
  .filters-bar > .filter-label, .filters-bar > span { grid-column: 1 / -1; }
  .admin-period-bar { display: grid; grid-template-columns: 1fr 1fr; }
  .admin-period-bar > label:first-child, .admin-period-bar > .data-freshness { grid-column: 1 / -1; }
  .chart-card { padding: 16px 14px; }
  .grafico-cab { flex-direction: column; gap: 8px; }
  .grafico-cifra { text-align: left; display: flex; align-items: baseline; gap: 8px; }
  .grafico-cifra span { margin: 0; max-width: none; }
  .grafico-lienzo, .chart-card.wide .grafico-lienzo, .chart-card.tall .grafico-lienzo { height: 250px; }
  .country-connection-table th:not(:first-child), .country-connection-table td:not(:first-child) { width: auto; }
  .tabla-barra { display: none; }
  .data-table th, .admin-table th { position: static; }
  .data-table td, .admin-table td { text-align: left !important; }
  .data-table tr, .admin-table tr { box-shadow: var(--shadow-sm); }
  .subscriptions-tabs, .security-tabs, .support-admin-tabs, .asi-pestanas, .pubadm-pestanas { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; }
  .subscriptions-tab, .security-tabs button, .support-admin-tabs button, .asi-pestanas .btn, .pubadm-pestana { white-space: nowrap; flex-shrink: 0; min-height: 44px; }
  .modal-actions .btn { flex: 1; }
  .pagination { justify-content: center; }
}
@media (max-width: 400px) {
  .admin-topbar-actions .btn svg { display: none; }
}

/* ── 17. Ajustes finos ─────────────────────────────────────── */
.admin-topbar .admin-topbar-search input[type="search"] { background: transparent !important; width: 100%; }
.data-table td[colspan]::before, .admin-table td[colspan]::before { content: none !important; }
.share3d-user-inline { display: block; margin-top: 2px; font-size: 12px; color: var(--text-dim); }
.online-dot { flex-shrink: 0; }
@media (max-width: 900px) {
  .admin-topbar-search { order: 2; flex: 1 1 160px; }
  .admin-topbar-actions { order: 3; }
  .admin-topbar-actions #themeToggleBtn, .admin-topbar-actions #topRefreshBtn { min-height: 44px; }
}
@media (max-width: 640px) {
  .data-table td[colspan], .admin-table td[colspan] { display: block; }
  .admin-topbar-search { flex-basis: 100%; }
  .admin-topbar-actions { flex: 1; }
  .admin-topbar-actions .btn { flex: 1; }
}
/* Valores largos legibles sin colapsar la columna; acciones siempre a la vista al desplazar la tabla. */
.data-table .col-email, .data-table .col-name { min-width: 190px; max-width: 300px; overflow-wrap: break-word; word-break: normal; }
.data-table .col-email span, .data-table .col-name > span { overflow-wrap: anywhere; }
.data-table td.col-actions, .data-table thead th:last-child:not([data-sortable]) {
  position: sticky; right: 0; z-index: 2; background: var(--bg-elev); box-shadow: -1px 0 0 var(--border-light);
}
.data-table thead th:last-child:not([data-sortable]) { background: var(--bg-elev-2); }
.data-table tbody tr:hover td.col-actions { background: var(--bg-elev-2); }
@media (max-width: 640px) {
  .data-table td.col-actions { position: static; box-shadow: none; }
  .data-table .col-email, .data-table .col-name { min-width: 0; max-width: none; }
}

/* Pestañas de los módulos que cargan su propia hoja después de ésta: misma apariencia que el resto. */
#adminApp :is(.pubadm-pestanas, .asi-pestanas) {
  display: flex; align-items: stretch; gap: 2px; flex-wrap: wrap; margin: 0 0 16px; padding: 0;
  border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: none;
}
#adminApp :is(.pubadm-pestana, .asi-pestanas .btn) {
  min-height: 40px; padding: 8px 14px; margin: 0 0 -1px; border: 0; border-bottom: 3px solid transparent; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: none; color: var(--text-muted); font-size: 13.5px; font-weight: 600; box-shadow: none;
}
#adminApp :is(.pubadm-pestana, .asi-pestanas .btn):hover { color: var(--text); background: var(--bg-elev-2); }
#adminApp :is(.pubadm-pestana.activa, .asi-pestanas .btn[aria-selected="true"]) { color: var(--accent); border-bottom-color: var(--accent); background: none; font-weight: 700; }
:root[data-theme="light"] #adminApp :is(.pubadm-pestana.activa, .asi-pestanas .btn[aria-selected="true"]) { color: var(--accent-2); }
#adminApp .pubadm-cabecera { display: block; }
#adminApp .pubadm-cabecera > div:first-child { margin-bottom: 16px; }

/* Membresía: los nombres largos de modelos se leen completos. */
.premium-model-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.premium-model-row { min-width: 0; align-items: flex-start; }
.premium-model-row strong, .premium-model-row span { min-width: 0; overflow-wrap: anywhere; line-height: 1.3; }
.data-table .col-email { min-width: 250px; }
/* El contorno de foco aparece al instante: no se anima junto con el resto del botón. */
.btn, .filter-chip, .page-btn, .admin-nav-btn, .attention-item, .admin-check-item { transition: background-color 0.15s, border-color 0.15s, color 0.15s; }
