/* 《未战先赢》多浏览器 / 移动端兼容层
   加载顺序：style.css → wxy.css → compat.css
   原则：所有新增规则要么是全浏览器等价降级（PC 版面不变），
        要么只在 .ua-* / @media 下生效，不触碰 PC 既有布局。 */

/* ============================================================
   一、新 CSS 语法降级（对所有浏览器等价，PC 视觉不变）
   ============================================================ */

/* inset:0 → 四边定位（iOS 13 / 微信 X5 / 旧 Safari 不支持 inset） */
.wxy-mask { top: 0; right: 0; bottom: 0; left: 0; }

/* min(...) → width + max-width（Safari 13 / 旧 X5 不支持 min()） */
.wxy-modal { width: 640px; max-width: 100%; }
.toast { max-width: 620px; }
.login-card { width: 440px; max-width: 100%; }

/* 登录页居中：grid + place-items 会让 max-width:100% 相对被撑开的轨道而失效，
   窄屏横向溢出；改用 flex 居中，同时兼容旧版 X5 / Android 内核 */
.login-wrap {
    display: -webkit-box;
    display: -webkit-flex;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    align-items: center;
    -webkit-box-pack: center;
    -webkit-justify-content: center;
    justify-content: center;
}
.login-card { -webkit-box-flex: 0; -webkit-flex: 0 1 auto; flex: 0 1 auto; }

/* place-items:center → 拆成 align-items / justify-items（旧 Safari） */
.login-wrap, .wxy-brand i, .wiz-step .n, .tcard .tno {
    align-items: center;
    justify-items: center;
}
.wxy-brand i, .wiz-step .n, .tcard .tno {
    justify-content: center;
    text-align: center;
}

/* 100vh 在 iOS Safari / 微信 WKWebView 会把地址栏算进去，底部被遮；
   只作用于 iOS / 安卓 UA，macOS Safari 不受影响 */
html.ua-ios .login-wrap {
    min-height: -webkit-fill-available;
    min-height: 100dvh;
}
html.ua-android .login-wrap {
    min-height: 100dvh;
}

/* 不支持 backdrop-filter 时提高不透明度，保证文字可读 */
html.ua-x5 .wxy-head,
html.ua-x5 .wxy-foot,
html.ua-x5 .wxy-modal,
html.ua-firefox .wxy-head,
html.ua-firefox .wxy-foot,
html.ua-legacy .panel,
html.ua-legacy .kpi,
html.ua-legacy .tcard,
html.ua-legacy .gcard,
html.ua-legacy .login-card {
    background-color: rgba(255, 255, 255, .97);
}

/* ============================================================
   二、旧内核 flex gap 回退
   Chrome < 84 / Safari < 14.1 / 微信安卓 X5 / UC 不支持 flex gap，
   用相邻兄弟 margin 补齐，PC 端与其它浏览器仍走原 gap。
   ============================================================ */
html.ua-legacy .wxy-head-in > * + *,
html.ua-legacy .wxy-brand > * + *,
html.ua-legacy .wxy-chip > * + *,
html.ua-legacy .wiz-step > * + *,
html.ua-legacy .kpi .k > * + *,
html.ua-legacy .stepper > * + *,
html.ua-legacy .tcard .thead > * + *,
html.ua-legacy .tcard .tactions > * + *,
html.ua-legacy .lrow > * + *,
html.ua-legacy .wxy-foot-in > * + *,
html.ua-legacy .wxy-modal .mfoot > * + *,
html.ua-legacy .gcard .head > * + *,
html.ua-legacy .trainer-hero > * + *,
html.ua-legacy .wiz > * + * {
    margin-left: 10px;
}
html.ua-legacy .rowlist > * + * { margin-top: 9px; }
html.ua-legacy .chips > *,
html.ua-legacy .tabs > * { margin: 0 8px 8px 0; }
html.ua-legacy .tcard .tstars > * + * { margin-left: 1px; }

/* ============================================================
   三、移动端通用（iOS / 安卓 / 微信 / 各品牌浏览器）
   ============================================================ */
html.ua-mobile input,
html.ua-mobile select,
html.ua-mobile textarea {
    /* iOS 会自动放大字号 < 16px 的输入框；微信 WKWebView 同样 */
    font-size: 16px;
    -webkit-appearance: none;
    appearance: none;
}
html.ua-mobile input[type="number"] {
    -moz-appearance: textfield;
}
html.ua-mobile input[type="number"]::-webkit-inner-spin-button,
html.ua-mobile input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
html.ua-mobile .stepper input { width: 62px; }
html.ua-mobile .stepper button { width: 38px; height: 38px; font-size: 19px; }
html.ua-mobile .btn-primary,
html.ua-mobile .btn-ghost,
html.ua-mobile .stampbtn,
html.ua-mobile .hirebtn { min-height: 44px; }
html.ua-mobile .chip,
html.ua-mobile .mcard,
html.ua-mobile .wiz-step { min-height: 40px; }

@media (max-width: 768px) {
    .toast { max-width: 86vw; }
    .wxy-modal { padding: 20px 18px 16px; }
    .login-card { padding: 26px 22px; }
    /* 表格在窄屏横向滚动，不撑破整页 */
    .panel { overflow-x: auto; }
    /* 两列 / 三列的键值表交给文字换行，四列以上才横滑；
       税率、上交集团这类长文本被 420px 宽度切掉是课堂里最常见的投诉 */
    .tb { min-width: 0; }
    /* :has() 不被旧内核识别时整条规则忽略，退化为上面的自适应宽度 */
    .tb:has(td:nth-child(4)),
    .tb:has(th:nth-child(4)) { min-width: 480px; }
}

/* 弹窗在手机上改为底部抽屉：更贴合移动端习惯，按钮拇指可达 */
@media (max-width: 640px) {
    .wxy-mask {
        align-items: flex-end;
        padding: 0;
    }
    .wxy-modal {
        width: 100%;
        max-width: 100%;
        max-height: 90vh;
        padding: 24px 18px calc(18px + var(--safe-bottom));
        border-radius: 22px 22px 0 0;
        animation: wxySheet .26s cubic-bezier(.2, .85, .25, 1);
    }
    .wxy-modal::before { border-radius: 22px 22px 0 0; }
    .wxy-modal::after {
        content: "";
        position: absolute;
        top: 10px;
        left: 50%;
        width: 40px;
        height: 4px;
        transform: translateX(-50%);
        border-radius: 4px;
        background: rgba(14, 116, 144, .2);
    }
    .wxy-modal h3 { padding-top: 8px; }
    /* 弹窗内表格在窄屏取消固定最小宽，改自适应并允许换行，避免右侧被截断 */
    .wxy-modal .mbody .tb { min-width: 0; }
    .wxy-modal .mbody .tb th,
    .wxy-modal .mbody .tb td { padding: 7px 6px; word-break: break-word; }
    .wxy-modal .mfoot .btn-ghost,
    .wxy-modal .mfoot .btn-primary {
        flex: 1;
        min-width: 0;
    }
    @keyframes wxySheet {
        from { transform: translateY(100%); }
        to { transform: none; }
    }
}

/* ============================================================
   四、微信内置浏览器（iOS WKWebView / 安卓 X5）
   ============================================================ */
html.ua-wechat, html.ua-wechat body {
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
}
html.ua-wechat button,
html.ua-wechat .chip,
html.ua-wechat .mcard,
html.ua-wechat .wiz-step,
html.ua-wechat .tcard,
html.ua-wechat .tab {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}
html.ua-wechat .wxy-foot { padding-bottom: calc(14px + var(--safe-bottom)); }
html.ua-wechat.ua-ios .wxy-foot { padding-bottom: calc(18px + var(--safe-bottom)); }
html.ua-wechat.ua-ios .wxy-head-in { padding-top: calc(8px + var(--safe-top)); }
html.ua-wechat .wxy-modal { -webkit-overflow-scrolling: touch; }
/* X5 不支持毛玻璃时，弹窗遮罩加深一点，避免与背景混在一起 */
html.ua-wechat.ua-x5 .wxy-mask { background: rgba(30, 27, 75, .58); }

/* iOS 键盘弹起：固定底栏改为普通流，避免盖住正在填写的输入框 */
html.ua-keyboard .wxy-foot { position: static; box-shadow: none; }
html.ua-keyboard .wxy-shell { padding-bottom: 18px; }
html.ua-keyboard .wxy-modal { max-height: 68vh; }

/* ============================================================
   五、小屏 / 横屏 / 刘海 / 无障碍
   ============================================================ */
@media (max-width: 360px) {
    .wxy-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .method-grid { grid-template-columns: 1fr; }
    .wxy-brand small { display: none; }
    .wxy-head-in { gap: 6px; }
    .stepper input { width: 52px; }
    .panel { padding: 14px 12px; }
}

@media (max-height: 480px) and (orientation: landscape) {
    .wxy-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .kpi { padding: 8px 10px; }
    .kpi .v { font-size: 17px; }
    .wxy-foot { padding-top: 6px; padding-bottom: calc(6px + var(--safe-bottom)); }
    .wxy-shell { padding-bottom: calc(76px + var(--safe-bottom)); }
    .login-wrap { padding: 12px; }
    .login-card { padding: 18px 20px; }
}

/* 刘海屏横屏时左右内缩（竖屏 env() 为 0，不受影响） */
html.ua-ios .wxy-shell {
    padding-left: calc(20px + var(--safe-left));
    padding-right: calc(20px + var(--safe-right));
}
@media (max-width: 768px) {
    html.ua-ios .wxy-shell {
        padding-left: calc(12px + var(--safe-left));
        padding-right: calc(12px + var(--safe-right));
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ============================================================
   六、多品牌细节
   ============================================================ */
/* macOS Safari / iOS Safari：sticky 与 flex 需显式 webkit 前缀 */
html.ua-safari .wxy-head { position: -webkit-sticky; position: sticky; }
html.ua-safari .wxy-foot-in,
html.ua-safari .wxy-head-in { display: -webkit-flex; display: flex; }

/* Firefox：number input 与 flex 基线对齐 */
html.ua-firefox input[type="number"] { -moz-appearance: textfield; }
html.ua-firefox .wxy-kpis { grid-gap: 12px; }

/* 华为 / 夸克 / UC：内核较旧，禁用可能触发重绘的滤镜 */
html.ua-huawei .wxy-head,
html.ua-quark .wxy-head,
html.ua-x5 .wxy-head { -webkit-backdrop-filter: none; backdrop-filter: none; }

/* 打印：兼容层不影响助教回收表 */
@media print {
    html.ua-keyboard .wxy-foot { position: static; }
    .panel { overflow: visible; }
    .tb { min-width: 0; }
}
/* ============================================================
   七、触控 / 手机浏览器增强
   目标：iPhone / iPad / 安卓各品牌 / 微信内置浏览器
   规则全部带 .ua-* 或 @media 限定，PC 版面不变。
   ============================================================ */

/* 页面为浅色主题，锁住原生控件配色，避免 iOS 深色模式把 select / 日期框反成深色 */
html { color-scheme: light; }

/* 1) 背景固定：iOS 不支持 background-attachment: fixed，
      部分安卓内核固定背景拖慢滚动；窄屏与触屏统一改为随页滚动 */
@media (max-width: 1024px) {
    body { background-attachment: scroll; }
}
@media (hover: none) {
    body { background-attachment: scroll; }
}

/* 2) 动态视口：地址栏 / 微信工具栏收起时底部不留白、不遮挡（老内核忽略后一行） */
html.ua-mobile body { min-height: 100vh; min-height: 100dvh; }
html.ua-mobile .login-wrap { min-height: 100vh; min-height: 100dvh; }
@media (max-width: 640px) {
    .wxy-modal { max-height: 90vh; max-height: 90dvh; }
}

/* 3) 原生下拉与日期框：补回箭头、统一触控高度。
      iOS 上 select 默认圆角 + 无箭头，X5 上箭头位置偏移，都会让学员看不出可点 */
html.ua-mobile select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236f6a96' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}
html.ua-mobile input[type="date"],
html.ua-mobile input[type="datetime-local"],
html.ua-mobile input[type="time"],
html.ua-mobile select { min-height: 42px; }

/* 4) 表格横滑：惯性滚动 + 只接管横向，不把整页带着滑 */
html.ua-mobile .panel {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}
/* 顶部步骤条右侧渐隐，提示还能往右滑；不支持 mask 的内核直接忽略 */
html.ua-mobile .wiz {
    -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 22px), transparent 100%);
    mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 22px), transparent 100%);
}

/* 5) 触控目标：导航胶囊与底栏链接至少 36px，手指点得准 */
html.ua-touch .wxy-chip,
html.ua-touch .chip { min-height: 36px; }
html.ua-touch .wxy-foot a { display: inline-flex; align-items: center; min-height: 36px; }
/* 登录页底部的「返回首页 / 导师入口」：热区放大到 36px，排版不动 */
html.ua-touch .alt a { padding: 10px 6px; margin: -10px -6px; }

/* 6) 触屏按下反馈：替代 hover 在手机上留下的粘滞高亮 */
html.ua-touch .wiz-step:active,
html.ua-touch .chip:active,
html.ua-touch .wxy-chip:active,
html.ua-touch .mcard:active,
html.ua-touch .gcard:active { transform: scale(.975); }

/* 7) 顶部安全区：添加到主屏（standalone）后头部不被状态栏压住；
      普通浏览器与微信内 env() 为 0，不产生额外留白 */
html.ua-mobile .wxy-head { padding-top: var(--safe-top); }

/* 8) iOS 微信滚动时固定底栏会轻微上浮，提升为独立合成层 */
html.ua-ios .wxy-foot { -webkit-transform: translateZ(0); transform: translateZ(0); }

/* 9) 安卓下拉刷新：误触会把整页重载（草稿虽在本地，但会打断填报），统一禁用 */
html.ua-android body { overscroll-behavior-y: contain; }

/* 10) 微信内长按：按钮 / 导航不弹「复制 / 保存图片」，输入框与正文仍可选 */
html.ua-wechat .wxy-chip,
html.ua-wechat .wiz-step,
html.ua-wechat .tab,
html.ua-wechat .wxy-foot a { -webkit-touch-callout: none; }

/* 11) 低端安卓：毛玻璃一律去掉，避免滚动掉帧 */
html.ua-legacy .wxy-head,
html.ua-legacy .wxy-foot,
html.ua-legacy .panel,
html.ua-legacy .kpi {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

/* 12) 横屏小高度：弹窗占满可视高度，内部滚动，按钮不被切掉 */
@media (max-height: 500px) and (orientation: landscape) {
    .wxy-modal { max-height: 94vh; }
    .wxy-modal .mfoot { position: sticky; bottom: 0; background: inherit; }
}
