/* ═══════════════════════════════════════════════════════════════
   AMC · HABARI — Layout
   App shell, sidebar, topbar, main grid.
   ═══════════════════════════════════════════════════════════════ */

/* ── App Shell ───────────────────────────────────────────────── */
.app-shell {
    display: flex;
    min-height: 100vh;
    background-image:
        radial-gradient(600px circle at 15% 50%, rgba(16, 185, 129, 0.15) 0%, transparent 100%),
        radial-gradient(600px circle at 85% 30%, rgba(59, 130, 246, 0.15) 0%, transparent 100%);
    background-attachment: fixed;
    background-color: var(--c-bg);
    /* ensure fallback base color */
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--c-surface);
    border-right: 1px solid var(--c-border);
    transition: width var(--transition), box-shadow var(--transition);
}

.sidebar-backdrop {
    display: none;
}

.sidebar-rail-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--r-md);
    border: 1px solid var(--c-border);
    background: var(--c-surface);
    color: var(--c-text-muted);
    cursor: pointer;
    position: absolute;
    top: 50%;
    right: var(--sp-2);
    transform: translateY(-50%);
    z-index: 2;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.sidebar-rail-toggle:hover {
    background: var(--c-surface-2);
    color: var(--c-text);
    border-color: var(--c-border-hi);
}

.sidebar-rail-toggle:focus-visible {
    outline: none;
    box-shadow: var(--glow-blue);
}

/* Sidebar — Brand */
.sidebar-brand {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-5) calc(var(--sp-4) + 46px) var(--sp-4) var(--sp-4);
    border-bottom: 1px solid var(--c-border);
    flex-shrink: 0;
}

.sidebar-brand-logo {
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    background: linear-gradient(135deg, var(--c-primary), var(--c-teal));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px var(--c-primary-glow);
    color: #fff;
}

.sidebar-brand-text {
    line-height: 1.2;
    overflow: hidden;
}

.sidebar-brand-title {
    font-size: .82rem;
    font-weight: 800;
    color: var(--c-text);
    white-space: nowrap;
    letter-spacing: -.01em;
}

.sidebar-brand-sub {
    font-size: var(--t-caption);
    color: var(--c-text-faint);
    white-space: nowrap;
}

/* Sidebar — Nav */
.sidebar-nav {
    flex: 1;
    padding: var(--sp-4) var(--sp-3);
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-section {
    margin-bottom: var(--sp-5);
}

.nav-section-label {
    font-size: .6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--c-text-faint);
    padding: 0 var(--sp-3);
    margin-bottom: var(--sp-2);
    white-space: nowrap;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 9px var(--sp-3);
    border-radius: var(--r-md);
    color: var(--c-text-muted);
    font-size: var(--t-body);
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
    -webkit-user-select: none;
    user-select: none;
    white-space: nowrap;
    min-height: 40px;
}

.nav-item:hover {
    background: var(--c-surface-2);
    color: var(--c-text);
}

.nav-item.active {
    background: var(--c-primary-soft);
    color: var(--c-primary);
    font-weight: 600;
}

.nav-item.active .nav-icon {
    opacity: 1;
}

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    flex-shrink: 0;
    opacity: .7;
    transition: opacity var(--transition);
}

.nav-item:hover .nav-icon,
.nav-item.active .nav-icon {
    opacity: 1;
}

/* Sidebar — Footer */
.sidebar-footer {
    padding: var(--sp-3) var(--sp-3) var(--sp-5);
    border-top: 1px solid var(--c-border);
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-2);
    border-radius: var(--r-md);
    cursor: pointer;
    transition: background var(--transition);
    overflow: hidden;
}

.sidebar-user:hover {
    background: var(--c-surface-2);
}

.sidebar-user-avatar {
    width: 34px;
    height: 34px;
    border-radius: var(--r-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .72rem;
    color: #fff;
    letter-spacing: .02em;
    flex-shrink: 0;
}

.sidebar-user-info {
    overflow: hidden;
}

.sidebar-user-name {
    font-weight: 600;
    font-size: var(--t-body);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: var(--t-caption);
    color: var(--c-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Topbar ──────────────────────────────────────────────────── */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--sp-6);
    background: var(--bg-surface);
    opacity: 0.95;
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    backdrop-filter: blur(12px) saturate(180%);
    border-bottom: 1px solid var(--c-border);
}

.topbar-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -.01em;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}

/* ── Main content area ───────────────────────────────────────── */
.app-main {
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left var(--transition);
}

.app-content {
    padding: var(--sp-6) var(--sp-8);
    flex: 1;
    max-width: var(--content-max);
    width: 100%;
}

/* ── Page headers ────────────────────────────────────────────── */
.page-header {
    margin-bottom: var(--sp-6);
}

.page-title {
    font-size: var(--t-title);
    font-weight: 800;
    letter-spacing: -.02em;
    line-height: 1.2;
    margin-bottom: var(--sp-1);
}

.page-subtitle {
    color: var(--c-text-muted);
    font-size: var(--t-sm);
}

.page-actions {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    flex-wrap: wrap;
}

.page-header-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-4);
    flex-wrap: wrap;
    margin-bottom: var(--sp-6);
}

/* ── Section grid ────────────────────────────────────────────── */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-6);
}

.profile-grid-2 {
    display: grid;
    grid-template-columns: 1fr 320px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--sp-5);
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--sp-4);
}

/* ── Source badges ───────────────────────────────────────────── */
.topbar-source-badge {
    font-size: var(--t-caption);
    font-weight: 700;
    padding: 3px 10px;
    border-radius: var(--r-full);
    letter-spacing: .05em;
}

.source-amc {
    background: var(--badge-amc-bg);
    color: var(--badge-amc-text);
    border: 1px solid var(--badge-amc-border);
}

.source-habari {
    background: var(--badge-habari-bg);
    color: var(--badge-habari-text);
    border: 1px solid var(--badge-habari-border);
}

.source-global {
    background: var(--badge-global-bg);
    color: var(--badge-global-text);
    border: 1px solid var(--badge-global-border);
}

/* ── Bottom Navigation (mobile) ──────────────────────────────── */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    height: var(--bottom-nav-h);
    display: none;
    /* shown in mobile breakpoint */
    align-items: center;
    justify-content: space-around;
    background: var(--bg-surface);
    opacity: 0.98;
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    backdrop-filter: blur(16px) saturate(180%);
    border-top: 1px solid var(--c-border);
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--r-md);
    color: var(--c-text-faint);
    font-size: .58rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    cursor: pointer;
    background: none;
    border: none;
    font-family: inherit;
    transition: color var(--transition), background var(--transition);
    min-width: 52px;
    min-height: 44px;
}

.bottom-nav-item:hover {
    color: var(--c-text-muted);
}

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

.bottom-nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
}

.bottom-nav-label {
    line-height: 1;
}



/* ── Sheet overlay ───────────────────────────────────────────── */
.sheet-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
    z-index: calc(var(--sheet-z) - 1);
    transition: opacity var(--transition);
}

.sheet-overlay.active {
    display: block;
}

/* ── Bottom Sheet ────────────────────────────────────────────── */
.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--sheet-z);
    background: var(--c-surface-2);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    border-top: 1px solid var(--c-border-hi);
    box-shadow: var(--shadow-xl);
    transform: translateY(100%);
    transition: transform var(--dur-slow) var(--ease-out);
    max-height: 92dvh;
    overflow-y: auto;
    padding-bottom: env(safe-area-inset-bottom, 16px);
}

.bottom-sheet.open {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 36px;
    height: 4px;
    border-radius: var(--r-full);
    background: var(--c-border-hi);
    margin: var(--sp-3) auto var(--sp-2);
}

.bottom-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-3) var(--sp-5) var(--sp-2);
}

.bottom-sheet-title {
    font-weight: 700;
    font-size: var(--t-sub);
}

.bottom-sheet-close {
    color: var(--c-text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    background: none;
    border: none;
    font-family: inherit;
    line-height: 1;
    padding: var(--sp-1);
}

.bottom-sheet-body {
    padding: var(--sp-3) var(--sp-5) var(--sp-6);
}

/* ── Login view — hide shell chrome ──────────────────────────── */
/* When the router switches to login-view, suppress all nav chrome */
.login-view~.bottom-nav,
#app.login-view~nav#bottom-nav {
    display: none !important;
}

/* Since bottom-nav is a sibling of #app in the body, target via body class instead */
body.is-login .bottom-nav {
    display: none !important;
}

/* ── Breakpoints ─────────────────────────────────────────────── */

/* Mobile (≤767px) */
@media (max-width: 767px) {
    .app-sidebar {
        display: none;
    }

    .app-main {
        margin-left: 0;
        padding-bottom: calc(var(--bottom-nav-h) + 40px);
    }

    .app-content {
        padding: var(--sp-4);
    }

    .bottom-nav {
        display: flex;
    }



    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }

    .topbar-title {
        font-size: .9rem;
    }
}

/* Tablet (768–1023px) */
@media (min-width: 768px) and (max-width: 1023px) {
    .app-sidebar {
        width: var(--sidebar-rail-w);
        z-index: 130;
    }

    .app-sidebar.is-expanded {
        width: var(--sidebar-w);
        box-shadow: var(--shadow-xl);
    }

    .app-main {
        margin-left: var(--sidebar-rail-w);
    }

    .app-sidebar:not(.is-expanded) .sidebar-brand-text,
    .app-sidebar:not(.is-expanded) .sidebar-user-info,
    .app-sidebar:not(.is-expanded) .sidebar-footer .btn,
    .app-sidebar:not(.is-expanded) .nav-section-label,
    .app-sidebar:not(.is-expanded) .nav-item .nav-label {
        display: none;
    }

    .app-sidebar:not(.is-expanded) .sidebar-brand {
        justify-content: center;
        padding: var(--sp-4) 0;
    }

    .app-sidebar.is-expanded .sidebar-brand {
        justify-content: space-between;
        padding-right: calc(var(--sp-4) + 46px);
    }

    .app-sidebar.is-expanded .sidebar-brand-text {
        display: block;
    }

    .app-sidebar:not(.is-expanded) .sidebar-user {
        justify-content: center;
    }

    .app-sidebar:not(.is-expanded) .nav-item {
        justify-content: center;
        padding: 10px;
        gap: 0;
        border-radius: var(--r-md);
    }

    .app-sidebar.is-expanded .nav-item {
        justify-content: flex-start;
        padding: 9px var(--sp-3);
        gap: var(--sp-3);
    }

    .sidebar-footer {
        padding: var(--sp-3) var(--sp-2) var(--sp-5);
    }

    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .app-content {
        padding: var(--sp-5) var(--sp-6);
    }

    .bottom-nav {
        display: none !important;
    }

    .sidebar-rail-toggle {
        display: inline-flex;
        flex-shrink: 0;
    }

    .app-sidebar:not(.is-expanded) .sidebar-rail-toggle {
        display: none;
    }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        opacity: 0;
        pointer-events: none;
        background: rgba(0, 0, 0, .48);
        -webkit-backdrop-filter: blur(3px);
        backdrop-filter: blur(3px);
        z-index: 120;
        transition: opacity var(--transition);
    }

    body.tablet-sidebar-expanded .sidebar-backdrop {
        opacity: 1;
        pointer-events: auto;
    }


}

/* Desktop (≥1024px) */
@media (min-width: 1024px) {
    .bottom-nav {
        display: none !important;
    }

    .fab-register {
        display: none !important;
    }
}