/**
 * 全局状态栏适配样式
 * 用于 App 打包时 statusbar: { immersed: true } 的情况
 * 为所有页面内容添加顶部间距，避免与状态栏重叠
 */

/* 定义状态栏高度变量 */
:root {
    --status-bar-height: env(safe-area-inset-top, 0px);
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
}

/* 强制状态栏高度（App环境下） */
.app-env,
.force-app-mode {
    --status-bar-height: 44px; /* iPhone默认状态栏高度 */
}

/* ⭐ HBuilder X App 强制模式（通过URL参数 ?app_mode=1 启用） */
.app-mode-enabled {
    --status-bar-height: 44px;
}

.app-mode-enabled body {
    padding-top: max(44px, env(safe-area-inset-top, 0px)) !important;
}

@media (max-width: 375px) {
    .app-env {
        --status-bar-height: 40px;
    }
}

@media (min-width: 414px) {
    .app-env {
        --status-bar-height: 47px;
    }
}

/* Android 设备 */
@media (max-height: 700px) {
    .app-env {
        --status-bar-height: 32px;
    }
}

/* ===== 通用页面容器样式 ===== */

/* 主容器添加顶部间距 */
body {
    padding-top: var(--status-bar-height) !important;
}

/* 固定头部适配 */
.header-fixed,
.fixed-header,
.header {
    padding-top: var(--status-bar-height) !important;
    top: 0 !important;
}

/* 导航栏适配 */
.navbar,
.nav-bar,
.top-nav {
    padding-top: var(--status-bar-height) !important;
}

/* 返回按钮位置调整 */
.back-btn,
.go-back,
.back-button {
    top: calc(50% + var(--status-bar-height) / 2) !important;
}

/* 页面主内容区 */
.main-content,
.content,
.container {
    padding-top: calc(10px + var(--status-bar-height)) !important;
}

/* ===== 特定页面样式 ===== */

/* 首页搜索页 */
body.index-page {
    padding-top: var(--status-bar-height) !important;
}

body.index-page .top-buttons-container {
    margin-top: var(--status-bar-height) !important;
}

/* 播放器页面 - 全屏时不添加padding */
body.player-page {
    padding-top: 0 !important;
}

body.player-page.fullscreen-active {
    padding-top: 0 !important;
}

body.player-page .header {
    padding-top: var(--status-bar-height) !important;
}

/* 单剧详情页 */
body.drama-page {
    padding-top: var(--status-bar-height) !important;
}

/* 任务系统页面 */
body.task-page {
    padding-top: var(--status-bar-height) !important;
}

body.task-page .header {
    padding-top: calc(15px + var(--status-bar-height)) !important;
}

/* 用户中心页面 */
body.user-page {
    padding-top: var(--status-bar-height) !important;
}

/* 管理后台页面 */
body.admin-page {
    padding-top: var(--status-bar-height) !important;
}

body.admin-page .admin-header {
    padding-top: var(--status-bar-height) !important;
}

/* ===== 沉浸式状态栏文字颜色适配 ===== */

/* 深色文字（浅色背景） */
.status-bar-dark {
    padding-top: var(--status-bar-height) !important;
}

/* 浅色文字（深色背景） */
.status-bar-light {
    padding-top: var(--status-bar-height) !important;
}

/* ===== 刘海屏/挖孔屏特殊适配 ===== */

@supports (padding-top: env(safe-area-inset-top)) {
    body {
        padding-top: max(var(--status-bar-height), env(safe-area-inset-top)) !important;
    }
    
    .header-fixed,
    .header {
        padding-top: max(var(--status-bar-height), env(safe-area-inset-top)) !important;
    }
}

/* iOS 设备特殊处理 */
@supports (-webkit-touch-callout: none) {
    body {
        padding-top: max(44px, env(safe-area-inset-top)) !important;
    }
    
    .header {
        padding-top: max(44px, env(safe-area-inset-top)) !important;
    }
}

/* ===== 底部安全区域适配（有刘海的底部） ===== */

body {
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
}

.fixed-bottom,
.bottom-bar {
    padding-bottom: env(safe-area-inset-bottom, 0px) !important;
}

/* ===== 横屏模式适配 ===== */

@media screen and (orientation: landscape) {
    /* 横屏时状态栏通常隐藏，但保留安全区域 */
    body:not(.player-page) {
        padding-top: env(safe-area-inset-left, 0px) !important;
        padding-left: env(safe-area-inset-left, 0px) !important;
        padding-right: env(safe-area-inset-right, 0px) !important;
    }
}

/* ===== 特定设备适配 ===== */

/* iPhone X / XS / 11 Pro */
@media (width: 375px) and (height: 812px) {
    body {
        --status-bar-height: 44px;
    }
}

/* iPhone XS Max / 11 Pro Max */
@media (width: 414px) and (height: 896px) {
    body {
        --status-bar-height: 44px;
    }
}

/* iPhone 12 / 12 Pro / 13 / 13 Pro / 14 */
@media (width: 390px) and (height: 844px) {
    body {
        --status-bar-height: 47px;
    }
}

/* iPhone 12 Pro Max / 13 Pro Max / 14 Plus */
@media (width: 428px) and (height: 926px) {
    body {
        --status-bar-height: 47px;
    }
}

/* iPhone 14 Pro / 15 */
@media (width: 393px) and (height: 852px) {
    body {
        --status-bar-height: 59px; /* 灵动岛 */
    }
}

/* iPhone 14 Pro Max / 15 Plus / 15 Pro Max */
@media (width: 430px) and (height: 932px) {
    body {
        --status-bar-height: 59px; /* 灵动岛 */
    }
}

/* ===== 工具类 ===== */

/* 添加顶部间距 */
.pt-safe {
    padding-top: var(--status-bar-height) !important;
}

/* 添加顶部margin */
.mt-safe {
    margin-top: var(--status-bar-height) !important;
}

/* 固定定位元素适配 */
.fixed-safe {
    top: var(--status-bar-height) !important;
}

/* 全屏模式（用于播放器） */
.fullscreen-mode {
    padding-top: 0 !important;
    margin-top: 0 !important;
}

.fullscreen-mode .header {
    display: none !important;
}
