/* iPad 横屏 (768px - 1024px)：适配平板布局 */
@media (min-width: 768px) and (max-width: 1024px) {
    .main-wrapper {
        padding: 18px 24px 36px;
    }
    
    .stat-row {
        grid-template-columns: repeat(4, 1fr);
        gap: 14px;
    }
    
    .stat-item {
        padding: 16px 18px;
    }
    
    .settings-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* iPad 竖屏 (641px - 767px)：适配竖屏平板 */
@media (min-width: 641px) and (max-width: 767px) {
    .main-wrapper {
        padding: 16px 20px 32px;
    }
    
    .stat-row {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .settings-grid {
        grid-template-columns: 1fr;
    }
}

/* ≤1024px：收起侧边栏，切到移动端形态 */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        width: 260px;
        border-right: none;
    }

    .sidebar-tools {
        display: none;
    }

    .app-container.sidebar-collapsed .sidebar {
        width: 260px;
    }

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

    .app-container.sidebar-collapsed .nav-group,
    .app-container.sidebar-collapsed .sidebar-footer {
        padding-left: 12px;
        padding-right: 12px;
    }

    .app-container.sidebar-collapsed .nav-item {
        justify-content: flex-start;
        gap: 10px;
        padding-left: 14px;
        padding-right: 14px;
    }

    .app-container.sidebar-collapsed .nav-label {
        max-width: 160px;
        opacity: 1;
    }

    /* 注意：ui.js toggleSidebar 用的是 .open */
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.08);
    }

    .main-wrapper {
        margin-left: 0;
        padding: 16px 20px 32px;
    }

    .sidebar-toggle {
        display: inline-flex;
    }

    .view-title {
        font-size: 20px;
    }
}

/* ≤640px：卡片/统计再紧凑一级 */
@media (max-width: 640px) {
    .main-wrapper {
        padding: 14px 16px 28px;
    }

    .stat-row {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-item {
        padding: 14px 16px;
    }

    .stat-number {
        font-size: 20px;
    }

    .dashboard-chart {
        height: auto;
        min-height: 220px;
    }

    .cute-status-chart,
    .cute-status-chart.cute-status-chart-triple,
    .cute-status-chart-simple {
        grid-template-columns: 1fr;
        gap: 14px;
        min-height: 360px;
    }
    
    .cute-status-chart-simple {
        padding: 16px;
    }
    
    .cute-status-list {
        order: 1;
    }
    
    .cute-donut {
        order: 0;
    }

    .cute-stat-pill {
        max-width: none;
    }

    .cute-donut {
        order: -1;
    }

    .cute-summary-grid {
        grid-template-columns: 1fr;
    }

    .settings-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .k-card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 16px 18px;
    }

    .k-card-body {
        padding: 18px;
        overflow-x: visible;
    }

    table { min-width: 0; }

    .modal-overlay { padding: 16px; }
    .modal-content { max-height: calc(100vh - 32px); }
    .modal-body { padding: 18px; }
}

/* ≤480px：登录页内边距收紧 */
@media (max-width: 480px) {
    .login-page {
        padding: max(16px, env(safe-area-inset-top))
                 max(16px, env(safe-area-inset-right))
                 max(16px, env(safe-area-inset-bottom))
                 max(16px, env(safe-area-inset-left));
    }
    .login-card {
        padding: 28px 22px 24px;
    }
    .login-input {
        height: 44px;
        font-size: 16px; /* ≥16px 防止 iOS 聚焦时自动缩放 */
    }
    .login-btn {
        height: 44px;
    }
}

@media (max-width: 640px) {

    /* 顶栏按钮在窄屏下自然换行并自适应 */
    #tab-accounts .k-card-header > div,
    #tab-assigned .k-card-header > div,
    #tab-cards .k-card-header > div,
    #tab-logs .k-card-header > div {
        flex-wrap: wrap;
        width: 100%;
    }
    #tab-accounts .k-card-header .ui-btn,
    #tab-accounts .k-card-header .k-dropdown,
    #tab-assigned .k-card-header .ui-btn,
    #tab-assigned .k-card-header .k-dropdown,
    #tab-cards .k-card-header .ui-btn,
    #tab-cards .k-card-header .k-dropdown,
    #tab-logs .k-card-header .ui-btn,
    #tab-logs .k-card-header .k-dropdown {
        flex: 1 1 auto;
        min-width: 0;
    }

    /* 筛选栏输入框填满单行。
       按输入框本身定位而不是 card-body 的第一个 div：
       账号池的 card-body 里还有巡检进度条，用 :first-child 会错位 */
    #tab-accounts .k-card-body .k-input[type="text"],
    #tab-assigned .k-card-body .k-input[type="text"],
    #tab-cards .k-card-body .k-input[type="text"],
    #tab-logs .k-card-body .k-input[type="text"] {
        width: 100%;
        min-width: 0;
        flex: 1 1 100%;
    }
    /* 按 .k-input[type=date] 本身定位，不依赖筛选栏在 card-body 里的位置：
       账号池的 card-body 里还有巡检进度条，用 :first-child 会错位 */
    #tab-accounts .k-card-body .k-input[type="date"],
    #tab-assigned .k-card-body .k-input[type="date"],
    #tab-cards .k-card-body .k-input[type="date"],
    #tab-logs .k-card-body .k-input[type="date"] {
        flex: 1 1 140px;
        min-width: 0;
    }

    /* 解除外层 overflow-x:auto 带来的横滚，卡片布局不需要。
       直接按 .pagination 选择，同理不依赖子元素序号 */
    #tab-accounts .k-card-body > .pagination,
    #tab-assigned .k-card-body > .pagination {
        overflow-x: visible !important;
    }

    /* 表格 → 堆叠布局 */
    #tab-accounts table,
    #tab-assigned table,
    #tab-cards table,
    #tab-logs table {
        display: block;
        min-width: 0;
    }
    #tab-accounts thead,
    #tab-assigned thead,
    #tab-cards thead,
    #tab-logs thead {
        display: none;
    }
    #tab-accounts tbody,
    #tab-assigned tbody,
    #tab-cards tbody,
    #tab-logs tbody {
        display: block;
    }
    #tab-accounts tbody tr,
    #tab-assigned tbody tr,
    #tab-cards tbody tr,
    #tab-logs tbody tr {
        display: block;
        padding: 12px 14px;
        margin-bottom: 10px;
        background: var(--bg-surface);
        border: 1px solid var(--border);
        border-radius: 10px;
    }
    #tab-accounts tbody tr:hover,
    #tab-assigned tbody tr:hover,
    #tab-cards tbody tr:hover,
    #tab-logs tbody tr:hover {
        background: var(--bg-subtle);
    }
    #tab-accounts tbody td[data-label],
    #tab-assigned tbody td[data-label],
    #tab-cards tbody td[data-label],
    #tab-logs tbody td[data-label] {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        padding: 6px 0;
        border: none;
        font-size: 13px;
        min-height: 28px;
    }
    #tab-accounts tbody td[data-label]::before,
    #tab-assigned tbody td[data-label]::before,
    #tab-cards tbody td[data-label]::before,
    #tab-logs tbody td[data-label]::before {
        content: attr(data-label);
        flex: 0 0 auto;
        color: var(--text-muted);
        font-size: 12px;
        font-weight: 500;
        line-height: 1.8;
    }
    /* 操作日志：详情字段通常较长，改成纵向（标签在上、内容在下）以避免挤压 */
    #tab-logs tbody td[data-label="详情"] {
        flex-direction: column;
        align-items: stretch;
    }
    #tab-logs tbody td[data-label="详情"]::before {
        margin-bottom: 4px;
    }
    #tab-cards tbody td[data-label] > *,
    #tab-logs tbody td[data-label] > * {
        text-align: right;
        min-width: 0;
    }
    #tab-logs tbody td[data-label="详情"] {
        text-align: left;
    }

    #tab-accounts tbody td[colspan],
    #tab-assigned tbody td[colspan],
    #tab-cards tbody td[colspan],
    #tab-logs tbody td[colspan] {
        display: block;
        padding: 24px 0;
        text-align: center;
    }

    /* 分页按钮不要挤在一行 */
    .pagination { row-gap: 6px; }

    #tab-accounts .account-table-scroll,
    #tab-assigned .account-table-scroll {
        overflow: visible;
        padding-bottom: 0;
    }

    #tab-accounts tbody tr,
    #tab-assigned tbody tr {
        position: relative;
        padding: 13px 14px;
        background: var(--bg-surface);
        border: none;
        border-radius: 8px;
        box-shadow: 0 8px 24px rgba(24, 24, 27, 0.06);
    }

    #tab-accounts tbody tr:hover,
    #tab-assigned tbody tr:hover {
        background: var(--bg-surface);
    }

    #tab-accounts tbody tr:has(td[colspan]),
    #tab-assigned tbody tr:has(td[colspan]) {
        padding: 0;
        background: transparent;
        box-shadow: none;
    }

    #tab-accounts tbody td[data-label],
    #tab-assigned tbody td[data-label] {
        display: grid;
        grid-template-columns: 78px minmax(0, 1fr);
        align-items: center;
        gap: 10px;
        padding: 5px 0;
        min-height: 26px;
    }

    #tab-accounts tbody td[data-label]::before,
    #tab-assigned tbody td[data-label]::before {
        color: var(--text-subtle);
        font-size: 11px;
        line-height: 1.4;
    }

    #tab-accounts tbody td[data-label] > *,
    #tab-assigned tbody td[data-label] > * {
        text-align: left;
        justify-self: stretch;
        min-width: 0;
    }

    #tab-accounts tbody td[data-label="选择"] {
        position: absolute;
        top: 12px;
        right: 12px;
        display: block;
        min-height: 0;
        padding: 0;
    }

    #tab-accounts tbody td[data-label="选择"]::before {
        content: none;
    }

    #tab-accounts tbody td[data-label="ID"] {
        padding-right: 36px;
    }

    #tab-accounts tbody .account-email-cell,
    #tab-assigned tbody .account-email-cell {
        display: block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #tab-accounts tbody td[data-label]:has(.k-progress-bg),
    #tab-assigned tbody td[data-label]:has(.k-progress-bg) {
        display: grid;
        grid-template-columns: 78px minmax(0, 1fr);
        align-items: center;
    }

    #tab-accounts tbody td[data-label]:has(.k-progress-bg)::before,
    #tab-assigned tbody td[data-label]:has(.k-progress-bg)::before {
        margin-bottom: 0;
    }

    #tab-accounts tbody td[data-label]:has(.k-progress-bg) > div,
    #tab-assigned tbody td[data-label]:has(.k-progress-bg) > div {
        max-width: none !important;
        width: 100%;
    }

    #tab-accounts tbody td[data-label] .k-progress-bg,
    #tab-assigned tbody td[data-label] .k-progress-bg {
        width: 100%;
    }

    #tab-accounts tbody td[data-label="操作"],
    #tab-assigned tbody td[data-label="操作"] {
        display: block;
        padding-top: 10px;
    }

    #tab-accounts tbody td[data-label="操作"]::before,
    #tab-assigned tbody td[data-label="操作"]::before {
        content: none;
    }

    #tab-accounts tbody .account-actions,
    #tab-assigned tbody .account-actions {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 7px;
        width: 100%;
    }

    #tab-accounts tbody .account-actions .ui-btn,
    #tab-assigned tbody .account-actions .ui-btn {
        justify-content: center;
        min-width: 0;
        padding-left: 8px;
        padding-right: 8px;
    }

    /* 卡密表操作列：手机上同样铺满整行，按两列排 */
    #tab-cards tbody td[data-label="操作"] {
        display: block;
        padding-top: 10px;
    }

    #tab-cards tbody td[data-label="操作"]::before {
        content: none;
    }

    #tab-cards tbody .card-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 7px;
        width: 100%;
        flex-wrap: wrap;
    }

    #tab-cards tbody .card-actions .ui-btn {
        justify-content: center;
        min-width: 0;
        padding-left: 8px;
        padding-right: 8px;
    }
}

@media (max-width: 640px) {
    #tab-dashboard .k-card-body {
        overflow-x: visible !important;
    }

    /* 仅"最近活动"表卡片化；卡密分布矩阵、额度后缀表保持表格 + 横向滚动 */
    #tab-dashboard table:not(.k-card-dist-table):not(.k-credit-table),
    #tab-dashboard table:not(.k-card-dist-table):not(.k-credit-table) tbody,
    #tab-dashboard table:not(.k-card-dist-table):not(.k-credit-table) tr,
    #tab-dashboard table:not(.k-card-dist-table):not(.k-credit-table) td {
        display: block;
        width: 100%;
        min-width: 0;
    }

    #tab-dashboard table:not(.k-card-dist-table):not(.k-credit-table) thead {
        display: none;
    }

    #tab-dashboard table:not(.k-card-dist-table):not(.k-credit-table) tbody tr {
        padding: 11px 16px;
        border-bottom: 1px solid var(--border);
        background: var(--bg-surface);
    }

    #tab-dashboard table:not(.k-card-dist-table):not(.k-credit-table) tbody tr:last-child {
        border-bottom: none;
    }

    #tab-dashboard table:not(.k-card-dist-table):not(.k-credit-table) tbody td {
        padding: 0;
        border: none;
    }

    /* 额度后缀表：六列在 430px 放不下时靠卡片内横滚，不拆成卡片堆叠 */
    #tab-dashboard .k-credit-table-wrapper {
        overflow-x: auto;
        max-width: 100%;
        overscroll-behavior-x: contain;
    }
    #tab-dashboard .k-credit-table th,
    #tab-dashboard .k-credit-table td {
        padding: 8px 8px;
        font-size: 12px;
    }
    /* 手机上「参与统计」与「已耗尽」是次要信息，上方汇总块的注释里已有同样口径 */
    #tab-dashboard .k-credit-col-tracked,
    #tab-dashboard .k-credit-col-exhausted {
        display: none;
    }

    /* 卡密分布矩阵：在卡片内横向滚动，不撑破页面 */
    #tab-dashboard .k-card-dist-table-wrapper {
        overflow-x: auto;
        max-width: 100%;
        overscroll-behavior-x: contain;
    }
    #tab-dashboard .k-card-dist-table {
        width: max-content;
        min-width: 100%;
    }

    #tab-dashboard .recent-action {
        color: var(--text-main);
        font-weight: 700;
        white-space: nowrap !important;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #tab-dashboard .recent-detail {
        margin-top: 4px;
        line-height: 1.45;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    #tab-dashboard .recent-time {
        margin-top: 5px;
        font-size: 11px !important;
    }

    #tab-accounts .k-card-header {
        align-items: stretch;
    }

    #tab-accounts .k-card-header > div {
        display: grid !important;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 6px !important;
        width: 100%;
        flex-wrap: nowrap;
    }

    #tab-accounts .k-card-header .ui-btn,
    #tab-accounts .k-card-header .k-dropdown {
        width: 100%;
        min-width: 0;
        flex: 0 1 auto;
    }

    #tab-accounts .k-card-header .ui-btn-sm,
    #tab-accounts .k-card-header .k-dropdown-trigger {
        min-height: 30px;
        height: 30px;
        padding-left: 6px;
        padding-right: 6px;
        font-size: 10.5px;
    }

    #tab-accounts .k-card-header .k-dropdown-trigger.ui-btn {
        padding-right: 18px;
    }

    #tab-accounts .k-card-header .k-dropdown-trigger.ui-btn::after {
        right: 6px;
    }

    #tab-accounts tbody td[data-label],
    #tab-assigned tbody td[data-label] {
        grid-template-columns: 64px minmax(0, 1fr);
        gap: 8px;
    }

    #tab-accounts tbody td[data-label]:has(.k-progress-bg),
    #tab-assigned tbody td[data-label]:has(.k-progress-bg) {
        grid-template-columns: 64px minmax(0, 1fr);
    }

    #tab-accounts .account-subscription-cell .subscription-badge,
    #tab-assigned .account-subscription-cell .subscription-badge {
        justify-self: start !important;
        width: auto;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #tab-accounts .account-usage-cell > div:first-child,
    #tab-assigned .account-usage-cell > div:first-child {
        grid-column: 2;
        max-width: none !important;
        width: 100%;
    }

    #tab-accounts .account-usage-cell .k-progress-bg,
    #tab-assigned .account-usage-cell .k-progress-bg {
        grid-column: 2;
        width: 100%;
        min-width: 0;
    }

    #tab-accounts .account-action-cell,
    #tab-assigned .account-action-cell {
        display: block !important;
        padding-top: 10px;
    }

    #tab-accounts .account-action-cell::before,
    #tab-assigned .account-action-cell::before {
        content: none !important;
    }

    #tab-settings .k-card-header {
        flex-direction: row;
        align-items: center;
    }

    #tab-settings .k-card-title {
        flex: 1 1 auto;
    }

    #tab-settings .k-card-header .ui-btn {
        flex: 0 0 auto;
        width: auto;
        margin-left: auto;
    }

    .account-info-modal {
        padding: 10px;
    }

    .account-info-modal .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: calc(100dvh - 20px);
    }

    .account-info-modal .modal-body {
        padding: 14px;
    }

    .account-info-modal .account-detail-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
    }

    .account-info-modal .account-detail-row {
        padding: 9px 10px;
    }

    .account-info-modal .account-detail-row span {
        margin-bottom: 3px;
        font-size: 10.5px;
    }

    .account-info-modal .account-detail-row strong {
        font-size: 12px;
    }

    .account-info-modal .account-detail-section {
        margin-top: 14px;
    }

    .account-info-modal .account-usage-summary {
        padding: 12px;
    }

    .account-info-modal .account-usage-readout strong {
        font-size: 19px;
    }

    .account-info-modal .model-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
    }

    .account-info-modal .model-item {
        align-items: center;
        gap: 6px;
        padding: 7px;
        box-shadow: none;
    }

    .account-info-modal .model-icon {
        width: 20px;
        height: 20px;
        flex-basis: 20px;
    }

    .account-info-modal .model-title span {
        font-size: 11px;
    }

    .account-info-modal .model-id {
        font-size: 10px;
    }

    .account-info-modal .model-desc,
    .account-info-modal .model-params {
        display: none;
    }

    .card-log-modal {
        padding: 10px;
    }

    .card-log-content {
        width: 100%;
        max-width: 100% !important;
        max-height: calc(100dvh - 20px);
    }

    .card-log-body {
        max-height: none;
        overflow-x: hidden !important;
        overflow-y: auto;
    }

    .card-log-table,
    .card-log-table tbody,
    .card-log-table tr,
    .card-log-table td {
        display: block;
        width: 100%;
        min-width: 0;
    }

    .card-log-table thead {
        display: none;
    }

    .card-log-table tr {
        padding: 12px 14px;
        border-bottom: 1px solid var(--border);
    }

    .card-log-table tr:last-child {
        border-bottom: none;
    }

    .card-log-table td {
        display: grid;
        grid-template-columns: 70px minmax(0, 1fr);
        gap: 8px;
        padding: 3px 0;
        border: none;
        white-space: normal !important;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    .card-log-table td::before {
        content: attr(data-label);
        color: var(--text-muted);
        font-size: 11px;
        font-family: inherit;
    }

    .card-log-action,
    .card-log-time {
        white-space: nowrap !important;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* ========== 移动端触摸优化 ========== */

/* 所有可点击元素增加触摸反馈 */
@media (max-width: 1024px) {
    /* 通用触摸反馈 */
    button, 
    a,
    .nav-item,
    .ui-btn,
    .k-dropdown-trigger,
    [data-onclick],
    [role="button"] {
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* 活动元素触摸反馈 */
    button:active,
    a:active,
    .nav-item:active,
    .ui-btn:active:not(:disabled),
    .k-dropdown-trigger:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
    
    /* 优化滚动容器 */
    .main-wrapper,
    .modal-body,
    .k-card-body,
    .tab-panel {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    
    /* 增强卡片交互反馈 */
    .k-card:active {
        transform: scale(0.995);
        transition: transform 0.1s ease;
    }
    
    /* 表格行触摸反馈 */
    #tab-accounts tbody tr:active,
    #tab-assigned tbody tr:active,
    #tab-cards tbody tr:active,
    #tab-logs tbody tr:active {
        transform: scale(0.99);
        transition: transform 0.1s ease;
    }
}

/* ========== 更小屏幕 (≤375px) 优化 ========== */
@media (max-width: 375px) {
    .main-wrapper {
        padding: 12px 14px 24px;
    }
    
    .stat-row {
        gap: 8px;
    }
    
    .stat-item {
        padding: 12px 14px;
    }
    
    .k-card-header {
        padding: 14px 16px;
    }
    
    .k-card-body {
        padding: 16px;
    }
    
    .modal-overlay {
        padding: 4px;
    }
}

/* ========== 横屏小屏幕优化 ========== */
@media (max-height: 600px) and (orientation: landscape) {
    .main-wrapper {
        padding: 12px 16px 20px;
    }
    
    .modal-content {
        max-height: calc(100vh - 24px);
    }
    
    .stat-row {
        grid-template-columns: repeat(4, 1fr);
    }
}


/* ==========================================================
   补漏（放在文件末尾，确保覆盖 main.css 中后定义的同级规则）
   ========================================================== */

/* 1. .ui-btn-sm 定义在 .ui-btn 移动端规则之后，会把高度压回 28px；
      全站大部分按钮都是 sm，这里给触屏设备统一兜底 36px */
@media (max-width: 1024px) {
    .ui-btn-sm {
        min-height: 36px;
        padding: 6px 12px;
        font-size: 13px;
    }
    .k-pager-nav .ui-btn-sm {
        min-width: 36px;
    }
    /* 账号池顶栏 4 列紧凑网格：保留紧凑字号，但高度不低于 36px */
    #tab-accounts .k-card-header .ui-btn-sm,
    #tab-accounts .k-card-header .k-dropdown-trigger {
        min-height: 36px;
        height: 36px;
    }

    /* 2. textarea 基础规则在媒体查询之后，重新声明移动端内边距 */
    textarea.k-input {
        padding: 12px 14px;
        font-size: 16px;
    }

    /* 3. 设置页：.settings-field .k-input 固定 36px，优先级高于 .k-input */
    .settings-field .k-input {
        height: 44px;
        font-size: 16px;
    }
    .settings-field textarea.k-input {
        height: auto;
    }

    /* 4. 卡密 / 日志表格没有横滚容器，平板区间列多会撑破卡片 */
    #tab-cards .k-card-body,
    #tab-logs .k-card-body {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }
}

/* 5. 平板/手机取消设置项固定行高，避免长说明文字被裁切/重叠 */
@media (max-width: 1024px) {
    .settings-column {
        grid-template-rows: none;
        grid-auto-rows: auto;
        align-content: start; /* 同排列高度不同时，auto 行不再被拉伸 */
    }
    .settings-toggle-card {
        height: auto;
        min-height: 72px;
    }
    .settings-toggle-card strong {
        white-space: normal;
    }
    .settings-toggle-card small,
    .settings-help {
        height: auto;
        overflow: visible;
    }
}

/* 6. 手机端卡片化后不再需要横滚（≤640px 会改为堆叠布局） */
@media (max-width: 640px) {
    #tab-cards .k-card-body,
    #tab-logs .k-card-body {
        overflow-x: visible;
    }
}

/* 7. 触屏：复选框太小（16px），放大点击区域 */
@media (hover: none) and (pointer: coarse) {
    .k-checkbox {
        width: 20px;
        height: 20px;
    }
    /* 原勾号按 16px 绝对定位，放大后重新居中 */
    .k-checkbox:checked::after {
        left: 6px;
        top: 2px;
        width: 6px;
        height: 11px;
    }
    /* 触屏无 hover，去掉表格行 hover 背景粘滞 */
    tbody tr:hover,
    tbody tr:hover td {
        background: inherit;
    }
}

/* 8. 全局 toast（ui.js 内联定位）：手机上居中、限宽、避开刘海 */
@media (max-width: 640px) {
    .app-toast {
        top: calc(12px + env(safe-area-inset-top)) !important;
        left: 12px !important;
        right: 12px !important;
        max-width: none;
        text-align: center;
        word-break: break-word;
    }
}

/* 9. 下拉菜单不超出屏幕 */
@media (max-width: 1024px) {
    .k-dropdown-menu {
        max-width: calc(100vw - 24px);
        max-height: min(280px, 50vh);
    }
    .k-dropdown-item {
        min-height: 40px;
        display: flex;
        align-items: center;
    }
}

/* 10. 设置页窄屏：1fr 的最小值是内容宽度，会被宽内容撑出卡片 → 改为 minmax(0,1fr) */
@media (max-width: 1024px) {
    .settings-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .settings-column {
        grid-template-columns: minmax(0, 1fr);
        min-width: 0;
    }
    .settings-toggle-card .k-checkbox {
        flex-shrink: 0;
    }
    .settings-field .k-input {
        width: 100%;
        max-width: 100%;
    }
}
@media (max-width: 767px) {
    .settings-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}
@media (max-width: 640px) {
    /* 标题 + 分类面包屑占满左侧，保存按钮固定在右侧 */
    #tab-settings .k-card-header > div:first-child {
        flex: 1 1 auto;
        min-width: 0;
    }
    #tab-settings .k-card-header .k-card-title {
        flex: 0 0 auto;
    }
    #tab-settings [data-settings-category] {
        padding: 6px 2px !important;
        min-height: 32px;
    }
}

/* 概览 · 额度使用：窄屏下两栏汇总改单列，后缀表允许横向滚动 */
@media (max-width: 767px) {
    .k-credit-summary {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 640px) {
    .k-credit-bucket {
        padding: 14px 16px;
    }
    .k-credit-percent {
        font-size: 22px;
    }
}
