/* ============================================================
   Layout — Sidebar + Topbar + Content
   ============================================================ */

/* ── App Shell ── */
.app-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: 56px 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar content";
    min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    grid-area: sidebar;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width var(--dur-normal) var(--ease);
    z-index: 100;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    height: 56px;
}

.sidebar-brand-icon {
    width: 32px;
    height: 32px;
    background: var(--accent);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.sidebar-brand-name {
    font-weight: 800;
    font-size: var(--text-lg);
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.sidebar-brand-name span { color: var(--accent); }

/* Nav */
.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    overflow-y: auto;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    padding: 8px 12px 4px;
    margin-top: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--dur-fast) var(--ease);
    position: relative;
    white-space: nowrap;
    text-decoration: none;
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--accent-subtle);
    color: var(--accent);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0; top: 4px; bottom: 4px;
    width: 3px;
    background: var(--accent);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.nav-item-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 15px;
}

.nav-badge {
    margin-left: auto;
    background: var(--status-danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: var(--radius-full);
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 12px 8px;
    border-top: 1px solid var(--border);
}

/* ── Topbar ── */
.topbar {
    grid-area: topbar;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar-title {
    font-size: var(--text-lg);
    font-weight: 700;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--dur-fast) var(--ease);
    color: var(--text-secondary);
    position: relative;
}

.topbar-icon-btn:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.notification-dot {
    position: absolute;
    top: 6px; right: 6px;
    width: 7px; height: 7px;
    background: var(--status-danger);
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all var(--dur-fast) var(--ease);
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-xs);
    font-weight: 700;
    color: #fff;
}

/* ── Content Area ── */
.content {
    grid-area: content;
    padding: 24px;
    overflow-y: auto;
    animation: fadeInUp var(--dur-slow) var(--ease);
}

/* ── Page Header ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-title {
    font-size: var(--text-2xl);
    font-weight: 800;
    letter-spacing: -0.02em;
}

.page-subtitle {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    margin-top: 2px;
}

/* ── Grid Utilities ── */
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.devices-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }

/* ── Responsive ── */
@media (max-width: 1200px) {
    .app-shell { grid-template-columns: 64px 1fr; }
    .sidebar { width: 64px; }
    .sidebar-brand-name,
    .nav-item span,
    .nav-section-label,
    .nav-badge { display: none; }
    .nav-item  { padding: 12px; justify-content: center; }
    .nav-item::before { display: none; }
    .nav-item.active { background: var(--accent-subtle); }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .app-shell {
        grid-template-columns: 1fr;
        grid-template-rows: 56px 1fr 56px;
        grid-template-areas:
            "topbar"
            "content"
            "sidebar";
    }
    .sidebar {
        height: 56px;
        width: 100%;
        flex-direction: row;
        justify-content: space-around;
        border-right: none;
        border-top: 1px solid var(--border);
        position: fixed;
        bottom: 0;
        left: 0;
    }
    .sidebar-brand, .sidebar-footer, .nav-section-label { display: none; }
    .sidebar-nav { display: flex; flex-direction: row; padding: 0; overflow-x: auto; }
    .nav-item { flex-direction: column; gap: 2px; font-size: 9px; padding: 8px 12px; }
    .nav-item-icon { font-size: 18px; }
    .nav-item span { display: block; }
    .nav-item::before { display: none; }
    .content { padding: 16px; padding-bottom: 72px; }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: 1fr; }
}
