/* ============================================================
   响应式收口层 (2026-11-12 随全站 UI 重塑更新)
   ------------------------------------------------------------
   目标: 桌面(≥1281px) 保持设计稿布局; 平板(768~1180) 与手机(≤720) 完整可用。
   必须**最后**加载(index.php 里排在 logs.css 之后), 用媒体查询覆盖前面各页样式,
   不改动各页原有规则, 便于回滚(删掉本文件即回到旧表现)。

   断点约定(全站统一, 新增响应式规则请沿用):
     ≤1280  lg  小笔记本 / 大平板横屏
     ≤1180  md  平板横屏 / iPad Pro 竖屏
     ≤ 960  tab  侧边栏导轨转抽屉(顶栏随之收窄)
     ≤ 860  phone-l 大屏 HUD 改两行(品牌独占首行)
     ≤ 720  phone   手机(竖屏为主)
     ≤ 560  phone-s 小屏手机
     ≤ 400  phone-xs
   + (pointer: coarse) 触屏命中区 / 输入框字号(iOS 聚焦缩放)

   配套 JS(index.php → assets/core.js): setupNavToggle() 抽屉开合;
   syncTopbarH() 在旋转/resize 时回写 --topbar-h。
   ============================================================ */

/* ------------------------------------------------------------
   1. 基础: 文本缩放 / 横向溢出兜底 / 动态视口高度 / 安全区
   ------------------------------------------------------------ */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* 手机上个别长串(20 位 RID / 15 位 IMEI / 无空格长备注)会把整页顶宽,
   导致「页面能左右拖、卡片被推出屏幕」。
   用 overflow-x: clip 而非 hidden —— clip 不建立滚动容器, 顶栏 position:sticky 仍生效。 */
@media (max-width: 960px) {
    body:not(.mode-dash) { overflow-x: clip; }
}

/* 移动浏览器地址栏收起/展开会改变 100vh, 用 dvh 让满屏布局跟手(不支持的浏览器保留 vh 原样) */
@supports (height: 100dvh) {
    #dash-shell { height: 100dvh; }
    .login-body, .login-split, .login-hero, .login-side { min-height: 100dvh; }
    .admin-body { min-height: calc(100dvh - var(--topbar-h, 52px)); }
    body.mode-records #view-records { height: calc(100dvh - var(--topbar-h, 52px)); }
    .dev-list-pane { max-height: calc(100dvh - var(--topbar-h, 52px) - 28px); }
    .modal-box { max-height: 86dvh; }
    .sit-drone-detail { max-height: calc(100dvh - 16px); }
}

/* 全面屏横屏时左右安全区(刘海/圆角)不让内容贴边 */
@media (max-width: 960px) {
    .container {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
}

/* ------------------------------------------------------------
   2. 触屏: 命中区放大 + 输入字号提到 16px(否则 iOS Safari 聚焦时会整页放大)
   ------------------------------------------------------------ */
@media (pointer: coarse) {
    /* 只在 hover 才显形的控件(设备列表图钉)在触屏上常年看不见: 提高默认可见度并把命中区撑到 ~32px */
    .pin-btn { opacity: .55; padding: 8px; top: 2px; right: 2px; font-size: 15px; }
    .pin-btn.pinned { opacity: 1; }

    .btn {
        min-height: 38px;
        padding: 9px 14px;
        font-size: 14px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
    }
    .btn-sm { min-height: 32px; padding: 6px 10px; font-size: 13px; }
    /* .btn 的 display/min-height 写在小节末尾会压过 base.css 的 .btn-block, 这里按同权重补回 */
    .btn.btn-block { display: flex; min-height: 46px; font-size: 15px; }

    input, select, textarea { font-size: 16px; padding: 10px 12px; }
    input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; }
    input[type="file"] { padding: 8px; }

    /* 各页固定小字号的筛选/编辑控件: 一并提到 16px, 避免聚焦缩放后错位 */
    .dev-search,
    .rec-toolbar input[type="date"], .rec-toolbar input[type="text"],
    .rec-toolbar select,
    .tl-row select,
    .user-search, .cm-search, .asg-user select,
    .asg-manual input, .asg-search input,
    .kv-fence .fence-input, .kv-alias .fence-input,
    #ota-devices td select { font-size: 16px; }
    .kv-fence .fence-input { width: 76px; }
    .tl-row select { width: 74px; height: 32px; }
    .asg-manual input { width: 200px; }

    /* 小图标按钮(导航码/图例开关)补足命中区 */
    .nav-btn { padding: 3px 9px; font-size: 12px; }
    .sit-legend .lg-btn, .alert-banner .btn { min-height: 34px; }

    .dash-tab { padding: 9px 14px; }
    #nav a { min-height: 34px; }
    .log-tab, .log-disp { min-height: 36px; }
}

/* ------------------------------------------------------------
   3. 后台顶栏横排导航(窄屏: 行内边距收窄, 导航行横滑)
   ------------------------------------------------------------ */
@media (max-width: 960px) {
    .topbar {
        gap: 6px 10px;
        padding: 6px 10px 0;
        padding-top: calc(6px + env(safe-area-inset-top));
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
    }
    .topbar nav {
        margin: 2px -10px 0;
        padding: 4px 10px 8px;
    }
    .topbar nav .nav-group + .nav-group { margin-left: 6px; padding-left: 10px; }
}

/* 顶栏在平板/手机上收成两行: 第一行(菜单 + 平台名 + 账号操作), 第二行(当前页名) */
@media (max-width: 860px) {
    .topbar {
        flex-wrap: wrap; gap: 8px 10px;
        height: auto; padding: 8px 10px;
        padding-top: calc(8px + env(safe-area-inset-top));
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
    }
    .topbar .brand {
        /* flex-basis 必须为 0: 用 auto 时平台名的 max-content 会把「账号操作区」挤到下一行 */
        flex: 1 1 0; min-width: 0; display: flex; align-items: center;
        gap: 6px; font-size: 14px; white-space: nowrap;
    }
    .topbar .brand .brand-txt { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
    .topbar .brand .brand-badge { flex: none; margin-right: 0; }
    .topbar .brand small { display: none; }

    .crumb {
        order: 5; flex: 1 1 100%;
        padding-top: 6px; border-top: 1px solid var(--border);
        font-size: 12px;
    }
    .crumb h2 { font-size: 14px; }

    .topbar .user-info { flex: none; gap: 8px; font-size: 12px; }
    #to-dash-btn .btn-txt { display: inline; }

    /* 历史记录/大屏是满屏地图布局, 面包屑里没有页名(records.css 隐藏了 #view-title),
       再占一行只是白吃 30px 高度 —— 平板/手机上整行去掉, 顶栏只留一行。 */
    body.mode-records .crumb { display: none; }
}

@media (max-width: 560px) {
    .topbar .brand { font-size: 13px; }
    .topbar .brand .brand-badge { width: 18px; height: 18px; }
    .topbar .user-visible { display: none; }
    #user-name { display: none; }
    #to-dash-btn .btn-txt { display: none; }
    .container { padding: 10px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
}

/* ------------------------------------------------------------
   4. 表格: 窄屏改为「表格自身横滑」, 不把整页顶宽
   ------------------------------------------------------------ */
@media (max-width: 960px) {
    .table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }
    .table th, .table td { padding: 8px 10px; }
    /* 表头 sticky 在自身滚动盒里没有意义(页面滚动时不再跟随), 关掉避免半透明叠字 */
    .table th { position: static; }
    /* 已有独立滚动容器的表格保持原样(任务表/机型库/存储明细) */
    .cm-table-wrap .table,
    .log-storage-table .table,
    .rpts-body .table { display: table; overflow: visible; }
    .cm-table-wrap .table th,
    .log-storage-table .table th,
    .rpts-body .table th { position: sticky; }
}

/* ------------------------------------------------------------
   5. 卡片 / 表单 / 弹窗
   ------------------------------------------------------------ */
@media (max-width: 720px) {
    .card { padding: 12px; border-radius: 10px; margin-bottom: 12px; }
    .card h2, .card h3 { font-size: 15px; }

    /* 手机上将弹窗改为底部抽屉: 内容多时单手可及, 关闭按钮不被键盘遮挡 */
    .modal-mask { padding: 0; align-items: flex-end; }
    .modal-box,
    .modal-box-wide, .modal-box-pts, .modal-box-hist, .modal-box-card,
    .dev-events-box {
        width: 100%; max-width: none;
        max-height: 92dvh;
        border-radius: 14px 14px 0 0;
        border-bottom: none;
        padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
    }
    .modal-actions { gap: 10px; }
    .modal-actions .btn { flex: 1 1 auto; }
    .nav-qr-img img { width: min(200px, 60vw); height: auto; }

    .row > * { min-width: 0; }

    /* 告警横幅: 文案与两个按钮在 360px 上会互相挤压, 允许换行 */
    .alert-banner { flex-wrap: wrap; gap: 8px 12px; padding: 10px 12px; font-size: 13px; }
    .alert-banner .alert-actions { margin-left: 0; width: 100%; }
    .alert-banner .alert-actions .btn { flex: 1 1 auto; }

    /* 轻提示贴底时要让开安全区(iPhone 小白条) */
    .toast { left: 12px; right: 12px; bottom: calc(16px + env(safe-area-inset-bottom)); }
}

/* ------------------------------------------------------------
   6. 设备页: 手机/平板上左列表与详情上下排, 键值行不再撑宽卡片
   ------------------------------------------------------------ */
@media (max-width: 1180px) {
    .dev-card, .dev-sections, .dev-sections > .card { min-width: 0; max-width: 100%; }
    .kv-list, .kv-list-col, .kv-list-cols { min-width: 0; }
    #dev-bindings .table, .dev-rec-table { max-width: 100%; }
}

@media (max-width: 900px) {
    /* 上下排(device.css 已把 .dev-layout 改成 column): 详情整宽, 不许内容撑出 */
    .dev-detail-pane { flex: 1 1 auto; width: 100%; min-width: 0; }
    .dev-list-pane { max-height: none; }
    /* 列表在详情上方时给一个上限高度, 避免 200 台设备把详情推到很深 */
    .dev-list { max-height: 42vh; overflow-y: auto; }
    .dev-row .imei { font-size: 15px; }
}

@media (max-width: 720px) {
    /* 键值行: 标签列固定 84px —— 「设备固件版本」6 字不折行, 值区仍有 240px 以上 */
    .dev-kv-cols .kv-list > .kv { gap: 8px; padding: 8px 0; }
    .dev-kv-cols .kv-list > .kv .k { flex: 0 0 84px; min-width: 84px; max-width: 84px; font-size: 12px; }
    .dev-kv-cols .kv-list > .kv .v { word-break: break-word; }
    .dev-head h3 { font-size: 14px; }
    .dev-head-actions .btn { flex: 1 1 auto; }
    #dev-bindings .table { max-width: 100%; }
    .map { height: 300px; }
}

/* ------------------------------------------------------------
   7. 大屏壳: HUD 顶栏窄屏收纳(布局细节由 situation/stats/records.css 各自收口,
      本层只处理 chrome 自身换行与让位, 不再干预面板/图例的 fixed 坐标)
   ------------------------------------------------------------ */
@media (max-width: 860px) {
    #dash-chrome {
        flex-wrap: wrap; gap: 8px 12px;
        padding: 8px 10px;
        padding-top: calc(8px + env(safe-area-inset-top));
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
    }
    .dash-brand {
        order: -1; flex: 1 1 100%;
        max-width: 100%; font-size: 13px; letter-spacing: 1px; gap: 7px;
    }
    .dash-brand svg { width: 20px; height: 20px; }
    .dash-brand-txt { overflow: hidden; text-overflow: ellipsis; }

    .dash-menu {
        flex: 1 1 auto; max-width: 100%; min-width: 0;
        height: 40px; padding: 0 8px; gap: 6px;
        overflow-x: auto; scrollbar-width: none;
    }
    .dash-menu::-webkit-scrollbar { display: none; }
    .dash-tab { padding: 5px 12px; font-size: 12.5px; white-space: nowrap; flex: none; }
    /* 三态看板在手机上挤成一团, 只保留今日架次(设备情况看板桌面端才显示) */
    .dash-sep, .dash-status-line { display: none; }
    .admin-entry-btn { padding: 5px 12px; flex: none; font-size: 12px; letter-spacing: 1px; }
}

@media (max-width: 720px) {
    .dash-brand { font-size: 12px; letter-spacing: 0; }
    .dash-brand svg { width: 18px; height: 18px; }
}

/* 手机横屏(高度 ≤520): 品牌行省掉, HUD 收成一行 */
@media (max-width: 960px) and (max-height: 520px) {
    .dash-brand { display: none; }
    #dash-chrome { padding-top: calc(6px + env(safe-area-inset-top)); }
    body.mode-records #view-records { height: calc(100dvh - var(--topbar-h, 52px)); }
}

/* ------------------------------------------------------------
   8. 白名单 / 飞手 / 机型库 / 用户 / 分配: 表格与表单在窄屏的兜底
   ------------------------------------------------------------ */
@media (max-width: 720px) {
    .user-toolbar { gap: 8px; }
    .user-toolbar-right { width: 100%; }
    .user-toolbar-right .btn { flex: 1 1 auto; }
    .pilot-form-actions { padding-top: 8px; }
    .pilot-form-actions .btn { flex: 1 1 auto; }
    .asg-head { padding: 12px; gap: 10px; }
    .asg-head-main, .asg-head-side { width: 100%; }
    .asg-head-side .btn { flex: 1 1 auto; }
    .asg-panel { min-height: 320px; max-height: none; }
    .asg-item { padding: 10px; }
    .asg-item-side .btn { min-width: 34px; }
    .pwd-page { max-width: none; }
    .ota-force, .pl-wl { min-height: 32px; }
    /* 登录页窄屏: 品牌视觉隐藏后登录卡居中放大 */
    .login-side { padding: 20px 0; }
    .login-card { width: 92%; }
}

/* 小屏(≤560)再收一档 */
@media (max-width: 560px) {
    .log-storage-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 400px) {
    .topbar .brand .brand-txt { font-size: 12px; }
    .dash-tab { padding: 7px 9px; font-size: 12px; }
    .dev-kv-cols .kv-list > .kv .k { flex: 0 0 76px; min-width: 76px; max-width: 76px; }
}
