/* ════════════════════════════════════════════════════════
   QURAN ACADEMY – MAIN LAYOUT
   App shell, sidebar, top bar, bottom nav, page layout
════════════════════════════════════════════════════════ */

/* ─── App Loading Screen ─────────────────────────── */
.app-loading {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #0a1628 0%, #0d3b2e 50%, #0a1628 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.app-loading.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-6);
    animation: loadingFadeIn 0.6s ease forwards;
}

.loading-star {
    width: 80px;
    height: 80px;
    color: var(--color-primary);
    animation: loadingPulse 2s ease-in-out infinite;
}

.loading-bismillah {
    font-family: var(--font-quran);
    font-size: 1.6rem;
    color: var(--color-accent);
    direction: rtl;
    text-align: center;
    opacity: 0.9;
    letter-spacing: 0.02em;
}

.loading-bar-wrapper {
    width: 200px;
    height: 3px;
    background: rgba(255,255,255,0.1);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.loading-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
    border-radius: var(--radius-full);
    animation: loadingBar 2.5s ease-out forwards;
}

.loading-label {
    color: rgba(255,255,255,0.5);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

@keyframes loadingFadeIn {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes loadingPulse {
    0%, 100% { transform: scale(1); opacity: 0.9; }
    50%       { transform: scale(1.08); opacity: 1; }
}

@keyframes loadingBar {
    0%   { width: 0%; }
    30%  { width: 40%; }
    60%  { width: 70%; }
    100% { width: 100%; }
}

/* ─── App Shell Layout ───────────────────────────── */
.app {
    display: flex;
    height: 100dvh;
    overflow: hidden;
    position: relative;
}

/* ─── Sidebar ─────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    height: 100dvh;
    background: var(--color-sidebar-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: var(--z-fixed);
    flex-shrink: 0;
    transition: transform var(--transition-smooth), width var(--transition-smooth);
}

/* Sidebar Logo */
.sidebar-logo {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-6) var(--sp-5);
    flex-shrink: 0;
}

.sidebar-logo-mark {
    flex-shrink: 0;
}

.sidebar-logo-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-app-name {
    font-size: var(--text-base);
    font-weight: var(--font-bold);
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-app-sub {
    font-size: var(--text-xs);
    color: rgba(255,255,255,0.4);
    font-weight: var(--font-normal);
    margin-top: 1px;
}

.sidebar-divider {
    height: 1px;
    background: var(--color-sidebar-border);
    margin: 0 var(--sp-4);
    flex-shrink: 0;
}

/* Sidebar Nav */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--sp-3) var(--sp-3);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); }

.sidebar-section-label {
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.3);
    padding: var(--sp-4) var(--sp-3) var(--sp-2);
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-3);
    border-radius: var(--radius-lg);
    color: var(--color-sidebar-text);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
    text-decoration: none;
    border: none;
    background: none;
    width: 100%;
    text-align: start;
    white-space: nowrap;
}

.sidebar-item svg {
    flex-shrink: 0;
    opacity: 0.7;
    transition: opacity var(--transition-fast);
}

.sidebar-item:hover {
    background: var(--color-sidebar-item-hover);
    color: var(--color-sidebar-text-active);
}

.sidebar-item:hover svg { opacity: 1; }

.sidebar-item.active {
    background: var(--color-sidebar-item-active);
    color: var(--color-sidebar-text-active);
    font-weight: var(--font-semibold);
}

.sidebar-item.active svg { opacity: 1; }

.sidebar-item-badge {
    margin-inline-start: auto;
    background: var(--color-primary);
    color: white;
    font-size: 10px;
    font-weight: var(--font-bold);
    padding: 1px 6px;
    border-radius: var(--radius-full);
    min-width: 18px;
    text-align: center;
}

/* Sidebar Footer */
.sidebar-spacer { flex: 1; }

.sidebar-footer {
    padding: var(--sp-4) var(--sp-3);
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    flex-shrink: 0;
}

.sidebar-user-card {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3);
    border-radius: var(--radius-lg);
    background: rgba(255,255,255,0.06);
}

.sidebar-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    font-weight: var(--font-bold);
    color: white;
    flex-shrink: 0;
}

.sidebar-user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sidebar-user-name {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    color: #ffffff;
    truncate: ellipsis;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user-role {
    font-size: var(--text-xs);
    color: rgba(255,255,255,0.4);
}

.sidebar-actions {
    display: flex;
    gap: var(--sp-2);
}

.sidebar-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-2);
    border-radius: var(--radius-md);
    background: rgba(255,255,255,0.06);
    border: none;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    transition: background var(--transition-fast), color var(--transition-fast);
    height: 36px;
}

.sidebar-action-btn:hover {
    background: rgba(255,255,255,0.12);
    color: #ffffff;
}

.sidebar-action-btn.danger:hover {
    background: rgba(239,68,68,0.2);
    color: #ef4444;
}

/* ─── Main Wrapper ──────────────────────────────── */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    position: relative;
}

/* ─── Top Bar ────────────────────────────────────── */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--page-padding);
    height: var(--top-bar-height);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
    z-index: var(--z-sticky);
    position: sticky;
    top: 0;
    gap: var(--sp-4);
    transition: background var(--transition-slow), border-color var(--transition-slow);
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    min-width: 0;
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex-shrink: 0;
}

.page-title {
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hamburger-btn {
    display: none;
}

/* Icon Button */
.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-lg);
    background: none;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
    position: relative;
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--color-border-light);
    color: var(--color-text);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* Notification badge */
.notif-btn { position: relative; }

.notif-badge {
    position: absolute;
    top: 4px;
    inset-inline-end: 4px;
    width: 16px;
    height: 16px;
    border-radius: var(--radius-full);
    background: var(--color-error);
    color: white;
    font-size: 9px;
    font-weight: var(--font-bold);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--color-surface);
}

/* Language pill */
.lang-pill {
    height: 32px;
    padding: 0 var(--sp-3);
    border-radius: var(--radius-full);
    background: var(--color-primary-light);
    border: 1px solid var(--color-primary);
    color: var(--color-primary);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.lang-pill:hover {
    background: var(--color-primary);
    color: white;
}

/* Top avatar */
.top-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
    font-weight: var(--font-bold);
    color: white;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color var(--transition-fast), transform var(--transition-fast);
    flex-shrink: 0;
}

.top-avatar:hover {
    border-color: var(--color-primary);
    transform: scale(1.05);
}

/* ─── Page Content ───────────────────────────────── */
.page-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--color-bg);
    transition: background var(--transition-slow);
}

/* Pre-auth pages fill full height */
.page-content.full-page {
    height: 100dvh;
    overflow: hidden;
}

/* Page inner padding */
.page-inner {
    padding: var(--page-padding);
    max-width: var(--content-max-width);
    margin: 0 auto;
}

.page-inner-wide {
    padding: var(--page-padding);
}

/* ─── Bottom Navigation (Mobile Student) ──────── */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    z-index: var(--z-fixed);
    flex-direction: row;
    align-items: center;
    justify-content: space-around;
    padding-bottom: env(safe-area-inset-bottom, 0);
    transition: background var(--transition-slow);
}

.bnav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: var(--sp-2) var(--sp-1);
    color: var(--color-text-muted);
    background: none;
    border: none;
    cursor: pointer;
    transition: color var(--transition-fast);
    position: relative;
    height: 100%;
}

.bnav-item.active {
    color: var(--color-primary);
}

.bnav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.bnav-label {
    font-size: 10px;
    font-weight: var(--font-semibold);
    letter-spacing: 0.02em;
}

/* Center Quran button */
.bnav-center {
    position: relative;
    margin-top: -16px;
}

.bnav-center-btn {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: var(--shadow-primary);
    transition: transform var(--transition-spring), box-shadow var(--transition-fast);
}

.bnav-center:hover .bnav-center-btn,
.bnav-center.active .bnav-center-btn {
    transform: scale(1.08);
    box-shadow: var(--shadow-primary-lg);
}

/* Active indicator dot */
.bnav-item.active::after {
    content: '';
    position: absolute;
    bottom: 6px;
    width: 4px;
    height: 4px;
    border-radius: var(--radius-full);
    background: var(--color-primary);
}

.bnav-center.active::after { display: none; }

/* ─── Overlay Systems ───────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--color-overlay);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-4);
    backdrop-filter: blur(4px);
    animation: fadeIn var(--transition-normal) ease;
}

.modal-container {
    background: var(--color-surface);
    border-radius: var(--radius-2xl);
    max-width: 520px;
    width: 100%;
    max-height: 90dvh;
    overflow-y: auto;
    box-shadow: var(--shadow-2xl);
    animation: slideUp 0.3s var(--transition-spring);
}

/* Notification Panel */
.notif-panel {
    position: fixed;
    inset-block-start: 0;
    inset-inline-end: 0;
    width: 380px;
    max-width: 100vw;
    height: 100dvh;
    background: var(--color-surface);
    border-inline-start: 1px solid var(--color-border);
    z-index: var(--z-modal);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
    animation: slideInRight 0.3s ease;
}

.notif-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-5) var(--sp-5);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.notif-panel-title {
    font-size: var(--text-lg);
    font-weight: var(--font-bold);
}

.notif-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: var(--sp-3);
}

/* Search Overlay */
.search-overlay {
    position: fixed;
    inset: 0;
    background: var(--color-overlay);
    z-index: var(--z-modal);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 80px;
    backdrop-filter: blur(8px);
    animation: fadeIn var(--transition-fast) ease;
}

.search-box {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    background: var(--color-surface);
    border-radius: var(--radius-2xl);
    padding: var(--sp-4) var(--sp-5);
    width: min(600px, 90vw);
    box-shadow: var(--shadow-2xl);
    animation: slideDown 0.25s ease;
}

.search-icon { color: var(--color-text-muted); flex-shrink: 0; }

#search-input {
    flex: 1;
    border: none;
    background: none;
    font-size: var(--text-lg);
    color: var(--color-text);
    outline: none;
    font-family: var(--font-en);
}

#search-input::placeholder { color: var(--color-text-muted); }

.search-results {
    width: min(600px, 90vw);
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    margin-top: var(--sp-3);
    overflow: hidden;
    box-shadow: var(--shadow-xl);
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: var(--color-overlay);
    z-index: calc(var(--z-fixed) - 1);
    animation: fadeIn var(--transition-fast) ease;
}

/* Toast Container */
.toast-container {
    position: fixed;
    top: var(--sp-5);
    inset-inline-end: var(--sp-5);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    max-width: 360px;
    width: calc(100vw - 40px);
}

/* ─── Responsive Breakpoints ─────────────────── */
@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        inset-block-start: 0;
        inset-inline-start: -var(--sidebar-width);
        transform: translateX(-100%);
        height: 100dvh;
    }

    [dir="rtl"] .sidebar {
        transform: translateX(100%);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .hamburger-btn { display: flex !important; }
    .main-wrapper { width: 100%; }
}

@media (max-width: 768px) {
    :root {
        --page-padding: 1rem;
        --top-bar-height: 58px;
    }

    .top-bar { padding: 0 var(--sp-4); }
    .page-title { font-size: var(--text-lg); }

    /* Show bottom nav for student on mobile */
    .app.student-mode .bottom-nav {
        display: flex !important;
    }

    /* Add bottom padding when bottom nav is shown */
    .app.student-mode .page-content {
        padding-bottom: var(--bottom-nav-height);
    }
}

/* ─── RTL Layout Adjustments ─────────────────── */
[dir="rtl"] .sidebar {
    border-radius: 0;
}

[dir="rtl"] .notif-panel {
    animation: slideInLeft 0.3s ease;
}

/* ─── Fullscreen Pre-auth Pages ──────────────── */
.app.pre-auth .sidebar,
.app.pre-auth .top-bar,
.app.pre-auth .bottom-nav {
    display: none !important;
}

.app.pre-auth .main-wrapper {
    width: 100%;
}

.app.pre-auth .page-content {
    height: 100dvh;
    padding-bottom: 0;
}
