/* ===== 17-mobile.css | 手机浏览器兼容层（只覆盖小屏与触控，不改桌面版） ===== */

html.mch-mobile,
html.mch-mobile body {
  max-width: 100%;
  overflow-x: hidden;
}

@media (max-width: 900px), (pointer: coarse) and (max-width: 1024px) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  body {
    min-height: var(--mch-vh, 100dvh);
    overscroll-behavior-y: contain;
  }

  button,
  .btn,
  .tab,
  .ad-maintab,
  .ad-topbtn,
  .ad-toolbtn,
  .lm-x {
    touch-action: manipulation;
  }

  button,
  .btn,
  .ad-topbtn,
  .ad-toolbtn {
    min-height: 42px;
  }

  input,
  select,
  textarea {
    max-width: 100%;
    font-size: 16px !important; /* iOS 小于 16px 会在聚焦时自动放大页面 */
  }

  /* ---------- 登录页 ---------- */
  #loginBox {
    padding: max(12px, env(safe-area-inset-top)) 10px max(18px, env(safe-area-inset-bottom));
    gap: 18px;
  }

  .login-card {
    width: 100%;
    max-width: 480px;
    padding: 32px 20px 24px;
    border-radius: 16px;
  }

  .login-logo {
    width: 50px;
    height: 50px;
    font-size: 23px;
  }

  .login-title .t1 {
    font-size: 20px;
  }

  .login-row {
    gap: 14px;
    flex-wrap: wrap;
  }

  .seo-intro {
    width: 100%;
    padding: 0 4px;
  }

  .seo-feats {
    grid-template-columns: 1fr;
  }

  /* ---------- 主外壳与顶栏 ---------- */
  .ad-console {
    height: var(--mch-vh, 100dvh);
    max-height: var(--mch-vh, 100dvh);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  .ad-topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 7px 8px;
    padding: max(8px, env(safe-area-inset-top)) 10px 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .42);
  }

  .ad-brand {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    gap: 8px;
  }

  .ad-logo {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 9px;
    font-size: 18px;
  }

  .ad-title {
    max-width: 48vw;
    overflow: hidden;
    font-size: 17px;
    letter-spacing: .5px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ad-ver,
  .ad-ver-badge,
  .ad-topbar .who {
    display: none !important;
  }

  .ad-topbtns {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    max-width: 55vw;
    margin-left: 0;
    padding-bottom: 2px;
    overflow-x: auto;
    flex-wrap: nowrap;
    justify-content: flex-start;
    scrollbar-width: none;
  }

  .ad-topbtns::-webkit-scrollbar {
    display: none;
  }

  .ad-topbtn {
    min-height: 38px;
    padding: 7px 9px;
    flex: 0 0 auto;
    font-size: 12px;
    white-space: nowrap;
  }

  .ad-maintabs {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    padding: 5px 0 0;
    border-top: 1px solid rgba(224, 176, 84, .12);
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    scrollbar-width: none;
  }

  .ad-maintabs::-webkit-scrollbar {
    display: none;
  }

  .ad-maintab {
    min-height: 38px;
    padding: 9px 12px;
    flex: 0 0 auto;
    font-size: 13px;
    white-space: nowrap;
  }

  /* ---------- AI 工作台：左右栏改上下排列 ---------- */
  .ad-body {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    gap: 12px;
    padding: 10px;
    overflow: visible;
  }

  .ad-left {
    width: 100%;
    min-width: 0;
    max-height: none;
    gap: 10px;
    overflow: visible;
  }

  .ad-left > * {
    padding: 12px;
    border-radius: 12px;
  }

  .ad-left .ad-selectrow {
    flex-direction: column;
    gap: 8px;
  }

  .ad-left select,
  .ad-left .ad-go {
    width: 100%;
    min-height: 46px;
  }

  .ad-descbox textarea {
    min-height: 150px;
  }

  .ad-tools {
    position: sticky;
    bottom: 0;
    z-index: 8;
    padding: 10px;
    gap: 7px;
    background: rgba(20, 16, 9, .96);
    backdrop-filter: blur(8px);
  }

  .ad-toolbtn {
    flex: 1 1 30%;
    min-width: 0;
    padding: 9px 8px;
  }

  .ad-setrow {
    gap: 8px;
    line-height: 1.5;
  }

  .ad-setrow .sep {
    display: none;
  }

  .ad-right {
    width: 100%;
    min-height: 58vh;
    overflow: hidden;
  }

  .ad-right .ad-body2 {
    padding: 12px;
    overflow: visible;
  }

  .ad-codebox {
    font-size: 12px;
    overflow-wrap: anywhere;
  }

  #aiResult > .tip {
    margin: 32px auto 0;
    padding: 24px 16px;
    font-size: 13px;
  }

  #aiResult > .tip::before {
    font-size: 36px;
    margin-bottom: 12px;
  }

  .aiCodeHead {
    align-items: flex-start;
  }

  .aiCodeIcons {
    width: 100%;
    margin-left: 0;
    flex-wrap: wrap;
  }

  .aiCodeIcons .ad-toolbtn {
    flex: 1 1 42%;
  }

  .aiCodePre {
    max-height: 50vh;
    font-size: 12px;
  }

  #aiThink .at-top {
    top: max(12px, env(safe-area-inset-top));
    padding: 0 12px;
  }

  #aiThink .at-orb {
    width: min(90vw, 660px);
    height: min(50vw, 368px);
    margin-bottom: 16px;
  }

  #aiThink .at-main,
  #aiThink .at-sub {
    padding: 0 16px;
    text-align: center;
  }

  .pwa-bar {
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 10px;
    max-width: none;
  }

  /* ---------- 后台标签页 ---------- */
  #app {
    width: 100%;
    max-width: 100%;
    padding: 12px 10px calc(24px + env(safe-area-inset-bottom));
    overflow-x: hidden;
  }

  .ad-console.show-app > #app {
    min-height: 0;
    overflow-x: hidden;
  }

  #app .tabs {
    margin-bottom: 12px;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }

  #app .tabs::-webkit-scrollbar {
    display: none;
  }

  #app .tab {
    flex: 0 0 auto;
    padding: 10px 14px;
    white-space: nowrap;
  }

  #app .card {
    max-width: 100%;
    padding: 14px;
    margin-bottom: 12px;
    overflow-x: auto;
  }

  #app .card h3 {
    margin-bottom: 12px;
  }

  #app .row {
    align-items: stretch;
    gap: 10px;
  }

  #app .field {
    flex: 1 1 100%;
    min-width: 0 !important;
  }

  #app .field input,
  #app .field select {
    width: 100%;
    min-height: 44px;
  }

  .enc-v {
    gap: 12px;
  }

  .enc-v .field > input[type=file],
  .enc-v .field > select,
  .enc-v .field > input[type=text],
  .enc-v .field > input[type=number],
  .enc-v .field > input:not([type]) {
    width: 100%;
    max-width: none;
  }

  .enc-v .field > .btn {
    width: 100%;
    align-self: stretch;
  }

  .checkbox {
    min-height: 44px;
    padding-bottom: 0;
  }

  #app table {
    min-width: 720px;
  }

  .lic-card {
    align-items: flex-start;
    gap: 8px;
    padding: 11px;
  }

  .lic-card .lic-key {
    width: 100%;
    overflow-wrap: anywhere;
    font-size: 13px;
  }

  .lic-card .lic-ops {
    width: 100%;
    margin-left: 0;
  }

  .stat-chip {
    flex: 1 1 calc(50% - 8px);
    min-width: 0;
  }

  .nav-cfg {
    min-width: 680px;
  }

  #status {
    top: max(8px, env(safe-area-inset-top));
    width: calc(100vw - 20px);
    max-width: none;
    padding: 11px 14px;
    text-align: center;
  }

  /* ---------- 授权管理 ---------- */
  #tab-lic,
  #tab-lic .lm-card,
  #tab-lic .lm-split,
  #tab-lic .lm-cfgwrap {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  #tab-lic .lm-card {
    overflow: visible;
  }

  #tab-lic .lm-split,
  #tab-lic .lm-cfgwrap {
    grid-template-columns: minmax(0, 1fr);
  }

  #tab-lic .lm-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  #tab-lic .lm-row,
  #tab-lic .lm-brow {
    grid-template-columns: minmax(0, 1fr);
    gap: 7px;
    padding: 12px;
  }

  #tab-lic .lm-c-key,
  #tab-lic .lm-c-acct,
  #tab-lic .lm-c-bind,
  #tab-lic .lm-c-exp,
  #tab-lic .lm-c-rem,
  #tab-lic .lm-c-mach,
  #tab-lic .lm-c-seen,
  #tab-lic .lm-c-ctime,
  #tab-lic .lm-c-ops {
    grid-column: 1 / -1;
    grid-area: auto;
    justify-self: stretch;
    text-align: left;
  }

  #tab-lic .lm-c-ops {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-left: 0;
  }

  #tab-lic .lm-c-rem,
  #tab-lic .lm-c-exp,
  #tab-lic .lm-c-mach {
    justify-self: start;
    text-align: left;
  }

  #tab-lic .lm-menu,
  #tab-lic .lm-opsm {
    right: auto;
    left: 0;
    max-width: calc(100vw - 44px);
  }

  .lm-code,
  .lm-src {
    max-height: 320px;
  }

  .lm-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* ---------- 监控、统计、SEO ---------- */
  .lm-mon-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .lm-mon-toolbar,
  .lm-mon-tools,
  .lm-mon-filters {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .lm-mon-filters .lm-inp,
  .lm-mon-tools .btn,
  .lm-mon-toolbar select {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  #vsChart {
    min-width: 620px;
  }

  #tab-stats .card {
    overflow-x: auto;
  }

  /* ---------- 弹窗：手机上改为单列全宽，允许整页滚动 ---------- */
  #licModal,
  #chgPwModal,
  #srcModal,
  #codeImportModal,
  #lmCloneModal,
  #lmNewModal,
  #aiLicModal,
  #encLicModal,
  #lmAddSrcModal,
  #vipModal,
  .ad-modal {
    align-items: flex-start !important;
    justify-content: flex-start !important;
    overflow-y: auto !important;
    padding: max(8px, env(safe-area-inset-top)) 8px max(12px, env(safe-area-inset-bottom)) !important;
  }

  .modal-card,
  .lmc-card,
  .cim-box,
  .ad-modal-box,
  #vipModal .vip-shell {
    width: 100% !important;
    max-width: 100% !important;
    max-height: none !important;
    margin: 0 auto !important;
    border-radius: 14px !important;
  }

  .modal-card,
  .lmc-card,
  .cim-box {
    padding: 18px 14px !important;
  }

  .ad-modal-box {
    min-height: 0;
  }

  .ad-modal-head,
  .ad-modal-body,
  .ad-modal-foot {
    padding: 11px 12px;
  }

  .ad-modal-foot {
    flex-wrap: wrap;
  }

  .cim-row {
    flex-direction: column;
    gap: 12px;
    padding: 12px;
  }

  .cim-col {
    width: 100%;
    padding: 0;
  }

  .cim-div {
    width: 100%;
    height: 1px;
    margin: 0;
  }

  .cim-opts {
    gap: 12px;
  }

  .cim-foot,
  .lmc-actions {
    gap: 8px;
  }

  .cim-foot .cim-btn,
  .lmc-actions .btn {
    flex: 1 1 100%;
  }

  .lmc-row {
    flex-direction: column;
    gap: 0;
  }

  .lmc-remote-row {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .lmc-remote-init {
    flex: 1 1 100%;
    width: 100%;
  }

  .lmc-rkey {
    font-size: 13px;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 480px) {
  .ad-title {
    max-width: 42vw;
    font-size: 16px;
  }

  .ad-topbtns {
    max-width: 52vw;
  }

  .ad-maintab {
    padding: 9px 11px;
    font-size: 12.5px;
  }

  #app {
    padding-right: 8px;
    padding-left: 8px;
  }

  #app .card {
    padding: 12px 10px;
  }

  .lm-stats,
  .lm-mon-summary {
    grid-template-columns: 1fr;
  }

  .stat-chip {
    flex-basis: 100%;
  }

  .ad-toolbtn {
    flex-basis: 100%;
  }
}
