/* ============================================================
   LAYOUT.CSS — Sidebar + Main + Mobile Nav
   ─────────────────────────────────────────
   Clean rebuild: no legacy conflicts
   ============================================================ */

/* ══════════════════════════════════════════════════════════════
   DESKTOP LAYOUT (default)
   ══════════════════════════════════════════════════════════════ */

/* ── Fixed Sidebar ── */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-sidebar);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-brand-logo {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    object-fit: contain;
}

.sidebar-brand-title {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
    margin: 0;
}

/* ── Nav Items ── */
.sidebar-nav {
    flex: 1;
    padding: 0 0 12px 12px;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    padding: 20px 16px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    margin-bottom: 2px;
    border-radius: var(--radius-md) 0 0 var(--radius-md);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition);
    cursor: pointer;
    position: relative;
}

.nav-item:hover {
    background: var(--brand-tint-05);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--brand-tint-08);
    color: var(--brand-primary);
    font-weight: 600;
}

.nav-item.active::after {
    content: '';
    position: absolute;
    right: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    background: var(--brand-primary);
    border-radius: 3px 0 0 3px;
}

.nav-icon {
    font-size: 22px;
    line-height: 1;
}

.nav-badge {
    margin-left: auto;
    display: flex;
    align-items: center;
}

/* ── Sidebar Footer ── */
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-device {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-device-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    flex-shrink: 0;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

.sidebar-device-info {
    flex: 1;
    min-width: 0;
}

.sidebar-device-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-device-status {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

.sidebar-version {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 8px;
    text-align: center;
    letter-spacing: 0.5px;
}

/* ── Theme Toggle ── */
.theme-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}

.theme-btn:hover {
    background: var(--brand-tint-10);
    border-color: var(--brand-primary);
}

[data-theme="light"] .theme-btn {
    border-color: rgba(0, 0, 0, 0.08);
    background: rgba(0, 0, 0, 0.04);
}

/* ── Main Content ── */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
}

/* ── View Container ── */
.view-container {
    padding: 14px 16px;
}

/* ── Mobile header, bottom nav, sidebar-overlay — HIDDEN on desktop ── */
.mobile-header,
.bottom-nav {
    display: none;
}

.sidebar-overlay {
    display: none;
}

/* ══════════════════════════════════════════════════════════════
   MOBILE LAYOUT (≤768px)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    :root {
        --bottom-nav-height: 64px;
        --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* ── Force scroll on mobile ── */
    html,
    body {
        height: auto !important;
        min-height: 100vh;
        overflow-x: hidden;
        overflow-y: visible;
        background-attachment: scroll !important;
    }

    /* ── Kill desktop layout ── */
    .sidebar,
    .sidebar-overlay {
        display: none !important;
    }

    /* ── Main content: no margin, no stacking tricks ── */
    .main-content {
        margin-left: 0;
    }

    .view-container {
        padding-top: 56px;
        padding-left: 10px;
        padding-right: 10px;
        padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 12px);
    }

    /* ══════════════════════════════════════════
       MOBILE HEADER
       ══════════════════════════════════════════ */
    .mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 200;
        height: 52px;
        padding: 0 16px;
        background: rgba(15, 23, 42, 0.95);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-bottom: 1px solid var(--border-subtle);
    }

    .mobile-header-brand {
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .mobile-brand-logo {
        width: 28px;
        height: 28px;
        border-radius: 8px;
        object-fit: contain;
    }

    .mobile-brand-name {
        font-size: 17px;
        font-weight: 700;
        background: linear-gradient(135deg, var(--brand-primary), #06F9F9);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }

    .mobile-header-actions {
        display: flex;
        align-items: center;
        gap: 4px;
    }

    [data-theme="light"] .mobile-header {
        background: rgba(255, 255, 255, 0.95);
        border-bottom-color: rgba(0, 0, 0, 0.08);
    }

    /* ══════════════════════════════════════════
       BOTTOM NAVIGATION BAR
       ══════════════════════════════════════════ */
    .bottom-nav {
        display: flex;
        align-items: stretch;
        justify-content: space-around;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 300;
        height: var(--bottom-nav-height);
        padding-bottom: var(--safe-area-bottom);
        background: rgba(15, 23, 42, 0.95);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        border-top: 1px solid var(--border-subtle);
        box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.15);
    }

    [data-theme="light"] .bottom-nav {
        background: rgba(255, 255, 255, 0.95);
        border-top-color: rgba(0, 0, 0, 0.06);
        box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
    }

    /* ── Nav items ── */
    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        text-decoration: none;
        color: var(--text-muted);
        font-size: 10px;
        font-weight: 500;
        letter-spacing: 0.02em;
        transition: color 0.2s ease;
        padding: 6px 0;
        -webkit-tap-highlight-color: transparent;
    }

    .bottom-nav-item .material-icons {
        font-size: 22px;
        transition: color 0.2s ease;
    }

    .bottom-nav-item.active {
        color: var(--brand-primary);
    }

    /* ── Center elevated button ── */
    .bottom-nav-center {
        position: relative;
    }

    .bottom-nav-center-btn {
        width: 48px;
        height: 48px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
        display: flex;
        align-items: center;
        justify-content: center;
        margin-top: -18px;
        box-shadow: 0 4px 16px rgba(var(--brand-rgb), 0.35);
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }

    .bottom-nav-center-btn .material-icons {
        color: var(--text-on-brand);
        font-size: 24px;
    }

    .bottom-nav-center.active .bottom-nav-center-btn {
        transform: scale(1.08);
        box-shadow: 0 6px 24px rgba(var(--brand-rgb), 0.5);
    }

    /* ── Tables horizontal scroll ── */
    .data-table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .data-table {
        min-width: 600px;
    }

    /* ── Toast position above bottom nav ── */
    .toast-container {
        bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 12px) !important;
    }
}