/* TeamMDM panel shell — dual sidebar (layout ref. internal only). Brand: --mdm-brand */

:root,
[data-bs-theme="dark"] {
    --shell-bg: #202022;
    --shell-paper: #2a2a2e;
    --shell-rail: #18181a;
    --shell-subnav: #202022;
    --shell-border: rgba(255, 255, 255, 0.08);
    --shell-text: #e6e6e6;
    --shell-muted: #9ca3af;
    --shell-accent: var(--mdm-brand, #044bd9);
    --shell-accent-hover: var(--mdm-brand-dark, #0338a9);
    --shell-accent-soft: rgba(4, 75, 217, 0.14);
    --shell-accent-glow: rgba(4, 75, 217, 0.25);
    --shell-radius-lg: 16px;
    --shell-radius-md: 12px;
    --shell-radius-sm: 10px;
    --shell-font: "Mulish", ui-sans-serif, system-ui, sans-serif;
    --shell-font-display: "Mulish", ui-sans-serif, system-ui, sans-serif;
    --shell-sidebar-w: 16.5rem;
}

[data-bs-theme="light"] {
    --shell-bg: #f4f4f5;
    --shell-paper: #ffffff;
    --shell-rail: #ffffff;
    --shell-subnav: #fafafa;
    --shell-border: rgba(0, 0, 0, 0.08);
    --shell-text: #27272a;
    --shell-muted: #71717a;
    --shell-accent: var(--mdm-brand, #044bd9);
    --shell-accent-hover: var(--mdm-brand-dark, #0338a9);
    --shell-accent-soft: rgba(4, 75, 217, 0.1);
    --shell-accent-glow: rgba(4, 75, 217, 0.2);
}

html.theme-teammdm {
    color-scheme: dark;
}

html.theme-teammdm[data-bs-theme="light"] {
    color-scheme: light;
}

body.app-shell {
    font-family: var(--shell-font);
    background: var(--shell-bg);
    color: var(--shell-text);
    font-size: 0.9375rem;
}

body.app-shell.app-body {
    background: var(--shell-bg);
    background-image: none;
}

/* Shell */
body.app-shell .shell-layout {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

/* Sidebar único */
body.app-shell .shell-sidebar {
    width: var(--shell-sidebar-w);
    flex-shrink: 0;
    background: var(--shell-rail);
    border-right: 1px solid var(--shell-border);
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    position: sticky;
    top: 0;
    z-index: 1035;
}

body.app-shell .shell-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 1rem 1rem 0.85rem;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--shell-border);
}

body.app-shell .shell-sidebar-brand-name {
    display: block;
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.2;
}

body.app-shell .shell-sidebar-brand-ver {
    display: block;
    font-size: 0.72rem;
    color: var(--shell-muted);
}

body.app-shell .shell-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0.65rem 1rem;
}

body.app-shell .shell-sidebar-section {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--shell-muted);
    margin: 0.85rem 0.45rem 0.35rem;
}

body.app-shell .shell-sidebar-list {
    list-style: none;
    margin: 0 0 0.25rem;
    padding: 0;
}

body.app-shell .shell-sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.55rem 0.65rem;
    border-radius: var(--shell-radius-md);
    color: var(--shell-muted);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.875rem;
    transition: background 0.15s ease, color 0.15s ease;
}

body.app-shell .shell-sidebar-link .bi {
    font-size: 1.05rem;
    width: 1.25rem;
    text-align: center;
}

body.app-shell .shell-sidebar-link:hover {
    background: var(--shell-accent-soft);
    color: var(--shell-text);
}

body.app-shell .shell-sidebar-link.is-active {
    background: var(--shell-accent-soft);
    color: var(--shell-accent);
}

body.app-shell .shell-sidebar-foot {
    padding: 0.65rem;
    border-top: 1px solid var(--shell-border);
}

body.app-shell .shell-rail,
body.app-shell .shell-subnav {
    display: none !important;
}

body.app-shell .shell-rail {
    width: var(--shell-rail-w);
    flex-shrink: 0;
    background: var(--shell-rail);
    border-right: 1px solid var(--shell-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem 0;
    gap: 0.35rem;
    position: sticky;
    top: 0;
    height: 100dvh;
    z-index: 1035;
}

body.app-shell .shell-rail-brand {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: var(--shell-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.75rem;
}

body.app-shell .shell-rail-brand img {
    width: 1.75rem;
    height: 1.75rem;
}

body.app-shell .shell-rail-link {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: var(--shell-radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--shell-muted);
    text-decoration: none;
    border: 1px solid transparent;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

body.app-shell .shell-rail-link .bi {
    font-size: 1.2rem;
}

body.app-shell .shell-rail-link:hover {
    color: var(--shell-text);
    background: var(--shell-accent-soft);
}

body.app-shell .shell-rail-link.is-active {
    color: var(--shell-accent);
    background: var(--shell-paper);
    border-color: var(--shell-border);
    box-shadow: 0 0 0 1px var(--shell-accent-glow);
}

body.app-shell .shell-rail-spacer {
    flex: 1;
}

body.app-shell .shell-subnav {
    width: var(--shell-subnav-w);
    flex-shrink: 0;
    background: var(--shell-subnav);
    border-right: 1px solid var(--shell-border);
    padding: 1.25rem 0.85rem 1rem;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100dvh;
    z-index: 1030;
}

body.app-shell .shell-subnav-title {
    font-family: var(--shell-font-display);
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--shell-accent);
    margin: 0 0.35rem 1rem;
}

body.app-shell .shell-subnav-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
    overflow-y: auto;
}

body.app-shell .shell-subnav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.65rem;
    border-radius: var(--shell-radius-sm);
    color: var(--shell-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.875rem;
    transition: background 0.2s ease, color 0.2s ease;
}

body.app-shell .shell-subnav-link .bi {
    font-size: 1rem;
    opacity: 0.85;
}

body.app-shell .shell-subnav-link:hover {
    color: var(--shell-text);
    background: var(--shell-accent-soft);
}

body.app-shell .shell-subnav-link.is-active {
    color: var(--shell-text);
    background: var(--shell-paper);
    box-shadow: inset 0 0 0 1px var(--shell-border);
}

body.app-shell .shell-subnav-link.is-active .bi {
    color: var(--shell-accent);
}

body.app-shell .shell-subnav-foot {
    margin-top: auto;
    padding-top: 0.75rem;
    border-top: 1px solid var(--shell-border);
    font-size: 0.68rem;
    color: var(--shell-muted);
    text-align: center;
    line-height: 1.35;
}

body.app-shell .shell-stage {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    height: 100dvh;
    overflow: hidden;
    padding-bottom: var(--app-mobile-nav-h, 4.25rem);
}

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

/* Topbar Gogo */
body.app-shell .app-topbar {
    background: transparent;
    border-bottom: 1px solid var(--shell-border);
    backdrop-filter: none;
    padding-inline: 1.5rem;
}

body.app-shell .app-topbar::before {
    display: none;
}

body.app-shell .app-topbar-title {
    font-family: var(--shell-font-display);
    font-weight: 700;
    font-size: 1.35rem;
    letter-spacing: -0.03em;
}

body.app-shell .app-topbar-subtitle {
    color: var(--shell-muted);
}

body.app-shell .btn-user-menu {
    background: var(--shell-paper);
    border-color: var(--shell-border);
    border-radius: var(--shell-radius-lg);
}

body.app-shell .btn-icon {
    border-radius: var(--shell-radius-md);
    background: var(--shell-paper);
    border-color: var(--shell-border);
    color: var(--shell-muted);
}

body.app-shell .user-avatar {
    background: var(--mdm-brand, #044bd9) !important;
}

/* Content + cards */
body.app-shell .app-content {
    background: transparent;
    padding: 1.25rem 1.5rem 2rem;
}

body.app-shell .app-content--map {
    flex: 1 1 auto;
    min-height: 0;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body.app-shell .map-page {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
}

body.app-shell .card,
body.app-shell .mdm-options-panel,
body.app-shell .mdm-stat-card {
    background: var(--shell-paper);
    border: 1px solid var(--shell-border);
    border-radius: var(--shell-radius-lg);
    box-shadow: none;
}

body.app-shell .card:not(.auth-card) {
    border-top: 1px solid var(--shell-border);
}

body.app-shell .btn-primary {
    --bs-btn-bg: var(--shell-accent);
    --bs-btn-border-color: var(--shell-accent);
    --bs-btn-hover-bg: var(--shell-accent-hover);
    --bs-btn-hover-border-color: var(--shell-accent-hover);
    border-radius: var(--shell-radius-lg);
    font-weight: 600;
}

body.app-shell .btn-outline-primary {
    --bs-btn-color: var(--shell-accent);
    --bs-btn-border-color: var(--shell-accent);
    border-radius: var(--shell-radius-lg);
}

body.app-shell .form-control,
body.app-shell .form-select {
    background: var(--shell-bg);
    border-color: var(--shell-border);
    border-radius: var(--shell-radius-md);
    color: var(--shell-text);
}

body.app-shell .table thead th {
    background: var(--shell-bg);
    color: var(--shell-muted);
    border-color: var(--shell-border);
}

body.app-shell .app-footer {
    border-top: 1px solid var(--shell-border);
    color: var(--shell-muted);
    background: transparent;
}

body.app-shell .app-footer-brand {
    color: var(--shell-text);
}

body.app-shell .app-footer-link {
    color: var(--shell-accent);
}

body.app-shell .app-mobile-nav {
    background: var(--shell-rail);
    border-top: 1px solid var(--shell-border);
}

body.app-shell .app-mobile-nav-item.is-active {
    color: var(--shell-accent);
}

body.app-shell .api-status-chip {
    background: var(--shell-paper);
    border-color: var(--shell-border);
    border-radius: var(--shell-radius-md);
}

/* Map */
body.app-shell .map-drawer {
    background: var(--shell-subnav);
    border-color: var(--shell-border);
}

body.app-shell .mdm-map-canvas {
    background: var(--shell-bg);
}

body.app-shell .btn-glass {
    background: var(--shell-paper);
    border-color: var(--shell-border);
    border-radius: var(--shell-radius-md);
}

/* Auth */
body.auth-body.shell-auth {
    background: var(--shell-bg);
    font-family: var(--shell-font);
}

body.auth-body.shell-auth .auth-card {
    background: var(--shell-paper);
    border: 1px solid var(--shell-border);
    border-radius: var(--shell-radius-lg);
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
}

body.auth-body.shell-auth .btn-primary {
    border-radius: var(--shell-radius-lg);
}

/* Ocultar shell antiguo si queda markup */
body.app-shell .app-sidebar {
    display: none !important;
}

@media (max-width: 991.98px) {
    body.app-shell .shell-rail,
    body.app-shell .shell-subnav {
        display: none !important;
    }
}

body.app-shell .shell-offcanvas {
    background: var(--shell-subnav);
    color: var(--shell-text);
}

body.app-shell .shell-offcanvas .btn-close {
    filter: invert(1) grayscale(1);
}

html.theme-teammdm[data-bs-theme="light"] .shell-offcanvas .btn-close {
    filter: none;
}
