/* ============ 独立移动端（body.m-ui 生效） ============
   底部导航 / 手势抽屉 / 卡片化列表 / safe-area / 触控目标
*/

/* --- 壳布局：顶栏 + 内容 + 底部导航，抽屉覆盖层 --- */
.m-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: var(--bg, #0b0a08);
}
.m-main {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  overflow: auto;
  padding: 3% 4% 14%;
  width: 100%;
  max-width: none;
  margin: 0;
  box-sizing: border-box;
}

/* 顶栏 */
.m-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 3%;
  flex: 0 0 8%;
  height: 8%;
  width: 100%;
  padding: 0 4%;
  background: var(--panel, #14110d);
  border-bottom: 1px solid var(--line, #2a2318);
}
.m-topbar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text, #f0eae0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.m-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 12%;
  height: auto;
  aspect-ratio: 1;
  border: none;
  background: transparent;
  color: var(--text, #f0eae0);
  border-radius: 22%;
  cursor: pointer;
}
.m-icon-btn:active { background: var(--panel-2, #1a1610); }

/* 底部导航（safe-area 感知） */
.m-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  display: flex;
  width: 100%;
  height: 10%;
  background: var(--panel, #14110d);
  border-top: 1px solid var(--line, #2a2318);
}
.m-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 100%;
  min-height: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted, #c2b9ac);
  font-size: 11px;
  cursor: pointer;
}
.m-tab { position: relative; transition: color 0.18s ease, transform 0.18s ease; }
.m-tab.active { color: var(--accent, #c8956a); font-weight: 700; }
.m-tab.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 22%;
  right: 22%;
  height: 2px;
  border-radius: 2px;
  background: var(--accent, #c8956a);
}
.m-tab:active { transform: translateY(1px); }
.m-tab-ico { position: relative; display: inline-flex; }
.m-badge {
  position: absolute;
  top: -6px;
  right: -12px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
  font-weight: 700;
}

/* 抽屉 + 背板 */
.m-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(12, 10, 8, 0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}
.m-backdrop.show { opacity: 1; pointer-events: auto; }
.m-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 61;
  width: min(82vw, 320px);
  display: flex;
  flex-direction: column;
  background: var(--panel, #14110d);
  transform: translateX(-100%);
  transition: transform 0.24s ease;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 4px 0 18px rgba(0, 0, 0, 0.12);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.m-drawer.open { transform: translateX(0); }
.m-drawer[style*="translateX"] { transition: none; } /* 手势跟手时去掉动画 */
.m-drawer-lock { overflow: hidden; }
.m-drawer-head {
  padding: 16px 16px 10px;
  border-bottom: 1px solid var(--line, #2a2318);
}
.m-brand { font-size: 18px; font-weight: 800; color: var(--accent, #c8956a); }
.m-muted { color: var(--muted, #c2b9ac); font-size: 12px; margin-top: 2px; }
.m-nav { flex: 1; padding: 6px 8px 16px; }
.m-nav-section { margin-top: 8px; }
.m-nav-group {
  padding: 8px 10px 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted, #c2b9ac);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.m-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text, #f0eae0);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.m-nav-item.active { background: var(--accent, #c8956a); color: #fff; }
.m-nav-item:active { background: var(--panel-2, #1a1610); }
.m-drawer-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 12px 14px;
  border-top: 1px solid var(--line, #2a2318);
}

/* --- 卡片化列表 --- */
.m-card-list { display: flex; flex-direction: column; gap: 10px; }
.m-card {
  background: var(--panel, #14110d);
  border: 1px solid var(--line, #2a2318);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 1px 4px rgba(20, 14, 8, 0.12);
}
.m-card-unread { border-left: 3px solid var(--accent, #c8956a); }
.m-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.m-card-title { font-size: 15px; font-weight: 700; color: var(--text, #f0eae0); }
.m-card-body {
  margin-top: 4px;
  font-size: 13px;
  color: var(--muted, #c2b9ac);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.m-card-body.clamp {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* --- 移动端全局微调（复用桌面渲染器的页面） --- */
body.m-ui .page-stack { gap: 10px; }
body.m-ui .card { border-radius: 14px; padding: 12px; }
body.m-ui .toolbar { flex-wrap: wrap; gap: 8px; }
body.m-ui .toolbar input,
body.m-ui .toolbar select { max-width: 100%; min-height: 40px; }
body.m-ui .btn { min-height: 40px; }
body.m-ui .btn.sm { min-height: 34px; }
body.m-ui .stat-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
body.m-ui .stat { border-radius: 12px; padding: 10px 12px; }
body.m-ui .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
body.m-ui .subtabs { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
body.m-ui .subtab { min-height: 40px; white-space: nowrap; }
body.m-ui table { font-size: 12.5px; }
body.m-ui .modal { width: 94vw; max-width: 94vw; max-height: 86dvh; }
body.m-ui .modal-body { max-height: 62dvh; overflow-y: auto; }

/* 悬浮导航按钮：移动端隐藏（内联样式优先级高，需 !important；回顶用底部 tab 重复点击实现） */
body.m-ui #global-float-nav { display: none !important; }

/* ============ 全页面表格移动化（卡片化）+ 弹窗底部抽屉 ============ */
body.m-ui table[data-mobilified] { display: none; }

.m-table-cards { margin-top: 2px; }
.m-card-row .m-card-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.m-card-row .m-card-title-row .m-card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text, #f0eae0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.m-card-row .m-card-title-row input[type="checkbox"] { flex: 0 0 auto; }
.m-kv-list { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.m-kv {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  line-height: 1.5;
}
.m-kv-k { color: var(--muted, #c2b9ac); flex: 0 0 auto; }
.m-kv-v {
  color: var(--text, #f0eae0);
  text-align: right;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
  word-break: break-word;
}
.m-kv-v input, .m-kv-v select { max-width: 46vw; min-height: 34px; }
.m-kv-v .btn.sm { min-height: 30px; }
.m-card-actions {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line, #2a2318);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.m-card-dim { opacity: .55; }
.m-card-overridden { border-left: 3px solid var(--accent, #c8956a); }

/* 弹窗 → 底部抽屉（bottom sheet）：高度随内容自适应，仅内容超高时才滚到 88dvh */
body.m-ui .modal-backdrop { align-items: flex-end; }
body.m-ui .modal {
  width: 100vw;
  max-width: 100vw;
  margin: 0;
  border-radius: 16px 16px 0 0;
  /* 覆盖窄屏媒体查询里的 min-height:100%（那会把抽屉撑满整屏、内容下留大片空白遮挡页面） */
  min-height: 0;
  height: auto;
  max-height: 88dvh;
  animation: sheetUp .26s cubic-bezier(.22,.9,.36,1);
}
body.m-ui .modal-body {
  max-height: none;
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
}
/* 移动端底部抽屉：移除头部关闭按钮（点击背板/向下滑动手势关闭），改为拖拽把手 */
body.m-ui .modal-head .btn { display: none; }
body.m-ui .modal-head h3 { flex: 1; }
body.m-ui .modal-head::before {
  content: '';
  position: absolute;
  top: 6px; left: 50%;
  width: 38px; height: 4px;
  margin-left: -19px;
  border-radius: 2px;
  background: var(--line, #2a2318);
}
body.m-ui .modal-head { position: relative; padding-top: 18px; }
body.m-ui .modal-xl, body.m-ui .modal-lg { max-width: 100vw; width: 100vw; }
body.m-ui .modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 1px solid var(--line, #2a2318);
}
body.m-ui .modal-foot {
  position: sticky;
  bottom: 0;
  background: var(--panel, #14110d);
  border-top: 1px solid var(--line, #2a2318);
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
}
@keyframes sheetUp {
  from { transform: translateY(32px); opacity: .5; }
  to { transform: translateY(0); opacity: 1; }
}

/* 名称链接按钮作为卡片标题的样式 */
.m-card-row .m-card-title-row button.linkish {
  font-size: 15px;
  font-weight: 700;
  padding: 0;
  min-height: 0;
}

/* ============ 设计系统 v2 · 移动端同步 ============ */
/* 底部导航：活动指示点 + 图标弹跳 */
.m-tab { transition: color var(--dur, .22s) ease; }
.m-tab .ico { transition: transform .22s cubic-bezier(.34,1.56,.64,1); }
.m-tab.active .ico { transform: translateY(-2px) scale(1.12); }
.m-tab.active .m-tab-label { letter-spacing: .02em; }
.m-tabbar { box-shadow: 0 -6px 24px rgba(2,6,16,.35); }
.m-tabbar::before {
  content: '';
  position: absolute; top: 0; left: 24%; right: 24%; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(230,188,143,.4), transparent);
}
.m-tabbar { position: fixed; }

/* 抽屉：头部品牌渐变底 */
.m-drawer-head {
  background:
    radial-gradient(80% 100% at 0% 0%, rgba(200,149,106,.16), transparent 70%),
    var(--panel-2, #1a1610);
  border-bottom: 1px solid var(--line, #2a2318);
}
.m-drawer { box-shadow: 8px 0 32px rgba(2,6,16,.4); }

/* 卡片按压反馈 */
.m-card { transition: transform .16s ease, box-shadow .16s ease; }
.m-card:active { transform: scale(.985); }
.m-kv-v strong, .m-kv-v { font-variant-numeric: tabular-nums; }

/* 汇总条移动端两列 */
body.m-ui .filter-stats { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
body.m-ui .filter-stats .stat { border-radius: 12px; padding: 10px 12px; }

/* 移动端登录：独立一屏，不是把 PC 两栏压窄 */
body.m-ui .login-scene {
  display: block;
  min-height: 100dvh;
  padding: 0;
  overflow: auto;
}
body.m-ui .login-scene::before,
body.m-ui .login-scene::after { animation: none; }
body.m-ui .login-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: none;
  min-height: 100dvh;
  gap: 0;
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
}
body.m-ui .login-brandpane { gap: 16px; }
body.m-ui .login-brandpane-hero h2 {
  font-size: 28px;
  line-height: 1.25;
}
body.m-ui .login-brandpane-hero p { display: none; }
body.m-ui .login-features {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 8px;
  order: 3;
  overflow: visible;
}
body.m-ui .login-feature {
  flex: 1 1 calc(50% - 8px);
  min-width: 0;
  grid-template-columns: 1fr;
  gap: 6px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(200, 149, 106, 0.08);
  border: 1px solid rgba(200, 149, 106, 0.18);
}
body.m-ui .login-feature-copy span { display: none; }
body.m-ui .login-brandpane-foot { display: none; }
body.m-ui .login-panel {
  order: 2;
  margin-top: 8px;
  padding: 4px 0 20px;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  animation: none;
}
body.m-ui .login-field input {
  min-height: 48px;
  font-size: 16px;
}
body.m-ui .btn.login-submit,
body.m-ui .login-form .btn.ghost {
  min-height: 48px;
}

/* 手机壳内的业务页：单列，不套桌面多栏，也不出现桌面版权 */
body.m-ui .site-copyright { display: none !important; }
body.m-ui.has-site-copyright { padding-bottom: 0; }
body.m-ui #global-float-nav {
  bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important;
}
body.m-ui .dash-hero,
body.m-ui .dash-site-grid,
body.m-ui .dash-charts,
body.m-ui .grid-2,
body.m-ui .grid-3,
body.m-ui .grid.two,
body.m-ui .u-grid-2,
body.m-ui .u-grid-3,
body.m-ui .chart-row,
body.m-ui .agent-bind-grid {
  grid-template-columns: 1fr;
}
body.m-ui .page-head {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}
body.m-ui .page-head h1 { font-size: 1.15rem; }
body.m-ui .dash-hero { padding: 14px; }
body.m-ui .dash-hero-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}
body.m-ui .dash-hero-actions .btn {
  white-space: normal;
  flex: 1 1 calc(50% - 8px);
}
body.m-ui .stats,
body.m-ui .stats.stats-6,
body.m-ui .dash-site-metrics {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
body.m-ui .table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
body.m-ui .toolbar,
body.m-ui .btn-row {
  flex-wrap: wrap;
}
body.m-ui .subtabs {
  overflow-x: auto;
  flex-wrap: nowrap;
  max-width: 100%;
}

/* ============ Design System v3 · 移动端收尾 ============ */
/* 抽屉品牌锁形：印章 + 骏瑞轩 */
.m-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text, #f0eae0);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.m-brand .brand-seal {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(145deg, #e6bc8f, #c8956a);
  color: #241a10;
}
.m-brand .brand-seal-char { font-size: 15px; }
/* 底部导航活动色与顶栏统一暖金 */
.m-tab.active { color: var(--accent-2, #e6bc8f); }
.m-topbar { background: rgba(18, 15, 12, 0.9); backdrop-filter: blur(12px); }
[data-theme="light"] .m-topbar { background: rgba(253, 250, 245, 0.94); }
[data-theme="light"] .m-nav-item.active { color: #241a10; }
