/**
 * 关键页面移动端 UI 补充（E7-10）
 * 在 mobile.css 之后加载，统一 --mika-* touch 与 safe-area。
 */
@media screen and (max-width: 768px) {
    /* 防止任意子元素把页面撑出视口；滚动条仍留给纵向 */
    html,
    body {
        max-width: 100%;
        overflow-x: hidden;
        overflow-x: clip;
    }

    #page.site,
    .app-layout,
    .app-layout-body,
    .content-zone,
    #content,
    #primary,
    #primary-home,
    .home-item,
    .home-item > .wrapper,
    .home-item-left {
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }

    /* 分类外层只限宽；真正横向拖拽在列表轨上（对齐列表卡标签） */
    .module-nav,
    .mika-home-tools-cats {
        max-width: 100%;
        min-width: 0;
        overflow: hidden;
    }

    .post-cats-list,
    .mika-home-tools-cats .post-cats-list {
        max-width: 100%;
        min-width: 0;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
        scrollbar-width: none;
        -ms-overflow-style: none;
        cursor: grab;
        touch-action: pan-x;
    }

    .post-cats-list::-webkit-scrollbar,
    .mika-home-tools-cats .post-cats-list::-webkit-scrollbar {
        display: none;
        width: 0;
        height: 0;
    }

    .post-cats-list.is-dragging {
        cursor: grabbing;
        user-select: none;
    }

    .post-cats-list {
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
    }

    .mika-home-tools-chip,
    .post-cats-list .cat-item {
        flex: 0 0 auto;
    }

    /* 分类 tab + 换一换/更多：超宽时换一换整块换行靠右 */
    .home-item .modules-top .module-head-tools,
    body.home.app-layout-active .home-item.module-posts .module-head-tools {
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center;
        gap: 8px 10px;
        width: 100%;
        min-width: 0;
    }

    .home-item .modules-top .module-head-tools .module-nav,
    .home-item .modules-top .module-head-tools .post-type-tabs,
    body.home.app-layout-active .home-item.module-posts .module-head-tools .module-nav,
    body.home.app-layout-active .home-item.module-posts .module-head-tools .post-type-tabs {
        flex: 1 1 calc(100% - 9.5em);
        min-width: min(100%, 12em);
        max-width: 100%;
        margin-right: 0;
    }

    .home-item .modules-top .module-head-tools .module-action,
    body.home.app-layout-active .home-item.module-posts .module-head-tools .module-action,
    body.home.app-layout-active .home-item.module-posts .modules-top .module-action {
        flex: 0 0 auto;
        margin-left: auto !important;
        max-width: 100%;
    }

    /* 换一换 / 更多：移动端改小 */
    body.home.app-layout-active .home-item.module-posts .module-head-tools .module-action > *,
    body.home.app-layout-active .module-posts .module-action > .button,
    body.home.app-layout-active .module-posts .module-action > a.button,
    .home-item .modules-top .module-action > * {
        height: 26px !important;
        min-height: 26px !important;
        padding: 0 9px !important;
        font-size: 12px !important;
        line-height: 26px !important;
        gap: 3px;
    }

    .home-item .modules-top .module-action i {
        font-size: 14px !important;
        line-height: 14px !important;
    }

    /* 底部「加载更多」按钮改小 */
    body.home .home-item .modules-bottom.module-load-button .button,
    .home-item .modules-bottom.module-load-button .button {
        min-width: 96px !important;
        width: auto !important;
        max-width: 160px;
        height: 30px !important;
        padding: 0 14px !important;
        font-size: 12px !important;
        margin-top: 14px !important;
    }

    .home-item .modules-bottom.load-more,
    .home-item .modules-bottom.module-load-button {
        padding-top: 12px !important;
    }

    /* --mika-gap / --mika-radius 由 Main.php 注入，移动端不再硬覆盖 */

    .mika-login.login-container,
    .mika-confirm-pay.confirm-pay-container,
    .mika-pay-vip.pay-vip-container {
        padding: var(--mika-gap);
    }

    .mika-account .account-page-left.account-mobile-hidden,
    .mika-account .account-page-right.account-mobile-hidden {
        display: none;
    }

    .modal-dialog {
        max-width: calc(100vw - 20px);
        margin: 10px auto;
    }

    .mika-circle .circle-editor-simple .simple-text-input {
        min-height: 40px;
        font-size: 14px;
    }

    .mika-single .single-article {
        padding: var(--mika-gap);
        margin-bottom: var(--mika-gap);
    }

    .footer-mobile-tabbar {
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    }

    body.app-layout-active .footer-mobile-tabbar .toolbar-inner > * {
        font-size: 11px;
        gap: 2px;
        min-height: 44px;
    }

    body.app-layout-active .footer-mobile-tabbar .toolbar-inner .name {
        font-size: 10px;
        line-height: 1.2;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .modal-dialog,
    .mika-modal-content {
        max-width: calc(100vw - 24px);
    }

    .mika-pay .pay-qrcode img {
        max-width: min(220px, 70vw);
        height: auto;
    }

    button,
    .button,
    .form-container .form-button button,
    .pay-button button,
    .vip-pay-btn {
        min-height: 44px;
    }

    /* 弹窗关闭钮不受 touch min-height 影响，否则 background 会被拉成竖椭圆 */
    .mika-modal-content > button.close,
    .mika-drawer > button.close {
        min-height: 0;
        min-width: 0;
    }
}

@media screen and (max-width: 480px) {
    .mika-account .back-warp .page-title {
        font-size: 16px;
    }

    .mika-circle .circle-tab-nav,
    .mika-circle .circle-list-tab {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }
}

/* ══════════════════════════════════════════════════════════════
   Mobile modals — shared shell + high-frequency dialogs
   ══════════════════════════════════════════════════════════════ */
@media screen and (max-width: 768px) {
    /* 默认：卡片弹窗上下居中（底栏发布面板 .mika-compose-sheet 仍贴底） */
    .mika-modal,
    .mika-modal-dialog {
        align-items: center;
        justify-content: center;
        padding: 12px;
        box-sizing: border-box;
    }

    /* 兜底：任意弹窗壳不溢出视口（含加载态） */
    .mika-modal-content {
        width: min(100%, calc(100vw - 24px)) !important;
        max-width: calc(100vw - 24px) !important;
        max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        box-sizing: border-box;
    }

    /* Login */

    /* Recharge — break desktop nowrap chips */

    /* VIP — 保持横排套餐，压高度让 CTA 尽量进首屏 */

    /* Confirm pay — design 42 */

    /* Pay method / check / QR */

    .mika-modal-content:has(.qrcode-pay-container) .pay-qrcode img {
        width: 100%;
        height: 100%;
    }


    /* Image upload */

    /* Join / topic / binding / password / report / captcha / withdraw */

    .mika-modal-content .close i {
        width: 32px;
        height: 32px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        line-height: 1;
    }
}

@media screen and (max-width: 640px) {

    .mika-modal-content:has(.qrcode-pay-container) .pay-qrcode img {
        width: 100%;
        height: 100%;
    }
}

/* ── 发布动作面板（移动端底栏） ── */
.mika-compose-sheet {
    position: fixed;
    inset: 0;
    z-index: 320;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    pointer-events: none;
}

.mika-compose-sheet[hidden] {
    display: none !important;
}

.mika-compose-sheet.is-open {
    pointer-events: auto;
}

.mika-compose-sheet__backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    padding: 0;
    margin: 0;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    transition: opacity 0.2s ease;
    cursor: pointer;
}

.mika-compose-sheet.is-open .mika-compose-sheet__backdrop {
    opacity: 1;
}

.mika-compose-sheet__panel {
    position: relative;
    z-index: 1;
    width: min(calc(100% - 20px), 480px);
    margin: 0 10px calc(10px + env(safe-area-inset-bottom, 0px));
    padding: 8px 12px 12px;
    border-radius: 16px;
    background: var(--mika-color-surface, #fff);
    box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.12);
    transform: translateY(calc(100% + 24px));
    transition: transform 0.22s ease;
}

/* 暗色：对齐底栏 / 右侧导航毛玻璃，避免实色黑底 */
html.dark-theme .mika-compose-sheet__panel,
body.dark-theme .mika-compose-sheet__panel {
    background: #3f3f3fc4;
    -webkit-backdrop-filter: blur(16px) saturate(1.4);
    backdrop-filter: blur(16px) saturate(1.4);
    border: 1px solid #ffffff24;
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.35);
    color: #ebf4f8b3;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    html.dark-theme .mika-compose-sheet__panel,
    body.dark-theme .mika-compose-sheet__panel {
        background: #3f3f3f;
    }
}

.mika-compose-sheet.is-open .mika-compose-sheet__panel {
    transform: translateY(0);
}

.mika-compose-sheet__handle {
    width: 36px;
    height: 4px;
    margin: 4px auto 12px;
    border-radius: 999px;
    background: var(--mika-color-border, #e5e7eb);
}

html.dark-theme .mika-compose-sheet__handle,
body.dark-theme .mika-compose-sheet__handle {
    background: #ffffff3d;
}

.mika-compose-sheet__title {
    margin: 0 4px 12px;
    font-size: 15px;
    font-weight: 600;
    color: var(--mika-color-text, #0f172a);
}

html.dark-theme .mika-compose-sheet__title,
body.dark-theme .mika-compose-sheet__title {
    color: #f4f4f5;
}

.mika-compose-sheet__list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mika-compose-sheet__item {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 48px;
    padding: 10px 14px;
    border-radius: 12px;
    color: var(--mika-color-text, #0f172a);
    text-decoration: none;
    background: color-mix(in srgb, var(--mika-color-bg, #f5f7f9) 88%, transparent);
    transition: background 0.15s ease;
}

html.dark-theme .mika-compose-sheet__item,
body.dark-theme .mika-compose-sheet__item {
    color: #f4f4f5;
    background: #ffffff14;
    border: 1px solid #ffffff24;
}

.mika-compose-sheet__item:hover,
.mika-compose-sheet__item:focus-visible {
    background: color-mix(in srgb, var(--mika-color-primary, #5b6068) 10%, var(--mika-color-bg, #f5f7f9));
}

html.dark-theme .mika-compose-sheet__item:hover,
html.dark-theme .mika-compose-sheet__item:focus-visible,
body.dark-theme .mika-compose-sheet__item:hover,
body.dark-theme .mika-compose-sheet__item:focus-visible {
    background: #ffffff2e;
}

.mika-compose-sheet__item i {
    font-size: 20px;
    color: var(--mika-color-primary, #5b6068);
}

html.dark-theme .mika-compose-sheet__item i,
body.dark-theme .mika-compose-sheet__item i {
    color: #62d3e5;
}

.mika-compose-sheet__item span {
    font-size: 15px;
    font-weight: 500;
}

.mika-compose-sheet__cancel {
    display: block;
    width: 100%;
    margin-top: 10px;
    min-height: 44px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--mika-color-text-muted, #64748b);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
}

html.dark-theme .mika-compose-sheet__cancel,
body.dark-theme .mika-compose-sheet__cancel {
    color: #a1a1aa;
}

html.mika-compose-sheet-open,
html.mika-compose-sheet-open body {
    overflow: hidden;
}

@media screen and (min-width: 769px) {
    .mika-compose-sheet {
        display: none !important;
    }
}

/* 移动端最终锁：幻灯 1fr 的最小内容宽、顶栏国旗会把整页撑出视口 */
@media screen and (max-width: 768px) {
    html,
    body {
        overflow-x: hidden !important;
        max-width: 100% !important;
    }

    .app-layout,
    .app-layout .header.header-in-zone,
    .app-layout .header.header-in-zone .header-top,
    .app-layout .content-zone,
    #primary-home,
    .home-item,
    .home-item > .wrapper {
        max-width: 100% !important;
        min-width: 0 !important;
        overflow-x: clip;
    }

    .home-item .mika-grid.grid-container,
    .home-item .grid-container[class*="slider_"] {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }

    .home-item .grid-container > .slider-container,
    .home-item .grid-container > .slider-item-card,
    .slider-container .carousel-area,
    .slider-container .carousel__viewport,
    .slider-container .carousel__track {
        min-width: 0 !important;
        max-width: 100% !important;
    }

    .carousel-area .carousel__slide {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
    }

    .app-layout .header-zone-right .mika-commerce-switch,
    .app-layout .header-zone-right .header-env-shell > .mika-commerce-switch,
    .app-layout .header-zone-right .header-env-shell__seam {
        display: none !important;
    }

    /* 1) 移动端顶栏固定：外壳占位，.header-top 吸顶 */
    body.app-layout-active .app-layout .header.header-in-zone,
    body.app-layout-active .app-layout .header.header-in-zone.header-fixed-top,
    body.app-layout-active .app-layout .header.header-in-zone.header-scroll-top {
        position: relative !important;
        z-index: 500;
        overflow: visible !important;
    }
    body.app-layout-active .app-layout .header.header-in-zone .header-top {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        z-index: 500;
        overflow: visible !important;
    }

    /* 左侧抽屉必须盖住顶栏/底栏：打开时抬高 body 层叠（暗色下 body 默认 z-index:1 会被顶栏 500 压住） */
    body.app-layout-active .app-layout .sidebar-menu,
    body.app-layout-active .app-layout .sidebar-menu.show {
        z-index: 1200 !important;
    }
    body.app-layout-active .app-layout:has(.sidebar-menu.show) > .app-layout-body,
    html.dark-theme body.app-layout-active .app-layout:has(.sidebar-menu.show) > .app-layout-body,
    body.dark-theme.app-layout-active .app-layout:has(.sidebar-menu.show) > .app-layout-body {
        z-index: 1200 !important;
    }
    body.app-layout-active .app-layout:has(.sidebar-menu.show) > .header,
    html.dark-theme body.app-layout-active .app-layout:has(.sidebar-menu.show) > .header,
    body.dark-theme.app-layout-active .app-layout:has(.sidebar-menu.show) > .header,
    body.app-layout-active .app-layout:has(.sidebar-menu.show) > .header .header-top {
        z-index: 400 !important;
    }
    body:has(.sidebar-menu.show) .footer-mobile-tabbar {
        z-index: 300 !important;
    }
    /* 毛玻璃必须放 ::before：直接写在 header-top 会成为 backdrop root，挡住头像弹窗采景 */
    html.dark-theme body.app-layout-active .app-layout .header.header-in-zone .header-top,
    body.dark-theme.app-layout-active .app-layout .header.header-in-zone .header-top {
        background: transparent !important;
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
        border-bottom: none !important;
        box-shadow: none !important;
    }
    html.dark-theme body.app-layout-active .app-layout .header.header-in-zone .header-top::before,
    body.dark-theme.app-layout-active .app-layout .header.header-in-zone .header-top::before {
        content: "" !important;
        position: absolute !important;
        inset: 0 !important;
        z-index: 0 !important;
        pointer-events: none !important;
        background: #3f3f3fc4 !important;
        -webkit-backdrop-filter: blur(16px) saturate(1.4) !important;
        backdrop-filter: blur(16px) saturate(1.4) !important;
        border-bottom: 1px solid #ffffff24 !important;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22) !important;
    }
    html.dark-theme body.app-layout-active .app-layout .header.header-in-zone .header-top-wrap,
    body.dark-theme.app-layout-active .app-layout .header.header-in-zone .header-top-wrap {
        position: relative !important;
        z-index: 1 !important;
    }

    /* 2) 列表左右等距并收窄外边距 */
    body.app-layout-active .app-layout .site-content {
        padding: 8px !important;
    }
    body.home.app-layout-active #primary-home {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    body.app-layout-active .app-layout .content-wrapper > .wrapper,
    body.app-layout-active .home-item > .wrapper {
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        width: 100% !important;
    }
    .mika-waterfall {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    /* 移动端瀑布流：一排 2 列（覆盖 PC post_row_count / 内联 width%） */
    .is-waterfall,
    .post-list.is-waterfall,
    .module-posts.is-waterfall,
    [class*="post-item-"].is-waterfall {
        --module-columns: 2 !important;
    }
    .mika-waterfall > *,
    .mika-waterfall > li,
    .is-waterfall .mika-waterfall > li,
    ul.mika-waterfall > li.post-list-item {
        width: 50% !important;
        max-width: 50% !important;
        padding-left: 4px !important;
        padding-right: 4px !important;
        box-sizing: border-box !important;
    }
    body.app-layout-active .archive-row .is-waterfall .mika-waterfall > li {
        padding-left: 4px !important;
        padding-right: 4px !important;
    }
    body.app-layout-active .archive-row #post-list .mika-grid:not(.mika-waterfall) {
        gap: 8px !important;
    }

    /* 3) 底栏暗色：对齐右侧导航毛玻璃 */
    html.dark-theme .footer-mobile-tabbar,
    html.dark-theme body.app-layout-active .footer-mobile-tabbar,
    body.dark-theme .footer-mobile-tabbar {
        background: #3f3f3fc4 !important;
        -webkit-backdrop-filter: blur(16px) saturate(1.4) !important;
        backdrop-filter: blur(16px) saturate(1.4) !important;
        border-top: 1px solid #ffffff24 !important;
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.28) !important;
    }

    /* 4) 左侧抽屉暗色：与 PC 侧栏共用 --mika-sidebar-shell-bg（style.css 暗色变量） */
    html.dark-theme body.home.app-layout-active .app-layout .sidebar-menu.sidebar-menu .sidebar-menu-inner,
    body.home.app-layout-active.dark-theme .app-layout .sidebar-menu.sidebar-menu .sidebar-menu-inner,
    html.dark-theme body.app-layout-active .app-layout .sidebar-menu .sidebar-menu-inner,
    html.dark-theme .app-layout .sidebar-menu .sidebar-menu-inner,
    body.dark-theme.app-layout-active .app-layout .sidebar-menu .sidebar-menu-inner,
    body.dark-theme .app-layout .sidebar-menu .sidebar-menu-inner {
        background: var(--mika-sidebar-shell-bg, rgba(34, 34, 37, 0.84)) !important;
        -webkit-backdrop-filter: var(--mika-sidebar-shell-blur, blur(20px) saturate(1.2)) !important;
        backdrop-filter: var(--mika-sidebar-shell-blur, blur(20px) saturate(1.2)) !important;
        border-right: 1px solid #ffffff24 !important;
        box-shadow: 8px 0 28px rgba(0, 0, 0, 0.35) !important;
    }
}

