/* ==========================================================================
   移动端适配样式 (Mobile Adaptation)
   --------------------------------------------------------------------------
   本文件在所有其它 CSS（style.css / work-countdown.css / emoji.css 等）之后
   加载，用于覆盖桌面端规则，实现真正的手机端体验：
   1. 侧边栏 → 左侧抽屉菜单（汉堡按钮 + 遮罩）
   2. 在线用户 → 右侧抽屉面板
   3. 顶部导航栏 / 安全区（刘海屏）/ 触控目标
   4. 聊天输入框防 iOS 自动放大、模态框全屏化
   ========================================================================== */

/* 桌面端默认隐藏移动端专属元素（移动端媒体查询内再显示） */
.mobile-topbar,
.mobile-backdrop,
.sidebar-close-btn,
.online-users-close {
    display: none;
}

@media (max-width: 768px) {
    html {
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    /* 图片与嵌入内容不横向溢出 */
    img,
    iframe,
    video {
        max-width: 100%;
    }

    body {
        overflow: hidden;
    }

    /* ---------- 布局容器 ---------- */
    .container,
    .main-site .container {
        display: block;
        height: 100vh;
        height: 100dvh;
        padding: 0;
        gap: 0;
        overflow: hidden;
    }

    .main-site {
        height: 100vh;
        height: 100dvh;
    }

    /* ---------- 移动端顶部导航栏 ---------- */
    .mobile-topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1500;
        height: 56px;
        height: calc(56px + env(safe-area-inset-top));
        padding-top: env(safe-area-inset-top);
        box-sizing: border-box;
        background: rgba(255, 255, 255, 0.92);
        backdrop-filter: blur(20px) saturate(180%);
        -webkit-backdrop-filter: blur(20px) saturate(180%);
        border-bottom: 1px solid rgba(226, 232, 240, 0.4);
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
    }

    .mobile-menu-toggle,
    .mobile-users-toggle {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
        margin: 0 6px;
        border: none;
        border-radius: 12px;
        background: transparent;
        color: #2d3748;
        font-size: 1.3rem;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        -webkit-tap-highlight-color: transparent;
    }

    .mobile-menu-toggle:active,
    .mobile-users-toggle:active {
        background: rgba(102, 126, 234, 0.12);
    }

    .mobile-topbar-title {
        flex: 1;
        min-width: 0;
        text-align: center;
        font-size: 1.02rem;
        font-weight: 700;
        color: #2d3748;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        padding: 0 4px;
    }

    /* 移动端遮罩 */
    .mobile-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1900;
        background: rgba(15, 23, 42, 0.45);
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }

    body.mobile-nav-open .mobile-backdrop,
    body.mobile-users-open .mobile-backdrop {
        display: block;
    }

    /* ---------- 侧边栏 → 左侧抽屉 ---------- */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        max-width: 84vw;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        margin: 0;
        border-radius: 0 16px 16px 0;
        transform: translateX(-105%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 2000;
        box-shadow: none;
    }

    /* 覆盖桌面端“收起”状态，移动端统一为抽屉 */
    .sidebar.collapsed {
        width: 280px;
        max-width: 84vw;
        min-width: 0;
        opacity: 1;
        transform: translateX(-105%);
        pointer-events: auto;
    }

    body.mobile-nav-open .sidebar,
    body.mobile-nav-open .sidebar.collapsed {
        transform: translateX(0);
        box-shadow: 0 0 60px rgba(0, 0, 0, 0.35);
    }

    /* 隐藏桌面端的收起按钮与图标栏 */
    .sidebar-toggle-btn,
    .sidebar-icon-bar {
        display: none !important;
    }

    /* 抽屉关闭按钮 */
    .sidebar-close-btn {
        display: flex;
        position: absolute;
        right: 14px;
        top: 50%;
        transform: translateY(-50%);
        width: 34px;
        height: 34px;
        align-items: center;
        justify-content: center;
        border: 1px solid rgba(226, 232, 240, 0.5);
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.9);
        color: #64748b;
        font-size: 0.95rem;
        cursor: pointer;
        z-index: 2;
        -webkit-tap-highlight-color: transparent;
    }

    .sidebar-header {
        padding: 18px 20px;
        padding-top: calc(18px + env(safe-area-inset-top));
        border-radius: 0;
    }

    .sidebar-header h2 {
        font-size: 1.35rem;
        padding-right: 40px;
        text-align: left;
    }

    .sidebar-menu {
        padding: 10px 0;
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    .menu-item {
        padding: 15px 20px;
        margin: 4px 12px;
        border-radius: 14px;
    }

    /* ---------- 侧边栏底部（用户信息 + 操作按钮） ---------- */
    .sidebar-footer {
        flex-shrink: 0;
        padding: 14px;
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
        max-height: 46vh;
        overflow-y: auto;
        border-radius: 0 0 16px 16px;
    }

    .sidebar-footer .user-info {
        margin-bottom: 12px;
        padding: 12px;
        border-radius: 12px;
    }

    .sidebar-footer .user-avatar {
        width: 40px;
        height: 40px;
    }

    .sidebar-footer .username {
        font-size: 0.9rem;
    }

    .sidebar-footer .checkin-btn {
        width: 34px;
        height: 34px;
        font-size: 14px;
    }

    /* 个人设置 / 网站设置 / 退出登录 / 管理后台等按钮：紧凑化 */
    .sidebar-footer .btn {
        min-height: 44px;
        padding: 10px 14px;
        margin-bottom: 8px;
        font-size: 0.85rem;
        border-radius: 12px;
        letter-spacing: 0;
        text-transform: none;
        box-sizing: border-box;
    }

    .sidebar-footer .btn:last-child {
        margin-bottom: 0;
    }

    .sidebar-footer .btn i {
        margin-right: 10px;
        font-size: 1rem;
        width: 20px;
    }

    /* ---------- 主内容区域 ---------- */
    .main-content {
        margin: 0;
        margin-top: 56px;
        margin-top: calc(56px + env(safe-area-inset-top));
        height: calc(100vh - 56px);
        height: calc(100dvh - 56px - env(safe-area-inset-top));
        border-radius: 0;
        border: none;
        box-shadow: none;
        /* 关键：backdrop-filter 会为 fixed 后代建立新的包含块，
           导致在线用户抽屉脱离视口定位，这里在移动端移除它 */
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
    }

    .container.sidebar-collapsed .main-content {
        margin-left: 0;
    }

    /* ---------- 分区头部 ---------- */
    .section-header {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        padding: 12px 14px;
        gap: 8px 12px;
        border-radius: 0;
    }

    .section-header h2 {
        font-size: 1.2rem;
    }

    .section-header p {
        display: none;
    }

    .header-left {
        min-width: 0;
        flex: 1;
    }

    .header-right {
        width: auto;
        flex-shrink: 0;
    }

    /* 倒计时组件紧凑化 */
    .work-countdown-widget {
        min-width: 0;
        padding: 4px 10px;
        border-radius: 10px;
    }

    .countdown-display {
        flex-direction: row;
        text-align: left;
        gap: 6px;
    }

    .countdown-icon {
        width: 24px;
        height: 24px;
    }

    .countdown-label {
        font-size: 0.66rem;
    }

    .countdown-time {
        font-size: 0.95rem;
    }

    /* ---------- 聊天室布局 ---------- */
    #chat-content .section-body {
        display: flex;
        flex-direction: column;
        padding: 10px;
        gap: 0;
    }

    .chat-container {
        flex: 1;
        min-height: 0;
        border-radius: 14px;
    }

    .chat-messages {
        padding: 12px;
    }

    .message {
        margin-bottom: 14px;
    }

    .message-avatar {
        width: 38px;
        height: 38px;
        margin-right: 10px;
        flex-shrink: 0;
    }

    .message-image {
        max-width: 100%;
        max-height: 260px;
    }

    .message-text {
        word-break: break-word;
        overflow-wrap: break-word;
    }

    .chat-input-container {
        padding: 10px 12px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }

    .chat-input-wrapper {
        gap: 8px;
    }

    #messageInput {
        font-size: 16px; /* 防止 iOS 聚焦时自动放大 */
        height: 46px;
        padding: 8px 16px;
        min-width: 0;
    }

    .btn-send,
    .btn-image,
    .btn-emoji {
        width: 46px;
        height: 46px;
        flex-shrink: 0;
    }

    /* ---------- 在线用户 → 右侧抽屉 ---------- */
    .online-users {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 280px;
        max-width: 84vw;
        height: 100vh;
        height: 100dvh;
        margin: 0;
        padding: 16px;
        padding-top: calc(16px + env(safe-area-inset-top));
        border-radius: 16px 0 0 16px;
        transform: translateX(105%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 2000;
        box-shadow: none;
        box-sizing: border-box;
    }

    body.mobile-users-open .online-users {
        transform: translateX(0);
        box-shadow: 0 0 60px rgba(0, 0, 0, 0.35);
    }

    .online-users-close {
        display: flex;
        position: absolute;
        top: 16px;
        top: calc(16px + env(safe-area-inset-top));
        right: 16px;
        width: 34px;
        height: 34px;
        align-items: center;
        justify-content: center;
        border: 1px solid rgba(226, 232, 240, 0.5);
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.9);
        color: #64748b;
        font-size: 0.95rem;
        cursor: pointer;
        z-index: 2;
        -webkit-tap-highlight-color: transparent;
    }

    .online-users h3 {
        padding-right: 40px;
    }

    /* ---------- 工具/游戏/资源网格 ---------- */
    .tools-grid,
    .games-grid,
    .resources-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .tool-item,
    .game-item,
    .resource-item {
        padding: 20px 14px;
        border-radius: 16px;
    }

    .tool-item i,
    .game-item i,
    .resource-item i {
        font-size: 2rem;
        margin-bottom: 14px;
    }

    .tool-item h3,
    .game-item h3,
    .resource-item h3 {
        font-size: 1.05rem;
        margin-bottom: 10px;
    }

    .tool-item p,
    .game-item p,
    .resource-item p {
        font-size: 0.8rem;
    }

    .section-body {
        padding: 12px;
    }

    /* ---------- 内容查看器 ---------- */
    .content-viewer-container {
        border-radius: 0;
    }

    .content-viewer-header {
        padding: 10px 12px;
    }

    .btn-back {
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    /* ---------- 模态框 ---------- */
    .modal-content {
        width: calc(100% - 20px);
        max-width: 520px;
        margin: 4vh auto;
        padding: 22px 16px;
        border-radius: 20px;
        max-height: 92vh;
        max-height: 92dvh;
        overflow-y: auto;
        box-sizing: border-box;
    }

    .modal .close {
        width: 36px;
        height: 36px;
        font-size: 1.6rem;
        line-height: 34px;
        text-align: center;
        -webkit-tap-highlight-color: transparent;
    }

    .modal-content h2 {
        font-size: 1.25rem;
    }

    /* 网站设置等宽模态框全屏化 */
    .site-settings-modal {
        max-width: 100%;
        width: calc(100% - 20px);
        max-height: 92vh;
        max-height: 92dvh;
    }

    /* 表单控件防 iOS 自动放大 */
    .modal input,
    .modal select,
    .modal textarea,
    #floatMessageInput {
        font-size: 16px;
    }

    .form-group input,
    .form-group select,
    .setting-group input,
    .setting-group select {
        padding: 12px 14px;
    }

    /* ---------- 自定义确认对话框 ---------- */
    .custom-confirm-dialog {
        min-width: 0;
        max-width: calc(100vw - 32px);
        width: calc(100vw - 32px);
        padding: 24px 18px;
        box-sizing: border-box;
    }

    /* ---------- 工作时间 / 违禁词 对话框 ---------- */
    .work-settings-dialog,
    .banned-word-dialog {
        width: calc(100vw - 20px);
        max-width: 100vw;
        margin: 3vh auto;
        border-radius: 18px;
    }

    /* ---------- 聊天室悬浮窗（手机端为底部卡片） ---------- */
    .chat-float-window {
        width: calc(100vw - 16px);
        height: 46vh;
        max-height: 420px;
        bottom: 8px;
        right: 8px;
        left: 8px;
        border-radius: 16px;
        z-index: 3000;
    }

    .chat-float-input-container {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .chat-float-minimized {
        bottom: 10px;
        right: 10px;
        width: 52px;
        height: 52px;
        z-index: 3000;
    }

    /* ---------- 触控优化 ---------- */
    button,
    .menu-item,
    .tool-item,
    .game-item,
    .resource-item {
        -webkit-tap-highlight-color: transparent;
    }

    /* Toast 提示 */
    .toast-container {
        top: 10px;
        top: calc(10px + env(safe-area-inset-top));
        right: 10px;
        left: 10px;
    }

    .toast {
        min-width: 0;
        max-width: none;
        width: 100%;
        box-sizing: border-box;
    }
}

/* ==================== 小屏手机 (≤480px) ==================== */
@media (max-width: 480px) {
    .sidebar {
        width: 78vw;
    }

    .online-users {
        width: 80vw;
    }

    .section-header h2 {
        font-size: 1.1rem;
    }

    .countdown-time {
        font-size: 0.85rem;
    }

    .countdown-settings-btn {
        width: 22px;
        height: 22px;
    }

    .tools-grid,
    .games-grid,
    .resources-grid {
        gap: 10px;
    }

    .tool-item,
    .game-item,
    .resource-item {
        padding: 16px 10px;
    }

    .modal-content {
        width: calc(100% - 12px);
        margin: 2vh auto;
        padding: 20px 14px;
        max-height: 96vh;
        max-height: 96dvh;
    }

    .chat-float-window {
        height: 50vh;
    }
}

/* ==================== 深色主题适配（移动端新增元素） ==================== */
@media (max-width: 768px) {
    body.dark-theme .mobile-topbar {
        background: rgba(30, 41, 59, 0.92);
        border-bottom-color: rgba(71, 85, 105, 0.4);
    }

    body.dark-theme .mobile-topbar-title,
    body.dark-theme .mobile-menu-toggle,
    body.dark-theme .mobile-users-toggle {
        color: #e2e8f0;
    }

    body.dark-theme .mobile-menu-toggle:active,
    body.dark-theme .mobile-users-toggle:active {
        background: rgba(102, 126, 234, 0.18);
    }

    body.dark-theme .sidebar-close-btn,
    body.dark-theme .online-users-close {
        background: rgba(51, 65, 85, 0.9);
        border-color: rgba(71, 85, 105, 0.5);
        color: #cbd5e1;
    }
}
