/* ============================================================
   拾光笔记 — 移动端适配（2026-08-22 统一整改版）
   基于真机 390×844 六页走查 + 前两轮 punch-list 保留
   原则：只在 .mobile-nav / 真实页面类上打点，去死选择器、统一断点
   断点约定：手机 ≤767.98px，平板 ≤991.98px，小平板 768–1023.98px
   ============================================================ */

/* 导航项文字不换行（避免用户菜单外置后挤压左侧项导致换行） */
.custom-navbar .navbar-nav .nav-link { white-space: nowrap; }

/* ── 底部导航（真实类为 .mobile-nav；.mobile-bottom-nav 已废弃）── */
.mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--sg-surface, #ffffff);
    border-top: 1px solid var(--sg-border, #e2e8f0);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 1030;
    box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.06);
    padding-bottom: env(safe-area-inset-bottom, 0);
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
}

.mobile-nav .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--sg-text-secondary, #64748b);
    text-decoration: none;
    font-size: 0.66rem;
    padding: 4px 6px;
    border-radius: 10px;
    transition: all 0.2s ease;
    min-width: 48px;
    min-height: 44px;
    line-height: 1.2;
}

.mobile-nav .mobile-nav-item i {
    font-size: 1.2rem;
    margin-bottom: 2px;
}

.mobile-nav .mobile-nav-item.active {
    color: var(--sg-primary, #4f6ef7);
    background: rgba(79, 110, 247, 0.08);
}

/* 小拾入口是 <button>，重置默认外观使其与其它导航项一致 */
.mobile-nav .mobile-nav-item.mobile-nav-pa {
    border: none;
    background: transparent;
    cursor: pointer;
}
.mobile-nav .mobile-nav-item.mobile-nav-pa.active {
    color: var(--sg-primary, #4f6ef7);
    background: rgba(79, 110, 247, 0.08);
}

.mobile-nav .mobile-nav-item:active {
    background: rgba(79, 110, 247, 0.12);
    transform: scale(0.96);
}

.mobile-nav .mobile-nav-add {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-nav .mobile-nav-add-circle {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--sg-primary, #4f6ef7);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    margin-top: -16px;
    box-shadow: 0 4px 12px rgba(79, 110, 247, 0.35);
    transition: transform 0.2s ease;
}

.mobile-nav .mobile-nav-add:active .mobile-nav-add-circle {
    transform: scale(0.92);
}

[data-bs-theme="dark"] .mobile-nav {
    background: var(--sg-surface, #1e293b);
    border-top-color: var(--sg-border, #334155);
}

/* ══════════════ 手机端 ≤767.98px ══════════════ */
@media (max-width: 767.98px) {
    /* body 留白避开 56px 底部导航 + 安全区 */
    body {
        padding-bottom: calc(56px + env(safe-area-inset-bottom, 0) + 12px) !important;
    }
    #backToTop {
        bottom: calc(56px + env(safe-area-inset-bottom, 0) + 76px) !important;
    }
    /* 快速记录 FAB 在手机端隐藏（底部导航中间已有 + 号）+ 面板隐藏 */
    .btn.rounded-circle.position-fixed[style*="bottom: 80px"] {
        display: none !important;
    }
    #quickPanel {
        display: none !important;
    }
    .app-footer {
        padding-bottom: 24px;
    }

    /* ── 全局触控目标下限 44px ── */
    .btn,
    .nav-link,
    .page-link,
    .dropdown-item,
    .list-group-item-action {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
    .btn-sm {
        min-height: 36px;
    }
    .btn-icon,
    .btn-close {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* ── 笔记阅读页：标题与操作按钮上下堆叠、按钮换行不挤压标题 ── */
    .entry-header .d-flex.justify-content-between {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    .entry-header .d-flex.justify-content-between > div:first-child {
        min-width: 0;
    }
    .entry-header .btn-group {
        flex-wrap: wrap;
        gap: 4px;
    }
    .entry-header .btn-group .btn {
        flex: 0 0 auto;
    }

    /* ── 笔记详情/编辑器：标题与正文排版舒适 ── */
    .entry-detail-title,
    .entry-title-display {
        font-size: 1.25rem !important;
        line-height: 1.4 !important;
        word-break: break-word;
    }
    .entry-content {
        font-size: 1rem !important;
        line-height: 1.8 !important;
    }

    /* ── 编辑器工具栏：单行横向滑动，不再换行吞半屏 ── */
    .editor-toolbar,
    .entry-form-toolbar {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 4px;
        padding: 8px 4px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .editor-toolbar::-webkit-scrollbar,
    .entry-form-toolbar::-webkit-scrollbar {
        display: none;
    }
    .editor-toolbar .btn,
    .entry-form-toolbar .btn,
    .editor-toolbar .cm6-toolbar {
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* ── 浮动学习计时器避让底部导航 ── */
    #studyTimer {
        bottom: calc(56px + env(safe-area-inset-bottom, 0) + 10px) !important;
        left: 12px !important;
    }
}

/* ── 主题管理页（真实类 .topics-page）── */
@media (max-width: 767.98px) {
    .topics-page .topics-header { gap: 12px !important; }
    .topics-page .topics-actions {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        justify-content: stretch !important;
    }
    .topics-page .topics-actions .btn {
        flex: 1 1 100% !important;
        min-height: 44px !important;
        justify-content: center !important;
        font-size: 0.85rem !important;
    }
    .topics-page .topics-actions .btn svg { width: 18px !important; height: 18px !important; }
    .topics-page .topic-list-item { padding: 14px 12px !important; align-items: center !important; }
    .topics-page .topic-title-row { gap: 8px !important; }
    .topics-page .topic-title-row strong { font-size: 0.95rem !important; }
    .topics-page .topic-row-actions { display: flex !important; gap: 6px !important; }
    .topics-page .topic-row-actions .btn {
        min-width: 44px !important;
        min-height: 44px !important;
        padding: 0 !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    .topics-page .topic-row-actions .btn svg { width: 18px !important; height: 18px !important; }
}

/* ── 所有笔记页（真实类 .entries-page）── */
@media (max-width: 767.98px) {
    .entries-page .entries-header { gap: 12px !important; }
    .entries-page .entries-actions {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 8px !important;
        justify-content: stretch !important;
    }
    .entries-page .entries-actions .btn {
        flex: 1 1 100% !important;
        min-height: 44px !important;
        justify-content: center !important;
        font-size: 0.85rem !important;
    }
    .entries-page .entry-row,
    .entries-page .all-entry-item { padding: 14px 12px !important; row-gap: 6px !important; }
    .entries-page .entry-title-line strong { font-size: 0.95rem !important; line-height: 1.4 !important; }
    .entries-page .entry-title-line svg { width: 18px !important; height: 18px !important; flex-shrink: 0 !important; }
    .entries-page .entry-topic-chip { font-size: 0.75rem !important; padding: 2px 8px !important; }
    .entries-page .entry-date-cell { font-size: 0.7rem !important; color: var(--sg-text-secondary, #64748b) !important; }
    .entries-page .entry-meta-cell { display: flex !important; align-items: center !important; gap: 8px !important; }
    .entries-page .entry-format-pill { font-size: 0.65rem !important; padding: 2px 6px !important; }
    .entries-page .entry-word-count { font-size: 0.7rem !important; }
    .entries-page .pagination { flex-wrap: wrap; justify-content: center; gap: 4px; }
    .entries-page .pagination .page-link {
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ── 番茄钟（真实类）── */
@media (max-width: 767.98px) {
    .timer-ring-wrap { width: 220px; height: 220px; }
    .timer-display .time { font-size: 2.8rem; }
    .timer-btn { width: 52px; height: 52px; font-size: 1.1rem; }
    .timer-btn-primary { width: 64px; height: 64px; font-size: 1.3rem; }
    .timer-controls { gap: 0.75rem; }
    .pomo-stats { gap: 1.5rem; }
}

/* ── 小拾角色移动端边界保护（基础 60×72，配合 page_agent.pa-compact 浮标）── */
@media (max-width: 767.98px) {
    .pa-character { max-width: 60px; max-height: 72px; }
    .pa-character .pa-svg { width: 60px !important; height: 72px !important; }
}

/* ── 右上角折叠菜单（平板/手机）── */
@media (max-width: 991.98px) {
    .custom-navbar .container { padding-left: 12px; padding-right: 12px; }
    .navbar-brand { font-size: 1.1rem; }
    .navbar-brand i { font-size: 1.25rem; }
    #searchForm .input-group { flex-wrap: nowrap; }
    #searchForm .form-control { min-width: 0; }

    /* 折叠面板背景跟随导航栏，避免透底 */
    .custom-navbar .navbar-collapse {
        background: var(--sg-surface, #ffffff);
        margin: 8px -12px -8px;
        padding: 8px 12px 12px;
        border-radius: 0 0 14px 14px;
        box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
    }
    [data-bs-theme="dark"] .custom-navbar .navbar-collapse {
        background: var(--sg-surface, #1e293b);
    }
    /* 导航项：图标 + 文字并排，统一行高 */
    .custom-navbar .navbar-collapse .navbar-nav .nav-link {
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 11px 14px;
        min-height: 44px;
        border-radius: 10px;
        font-size: 0.92rem;
    }
    /* 搜索表单占满一行 */
    .custom-navbar .navbar-collapse > .d-flex { width: 100%; margin: 4px 0 8px; }
    .custom-navbar #searchForm .form-control { min-width: 0; }
    .custom-navbar #searchForm .btn { white-space: nowrap; }
    /* 用户菜单（始终可见）：单行紧凑图标条 */
    .custom-navbar .navbar-nav.ms-auto {
        margin-left: auto;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        gap: 2px;
    }
    .custom-navbar .navbar-nav.ms-auto .nav-item { display: flex; align-items: center; }
    .custom-navbar .navbar-nav.ms-auto .nav-link,
    .custom-navbar .navbar-nav.ms-auto .btn-outline-light { padding: 6px 8px; border-radius: 10px; }
    .custom-navbar .navbar-nav.ms-auto .dropdown-toggle img { width: 30px; height: 30px; }
    /* 手机端隐藏文字标签与用户名，保持图标行紧凑 */
    .custom-navbar .navbar-nav.ms-auto .d-md-none.ms-1 { display: none !important; }
    .custom-navbar .navbar-nav.ms-auto .d-inline { display: none !important; }
}

/* ══════════════ 小平板 768–1023.98px ══════════════ */
@media (min-width: 768px) and (max-width: 1023.98px) {
    /* 仪表盘/首页网格在此尺寸给 3 列（真实类由 Bootstrap col-* 管理，这里兜底为 2×2） */
    .dashboard-stat-card { min-height: 120px; }
}
