/* ============================================================
   InkOS Studio 手机版适配样式
   作用范围: 仅当 <body> 带 .inkos-mobile 类时生效
   设计原则: 不改动原有大布局(侧边栏 + 顶栏 + 主区),
             只做「缩小字体 / 缩小间距 / 补滚动 / 整体尺寸适配」
   ============================================================ */

/* ---------- 1. 尺寸缩放变量 ---------- */
:root {
  --ink-m-scale: 0.86;          /* 整体字体缩放系数(可由脚本动态覆盖) */
}

body.inkos-mobile {
  --ink-m-aside-w: 62vw;        /* 侧栏展开宽度(占屏 62%,够显示完整文字) */
  --ink-m-aside-max: 260px;     /* 侧栏最大宽度(平板/大屏上限) */
  --ink-m-pad-x: 10px;          /* 横向内边距(原 24~32px) */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ---------- 2. 视口高度修正(手机浏览器地址栏会伸缩) ---------- */
body.inkos-mobile .h-screen,
body.inkos-mobile [class*="h-screen"] {
  height: 100dvh !important;
  min-height: 100dvh !important;
}

/* ---------- 3. 侧边栏: 抽屉式浮层 + 允许纵向滚动 ---------- */
/* 展开时: 浮在主区上方(不挤压主区),宽度 62vw,文字完整显示 */
body.inkos-mobile aside {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  bottom: 0 !important;
  height: 100dvh !important;
  width: var(--ink-m-aside-w) !important;
  min-width: 0 !important;
  max-width: var(--ink-m-aside-max) !important;
  z-index: 2147482000 !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch;
  box-shadow: 2px 0 16px rgba(0, 0, 0, 0.35);
  transition: transform 0.22s ease, opacity 0.22s ease;
}

/* 侧边栏内部大间距压缩 */
body.inkos-mobile aside .px-6 { padding-left: var(--ink-m-pad-x) !important; padding-right: var(--ink-m-pad-x) !important; }
body.inkos-mobile aside .px-4 { padding-left: 8px !important; padding-right: 8px !important; }
body.inkos-mobile aside .py-8 { padding-top: 14px !important; padding-bottom: 14px !important; }
body.inkos-mobile aside .py-6 { padding-top: 10px !important; padding-bottom: 10px !important; }
body.inkos-mobile aside .space-y-6 > * + * { margin-top: 12px !important; }

/* 侧边栏按钮更紧凑 */
body.inkos-mobile aside button {
  min-height: 32px;
  line-height: 1.25;
}

/* 创建入口网格: 窄屏下仍保持两列,但压缩图标与文字间距,保证文字完整 */
body.inkos-mobile aside .grid-cols-2 { gap: 2px !important; }
body.inkos-mobile aside .grid-cols-2 > button {
  padding-left: 6px !important;
  padding-right: 6px !important;
  gap: 4px !important;
  justify-content: flex-start !important;
}
/* 关键: 取消创建入口文字的截断,允许完整显示(必要时缩小字号) */
body.inkos-mobile aside .grid-cols-2 > button span {
  overflow: visible !important;
  text-overflow: clip !important;
  white-space: nowrap !important;
  flex: 0 1 auto !important;
  min-width: 0;
  font-size: 12px !important;
  letter-spacing: -0.2px;
}
body.inkos-mobile aside .grid-cols-2 > button svg { flex-shrink: 0; }

/* ---------- 3b. 抽屉遮罩(点击空白处收起侧栏) ---------- */
#inkos-aside-mask {
  position: fixed;
  inset: 0;
  z-index: 2147481500;
  background: rgba(0, 0, 0, 0.42);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}
body.inkos-mobile:not(.inkos-aside-collapsed) #inkos-aside-mask {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- 4. 侧边栏折叠态(默认收起,全屏给内容) ---------- */
body.inkos-mobile.inkos-aside-collapsed aside {
  transform: translateX(-102%);
  opacity: 0;
  box-shadow: none;
  pointer-events: none;
}

/* ---------- 5. 顶栏: 降高 + 收窄内边距 ---------- */
body.inkos-mobile header {
  height: auto !important;
  min-height: 44px;
  padding-left: var(--ink-m-pad-x) !important;
  padding-right: 46px !important; /* 右侧留出浮动按钮位置 */
  flex-wrap: wrap;
  row-gap: 4px;
}

/* ---------- 6. 主内容区: 占满全宽(侧栏已改为浮层) ---------- */
body.inkos-mobile main {
  overflow-y: auto !important;
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 12px !important; /* v1.10: 浮动按钮已移至右上角,底部不再需要大避让 */
  /* 侧栏是 fixed 浮层,不再挤压主区 */
  width: 100% !important;
  margin-left: 0 !important;
}

body.inkos-mobile main .px-8,
body.inkos-mobile main .p-8 { padding-left: var(--ink-m-pad-x) !important; padding-right: var(--ink-m-pad-x) !important; }
body.inkos-mobile main .px-6,
body.inkos-mobile main .p-6 { padding-left: var(--ink-m-pad-x) !important; padding-right: var(--ink-m-pad-x) !important; }
body.inkos-mobile main .py-8 { padding-top: 12px !important; padding-bottom: 12px !important; }
body.inkos-mobile main .py-6 { padding-top: 10px !important; padding-bottom: 10px !important; }

/* ---------- 7. 字体整体缩小 ---------- */
body.inkos-mobile { font-size: calc(14px * var(--ink-m-scale)); }

body.inkos-mobile .text-\[27px\] { font-size: calc(22px * var(--ink-m-scale)) !important; line-height: 1.3 !important; }
body.inkos-mobile .text-\[17px\] { font-size: calc(16px * var(--ink-m-scale)) !important; }
body.inkos-mobile .text-\[16px\] { font-size: calc(15.5px * var(--ink-m-scale)) !important; }
body.inkos-mobile .text-\[13px\] { font-size: calc(14px * var(--ink-m-scale)) !important; }
body.inkos-mobile .text-\[11px\] { font-size: calc(12.5px * var(--ink-m-scale)) !important; }

body.inkos-mobile .text-3xl { font-size: calc(23px * var(--ink-m-scale)) !important; line-height: 1.3 !important; }
body.inkos-mobile .text-2xl { font-size: calc(21px * var(--ink-m-scale)) !important; line-height: 1.3 !important; }
body.inkos-mobile .text-xl  { font-size: calc(18.5px * var(--ink-m-scale)) !important; }
body.inkos-mobile .text-lg  { font-size: calc(17px * var(--ink-m-scale)) !important; }
body.inkos-mobile .text-base { font-size: calc(15.5px * var(--ink-m-scale)) !important; }
body.inkos-mobile .text-sm  { font-size: calc(14.5px * var(--ink-m-scale)) !important; }
body.inkos-mobile .text-xs  { font-size: calc(12.5px * var(--ink-m-scale)) !important; }

/* ---------- 8. 防溢出: 长文本 / 表格 / 代码块 ---------- */
body.inkos-mobile main table { display: block; overflow-x: auto; max-width: 100%; }
body.inkos-mobile main pre,
body.inkos-mobile main code {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 11px !important;
}
body.inkos-mobile main img,
body.inkos-mobile main canvas,
body.inkos-mobile main svg { max-width: 100%; height: auto; }

/* 通用: 卡片/网格在窄屏下单列排布,避免挤压错位 */
body.inkos-mobile main .grid-cols-2,
body.inkos-mobile main .grid-cols-3,
body.inkos-mobile main .grid-cols-4 { grid-template-columns: 1fr !important; }

/* 弹窗/抽屉宽度适配 */
body.inkos-mobile [role="dialog"],
body.inkos-mobile .fixed > .max-w-lg,
body.inkos-mobile .fixed > .max-w-xl,
body.inkos-mobile .fixed > .max-w-2xl {
  max-width: calc(100vw - 16px) !important;
  width: calc(100vw - 16px) !important;
  max-height: calc(100dvh - 32px) !important;
  overflow-y: auto !important;
}

/* 输入框字体不小于 16px,避免 iOS Safari 自动放大导致错位 */
body.inkos-mobile input,
body.inkos-mobile textarea,
body.inkos-mobile select { font-size: 16px !important; }

/* ---------- 9. 浮动切换按钮(由脚本注入) ----------
   v1.10: 从右下角移到右上角,避免遮挡聊天输入区/发送按钮 */
#inkos-mobile-toggle {
  position: fixed;
  right: 10px;
  top: 54px;
  bottom: auto;
  z-index: 2147483000;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#inkos-mobile-toggle button {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid rgba(128, 128, 128, 0.45);
  background: rgba(28, 28, 32, 0.82);
  color: #f5f5f5;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

#inkos-mobile-toggle button:active { transform: scale(0.93); }

/* 侧边栏折叠按钮仅在手机版下显示 */
#inkos-mobile-toggle #inkos-aside-btn { display: none; }
body.inkos-mobile #inkos-mobile-toggle #inkos-aside-btn { display: flex; }

/* v1.11: 换行按钮 — 注入在聊天输入区(发送键左侧),仅手机版显示;
   桌面版隐藏(桌面有 Shift+Enter,不需要它) */
#inkos-composer-newline { display: none; }
body.inkos-mobile #inkos-composer-newline {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  height: 32px;
  width: 32px;
  border-radius: 8px;
  border: 1px solid rgba(128, 128, 128, 0.45);
  background: rgba(28, 28, 32, 0.82);
  color: #f5f5f5;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}
body.inkos-mobile #inkos-composer-newline:active {
  transform: scale(0.93);
  background: rgba(37, 99, 235, 0.55);
}

/* 手机版激活时按钮高亮 */
body.inkos-mobile #inkos-mobile-toggle #inkos-mobile-btn {
  background: rgba(37, 99, 235, 0.9);
  border-color: rgba(96, 165, 250, 0.8);
}

/* 提示气泡 (v1.10: 随按钮移到右上角) */
#inkos-mobile-tip {
  position: fixed;
  right: 56px;
  top: 54px;
  z-index: 2147483000;
  max-width: 190px;
  padding: 6px 9px;
  border-radius: 8px;
  background: rgba(28, 28, 32, 0.92);
  color: #f0f0f0;
  font-size: 11.5px;
  line-height: 1.45;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
}
#inkos-mobile-tip.show { opacity: 1; }

/* ============================================================
   10. 常驻可见的「删除 / 改名」菜单  ← 方案 A
   ------------------------------------------------------------
   InkOS 的会话(含书籍对话)行里,操作按钮用的是
   opacity-0 + group-hover/session:opacity-100,
   也就是「鼠标悬停才出现」。手机没有悬停,所以永远看不见。
   这里把它强制改为常驻显示,并把触摸区域放大到 32px。
   ============================================================ */

/* 会话行内的操作触发器: 强制常驻显示 + 放大触摸区域 */
body.inkos-mobile .group\/session button[class*="opacity-0"],
body.inkos-mobile button[class*="group-hover/session:opacity-100"],
body.inkos-mobile button[class*="group-hover\\/session:opacity-100"] {
  opacity: 1 !important;
  visibility: visible !important;
}

/* 保证承载按钮的外层容器也为可见状态(有些版本包了一层 wrapper) */
body.inkos-mobile .group\/session > div > div[class*="transition-opacity"],
body.inkos-mobile .group\/session [class*="transition-opacity"] {
  opacity: 1 !important;
}

/* 放大触摸热区: 原 h-6 w-6 = 24px,手机上手感太差 */
body.inkos-mobile .group\/session [class*="transition-opacity"] {
  height: 32px !important;
  width: 32px !important;
  min-height: 32px;
  border-radius: 8px !important;
}
body.inkos-mobile .group\/session [class*="transition-opacity"] svg {
  width: 16px !important;
  height: 16px !important;
}

/* 常驻按钮给一点底色,让用户看得出「这里可以点」 */
body.inkos-mobile .group\/session [class*="transition-opacity"] {
  background: rgba(128, 128, 128, 0.12);
}
body.inkos-mobile .group\/session [class*="transition-opacity"]:active {
  background: rgba(128, 128, 128, 0.3);
  transform: scale(0.94);
}

/* 会话行整体加高,给两个按钮留出空间,避免互相压住 */
body.inkos-mobile .group\/session {
  min-height: 40px;
  padding-top: 6px !important;
  padding-bottom: 6px !important;
}

/* ============================================================
   11. 其它手机端常驻优化
   ============================================================ */

/* 11a. 顶部安全区(iPhone 刘海 / 灵动岛) */
body.inkos-mobile header {
  padding-top: max(0px, env(safe-area-inset-top)) !important;
}

/* 11b. 底部安全区(iPhone 横条) —— 浮动按钮整体上移 */
body.inkos-mobile #inkos-mobile-toggle {
  bottom: calc(14px + env(safe-area-inset-bottom));
}

/* 11c. 禁止长按选中弹出系统菜单(按钮/图标上),但正文仍可复制 */
body.inkos-mobile aside,
body.inkos-mobile header,
body.inkos-mobile #inkos-mobile-toggle {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* 11d. 去掉 300ms 点击延迟,滚动更顺 */
body.inkos-mobile a,
body.inkos-mobile button {
  touch-action: manipulation;
}

/* 11e. 滚动条在手机上细一点,少占地方 */
body.inkos-mobile aside::-webkit-scrollbar,
body.inkos-mobile main::-webkit-scrollbar { width: 3px; height: 3px; }
body.inkos-mobile aside::-webkit-scrollbar-thumb,
body.inkos-mobile main::-webkit-scrollbar-thumb {
  background: rgba(128, 128, 128, 0.35);
  border-radius: 3px;
}

/* 11f. 代码块 / 表格在手机上收紧,减少横向滚动 */
body.inkos-mobile main pre { margin: 6px 0 !important; border-radius: 8px !important; padding: 8px !important; }
body.inkos-mobile main table { font-size: 11.5px !important; }
body.inkos-mobile main table th,
body.inkos-mobile main table td { padding: 4px 6px !important; }

/* 11g. 弹窗在手机上从底部弹出感 + 不超出安全区 */
body.inkos-mobile [role="dialog"] {
  margin: auto !important;
}

/* 11h. 侧栏遮罩样式兜底(元素由脚本注入) */
body.inkos-mobile #inkos-aside-mask { display: block; }
body:not(.inkos-mobile) #inkos-aside-mask { display: none !important; }

/* 11i. 手机版下隐藏掉一些桌面专用的多余提示 */
body.inkos-mobile .inkos-desktop-only { display: none !important; }

/* ============================================================
   12. 右侧工作区抽屉 (v1.12)
   ------------------------------------------------------------
   - #inkos-ws-btn: 浮动按钮组中的 ☰ 钮(展开后变 ✕)
   - #inkos-ws-drawer: 右侧滑入抽屉(项目文件浏览 + 快捷入口)
   - #inkos-ws-mask: 抽屉展开时的遮罩,点击空白收起
   - 独立滚动,不影响聊天位置; 桌面版强制隐藏
   ============================================================ */

/* 抽屉遮罩 */
#inkos-ws-mask {
  position: fixed;
  inset: 0;
  z-index: 2147482000;
  background: rgba(0, 0, 0, 0.45);
  display: none;
}
body.inkos-ws-open #inkos-ws-mask { display: block; }
body:not(.inkos-mobile) #inkos-ws-mask,
body:not(.inkos-mobile) #inkos-ws-drawer { display: none !important; }

/* 抽屉本体: 默认藏在右侧屏幕外,展开时滑入 */
#inkos-ws-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 2147482500;
  width: min(70vw, 420px);
  background: #16161c;
  color: #e8e8ec;
  border-left: 1px solid rgba(128, 128, 128, 0.3);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.4);
  transform: translateX(105%);
  transition: transform 0.22s ease-out;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}
body.inkos-ws-open #inkos-ws-drawer { transform: translateX(0); }

/* 头部: 标题 + 标签页 */
.inkos-ws-head {
  flex-shrink: 0;
  padding: 10px 12px 0;
  border-bottom: 1px solid rgba(128, 128, 128, 0.25);
  background: rgba(28, 28, 34, 0.95);
}
.inkos-ws-title {
  display: block;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 8px;
}
.inkos-ws-tabs { display: flex; gap: 4px; }
.inkos-ws-tab {
  flex: 1;
  padding: 8px 0;
  border: none;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: #9a9aa4;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.inkos-ws-tab.active {
  color: #fff;
  border-bottom-color: #3b82f6;
  background: rgba(59, 130, 246, 0.12);
}

/* 内容区: 独立滚动 */
.inkos-ws-pane {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px;
  font-size: 13px;
}
.inkos-ws-pane::-webkit-scrollbar { width: 4px; }
.inkos-ws-pane::-webkit-scrollbar-thumb {
  background: rgba(128, 128, 128, 0.4);
  border-radius: 4px;
}
.inkos-ws-loading { color: #9a9aa4; padding: 16px 4px; }
.inkos-ws-empty { color: #9a9aa4; padding: 14px 4px; font-size: 12.5px; }
.inkos-ws-note {
  color: #8b8b96;
  font-size: 11.5px;
  line-height: 1.5;
  padding: 6px 4px 10px;
  border-bottom: 1px dashed rgba(128, 128, 128, 0.25);
  margin-bottom: 8px;
}

/* 路径栏: 返回上级 + 当前路径 */
.inkos-ws-pathbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 2px 10px;
  position: sticky;
  top: -10px;
  background: #16161c;
  z-index: 2;
}
.inkos-ws-up {
  flex-shrink: 0;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(128, 128, 128, 0.4);
  background: rgba(28, 28, 34, 0.9);
  color: #e8e8ec;
  font-size: 12px;
  cursor: pointer;
}
.inkos-ws-up:active { background: rgba(59, 130, 246, 0.5); }
.inkos-ws-cwd {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: rtl; /* 长路径靠左截断,保住文件名可见 */
  text-align: left;
  font-size: 12px;
  color: #b8b8c2;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* 文件/目录行 */
.inkos-ws-filelist, .inkos-ws-links { display: flex; flex-direction: column; gap: 2px; }
.inkos-ws-item, .inkos-ws-link {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 8px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #e8e8ec;
  text-align: left;
  font-size: 13px;
  cursor: pointer;
}
.inkos-ws-item:active, .inkos-ws-link:active { background: rgba(128, 128, 128, 0.16); }
.inkos-ws-item-icon { flex-shrink: 0; width: 20px; text-align: center; }
.inkos-ws-item-name {
  flex-shrink: 0;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.inkos-ws-item-meta {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  line-height: 1.45;
  color: #8b8b96;
  font-size: 11.5px;
  text-align: right;
}
.inkos-ws-link .inkos-ws-item-meta strong {
  color: #c8c8d0;
  font-weight: 600;
}

/* 文件预览: 等宽字体 + 可横向滚动 */
.inkos-ws-fileview { display: flex; flex-direction: column; gap: 8px; }

/* v1.14: 复制全文 / 下载 操作条 */
.inkos-ws-actions { display: flex; gap: 8px; }
.inkos-ws-action {
  flex: 1;
  padding: 9px 8px;
  border-radius: 8px;
  border: 1px solid rgba(96, 165, 250, 0.5);
  background: rgba(37, 99, 235, 0.22);
  color: #dbe6ff;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.inkos-ws-action:active { background: rgba(37, 99, 235, 0.5); }

/* v1.14: 复制兜底文本框(剪贴板 API 与 execCommand 都不可用时) */
.inkos-ws-copyfallback {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
  border: 1px dashed rgba(128, 128, 128, 0.4);
  background: rgba(0, 0, 0, 0.25);
}
.inkos-ws-copyfallback textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid rgba(128, 128, 128, 0.4);
  background: rgba(0, 0, 0, 0.35);
  color: #e8e8ec;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}
.inkos-ws-copyfallback button {
  align-self: flex-end;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid rgba(128, 128, 128, 0.4);
  background: rgba(28, 28, 34, 0.9);
  color: #e8e8ec;
  font-size: 12px;
  cursor: pointer;
}

.inkos-ws-pre {
  margin: 0;
  padding: 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(128, 128, 128, 0.25);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
  max-height: none;
  color: #d8d8e0;
}

/* 展开抽屉时,浮动按钮组的 ☰ 变 ✕ 高亮 */
body.inkos-ws-open #inkos-ws-btn {
  background: rgba(37, 99, 235, 0.9);
  border-color: rgba(96, 165, 250, 0.8);
}

/* 小屏(高度较低)时收紧内边距 */
@media (max-height: 600px) {
  .inkos-ws-head { padding: 6px 10px 0; }
  .inkos-ws-pane { padding: 8px; }
}
