/* ============================================================================
   全站移动端 & 钉钉 WebView 基础设施底座（严格隔离于 @media (max-width: 768px)）
   ============================================================================ */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --mobile-tabbar-h: 56px;
}

/* 桌面端默认隐藏移动端专属控件，零影响 PC 1440x900 视觉 */
.mobile-tabbar,
.mobile-card-list,
.mobile-tree-bar,
.mobile-view-switch,
.mobile-nav-hamburger,
.mobile-drawer-backdrop,
.mobile-profile-sheet {
  display: none;
}

@media (max-width: 768px) {
  html, body {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    -webkit-tap-highlight-color: transparent;
  }

  /* iOS 钉钉 WebView 防聚焦自动放大（表单/搜索输入字号 >=16px） */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select,
  textarea {
    font-size: 16px !important;
  }

  /* ── 1. 移动端底部固定 TabBar ── */
  body.has-mobile-tabbar .mobile-tabbar {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 980;
    height: calc(var(--mobile-tabbar-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: #ffffff;
    border-top: 1px solid #ebeef5;
    box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.05);
  }
  .mobile-tab-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    border: 0;
    background: transparent;
    color: #606266;
    font-size: 11px;
    line-height: 14px;
    text-decoration: none;
    cursor: pointer;
    padding: 4px 2px;
    min-height: 44px;
  }
  .mobile-tab-item.is-active {
    color: #2b85ff;
    font-weight: 500;
  }
  .mobile-tab-item svg {
    width: 22px;
    height: 22px;
    display: block;
  }
  .mobile-tab-badge {
    position: absolute;
    top: 4px;
    left: calc(50% + 8px);
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: #f53f3f;
    color: #ffffff;
    font-size: 10px;
    line-height: 16px;
    text-align: center;
    font-style: normal;
  }
  .mobile-tab-badge[hidden] { display: none !important; }

  body.has-mobile-tabbar .app > main > #content,
  body.has-mobile-tabbar .ac-workspace,
  body.has-mobile-tabbar .console-main,
  body.has-mobile-tabbar > main#content {
    padding-bottom: calc(var(--mobile-tabbar-h) + var(--safe-bottom) + 14px) !important;
  }

  /* ── 2. 主工作台 & 首页顶栏防溢出修复 ── */
  .app > main > header {
    max-width: 100vw !important;
    overflow: hidden !important;
    padding-left: 8px !important;
    padding-right: 8px !important;
  }
  body.is-home-page .ws-top-nav {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    scrollbar-width: none;
    max-width: calc(100vw - 88px) !important;
    gap: 10px !important;
  }
  body.is-home-page .ws-top-nav::-webkit-scrollbar { display: none; }
  body.is-home-page .ws-top-link { flex: none !important; white-space: nowrap !important; font-size: 13px !important; }
  body.is-home-page .ws-nav-badge { display: none !important; }
  body.is-home-page .header-search { display: none !important; }
  body.is-home-page .header-shortcuts { display: none !important; }
  .ws-card-head h3 { white-space: nowrap !important; }

  /* ── 2.5 列表顶部工具栏与搜索框防重叠 ── */
  .main-workspace-page:not(.tc-page) {
    height: auto !important;
    min-height: 100% !important;
    overflow: visible !important;
  }
  .main-workspace-page .main-list-toolbar {
    flex-wrap: wrap !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    flex: none !important;
    padding: 8px 10px !important;
    gap: 8px !important;
  }
  .main-workspace-page .main-list-tools {
    flex-wrap: wrap !important;
    width: 100% !important;
    height: auto !important;
    gap: 6px !important;
  }
  .main-list-search,
  .main-search-scope {
    flex: 1 1 100% !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    order: 10;
  }
  .main-list-search input.search,
  .main-search-scope input.search {
    width: 100% !important;
    padding-right: 32px !important;
  }
  .main-list-actions {
    width: 100% !important;
    justify-content: flex-end;
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  /* ── 3. 表单列表移动端卡片流 & 左侧树抽屉 ── */
  .main-workspace-split {
    display: block !important;
    position: relative;
  }
  .main-workspace-right {
    width: 100% !important;
    min-width: 0 !important;
  }
  .mobile-tree-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 12px;
    background: #f7faff;
    border-bottom: 1px solid #e5ecf6;
    font-size: 13px;
    color: #1f2b39;
    cursor: pointer;
  }
  .mobile-tree-bar-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .mobile-tree-bar-btn {
    flex: none;
    padding: 3px 10px;
    border-radius: 12px;
    background: #e6f2ff;
    color: #2b85ff;
    font-size: 12px;
  }
  .k-table-tree {
    display: none !important;
  }
  .k-table-tree.is-mobile-open {
    display: flex !important;
    flex-direction: column;
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 70dvh !important;
    max-height: 70dvh !important;
    z-index: 1190 !important;
    border-radius: 14px 14px 0 0 !important;
    box-shadow: 0 -10px 32px rgba(15, 23, 42, 0.22) !important;
    background: #ffffff !important;
    padding-bottom: var(--safe-bottom);
  }
  .k-table-tree.is-mobile-open .k-table-tree-operate { display: none !important; }
  .mobile-drawer-backdrop.is-open {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1170;
    background: rgba(15, 23, 42, 0.42);
  }

  .mobile-view-switch {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 30px;
    padding: 0 10px;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    background: #ffffff;
    color: #606266;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
  }

  /* 卡片流默认开启，表格仅在用户切到 is-mobile-table-mode 时显示（排除任务中心 .tc-page） */
  .main-workspace-page:not(.tc-page):not(.is-mobile-table-mode) .main-table-shell .table-wrap {
    display: none !important;
  }
  .main-workspace-page:not(.tc-page):not(.is-mobile-table-mode) .mobile-card-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 12px;
    background: #f2f4f7;
    min-height: 180px;
  }
  .main-workspace-page.is-mobile-table-mode .mobile-card-list {
    display: none !important;
  }
  .mobile-card {
    background: #ffffff;
    border-radius: 10px;
    padding: 12px 14px;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.05);
    border: 1px solid #ebeef5;
    display: flex;
    flex-direction: column;
    gap: 8px;
    cursor: pointer;
  }
  .mobile-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }
  .mobile-card-title {
    font-size: 15px;
    font-weight: 600;
    color: #1d2129;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .mobile-card-fields {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .mobile-card-field {
    display: flex;
    gap: 6px;
    font-size: 13px;
    line-height: 19px;
    color: #4e5969;
  }
  .mobile-card-field b {
    flex: none;
    font-weight: 400;
    color: #86909c;
  }
  .mobile-card-field span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .mobile-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 8px;
    border-top: 1px solid #f2f4f7;
    font-size: 12px;
    color: #86909c;
  }
  .mobile-card-author {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }
  .mobile-card-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }
  .mobile-card-list[data-mobile-list-layout="simple"] .mobile-card {
    padding: 10px 12px;
    gap: 4px;
  }
  .mobile-card-list[data-mobile-list-layout="simple"] .mobile-card-foot {
    display: none;
  }

  /* ── 4. 任务中心手机端审批卡片流 ── */
  body.is-task-center-page .app > main > #content {
    padding: 8px !important;
  }
  .tc-pill-bar {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    scrollbar-width: none;
    padding: 10px 12px !important;
    gap: 8px !important;
  }
  .tc-pill-bar::-webkit-scrollbar { display: none; }
  .tc-dabe-toolbar {
    flex-direction: column;
    align-items: stretch !important;
    padding: 8px 12px !important;
    gap: 8px !important;
  }
  .tc-dabe-toolbar-left,
  .tc-dabe-toolbar-right {
    width: 100%;
    justify-content: space-between;
  }
  .tc-dabe-search {
    flex: 1 1 auto !important;
    width: auto !important;
    min-width: 0 !important;
  }
  .tc-page .main-workspace-table.tc-dabe-table {
    min-width: 0 !important;
    width: 100% !important;
    display: block !important;
  }
  .tc-page .main-workspace-table.tc-dabe-table colgroup,
  .tc-page .main-workspace-table.tc-dabe-table thead {
    display: none !important;
  }
  .tc-page .main-workspace-table.tc-dabe-table tbody {
    display: flex !important;
    flex-direction: column;
    gap: 10px;
    padding: 10px 12px;
    background: #f2f4f7;
  }
  .tc-page .main-workspace-table.tc-dabe-table tbody tr {
    display: flex !important;
    flex-direction: column;
    gap: 8px;
    padding: 13px 14px;
    border-radius: 10px;
    background: #ffffff;
    border: 1px solid #ebeef5;
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.05);
  }
  .tc-page .main-workspace-table.tc-dabe-table td {
    display: block !important;
    width: 100% !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
  }
  .tc-page .tc-row-btns {
    display: flex;
    gap: 10px;
    padding-top: 8px;
    border-top: 1px solid #f2f4f7;
  }
  .tc-page .tc-row-btns button {
    flex: 1 1 0;
    height: 36px !important;
    font-size: 13px !important;
  }
  .tc-dabe-pager {
    justify-content: center !important;
    flex-wrap: wrap;
    height: auto !important;
    padding: 10px 12px !important;
    gap: 8px !important;
  }
  .tc-dabe-pager input.tc-pager-jump { display: none; }
  .tc-launch-cards { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px !important; }
  .tc-launch-filters { flex-direction: column; align-items: stretch !important; }
  .tc-launch-filters .tc-dabe-search { width: 100% !important; }
  .tc-dabe-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px !important; }
  .tc-analytics-split { grid-template-columns: 1fr !important; }

  /* ── 5. 独立 form.html & 详情/新建抽屉全屏单列适配 ── */
  body > header:has(#formBack) {
    max-width: 100vw !important;
    overflow: hidden !important;
    padding: 0 10px !important;
    gap: 8px !important;
  }
  body > main#content {
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }
  .overlay .drawer,
  #dialog .drawer {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
  }
  .drawer-head {
    padding: 10px 12px !important;
    flex-wrap: wrap;
    gap: 6px;
  }
  .drawer-foot {
    padding: 10px 12px calc(10px + var(--safe-bottom)) !important;
  }
  .detail-workspace,
  .detail-related-pane,
  .detail-dabe-body > .record-events {
    width: 100% !important;
    max-width: 100% !important;
  }
  .mobile-vertical .drawer-body .form-grid,
  .form-grid,
  .detail-field-row,
  .detail-field-row[data-cols="2"],
  .detail-field-row[data-cols="4"] {
    grid-template-columns: 1fr !important;
  }
  .detail-field-row > .field {
    padding: 10px 12px !important;
    border-right: 0 !important;
    border-bottom: 1px solid #f0f2f5 !important;
  }

  /* ── 6. 权限中心 & 管理后台手机端完全修复 ── */
  .ac-header,
  .console-topbar {
    max-width: 100vw !important;
    padding: 0 10px !important;
    overflow: hidden !important;
  }
  .ac-super-search,
  .console-super-search,
  .ac-header-right > .ac-top-icon,
  .ac-header-right > .ac-top-ai,
  .ac-header-right > .ac-divider,
  .console-topbar-right .ctb-icon,
  .console-topbar-right .ctb-console,
  .console-topbar-right .ctb-ai,
  .console-topbar-right .ctb-divider {
    display: none !important;
  }
  .ac-header-right,
  .console-topbar-right {
    margin-left: auto !important;
    flex: none !important;
  }
  .ac-tenant,
  .console-brand-text {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .mobile-nav-hamburger {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    margin-right: 6px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #ffffff;
    color: #303133;
    font-size: 18px;
    cursor: pointer;
    flex: none;
  }
  .ac-shell,
  .console-shell {
    display: block !important;
    width: 100vw !important;
    max-width: 100vw !important;
  }
  .ac-sidebar,
  .console-nav {
    position: fixed !important;
    top: 48px !important;
    left: 0 !important;
    bottom: 0 !important;
    width: 240px !important;
    z-index: 1080 !important;
    background: #ffffff !important;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 24px rgba(15, 23, 42, 0.16);
    overflow-y: auto !important;
  }
  .ac-sidebar.is-mobile-open,
  .console-nav.is-mobile-open {
    transform: translateX(0) !important;
  }
  .ac-workspace,
  .console-main {
    width: 100% !important;
    max-width: 100vw !important;
    padding: 10px !important;
    overflow-x: hidden !important;
  }
  .ac-stage,
  .console-main > * {
    max-width: 100%;
    overflow-x: auto;
  }
  .ac-stage {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    overflow: visible !important;
  }
  .ac-page-head {
    flex-wrap: wrap !important;
    gap: 8px !important;
    height: auto !important;
  }
  .ac-tabs {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    scrollbar-width: none;
    width: 100% !important;
    height: auto !important;
    min-height: 40px !important;
    flex: none !important;
    gap: 6px !important;
  }
  .ac-tabs::-webkit-scrollbar { display: none; }
  .ac-tabs > button {
    flex: none !important;
    white-space: nowrap !important;
  }
  .ac-auth-split,
  .ac-split {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    min-height: 0 !important;
    gap: 12px !important;
  }
  .ac-auth-split > :first-child,
  .ac-split > :first-child {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 200px !important;
    overflow-y: auto !important;
    flex: none !important;
  }
  .ac-auth-split > :last-child,
  .ac-split > :last-child {
    width: 100% !important;
    min-width: 0 !important;
    flex: none !important;
  }

  /* ── 7. 悬浮 AI 助手 & 应用中心弹窗移动端适配 ── */
  #wsAiFloat.ws-ai-float.is-xiaobei-visible {
    right: 10px !important;
    top: auto !important;
    bottom: calc(var(--mobile-tabbar-h) + var(--safe-bottom) + 14px) !important;
    transform: none !important;
  }
  #wsAiFloat .ws-ai-avatar {
    width: 48px !important;
    height: 48px !important;
  }
  #wsAiFloat .ws-ai-avatar svg {
    width: 44px !important;
    height: 44px !important;
  }
  #wsAiFloat .ws-ai-pill { display: none !important; }
  #xiaobeiDrawer.xb-drawer {
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 86dvh !important;
    max-height: 86dvh !important;
    border-radius: 16px 16px 0 0 !important;
  }
  #xiaobeiDrawer .xb-foot {
    padding-bottom: calc(10px + var(--safe-bottom)) !important;
  }
  .app-center-popover {
    left: 8px !important;
    right: 8px !important;
    top: 54px !important;
    width: auto !important;
    max-width: none !important;
  }
  .app-center-popover .ac-pop-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }

  /* ── 8. 个人底部菜单抽屉 ── */
  .mobile-profile-sheet.is-open {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1200;
    background: #ffffff;
    border-radius: 16px 16px 0 0;
    padding: 16px 16px calc(16px + var(--safe-bottom));
    box-shadow: 0 -10px 30px rgba(15, 23, 42, 0.2);
    gap: 10px;
  }
  .mobile-profile-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 10px;
    border-bottom: 1px solid #ebeef5;
  }
  .mobile-profile-head strong { font-size: 15px; color: #1d2129; }
  .mobile-profile-head span { font-size: 12px; color: #86909c; }
  .mobile-profile-links {
    display: grid;
    gap: 8px;
  }
  .mobile-profile-links a,
  .mobile-profile-links button {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 44px;
    padding: 0 14px;
    border-radius: 8px;
    border: 1px solid #ebeef5;
    background: #f9fafc;
    color: #303133;
    font-size: 14px;
    text-decoration: none;
    cursor: pointer;
  }
  .mobile-profile-links button.is-danger { color: #f53f3f; background: #fff5f5; border-color: #fde2e2; }
}
