/* ============================================================
   Tokmart - Layout: header, scroll area, pages, bottom nav, back button
   ============================================================ */

/* ===== HEADER ===== */
header {
    position: relative;
    z-index: var(--z-header);
    background: var(--primary);
    border-bottom: none;
    flex-shrink: 0;
    box-shadow: 0 2px 20px rgba(5,134,147,.15);
    padding-top: var(--safe-area-top);
}

.topbar {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
}

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

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

.logo {
    font-size: 24px;
    font-weight: 900;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFFFFF;
    user-select: none;
}

.logo .logo-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 20px;
}

.logo .logo-text {
    display: none !important;
}

.icon-btn {
    width: 42px;
    height: 42px;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 12px;
    background: rgba(255,255,255,0.08);
    color: #FFFFFF;
    font-size: 16px;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: all 0.25s var(--ease-spring);
    position: relative;
    touch-action: manipulation;
}

.icon-btn .badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--red);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    min-width: 18px;
    height: 18px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

.admin-icon {
    background: var(--secondary);
    color: #fff;
    border-color: var(--secondary) !important;
}

/* ===== MAIN CONTENT SHELL =====
   #app is the fixed, full-height flex column (header + this). Without an
   explicit height here, this block only grows to fit its own content, so
   .scroll-area's height:0/flex:1 below has nothing to size against and the
   page collapses to its content height - leaving the rest of #app's box as
   dead space that just shows its background color, looking like most of
   the screen is blank/hidden. */
#mainContent {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ===== SCROLL AREA =====
   No z-index here even though header/bottom-nav sit visually above this
   area: setting one would make .scroll-area a stacking context, which traps
   its fixed-position descendants (.auth-page.open, .settings-page.open,
   etc.) inside that context. Their own z-index:var(--z-modal) would then
   only be compared against siblings *inside* .scroll-area, never against
   header's z-index:var(--z-header) one level up - so header (and its logo)
   would keep painting on top of what's supposed to be a fullscreen overlay
   covering it. Plain flow order already keeps this below header/bottom-nav
   without needing a z-index. */
.scroll-area {
    flex: 1 1 auto !important;
    height: 0 !important;
    min-height: 0;
    overflow-y: auto !important;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    padding-bottom: 120px;
    position: relative;
    background: var(--bg);
    touch-action: pan-y;
}

.scroll-area::-webkit-scrollbar {
    width: 3px;
}

.scroll-area::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

/* ===== PAGES ===== */
.page {
    display: none;
    animation: pageFadeIn 0.4s var(--ease-out);
    padding: 0 18px;
    padding-bottom: 10px;
}

.page.active {
    display: block;
}

@keyframes pageFadeIn {
    0% { opacity: 0; transform: translateY(12px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* ===== BOTTOM NAVIGATION ===== */
.bottom-nav-wrapper {
    position: fixed;
    bottom: 16px;
    left: 16px;
    right: 16px;
    z-index: var(--z-bottom-nav);
    display: flex;
    justify-content: center;
    pointer-events: none;
    transition: all 0.4s var(--ease-out);
    padding-bottom: var(--safe-area-bottom);
}

.bottom-nav-wrapper.hidden {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
}

.bottom-nav {
    pointer-events: auto;
    background: var(--nav-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--border);
    border-radius: 28px;
    padding: 8px 12px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 2px;
    box-shadow: var(--nav-shadow), 0 0 0 1px rgba(255,255,255,0.5);
    max-width: 500px;
    width: 100%;
    min-height: 68px;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: none;
    border: none;
    color: var(--text3);
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 10px;
    transition: all 0.3s var(--ease-spring);
    border-radius: 16px;
    min-width: 52px;
    flex: 1;
    position: relative;
    touch-action: manipulation;
    text-decoration: none;
    height: 56px;
}

.nav-item:hover {
    color: var(--primary);
    background: var(--acSh);
}

.nav-item.active {
    color: var(--primary);
    background: var(--acSh);
}

.nav-item i {
    font-size: 22px;
    transition: all 0.3s var(--ease-spring);
    line-height: 1;
}

.nav-item.active i {
    transform: translateY(-2px) scale(1.1);
    color: var(--primary);
}

.nav-item span:last-child {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.3px;
    opacity: 0.9;
}

.nav-item.active span:last-child {
    color: var(--primary);
}

.nav-item .cat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: transparent;
    transition: all 0.3s var(--ease-spring);
    border: 2px solid transparent;
    position: relative;
}

.nav-item .cat-icon i {
    font-size: 20px;
    color: var(--text3);
    transition: all 0.3s var(--ease-spring);
}

.nav-item.active .cat-icon {
    background: var(--primary);
    border-color: var(--primary);
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 4px 15px rgba(5,134,147,.25);
}

.nav-item.active .cat-icon i {
    color: #fff;
    transform: scale(1.05);
}

.nav-item:hover:not(.active) .cat-icon {
    background: var(--acSh);
}

.nav-item:hover:not(.active) .cat-icon i {
    color: var(--primary);
}

.nav-item .badge {
    position: absolute;
    top: 0px;
    right: 4px;
    background: var(--red);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    min-width: 18px;
    height: 18px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    z-index: 2;
    border: 2px solid var(--nav-bg);
    box-shadow: 0 2px 8px rgba(231,76,60,.3);
    animation: badgePop 0.3s var(--ease-spring);
}

@keyframes badgePop {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@media(max-width:480px) {
    .bottom-nav { padding: 6px 8px; min-height: 58px; border-radius: 22px; }
    .nav-item { min-width: 40px; padding: 4px 6px; height: 48px; gap: 2px; }
    .nav-item i { font-size: 18px; }
    .nav-item span:last-child { font-size: 8px; }
    .nav-item .cat-icon { width: 32px; height: 32px; }
    .nav-item .cat-icon i { font-size: 16px; }
    .nav-item .badge { font-size: 8px; min-width: 16px; height: 16px; top: -2px; right: 0px; }
}

@media(min-width:768px) {
    .bottom-nav { padding: 10px 16px; min-height: 74px; border-radius: 32px; }
    .nav-item { min-width: 64px; padding: 8px 14px; height: 62px; }
    .nav-item i { font-size: 26px; }
    .nav-item span:last-child { font-size: 11px; }
    .nav-item .cat-icon { width: 44px; height: 44px; }
    .nav-item .cat-icon i { font-size: 22px; }
}

/* ===== BACK BUTTON ===== */
.detail-header,
.settings-page .detail-header,
.product-detail-page .detail-header,
.all-products-page .detail-header,
.category-products-page .detail-header,
.favorites-page .detail-header,
.orders-page .detail-header,
.order-detail-page .detail-header,
.recharge-page .detail-header,
.auth-page .detail-header,
.chat-app-user .chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    background: var(--primary);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 10;
    flex-shrink: 0;
    min-height: 64px;
    box-shadow: 0 2px 20px rgba(5,134,147,.15);
    padding-top: calc(12px + var(--safe-area-top));
}

.detail-header h2,
.settings-page .detail-header h2,
.product-detail-page .detail-header h2,
.all-products-page .detail-header h2,
.category-products-page .detail-header h2,
.favorites-page .detail-header h2,
.orders-page .detail-header h2,
.order-detail-page .detail-header h2,
.recharge-page .detail-header h2,
.auth-page .detail-header h2,
.chat-app-user .chat-header .chat-info .name {
    font-size: 18px;
    font-weight: 800;
    color: #fff;
    margin: 0;
    flex: 1;
    text-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    border: none;
    border-radius: 12px;
    background: rgba(255,255,255,0.15);
    color: #FFFFFF;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s var(--ease-spring);
    touch-action: manipulation;
    position: relative;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.1);
}

.back-btn:hover {
    background: rgba(255,255,255,0.25);
    transform: scale(1.05);
    border-color: rgba(255,255,255,0.3);
}

.back-btn:active {
    transform: scale(0.92);
    background: rgba(255,255,255,0.3);
}

.back-btn i {
    font-size: 18px;
    transition: transform 0.3s var(--ease-spring);
}

.back-btn:hover i {
    transform: translateX(-2px);
}
