/* ─────────────────────────────────────────────────────────────
   CREATEEL AI · 移动端 dock 层（v1.1）
   只负责 ≤768px 的 App 化形态：底部 dock + 更多面板 + 安全区。
   桌面端不加 .ekko-m 类，样式一条都不生效。
   与 official 前端零融合：不删不改官方 DOM，只新增与尺寸约束。
   ───────────────────────────────────────────────────────────── */

html.ekko-m {
  --ekko-dock-h: 56px;
  --ekko-dock-safe: env(safe-area-inset-bottom, 0px);
  --ekko-dock-total: calc(56px + env(safe-area-inset-bottom, 0px));
  --ekko-brand: #233176;
  --ekko-brand-2: #3390e7;
  --ekko-line: #e8ecf3;
  --ekko-muted: #8a94a6;
}

/* ① 主内容让位：把 #app 压短，dock 占的是真实空间，不是盖在内容上 */
html.ekko-m #app {
  min-height: 0 !important; /* 官方 min-height:100% 会把 height 又拉回满屏 */
  height: calc(100dvh - var(--ekko-dock-total)) !important;
  height: calc(100vh - var(--ekko-dock-total)) !important; /* 老 WebView 兜底，下一行覆盖 */
}
@supports (height: 100dvh) {
  html.ekko-m #app {
    height: calc(100dvh - var(--ekko-dock-total)) !important;
  }
}
/* 官方外壳各层都写死 100%/100vh，且 #app 与外壳都有 min-height:100% 兜底，
   只压 #app 会被 min-height 拉回满屏 —— 所以整条链一起压，并把 min-height 归零 */
html.ekko-m #app > .n-config-provider,
html.ekko-m #app .app-shell,
html.ekko-m #app .app-layout,
html.ekko-m #app .app-main,
html.ekko-m #app .chat-panel {
  min-height: 0 !important;
  max-height: 100% !important;
  height: 100% !important;
}
/* ② 页面头部收紧：手机上 dock 已经是主导航，顶部不再留双层空白 */
html.ekko-m .page-header {
  padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 12px 52px !important;
}

/* ③ dock 本体 */
#ekko-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 950;
  display: flex;
  align-items: stretch;
  height: var(--ekko-dock-total);
  padding-bottom: var(--ekko-dock-safe);
  box-sizing: border-box;
  background: #fff;
  border-top: 1px solid var(--ekko-line);
  box-shadow: 0 -1px 12px rgba(35, 49, 118, .06);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  transform: translateZ(0);
  font-family: inherit;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#ekko-dock .ekko-dock-item {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: none;
  padding: 6px 2px 4px;
  color: var(--ekko-muted);
  font-size: 10px;
  line-height: 1;
  font-weight: 500;
  cursor: pointer;
  transition: color .16s ease;
}

#ekko-dock .ekko-dock-item svg {
  width: 22px;
  height: 22px;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#ekko-dock .ekko-dock-item.is-active {
  color: var(--ekko-brand);
  font-weight: 600;
}

#ekko-dock .ekko-dock-item.is-active::before {
  content: "";
  position: absolute;
  top: 0;
  width: 22px;
  height: 2px;
  border-radius: 0 0 2px 2px;
  background: var(--ekko-brand);
}

#ekko-dock .ekko-dock-item {
  position: relative;
}

#ekko-dock .ekko-dock-item:active {
  background: #f4f6fb;
}

/* ④ 更多面板（半屏抽屉） */
#ekko-more-mask {
  position: fixed;
  inset: 0;
  z-index: 1180;
  background: rgba(15, 23, 42, .38);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}

#ekko-more-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1190;
  background: #fff;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 32px rgba(15, 23, 42, .16);
  transform: translateY(102%);
  transition: transform .22s cubic-bezier(.32, .72, 0, 1);
  padding: 8px 12px calc(12px + var(--ekko-dock-total));
  max-height: 76vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

html.ekko-m.ekko-more-open #ekko-more-mask {
  opacity: 1;
  pointer-events: auto;
}

html.ekko-m.ekko-more-open #ekko-more-sheet {
  transform: translateY(0);
}

#ekko-more-sheet .ekko-sheet-grip {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: #dde3ee;
  margin: 2px auto 12px;
}

#ekko-more-sheet .ekko-sheet-title {
  font-size: 12px;
  color: var(--ekko-muted);
  padding: 0 4px 8px;
  letter-spacing: .04em;
}

#ekko-more-sheet .ekko-sheet-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px 0;
}

#ekko-more-sheet .ekko-sheet-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 4px;
  border: 0;
  background: none;
  border-radius: 12px;
  color: #3d4759;
  font-size: 11px;
  line-height: 1.15;
  text-align: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

#ekko-more-sheet .ekko-sheet-item:active {
  background: #f4f6fb;
}

#ekko-more-sheet .ekko-sheet-item i {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #f2f5fb;
  color: var(--ekko-brand);
}

#ekko-more-sheet .ekko-sheet-item svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ⑤ 窄屏补充：代码块/表格不撑破页面，输入框字号 ≥16px 防 iOS 聚焦缩放 */
html.ekko-m pre,
html.ekko-m table {
  max-width: 100%;
  overflow-x: auto;
}

html.ekko-m textarea,
html.ekko-m input[type="text"],
html.ekko-m input[type="search"],
html.ekko-m .n-input__input-element,
html.ekko-m .n-input__textarea-element {
  font-size: 16px !important;
}

/* ⑥ 登录页不显示 dock（登录页没有 .app-shell，JS 也不会挂载） */

/* ④ 防横向溢出：官方不少地方用 <pre> 直出（技能 YAML、日志、代码块），
   手机上一律改成软换行，避免右侧被切掉、也免得用户左右拖 */
html.ekko-m pre,
html.ekko-m pre code,
html.ekko-m .markdown-body pre,
html.ekko-m .markdown-body pre code {
  white-space: pre-wrap !important;
  word-break: break-word !important;
  overflow-wrap: anywhere !important;
  max-width: 100% !important;
}
/* 官方有些页面（设置/用量/性能）在窄屏会超出视口，裁切会让右侧按钮看不见，
   这里给一个可横向滑动的兜底，比直接切掉强 */
html.ekko-m #app {
  overflow-x: hidden !important;
}
html.ekko-m #app .app-main {
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
}
