/**
 * 全站响应式：小屏 / 小型笔记本（1024–1366px）列表与表格适配
 * 宽表格横向滚动，避免单元格被挤到换行；极窄屏切换卡片式列表
 */

/* 防止 flex 子项撑破视口 */
.app-main,
.page-inner,
.page-body,
.content-wrap,
.content-main,
.panel,
.card,
.table-wrap {
    min-width: 0;
    max-width: 100%;
}

/* —— 统计栅格：任意数量自适应，不强行 4 列换行 —— */
.stat-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 148px), 1fr)) !important;
}

/* —— 表格容器：横向滚动，不换行挤扁 —— */
.table-wrap {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(127, 127, 127, 0.45) transparent;
}

.table-wrap::-webkit-scrollbar {
    height: 8px;
}

.table-wrap::-webkit-scrollbar-thumb {
    background: rgba(127, 127, 127, 0.45);
    border-radius: 999px;
}

.table-wrap::-webkit-scrollbar-track {
    background: transparent;
}

.table-wrap.has-scroll {
    box-shadow: inset -12px 0 12px -12px rgba(0, 0, 0, 0.22);
}

.table-wrap table,
.table-wrap .data-table {
    width: max-content;
    min-width: 100%;
    table-layout: auto;
}

.table-wrap th,
.table-wrap td {
    vertical-align: middle;
}

/* 标题列：过长省略，hover 可看全（title 由 JS 补充） */
.table-wrap .col-title,
.table-wrap td.td-title {
    max-width: min(280px, 36vw);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-wrap .col-mono,
.table-wrap td.mono {
    white-space: nowrap;
}

.table-wrap .col-nowrap,
.table-wrap .col-actions,
.table-wrap td.col-actions {
    white-space: nowrap;
}

/* 操作列 sticky，横滑时始终可见 */
.table-wrap .col-actions,
.table-wrap th:last-child.col-actions,
.table-wrap td:last-child.col-actions,
.data-table-sticky-actions th:last-child,
.data-table-sticky-actions td:last-child {
    position: sticky;
    right: 0;
    z-index: 2;
    background: var(--card, #141e30);
    box-shadow: -6px 0 12px rgba(0, 0, 0, 0.18);
}

.data-table-sticky-actions thead th:last-child {
    background: rgba(0, 0, 0, 0.35);
}

/* 面板标题行 */
.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.panel-head > * {
    flex-shrink: 0;
}

.panel-head h2,
.panel-head h3 {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* —— 前台顶栏：窄屏横向滑动，不折行 —— */
@media (max-width: 1366px) {
    :root {
        --pad: 20px;
    }

    .topbar-inner {
        flex-wrap: nowrap;
        gap: 12px;
        align-items: center;
    }

    .brand {
        flex-shrink: 0;
        max-width: 42%;
        font-size: 1rem;
    }

    .brand small {
        font-size: 11px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .nav {
        flex: 1;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-end;
        scrollbar-width: none;
        padding-bottom: 2px;
    }

    .nav::-webkit-scrollbar {
        display: none;
    }

    .nav a,
    .nav .credit-badge,
    .nav .nav-guide-btn {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 8px 12px;
        font-size: 13px;
    }

    .nav .nav-guide-btn {
        padding: 8px 14px !important;
        font-size: 13px !important;
    }

    .data-table th,
    .data-table td,
    .table-wrap th,
    .table-wrap td {
        padding: 10px 12px;
        font-size: 13px;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    .grid-3 {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    }

    .page-actions {
        flex-wrap: nowrap;
        overflow-x: auto;
        max-width: 100%;
        -webkit-overflow-scrolling: touch;
    }

    .page-actions .btn {
        flex-shrink: 0;
        white-space: nowrap;
    }
}

@media (max-width: 1100px) {
    .steps {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }

    .recharge-packages {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)) !important;
    }
}

/* —— 后台侧栏：中等宽度横滑菜单 —— */
@media (max-width: 1366px) {
    .admin-shell .content-main {
        padding-left: 20px;
        padding-right: 20px;
    }

    .admin-shell .side-nav {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 4px;
        scrollbar-width: none;
        max-width: 100%;
    }

    .admin-shell .side-nav::-webkit-scrollbar {
        display: none;
    }

    .admin-shell .side-nav a {
        flex-shrink: 0;
        white-space: nowrap;
        margin-bottom: 0;
        font-size: 13px;
        padding: 9px 12px;
    }

    .admin-shell .sidebar {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .orders-toolbar {
        flex-wrap: wrap;
    }

    .orders-toolbar label {
        flex: 1 1 160px;
        min-width: 0;
    }

    .filter-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }

    .filter-tabs .btn {
        flex-shrink: 0;
        white-space: nowrap;
    }
}

/* —— 极窄屏：表格变卡片列表 —— */
@media (max-width: 720px) {
    .table-wrap.is-card-mobile table,
    .table-wrap table.is-card-mobile {
        width: 100%;
        min-width: 0;
    }

    .table-wrap.is-card-mobile thead,
    .table-wrap table.is-card-mobile thead {
        display: none;
    }

    .table-wrap.is-card-mobile tbody tr,
    .table-wrap table.is-card-mobile tbody tr {
        display: block;
        margin-bottom: 12px;
        padding: 14px 16px;
        border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
        border-radius: 12px;
        background: rgba(0, 0, 0, 0.15);
    }

    .table-wrap.is-card-mobile tbody tr:hover,
    .table-wrap table.is-card-mobile tbody tr:hover {
        background: rgba(79, 156, 249, 0.06);
    }

    .table-wrap.is-card-mobile tbody td,
    .table-wrap table.is-card-mobile tbody td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 12px;
        padding: 8px 0;
        border: none;
        max-width: none;
        white-space: normal;
        text-align: right;
    }

    .table-wrap.is-card-mobile tbody td::before,
    .table-wrap table.is-card-mobile tbody td::before {
        content: attr(data-label);
        flex-shrink: 0;
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: var(--muted, #8fa3bf);
        text-align: left;
        max-width: 42%;
    }

    .table-wrap.is-card-mobile tbody td:empty,
    .table-wrap table.is-card-mobile tbody td:empty {
        display: none;
    }

    .table-wrap.is-card-mobile .col-actions,
    .table-wrap.is-card-mobile td:last-child,
    .table-wrap table.is-card-mobile td:last-child {
        position: static;
        box-shadow: none;
        justify-content: flex-end;
        padding-top: 12px;
        border-top: 1px solid rgba(255, 255, 255, 0.06);
    }

    .table-wrap.is-card-mobile tbody td.col-title,
    .table-wrap table.is-card-mobile tbody td.col-title {
        white-space: normal;
        text-align: right;
    }

    .topbar-inner {
        flex-direction: column;
        align-items: stretch;
    }

    .brand {
        max-width: 100%;
    }

    .nav {
        justify-content: flex-start;
    }
}
