/* ============================================================
   Panel FIRMS — /firms
   Identidad institucional PROFEPA (tokens copiados de index.html)
   ============================================================ */

:root {
    --profepa-beige: #e6d194;
    --profepa-vino: #611232;
    --profepa-negro: #161a1d;
    --profepa-gris: #98989A;
    --profepa-dorado: #a57f2c;
    --profepa-magenta: #9b2247;
    --profepa-verde-oscuro: #002f2a;
    --profepa-verde: #1e5b4f;
    --profepa-verde-claro: #4a9d7f;
    --profepa-verde-suave: #3d8f7c;
}

:root,
[data-theme="dark"] {
    --color-primario: var(--profepa-verde);
    --color-acento: var(--profepa-beige);
    --color-fondo: #0a1612;
    --color-fondo-panel: rgba(22, 26, 29, 0.95);
    --color-fondo-card: rgba(30, 40, 35, 0.9);
    --color-fondo-input: rgba(255, 255, 255, 0.1);
    --color-texto: #ffffff;
    --color-texto-suave: rgba(255, 255, 255, 0.85);
    --color-texto-muted: rgba(255, 255, 255, 0.6);
    --color-borde: rgba(30, 91, 79, 0.4);
    --color-borde-claro: rgba(255, 255, 255, 0.1);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    /* Serie de gráficas: verde institucional saturado, validado sobre #0a1612 */
    --chart-series: #23a377;
    --chart-grid: rgba(255, 255, 255, 0.08);
}

[data-theme="light"] {
    --color-primario: var(--profepa-verde);
    --color-acento: var(--profepa-dorado);
    --color-fondo: #e8ebe9;
    --color-fondo-panel: rgba(255, 255, 255, 0.98);
    --color-fondo-card: #f5f8f6;
    --color-fondo-input: rgba(30, 91, 79, 0.08);
    --color-texto: #0a0a0a;
    --color-texto-suave: rgba(0, 0, 0, 0.9);
    --color-texto-muted: rgba(0, 0, 0, 0.65);
    --color-borde: rgba(30, 91, 79, 0.35);
    --color-borde-claro: rgba(0, 0, 0, 0.15);
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.12);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.18);
    /* Serie de gráficas: validado sobre #f5f8f6 */
    --chart-series: #178a66;
    --chart-grid: rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--color-fondo);
    color: var(--color-texto);
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    min-height: 100vh;
}

/* ---------- Header ---------- */
.firms-header {
    background: var(--color-fondo-panel);
    border-bottom: 2px solid var(--color-primario);
    box-shadow: var(--shadow-sm);
    padding: 0.6rem 1.2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.firms-brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    text-decoration: none;
    color: var(--color-texto);
}

.firms-brand img { height: 42px; width: auto; border-radius: 6px; }

.firms-brand .brand-txt h1 {
    font-size: 1.05rem;
    margin: 0;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.firms-brand .brand-txt small {
    color: var(--color-texto-muted);
    font-size: 0.75rem;
    display: block;
}

.firms-header-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.firms-btn {
    background: var(--color-fondo-input);
    border: 1px solid var(--color-borde);
    color: var(--color-texto-suave);
    border-radius: 8px;
    padding: 0.35rem 0.75rem;
    font-size: 0.82rem;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    transition: background 0.15s ease;
}

.firms-btn:hover { background: var(--color-primario); color: #fff; }

.last-update {
    font-size: 0.78rem;
    color: var(--color-texto-muted);
    white-space: nowrap;
}

/* ---------- Badges de estado ---------- */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.75rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    border: 1px solid var(--color-borde-claro);
    background: var(--color-fondo-input);
    color: var(--color-texto-suave);
    white-space: nowrap;
}

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--profepa-gris); }
.status-badge.ok .status-dot { background: #22c55e; }
.status-badge.warn .status-dot { background: #f59e0b; }
.status-badge.err .status-dot { background: #ef4444; }

/* ---------- Layout ---------- */
.firms-main { padding: 1rem 1.2rem 2rem; max-width: 1500px; margin: 0 auto; }

.firms-alert {
    border-radius: 10px;
    border: 1px solid rgba(251, 191, 36, 0.35);
    background: rgba(251, 191, 36, 0.12);
    color: var(--color-texto-suave);
    padding: 0.6rem 0.9rem;
    font-size: 0.85rem;
    margin-bottom: 0.9rem;
    display: none;
}

.firms-alert.error {
    border-color: rgba(239, 68, 68, 0.4);
    background: rgba(239, 68, 68, 0.12);
}

.firms-alert.visible { display: block; }

/* ---------- KPIs ---------- */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.kpi-card {
    background: var(--color-fondo-card);
    border: 1px solid var(--color-borde-claro);
    border-left: 3px solid var(--color-primario);
    border-radius: 12px;
    padding: 0.8rem 1rem;
    box-shadow: var(--shadow-sm);
    min-height: 96px;
}

.kpi-card .kpi-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-texto-muted);
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.35rem;
}

.kpi-card .kpi-value {
    font-size: 1.7rem;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.kpi-card .kpi-sub {
    font-size: 0.74rem;
    color: var(--color-texto-muted);
    margin-top: 0.25rem;
}

.sat-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.2rem; }

.sat-chip {
    font-size: 0.74rem;
    background: var(--color-fondo-input);
    border: 1px solid var(--color-borde);
    border-radius: 999px;
    padding: 0.15rem 0.55rem;
    color: var(--color-texto-suave);
    font-variant-numeric: tabular-nums;
}

/* ---------- Tabs ---------- */
.nav-tabs { border-bottom: 1px solid var(--color-borde); }

.nav-tabs .nav-link {
    color: var(--color-texto-muted);
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    font-size: 0.9rem;
}

.nav-tabs .nav-link:hover { color: var(--color-texto); border-color: transparent; }

.nav-tabs .nav-link.active {
    color: var(--color-texto);
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--color-primario);
    font-weight: 600;
}

.tab-content { padding-top: 0.9rem; }

/* ---------- Paneles / tarjetas ---------- */
.panel-card {
    background: var(--color-fondo-card);
    border: 1px solid var(--color-borde-claro);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    padding: 0.9rem;
    margin-bottom: 0.9rem;
}

.panel-card h2 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-texto-muted);
    margin: 0 0 0.6rem;
}

/* ---------- Mapas ---------- */
.firms-map {
    width: 100%;
    height: 58vh;
    min-height: 380px;
    border-radius: 10px;
    border: 1px solid var(--color-borde-claro);
    z-index: 0;
}

.map-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    font-size: 0.76rem;
    color: var(--color-texto-muted);
    margin-top: 0.5rem;
    align-items: center;
}

.legend-item { display: inline-flex; align-items: center; gap: 0.35rem; }

.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(0, 0, 0, 0.25);
}

/* ---------- Filtros ---------- */
.filters-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: flex-end;
    margin-bottom: 0.9rem;
}

.filters-row label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-texto-muted);
    display: block;
    margin-bottom: 0.2rem;
}

.filters-row .form-control,
.filters-row .form-select {
    background: var(--color-fondo-input);
    color: var(--color-texto);
    border: 1px solid var(--color-borde);
    border-radius: 8px;
    font-size: 0.85rem;
    min-width: 150px;
}

.filters-row .form-control:focus,
.filters-row .form-select:focus {
    background: var(--color-fondo-input);
    color: var(--color-texto);
    border-color: var(--color-primario);
    box-shadow: 0 0 0 0.15rem rgba(30, 91, 79, 0.25);
}

[data-theme="dark"] .filters-row input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
}

.btn-apply {
    background: var(--color-primario);
    border: none;
    color: #fff;
    border-radius: 8px;
    padding: 0.42rem 1.1rem;
    font-size: 0.85rem;
}

.btn-apply:hover { background: var(--profepa-verde-suave); color: #fff; }
.btn-apply:disabled { opacity: 0.6; }

/* ---------- Gráficas ---------- */
.charts-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 0.9rem;
}

@media (max-width: 900px) {
    .charts-row { grid-template-columns: 1fr; }
}

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

/* ---------- Tabla ---------- */
.table-wrap { overflow-x: auto; }

.firms-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.firms-table th {
    text-align: left;
    color: var(--color-texto-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid var(--color-borde);
    white-space: nowrap;
}

.firms-table td {
    padding: 0.42rem 0.6rem;
    border-bottom: 1px solid var(--color-borde-claro);
    color: var(--color-texto-suave);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.firms-table tbody tr:hover { background: var(--color-fondo-input); }

.table-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin-top: 0.6rem;
    font-size: 0.8rem;
    color: var(--color-texto-muted);
}

.table-foot .pager { display: flex; gap: 0.4rem; }

/* ---------- Footer ---------- */
.firms-footer {
    border-top: 1px solid var(--color-borde-claro);
    padding: 0.9rem 1.2rem;
    font-size: 0.75rem;
    color: var(--color-texto-muted);
    display: flex;
    justify-content: space-between;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.firms-footer a { color: var(--profepa-verde-claro); text-decoration: none; }

/* Popup Leaflet acorde al tema */
[data-theme="dark"] .leaflet-popup-content-wrapper,
[data-theme="dark"] .leaflet-popup-tip {
    background: #1c2622;
    color: #fff;
}

.leaflet-popup-content { font-size: 0.8rem; line-height: 1.45; }

@media (max-width: 640px) {
    .firms-header { padding: 0.5rem 0.8rem; }
    .firms-main { padding: 0.8rem 0.8rem 1.5rem; }
    .firms-map { height: 48vh; }
    .firms-brand .brand-txt small { display: none; }
}
