/* =====================================================================
   Panel MDM · Hoja de estilos principal
   Usa variables nativas de Bootstrap 5.3 (data-bs-theme="dark|light")
   y añade ajustes propios para tipografía, densidad y accesibilidad.
   ===================================================================== */

:root {
    --mdm-brand: #044bd9;
    --mdm-brand-dark: #0338a9;
    --mdm-brand-light: #2f6aff;
    --mdm-radius: 0.625rem;
    --mdm-radius-sm: 0.375rem;
    --mdm-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
    --mdm-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    --mdm-transition: 180ms cubic-bezier(.4, 0, .2, 1);

    --app-sidebar-w: 17.5rem;
    --app-topbar-h: 3.75rem;
    --app-mobile-nav-h: 4.25rem;
    --app-sidebar-bg: #0b1220;
    --app-sidebar-fg: #e8eefc;
    --app-sidebar-muted: #94a3b8;
    --app-sidebar-active: rgba(47, 106, 255, 0.18);
    --app-sidebar-border: rgba(255, 255, 255, 0.08);
    --app-surface-elevated: rgba(255, 255, 255, 0.72);

    /* Override variables Bootstrap para usar el azul de marca */
    --bs-primary: var(--mdm-brand);
    --bs-primary-rgb: 4, 75, 217;
    --bs-link-color: var(--mdm-brand);
    --bs-link-hover-color: var(--mdm-brand-dark);
}

[data-bs-theme="dark"] {
    --mdm-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --mdm-shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
    --bs-primary: var(--mdm-brand-light);
    --bs-primary-rgb: 47, 106, 255;
    --bs-link-color: var(--mdm-brand-light);
    --bs-link-hover-color: #6b94ff;
    color-scheme: dark;
}

/* Botones primary y badges refrescados al azul de marca */
.btn-primary {
    --bs-btn-bg: var(--mdm-brand);
    --bs-btn-border-color: var(--mdm-brand);
    --bs-btn-hover-bg: var(--mdm-brand-dark);
    --bs-btn-hover-border-color: var(--mdm-brand-dark);
    --bs-btn-active-bg: var(--mdm-brand-dark);
    --bs-btn-active-border-color: var(--mdm-brand-dark);
    --bs-btn-disabled-bg: var(--mdm-brand);
    --bs-btn-disabled-border-color: var(--mdm-brand);
}
.btn-outline-primary {
    --bs-btn-color: var(--mdm-brand);
    --bs-btn-border-color: var(--mdm-brand);
    --bs-btn-hover-bg: var(--mdm-brand);
    --bs-btn-hover-border-color: var(--mdm-brand);
    --bs-btn-active-bg: var(--mdm-brand-dark);
    --bs-btn-active-border-color: var(--mdm-brand-dark);
}
.text-primary { color: var(--mdm-brand) !important; }
.bg-primary { background-color: var(--mdm-brand) !important; }
[data-bs-theme="dark"] .text-primary { color: var(--mdm-brand-light) !important; }
[data-bs-theme="dark"] .bg-primary { background-color: var(--mdm-brand-light) !important; }

/* Logo: en dark mode invertimos el azul oscuro a una variante más clara */
.brand-logo {
    display: inline-block;
    vertical-align: middle;
    filter: none;
    transition: filter var(--mdm-transition);
}
[data-bs-theme="dark"] .brand-logo {
    /* Aclara el azul para legibilidad sobre fondos oscuros */
    filter: brightness(1.35) saturate(1.1);
}

.user-avatar {
    background: var(--mdm-brand) !important;
}
[data-bs-theme="dark"] .user-avatar {
    background: var(--mdm-brand-light) !important;
}

/* ---------------------------------------------------------------- Base */

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 0.95rem;
    letter-spacing: -0.01em;
    min-height: 100vh;
}

body.app-body {
    background:
        radial-gradient(1200px 480px at 0% -10%, rgba(4, 75, 217, 0.07), transparent 55%),
        radial-gradient(900px 420px at 100% 0%, rgba(13, 202, 240, 0.06), transparent 50%),
        var(--bs-body-bg);
    display: flex;
    flex-direction: column;
}

[data-bs-theme="dark"] body.app-body {
    background:
        radial-gradient(1000px 420px at 0% -10%, rgba(77, 140, 255, 0.12), transparent 55%),
        radial-gradient(800px 380px at 100% 0%, rgba(32, 201, 151, 0.08), transparent 50%),
        var(--bs-body-bg);
}

main {
    flex: 1 0 auto;
}

/* --------------------------------------------------------------- Navbar */

.navbar {
    box-shadow: var(--mdm-shadow-sm);
    backdrop-filter: saturate(180%) blur(10px);
    background-color: rgba(var(--bs-body-bg-rgb), 0.88) !important;
}

.brand-stack {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.brand-title {
    font-size: 1rem;
    letter-spacing: -0.02em;
}

.brand-sub {
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--bs-secondary-color);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

@media (max-width: 991.98px) {
    .navbar-collapse {
        padding-bottom: 0.75rem;
    }
    .navbar-collapse .api-status-chip {
        width: 100%;
        justify-content: center;
    }
}

.navbar .nav-link {
    border-radius: var(--mdm-radius-sm);
    padding: 0.45rem 0.75rem;
    color: var(--bs-body-color);
    transition: background-color var(--mdm-transition), color var(--mdm-transition);
}

.navbar .nav-link:hover,
.navbar .nav-link:focus-visible {
    background: var(--bs-secondary-bg);
}

.navbar .nav-link.active {
    background: var(--bs-primary-bg-subtle);
    color: var(--bs-primary-text-emphasis);
    font-weight: 500;
}

.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--bs-primary);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
}

/* --------------------------------------------------------------- Tema */

.theme-icon-light { display: inline-block; }
.theme-icon-dark { display: none; }
[data-bs-theme="dark"] .theme-icon-light { display: none; }
[data-bs-theme="dark"] .theme-icon-dark { display: inline-block; }

/* --------------------------------------------------------------- Cards */

.card {
    border: 1px solid var(--bs-border-color-translucent);
    border-radius: calc(var(--mdm-radius) + 0.15rem);
    box-shadow: var(--mdm-shadow-sm);
    transition: box-shadow var(--mdm-transition), transform var(--mdm-transition);
}

body.app-shell .card:not(.auth-card) {
    border-top: 3px solid rgba(4, 75, 217, 0.35);
    background: rgba(255, 255, 255, 0.82);
}

[data-bs-theme="dark"] body.app-shell .card:not(.auth-card) {
    background: rgba(15, 23, 42, 0.75);
    border-top-color: rgba(47, 106, 255, 0.5);
}

.card.card-hoverable:hover {
    box-shadow: var(--mdm-shadow);
    transform: translateY(-1px);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--bs-border-color-translucent);
    font-weight: 600;
}

/* ------------------------------------------------------------ Tablas */

.table {
    --bs-table-bg: transparent;
    font-size: 0.9rem;
    vertical-align: middle;
}

.table thead th {
    border-bottom: 1px solid var(--bs-border-color);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    color: var(--bs-secondary-color);
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
}

.table tbody tr {
    transition: background-color var(--mdm-transition);
}

.table tbody tr:hover {
    background: var(--bs-secondary-bg);
}

/* Table en "tarjetas" en móvil */
@media (max-width: 575.98px) {
    .table-stack thead { display: none; }
    .table-stack tr {
        display: flex;
        flex-direction: column;
        border: 1px solid var(--bs-border-color);
        border-radius: var(--mdm-radius);
        margin-bottom: 0.75rem;
        padding: 0.5rem 0.75rem;
    }
    .table-stack td {
        display: flex;
        justify-content: space-between;
        gap: 1rem;
        border: 0;
        padding: 0.35rem 0;
    }
    .table-stack td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--bs-secondary-color);
        font-size: 0.75rem;
        text-transform: uppercase;
    }
}

/* ---------------------------------------------------------- Badges */

.badge {
    font-weight: 500;
    padding: 0.35em 0.65em;
    letter-spacing: 0.02em;
}

/* -------------------------------------------------------- Formularios */

.form-control,
.form-select {
    border-radius: var(--mdm-radius-sm);
    transition: border-color var(--mdm-transition), box-shadow var(--mdm-transition);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.18);
}

/* ---------------------------------------------------------- Botones */

.btn {
    border-radius: var(--mdm-radius-sm);
    font-weight: 500;
    transition: background-color var(--mdm-transition), transform var(--mdm-transition), box-shadow var(--mdm-transition);
}

.btn:active {
    transform: translateY(1px);
}

.btn .bi {
    vertical-align: -0.125em;
}

/* Estado de carga inyectado por JS (data-loading) */
.btn[data-loading="true"] {
    pointer-events: none;
    opacity: 0.75;
    position: relative;
}

.btn[data-loading="true"]::after {
    content: "";
    display: inline-block;
    width: 0.9em;
    height: 0.9em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    margin-left: 0.45rem;
    animation: mdm-spin 0.7s linear infinite;
    vertical-align: -0.15em;
}

@keyframes mdm-spin {
    to { transform: rotate(360deg); }
}

/* ----------------------------------------------------------- Login */

.auth-shell {
    background: radial-gradient(1200px 600px at 20% 0%, var(--bs-primary-bg-subtle), transparent 60%),
                radial-gradient(900px 500px at 90% 100%, var(--bs-info-bg-subtle), transparent 60%),
                var(--bs-body-bg);
}

.auth-card {
    width: 100%;
    max-width: 28rem;
    border-radius: calc(var(--mdm-radius) + 0.25rem);
}

/* ------------------------------------------------------------- Empty */

.empty-state {
    background: var(--bs-body-bg);
    border-radius: var(--mdm-radius);
}

/* ------------------------------------------------------------ Footer */

.app-footer {
    border-top: 1px solid var(--bs-border-color-translucent);
    margin-top: 3rem;
    flex-shrink: 0;
}

.app-footer-v2 {
    margin-top: auto;
    padding: 0.85rem 1rem;
    background: linear-gradient(90deg, #0b1220, #111827 40%, #0f172a);
    border-top: none;
    color: #94a3b8;
    font-size: 0.78rem;
}

.app-footer-inner {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.5rem 0.75rem;
}

.app-footer-brand {
    font-weight: 700;
    color: #f1f5f9;
    letter-spacing: -0.02em;
}

.app-footer-meta { color: #94a3b8; }

.app-footer-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #475569;
    display: inline-block;
}

.app-footer-link {
    color: #7dd3fc;
    text-decoration: none;
    font-weight: 600;
}

.app-footer-link:hover { color: #bae6fd; text-decoration: underline; }

/* --------------------------------------------------------- Scrollbar */

@media (hover: hover) {
    ::-webkit-scrollbar {
        width: 10px;
        height: 10px;
    }
    ::-webkit-scrollbar-track {
        background: transparent;
    }
    ::-webkit-scrollbar-thumb {
        background: var(--bs-border-color);
        border-radius: 10px;
    }
    ::-webkit-scrollbar-thumb:hover {
        background: var(--bs-secondary-color);
    }
}

/* ------------------------------------------------------- Utilidades */

.hover-underline:hover { text-decoration: underline; }

.text-monospace, .font-monospace {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    background: var(--bs-secondary-bg);
    color: var(--bs-body-color);
    font-size: 0.78rem;
}

.chip-muted {
    background: var(--bs-tertiary-bg);
    color: var(--bs-secondary-color);
}

/* ------------------------------------------------------ API status chip */

.api-status-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 500;
    border: 1px solid var(--bs-border-color-translucent);
    background: var(--bs-body-bg);
    color: var(--bs-secondary-color);
    white-space: nowrap;
}

.api-status-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--bs-secondary-color);
    box-shadow: 0 0 0 2px var(--bs-body-bg);
}

.api-status-chip.is-ok .api-status-dot {
    background: var(--bs-success);
    box-shadow: 0 0 0 2px var(--bs-success-bg-subtle);
}

.api-status-chip.is-degraded .api-status-dot {
    background: var(--bs-danger);
    box-shadow: 0 0 0 2px var(--bs-danger-bg-subtle);
}

/* -------------------------------------------------------- Stat cards */

.mdm-stat-card {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 1rem 1.1rem;
    border-radius: var(--mdm-radius);
    border: 1px solid var(--bs-border-color-translucent);
    background: var(--bs-body-bg);
    color: var(--bs-body-color);
    box-shadow: var(--mdm-shadow-sm);
    transition: box-shadow var(--mdm-transition), transform var(--mdm-transition);
}

.mdm-stat-card:hover {
    box-shadow: var(--mdm-shadow);
    transform: translateY(-2px);
}

.mdm-stat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0.75rem;
    font-size: 1.35rem;
    flex-shrink: 0;
}

.mdm-stat-body {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.mdm-stat-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--bs-secondary-color);
}

.mdm-stat-value {
    font-size: 1.65rem;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.03em;
}

.mdm-stat-card--neutral .mdm-stat-icon { background: var(--bs-secondary-bg); color: var(--bs-body-color); }
.mdm-stat-card--success .mdm-stat-icon { background: var(--bs-success-bg-subtle); color: var(--bs-success); }
.mdm-stat-card--warning .mdm-stat-icon { background: var(--bs-warning-bg-subtle); color: var(--bs-warning-text-emphasis); }
.mdm-stat-card--muted .mdm-stat-icon { background: var(--bs-tertiary-bg); color: var(--bs-secondary-color); }

@media (max-width: 575.98px) {
    .mdm-stat-card {
        flex-direction: column;
        align-items: flex-start;
        padding: 0.85rem;
    }
    .mdm-stat-value {
        font-size: 1.45rem;
    }
}

.app-main {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

/* -------------------------------------------------------- A11y focus */

:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: 2px;
    border-radius: var(--mdm-radius-sm);
}

/* --------------------------------------------------------- Leaflet (mapas) */

.leaflet-div-icon.mdm-map-marker-pin {
    background: transparent !important;
    border: none !important;
}

.mdm-map-shell {
    border-radius: var(--mdm-radius);
}

/* --------------------------------------------------------- Impresión */

@media print {
    .navbar, .app-footer, .app-sidebar, .app-topbar, .app-mobile-nav, .btn, .no-print { display: none !important; }
    main { padding: 0 !important; }
}

/* =================================================================
   Panel shell — sidebar, mapa
   ================================================================= */

body.app-shell {
    overflow-x: hidden;
}

body.app-shell.app-body {
    display: block;
    background-color: #eef2ff;
    background-image:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(4, 75, 217, 0.22), transparent),
        radial-gradient(circle at 100% 0%, rgba(6, 182, 212, 0.12), transparent 45%),
        linear-gradient(180deg, #eef2ff 0%, var(--bs-body-bg) 35%, var(--bs-body-bg) 100%);
}

[data-bs-theme="dark"] body.app-shell.app-body {
    background-color: #030712;
    background-image:
        radial-gradient(ellipse 70% 45% at 50% -15%, rgba(47, 106, 255, 0.2), transparent),
        radial-gradient(circle at 0% 100%, rgba(6, 182, 212, 0.08), transparent 40%),
        linear-gradient(180deg, #030712 0%, var(--bs-body-bg) 40%);
}

[data-bs-theme="dark"] {
    --app-sidebar-bg: #060a12;
    --app-surface-elevated: rgba(15, 23, 42, 0.85);
}

.app-shell {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

.app-stage {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding-bottom: var(--app-mobile-nav-h);
}

@media (min-width: 992px) {
    .app-stage {
        padding-bottom: 0;
    }
}

/* Sidebar desktop */
.app-sidebar {
    width: var(--app-sidebar-w);
    flex-shrink: 0;
    flex-direction: column;
    background:
        linear-gradient(180deg, rgba(47, 106, 255, 0.12) 0%, transparent 28%),
        linear-gradient(180deg, var(--app-sidebar-bg) 0%, #0f172a 100%);
    color: var(--app-sidebar-fg);
    border-right: 1px solid var(--app-sidebar-border);
    box-shadow: inset -3px 0 0 var(--mdm-brand-light), 4px 0 24px rgba(4, 75, 217, 0.08);
    padding: 1rem 0.85rem;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
}

.app-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.35rem 0.5rem 1.25rem;
    text-decoration: none;
    color: inherit;
}

.app-sidebar-brand:hover { color: #fff; }

.app-sidebar-brand-text .brand-title {
    display: block;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.03em;
}

.app-sidebar-brand-text .brand-sub {
    display: block;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--app-sidebar-muted);
}

.app-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding-right: 0.15rem;
}

.app-nav-section { margin-bottom: 1.25rem; }

.app-nav-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--app-sidebar-muted);
    padding: 0 0.65rem 0.5rem;
}

.app-nav-section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--app-sidebar-muted);
    padding: 0 0.65rem 0.5rem;
}

.app-nav-section-toggle.is-open .app-nav-chevron { transform: rotate(180deg); }

.app-nav-chevron {
    transition: transform var(--mdm-transition);
    font-size: 0.85rem;
}

.app-nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.app-nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.75rem;
    border-radius: 0.55rem;
    color: #cbd5e1;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: background var(--mdm-transition), color var(--mdm-transition);
}

.app-nav-link .bi {
    font-size: 1.05rem;
    opacity: 0.85;
}

.app-nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.app-nav-link.is-active {
    background: var(--app-sidebar-active);
    color: #fff;
    box-shadow: inset 3px 0 0 var(--mdm-brand-light);
}

.app-nav-list--nested .app-nav-link {
    padding-left: 1.15rem;
    font-size: 0.86rem;
}

.app-sidebar-foot {
    padding: 0.75rem 0.35rem 0;
    border-top: 1px solid var(--app-sidebar-border);
}

.app-sidebar-foot .api-status-chip {
    width: 100%;
    justify-content: center;
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--app-sidebar-border);
    color: #cbd5e1;
}

.app-sidebar-offcanvas {
    --bs-offcanvas-width: min(88vw, 20rem);
    background: var(--app-sidebar-bg);
    color: var(--app-sidebar-fg);
}

.app-sidebar-offcanvas .app-nav-section-label,
.app-sidebar-offcanvas .app-nav-link { color: #cbd5e1; }

/* Topbar */
.app-topbar {
    height: var(--app-topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1rem 0 1.25rem;
    border-bottom: 1px solid var(--bs-border-color-translucent);
    background: var(--app-surface-elevated);
    backdrop-filter: blur(12px) saturate(160%);
    position: sticky;
    top: 0;
    z-index: 1020;
    box-shadow: 0 1px 0 rgba(4, 75, 217, 0.08);
}

.app-topbar::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--mdm-brand), #06b6d4, #a855f7, var(--mdm-brand));
    background-size: 200% 100%;
    animation: app-topbar-shimmer 8s linear infinite;
}

@keyframes app-topbar-shimmer {
    0% { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}

.panel-v2-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #fff;
    background: linear-gradient(135deg, var(--mdm-brand), #06b6d4);
    box-shadow: 0 2px 8px rgba(4, 75, 217, 0.35);
}

.panel-version-badge {
    display: inline-flex;
    padding: 0.12rem 0.45rem;
    border-radius: 0.35rem;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--mdm-brand);
    background: rgba(4, 75, 217, 0.1);
    border: 1px solid rgba(4, 75, 217, 0.2);
}

[data-bs-theme="dark"] .panel-version-badge {
    color: var(--mdm-brand-light);
    background: rgba(47, 106, 255, 0.15);
    border-color: rgba(47, 106, 255, 0.35);
}

.app-topbar-start,
.app-topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
}

.app-topbar-actions { flex-shrink: 0; }

.app-topbar-title {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.app-topbar-subtitle {
    font-size: 0.75rem;
    color: var(--bs-secondary-color);
}

.app-user-label { max-width: 10rem; }

.btn-icon {
    width: 2.35rem;
    height: 2.35rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.55rem;
}

.btn-user-menu {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid var(--bs-border-color-translucent);
    background: var(--bs-body-bg);
    border-radius: 999px;
    padding: 0.25rem 0.65rem 0.25rem 0.25rem;
    font-weight: 500;
    max-width: 14rem;
}

.btn-user-menu.dropdown-toggle::after { margin-left: 0.15rem; }

.app-admin-pill { font-size: 0.62rem; }

/* Content */
.app-content {
    flex: 1;
    padding: 1.25rem 1.25rem 2rem;
    max-width: 100%;
}

@media (min-width: 1200px) {
    .app-content {
        padding: 1.5rem 2rem 2.5rem;
    }
}

.app-content > .container-xl,
.app-content .container-xl:first-child {
    max-width: 1320px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 0;
    padding-right: 0;
}

.app-content--fluid {
    padding-left: 1rem;
    padding-right: 1rem;
}

.app-content--map {
    padding: 0;
    display: flex;
    flex-direction: column;
    min-height: calc(100dvh - var(--app-topbar-h));
}

/* Mobile bottom nav */
.app-mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1030;
    height: var(--app-mobile-nav-h);
    padding-bottom: env(safe-area-inset-bottom);
    display: flex;
    background: var(--app-surface-elevated);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--bs-border-color-translucent);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.06);
}

.app-mobile-nav-item {
    flex: 1;
    border: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--bs-secondary-color);
    text-decoration: none;
    padding: 0.35rem 0.25rem;
}

.app-mobile-nav-item .bi { font-size: 1.15rem; }

.app-mobile-nav-item.is-active {
    color: var(--mdm-brand);
}

[data-bs-theme="dark"] .app-mobile-nav-item.is-active {
    color: var(--mdm-brand-light);
}

.app-toast-stack {
    bottom: calc(var(--app-mobile-nav-h) + 0.5rem) !important;
}

@media (min-width: 992px) {
    .app-toast-stack { bottom: 0.75rem !important; }
}

/* Tarjetas de filtros / opciones */
.mdm-options-panel {
    border: 1px solid var(--bs-border-color-translucent);
    border-radius: calc(var(--mdm-radius) + 0.15rem);
    background: var(--bs-body-bg);
    box-shadow: var(--mdm-shadow-sm);
}

.mdm-options-panel .card-header {
    padding: 0.85rem 1.1rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.mdm-options-panel .card-body {
    padding: 1rem 1.1rem 1.15rem;
}

/* Mapa V2 */
.map-page {
    display: flex;
    flex: 1;
    min-height: 0;
    height: calc(100dvh - var(--app-topbar-h));
    position: relative;
}

@media (max-width: 991.98px) {
    .app-content--map .map-page {
        height: calc(100dvh - var(--app-topbar-h) - var(--app-mobile-nav-h));
    }
}

.map-drawer {
    width: min(22rem, 92vw);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    padding: 1rem;
    background: var(--bs-body-bg);
    border-right: 1px solid var(--bs-border-color-translucent);
    z-index: 401;
    transition: transform var(--mdm-transition), opacity var(--mdm-transition);
}

.map-drawer-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
}

.map-filter,
.map-search-wrap { padding: 0 0.1rem; }

.map-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem 0.75rem;
    font-size: 0.72rem;
    color: var(--bs-secondary-color);
}

.map-legend-dot {
    display: inline-block;
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 50%;
    background: var(--dot, #64748b);
    margin-right: 0.25rem;
    vertical-align: -0.05em;
}

.map-device-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    min-height: 0;
    padding-right: 0.15rem;
}

.map-device-item {
    display: block;
    padding: 0.65rem 0.75rem;
    border-radius: 0.65rem;
    border: 1px solid var(--bs-border-color-translucent);
    background: var(--bs-secondary-bg);
    text-decoration: none;
    color: inherit;
    transition: border-color var(--mdm-transition), transform var(--mdm-transition);
}

.map-device-item:hover {
    border-color: var(--mdm-brand);
    transform: translateX(2px);
}

.map-device-item--muted {
    opacity: 0.85;
    cursor: default;
}

.map-device-item--muted:hover {
    transform: none;
    border-color: var(--bs-border-color-translucent);
}

.map-device-item-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.15rem;
}

.map-empty-list,
.map-empty-state {
    text-align: center;
    color: var(--bs-secondary-color);
    padding: 2rem 1rem;
}

.map-empty-list .bi,
.map-empty-state .bi {
    font-size: 1.75rem;
    display: block;
    margin-bottom: 0.5rem;
    opacity: 0.65;
}

.map-stage {
    flex: 1;
    position: relative;
    min-width: 0;
    min-height: 280px;
}

.mdm-map-canvas {
    width: 100%;
    height: 100%;
    background: #dbeafe;
}

[data-bs-theme="dark"] .mdm-map-canvas {
    background: #0f172a;
}

.map-toolbar {
    position: absolute;
    top: 0.85rem;
    left: 0.85rem;
    z-index: 500;
    display: flex;
    gap: 0.45rem;
}

.btn-glass {
    background: var(--app-surface-elevated);
    backdrop-filter: blur(10px);
    border: 1px solid var(--bs-border-color-translucent);
    font-weight: 600;
}

@media (max-width: 991.98px) {
    .map-page.drawer-collapsed .map-drawer {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-105%);
        opacity: 0;
        pointer-events: none;
    }

    .map-drawer {
        position: absolute;
        left: 0;
        top: 0;
        bottom: 0;
        box-shadow: var(--mdm-shadow);
    }
}

/* Marcadores Leaflet V2 */
:root {
    --mdm-map-activo: #22c55e;
    --mdm-map-enrollado: #044bd9;
    --mdm-map-inactivo: #eab308;
    --mdm-map-desenrollado: #ef4444;
}

.mdm-map-pin {
    position: relative;
    width: 28px;
    height: 28px;
}

.mdm-pin-core {
    position: absolute;
    inset: 6px;
    border-radius: 50%;
    background: var(--pin-color, #64748b);
    border: 2px solid #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.mdm-pin-pulse {
    position: absolute;
    inset: 2px;
    border-radius: 50%;
    background: var(--pin-color, #22c55e);
    opacity: 0.35;
    animation: mdm-pin-pulse 2s ease-out infinite;
}

@keyframes mdm-pin-pulse {
    0% { transform: scale(0.6); opacity: 0.45; }
    100% { transform: scale(1.35); opacity: 0; }
}

.leaflet-popup.mdm-leaflet-popup .leaflet-popup-content-wrapper {
    border-radius: 0.75rem;
    box-shadow: var(--mdm-shadow);
    padding: 0;
}

.leaflet-popup.mdm-leaflet-popup .leaflet-popup-content {
    margin: 0.85rem 1rem;
    min-width: 200px;
}

.mdm-map-popup-title { display: block; font-size: 0.95rem; margin-bottom: 0.25rem; }

.mdm-map-popup-meta {
    font-size: 0.78rem;
    color: var(--bs-secondary-color);
    margin-bottom: 0.5rem;
}

.mdm-map-popup-row {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.78rem;
    margin-bottom: 0.25rem;
}

.mdm-map-popup-badge {
    font-weight: 600;
    color: var(--badge-color, inherit);
}

.leaflet-control-zoom {
    border: none !important;
    box-shadow: var(--mdm-shadow-sm) !important;
    border-radius: 0.55rem !important;
    overflow: hidden;
}

/* Auth V2 */
body.auth-body {
    font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.auth-card {
    border: 1px solid var(--bs-border-color-translucent);
    background: var(--app-surface-elevated);
    backdrop-filter: blur(16px);
}
