/* ==========================================================================
   TurboLoader - Responsive Layout, Mobile Dock & Smart TV Safe Area
   Path: /static/css/layout.css
   ========================================================================== */

:root {
    --tv-safe-top: 0px;
    --shell-max-width: 1280px;
    --mobile-dock-height: 4.6rem;
}

/* ناحیه امن اختصاصی بالای صفحه برای جلوگیری از هم‌پوشانی کادر آدرس مرورگر تلویزیون */
.tv-safe-banner {
    height: var(--tv-safe-top);
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    overflow: hidden;
    pointer-events: none;
    transition: height var(--transition-smooth), opacity var(--transition-smooth);
    opacity: 0;
}

.tv-safe-banner-inner {
    width: 100%;
    max-width: var(--shell-max-width);
    padding: 0.4rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.72rem;
    color: rgba(148, 163, 184, 0.55);
    border-bottom: 1px solid rgba(56, 189, 248, 0.12);
}

/* فعال‌سازی خودکار یا دستی فضای امن در تلویزیون */
body.tv-mode {
    font-size: clamp(16px, 1.15vw, 21px);
    --tv-safe-top: clamp(3.75rem, 8vh, 5.75rem);
    --shell-max-width: 1560px;
}

body.tv-mode .tv-safe-banner {
    opacity: 1;
}

/* کانتینر اصلی برنامه */
.app-shell {
    width: 100%;
    max-width: var(--shell-max-width);
    margin: 0 auto;
    padding: 0.85rem 1rem calc(var(--mobile-dock-height) + 1.5rem + env(safe-area-inset-bottom, 0px));
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

@media (min-width: 768px) {
    .app-shell {
        padding: 1.25rem 1.75rem 2.5rem;
        gap: 1.5rem;
    }
}

/* هدر و نوار ناوبری اصلی (همیشه پایین‌تر از TV Safe Area) */
.app-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.85rem;
    padding: 0.85rem 1.15rem;
    position: relative;
    z-index: 20;
}

.brand-block {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-width: 0;
}

.brand-logo {
    width: 2.65rem;
    height: 2.65rem;
    border-radius: 0.95rem;
    background: linear-gradient(135deg, #4f46e5, #0ea5e9);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    color: #ffffff;
    font-size: 1rem;
    box-shadow: 0 10px 24px -6px rgba(14, 165, 233, 0.45);
    flex-shrink: 0;
}

/* نوار تب‌های دسکتاپ و تلویزیون */
.desktop-nav-tabs {
    display: none;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem;
    background: rgba(6, 10, 22, 0.72);
    border: 1px solid rgba(148, 163, 184, 0.14);
    border-radius: 1rem;
}

@media (min-width: 768px) {
    .desktop-nav-tabs {
        display: flex;
    }
}

.nav-tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 0.95rem;
    border-radius: 0.75rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.nav-tab-btn:hover {
    color: var(--text-primary);
    background: rgba(30, 41, 59, 0.6);
}

.nav-tab-btn.is-active {
    color: #ffffff;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.9), rgba(14, 165, 233, 0.85));
    border-color: rgba(56, 189, 248, 0.4);
    box-shadow: 0 8px 20px -6px rgba(56, 189, 248, 0.38);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* نوار ناوبری شناور پایین مخصوص موبایل (Thumb-Friendly) */
.mobile-bottom-dock {
    position: fixed;
    left: 0.75rem;
    right: 0.75rem;
    bottom: calc(0.65rem + env(safe-area-inset-bottom, 0px));
    z-index: 40;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 0.35rem;
    padding: 0.4rem;
    background: rgba(9, 14, 28, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 1.25rem;
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.85);
}

@media (min-width: 768px) {
    .mobile-bottom-dock {
        display: none;
    }
}

.mobile-dock-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    padding: 0.45rem 0.25rem;
    min-height: 46px;
    border-radius: 0.9rem;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.mobile-dock-btn.is-active {
    color: #38bdf8;
    background: rgba(56, 189, 248, 0.14);
}

/* کنترل نمایش ویوهای اصلی */
.view-section {
    display: none;
    flex-direction: column;
    gap: 1.25rem;
}

.view-section.is-active {
    display: flex;
    animation: fadeSlideUp 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* شبکه‌بندی کاشی‌ها (Bento & Tiles) */
.bento-hero-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
}

@media (min-width: 1024px) {
    .bento-hero-grid {
        grid-template-columns: 2fr 1fr;
        gap: 1.25rem;
    }
}

.tile-grid-2 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.9rem;
}

@media (min-width: 768px) {
    .tile-grid-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem;
    }
}

.tile-grid-3 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.9rem;
}

@media (min-width: 640px) {
    .tile-grid-3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1100px) {
    .tile-grid-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 1.1rem;
    }
}

.admin-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
}

@media (min-width: 900px) {
    .admin-stats-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 1rem;
    }
}

/* ریسپانسیو و بهینه‌سازی ابعاد لمسی در موبایل و ریموت تلویزیون */
@media (max-width: 640px) {
    .btn-base {
        min-height: 44px;
        font-size: 0.82rem;
    }

    .input-glass {
        min-height: 46px;
        font-size: 0.9rem;
    }
}

body.tv-mode .btn-base,
body.tv-mode .nav-tab-btn,
body.tv-mode .input-glass {
    min-height: 50px;
}

body.tv-mode .minimal-tile {
    padding: 1.2rem;
}

/* بستر استاندارد مودال‌ها */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(2, 6, 23, 0.84);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(0.85rem + var(--tv-safe-top) * 0.45) 0.85rem 0.85rem;
}

.modal-backdrop.hidden {
    display: none;
}

.modal-dialog {
    width: 100%;
    max-height: calc(100vh - 2rem - var(--tv-safe-top) * 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalScaleIn 190ms cubic-bezier(0.22, 1, 0.36, 1);
}