/* ============================================================
   移动端适配层（手机 / 小屏）
   只在窄屏生效，不改变桌面端任何表现。
   设计要点：
     1. 底部标签栏承担主导航，顶栏只留品牌 + 主题 + 新增
     2. 管理端表格在手机上换成卡片列表（表格在手机上必然挤爆）
     3. 所有可点区域 ≥ 44px，输入框 ≥ 16px（防 iOS 自动放大）
     4. 弹窗在手机上变成底部抽屉，拇指可达
   ============================================================ */

@media (max-width: 860px) {

  body {
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
  }

  /* ────────── 顶栏 ────────── */

  .topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    height: 54px;
    padding: 0 10px;
    gap: 8px;
    background: color-mix(in srgb, var(--panel) 88%, transparent);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border);
  }
  .topbar .search,
  .topbar .segmented,
  .topbar .storage-flag,
  .topbar .brand-sub { display: none !important; }
  .topbar .topbar-spacer { display: none; }
  .topbar .brand { min-width: 0; flex: 1 1 auto; }
  .topbar .brand-mark { width: 30px; height: 30px; border-radius: 9px; }
  .topbar .brand-mark svg { width: 16px; height: 16px; }
  .topbar .brand-title {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar .btn { height: 38px; min-width: 38px; padding: 0 10px; }
  .topbar .btn-primary { padding: 0 12px; }
  .topbar .btn-primary span { display: none; }

  /* ────────── 底部标签栏 ────────── */

  .mobile-tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 60;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: color-mix(in srgb, var(--panel) 94%, transparent);
    backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
  }
  .mobile-tabbar a,
  .mobile-tabbar button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: 0;
    background: none;
    color: var(--text-3);
    font-size: 10.5px;
    font-family: inherit;
    text-decoration: none;
    padding: 0;
    cursor: pointer;
  }
  .mobile-tabbar svg { width: 20px; height: 20px; }
  .mobile-tabbar .on { color: var(--accent); }
  .mobile-tabbar .on svg { filter: drop-shadow(0 0 6px color-mix(in srgb, var(--accent) 60%, transparent)); }

  .page { padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)); }
  .page-inner { padding: 14px 12px 24px; max-width: none !important; }

  /* ────────── 门户 ────────── */

  .portal-head {
    display: block;
    margin-bottom: 12px;
  }
  .portal-title { font-size: 22px; }
  .portal-desc { font-size: 12px; margin-top: 4px; }
  .portal-stats {
    display: flex !important;
    gap: 8px;
    margin-top: 12px;
  }
  .portal-stats .stat {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--panel);
  }
  .portal-stats .stat-num { font-size: 18px; }
  .portal-stats .stat-label { font-size: 10.5px; }

  .m-search {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 42px;
    margin: 12px 0 10px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--panel);
    color: var(--text-3);
  }
  .m-search svg { width: 15px; height: 15px; flex: 0 0 auto; }
  .m-search input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: none;
    outline: none;
    color: var(--text);
    font-size: 16px; /* 小于 16px 时 iOS 会自动放大页面 */
    font-family: inherit;
  }

  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 7px;
    padding-bottom: 4px;
    margin-bottom: 12px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .filters::-webkit-scrollbar { display: none; }
  .filters .pill {
    flex: 0 0 auto;
    white-space: nowrap;
    height: 32px;
    padding: 0 12px;
    font-size: 12.5px;
  }
  .portal-stats .stat { text-align: center; }
  .portal-stats .stat-num { font-size: 18px; }
  .portal-stats .stat-label { font-size: 10.5px; }
  .filters-note { display: none; }

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

  .card { border-radius: 14px; }
  .card .cover { aspect-ratio: 16 / 9; }
  .cover-preview { display: none !important; }
  .card .card-actions {
    opacity: 1;
    padding: 24px 10px 10px;
    background: linear-gradient(0deg, rgba(2, 6, 12, 0.82), transparent);
  }
  .card .card-actions .btn {
    height: 36px;
    padding: 0 14px;
    font-size: 13px;
    border-radius: 9px;
  }
  .card .card-body { padding: 10px 12px 12px; }
  .card .card-name { font-size: 15px; }

  /* ────────── 单屏聚焦 ────────── */

  .focus-stage-wrap { inset: 0 0 0 0; }
  .fit-stage { touch-action: none; }

  .focus-mbar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 6px;
    height: 52px;
    padding: 0 7px;
    border-radius: 14px;
    background: rgba(12, 18, 30, 0.86);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transition: opacity 0.25s, transform 0.25s;
  }
  .focus.idle .focus-mbar {
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
  }
  .focus-mbar .btn {
    height: 38px;
    min-width: 38px;
    padding: 0 8px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.14);
    color: #eaf1fb;
    font-size: 12.5px;
  }
  .focus-mbar .btn:active { background: rgba(255, 255, 255, 0.2); }
  .focus-mbar-title {
    flex: 1;
    min-width: 0;
    text-align: center;
    line-height: 1.15;
  }
  .focus-mbar-title b {
    display: block;
    font-size: 12.5px;
    color: #f2f7ff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .focus-mbar-title span { font-size: 10px; color: rgba(190, 208, 230, 0.55); }
  .focus-mbar-zoom {
    font-size: 11px;
    color: rgba(200, 218, 240, 0.8);
    font-variant-numeric: tabular-nums;
    min-width: 34px;
    text-align: center;
  }
  .focus-bar { display: none !important; }
  .focus-hint { display: none !important; }

  .gesture-hint {
    position: fixed;
    left: 50%;
    top: 14px;
    transform: translateX(-50%);
    z-index: 29;
    padding: 7px 14px;
    border-radius: 999px;
    background: rgba(10, 16, 26, 0.82);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(214, 230, 248, 0.86);
    font-size: 11.5px;
    white-space: nowrap;
    pointer-events: none;
    animation: ghFade 4.2s ease forwards;
  }
  @keyframes ghFade {
    0% { opacity: 0; transform: translateX(-50%) translateY(-6px); }
    12%, 72% { opacity: 1; transform: translateX(-50%) translateY(0); }
    100% { opacity: 0; transform: translateX(-50%) translateY(-6px); }
  }

  /* ────────── 轮播墙 ────────── */

  .wall-bar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 10px;
    gap: 6px;
    background: color-mix(in srgb, var(--panel) 90%, transparent);
    border-bottom: 1px solid var(--border);
  }
  .wall-bar .wall-progress { display: none; }
  .wall-bar .sep { display: none; }
  .wall-bar #wall-count { font-size: 12px; }
  .wall-bar .btn { height: 34px; font-size: 12px; padding: 0 10px; }
  .wall-grid { gap: 6px; padding: 6px; }

  /* ────────── 管理端 ────────── */

  .admin-head {
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
  }
  .admin-head h2 { font-size: 17px; }
  .admin-head .storage-flag { display: none; }
  .admin-head .spacer { display: none; }
  .admin-head .btn {
    height: 40px;
    font-size: 13px;
    padding: 0 12px;
    flex: 1 1 auto;
  }
  .admin-head .btn .lbl { display: inline; }

  .tbl-wrap { display: none !important; }

  .m-list { display: flex; flex-direction: column; gap: 10px; }
  .m-item {
    border: 1px solid var(--border);
    border-radius: 13px;
    background: var(--panel);
    padding: 11px 12px;
    display: flex;
    flex-direction: column;
    gap: 9px;
  }
  .m-item.is-off { opacity: 0.58; }
  .m-item-top { display: flex; align-items: center; gap: 10px; }
  .m-thumb {
    width: 62px;
    height: 38px;
    border-radius: 7px;
    overflow: hidden;
    flex: 0 0 auto;
    background: var(--stage-bg);
    border: 1px solid var(--border);
  }
  .m-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .m-thumb .thumb-art { width: 100%; height: 100%; }
  .m-info { flex: 1; min-width: 0; }
  .m-name {
    font-size: 14.5px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .m-meta {
    margin-top: 3px;
    font-size: 11px;
    color: var(--text-3);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .m-item .switch { flex: 0 0 auto; }
  .m-ops {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
  }
  .m-ops .btn {
    height: 36px;
    padding: 0;
    font-size: 12px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
  }
  .m-ops .btn svg { width: 14px; height: 14px; }
  .m-ops .btn-primary { font-weight: 500; }

  /* ────────── 弹窗 → 底部抽屉 ────────── */

  .modal-mask {
    align-items: flex-end;
    padding: 0;
  }
  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    border-radius: 18px 18px 0 0;
    border-bottom: 0;
    animation: sheetUp 0.26s cubic-bezier(0.22, 0.8, 0.3, 1);
  }
  @keyframes sheetUp { from { transform: translateY(28px); opacity: 0.6; } to { transform: none; opacity: 1; } }
  .modal::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 7px;
    width: 38px;
    height: 4px;
    margin-left: -19px;
    border-radius: 3px;
    background: var(--border-strong);
  }
  .modal-head { padding: 18px 14px 10px; }
  .modal-head h3 { font-size: 15.5px; }
  .modal-body {
    max-height: 62vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 4px 14px 12px;
  }
  .modal-foot {
    position: sticky;
    bottom: 0;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--panel);
    border-top: 1px solid var(--border);
    gap: 8px;
  }
  .modal-foot .btn { flex: 1; height: 44px; font-size: 14px; }

  .form-grid { gap: 12px; }
  .form-row { grid-template-columns: 1fr; gap: 6px; }
  .form-row > label { font-size: 12px; color: var(--text-2); }
  .input, .select, .textarea {
    font-size: 16px; /* 防 iOS 聚焦缩放 */
    min-height: 44px;
    border-radius: 10px;
  }
  .textarea { min-height: 76px; }
  .form-cols, .form-cols-3 { grid-template-columns: 1fr; }
  .seg-options button,
  .radio-row button { min-height: 40px; }

  /* ────────── 动作面板（动作面板 sheet） ────────── */

  .sheet-mask {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    align-items: flex-end;
    background: var(--mask);
    animation: fadeIn 0.18s ease;
  }
  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
  .sheet {
    width: 100%;
    max-height: 84vh;
    overflow-y: auto;
    border-radius: 18px 18px 0 0;
    background: var(--panel);
    border-top: 1px solid var(--border);
    padding: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px));
    animation: sheetUp 0.26s cubic-bezier(0.22, 0.8, 0.3, 1);
  }
  .sheet-title {
    padding: 10px 6px 8px;
    font-size: 12px;
    color: var(--text-3);
    text-align: center;
  }
  .sheet-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 50px;
    padding: 0 10px;
    border: 0;
    border-radius: 11px;
    background: none;
    color: var(--text);
    font-size: 14.5px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
  }
  .sheet-item:active { background: var(--panel-2); }
  .sheet-item svg { width: 18px; height: 18px; color: var(--text-2); flex: 0 0 auto; }
  .sheet-item .sheet-sub { display: block; font-size: 11px; color: var(--text-3); margin-top: 2px; }
  .sheet-item.danger { color: var(--danger); }
  .sheet-item.danger svg { color: var(--danger); }
  .sheet-sep { height: 1px; margin: 6px 10px; background: var(--border); }
  .sheet-cancel {
    margin-top: 8px;
    width: 100%;
    height: 48px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--panel-2);
    color: var(--text-2);
    font-size: 15px;
    font-family: inherit;
  }

  /* Toast 上移，避开标签栏 */
  .toast-wrap { bottom: calc(74px + env(safe-area-inset-bottom, 0px)); }

  /* 空状态 */
  .empty { padding: 34px 16px; }
  .empty h3 { font-size: 15px; }
  .empty p { font-size: 12.5px; }

  /* 本地存储提示条 */
  .dirty-bar {
    font-size: 11.5px;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }
}

/* 极窄屏（iPhone SE 之类） */
@media (max-width: 400px) {
  .portal-title { font-size: 20px; }
  .m-ops { grid-template-columns: repeat(5, 1fr); }
  .m-ops .btn .lbl { display: none; }
  .m-ops .btn { height: 38px; }
  .m-ops .btn svg { width: 16px; height: 16px; }
}

/* 横屏手机：管理端用两列卡片，聚焦态让画面尽量大 */
@media (max-width: 900px) and (orientation: landscape) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mobile-tabbar { height: calc(48px + env(safe-area-inset-bottom, 0px)); }
  .focus-mbar { height: 46px; bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
}

/* ────────── 登录页（手机） ────────── */

.login-page { padding: 20px 14px; align-items: center; }
.login-card { padding: 28px 20px 16px; }
.login-brand h1 { font-size: 18px; }
.login-field .input { height: 46px; font-size: 16px; } /* 16px 防 iOS 聚焦自动放大 */
.login-submit { height: 48px; }
.login-deco i:nth-child(3) { display: none; }
