/* ============================================================
   studio.css —— 创作沙盒（2026-11-19 重排版）
   ------------------------------------------------------------
   这一版只解决三件事：
     ① 整页固定在一屏 —— 页面本身不出现上下滚动条
     ② 三个区域各自独立上下滚动：AI 对话 / 程序源码 / 演示预览
     ③ 三个面板的头部统一（同样的高度、同样的标题层级），视觉一致

   ⚠️ 布局链（高度从哪来，不能断）：
     .app(100dvh) → .layout → .main.sandbox-mode(calc(100dvh - 56px))
       → .pagehead(flex:none) + .studio(flex:1,min-height:0) + .notice(flex:none)
         → 三栏 grid 行高 minmax(0,1fr)
           → 每栏内部再各自 flex column，最里层才是滚动容器

   ⚠️ 任何 min-height:XXXpx 都会把整页顶出滚动条 —— 一律改成 min-height:0，
      把高度让给 flex/grid 去算。
   ============================================================ */

/* ---------- ① 整页一屏 ---------- */
.main.sandbox-mode {
  height: calc(100dvh - 56px);   /* 减去顶部 56px 导航条 */
  max-width: none;               /* 沙盒是工作台，让它吃满宽度 */
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.main.sandbox-mode .pagehead {
  flex: none;
  align-items: center;
  margin-bottom: 12px;
}
.main.sandbox-mode .pagehead h1 { font-size: 19px; margin: 0; }
.main.sandbox-mode .pagehead .sub { font-size: 12.5px; }
.main.sandbox-mode .studio { flex: 1 1 auto; min-height: 0; }
.main.sandbox-mode > .notice {
  flex: none;
  margin-top: 10px;
  padding: 8px 12px;
  font-size: 11.5px;
  line-height: 1.55;
}

/* ---------- ② 三栏骨架 ----------
   用 flex 而不是 grid：隐藏一个面板后，剩下的区域自动铺满，
   不用为 8 种组合各写一条 grid-template-columns。 */
.studio {
  display: flex;
  gap: 0;
  height: 100%;
  min-height: 0;
}
.studio-ai   { flex: 0 0 clamp(320px, 24vw, 380px); }
.studio-code { flex: 1 1 0; min-width: 0; }
.studio-prev { flex: 0 0 clamp(340px, 28vw, 460px); }

/* 面板被隐藏 */
.studio-ai.is-off,
.studio-code.is-off,
.studio-prev.is-off { display: none; }
/* 只剩一个面板时，让它吃满整行（预览面板除外：它宽度固定） */
.studio.sg-one > .studio-ai,
.studio.sg-one > .studio-code { flex: 1 1 0; }
/* 代码面板藏了 → AI 对话框吃掉剩余宽度，模拟器保持最右、宽度不动 */
.studio.sg-nocode .studio-ai { flex: 1 1 clamp(320px, 24vw, 380px); }

/* ---------- 面板显隐切换按钮 ---------- */
.sg-panels { display: inline-flex; align-items: center; gap: 6px; }
.sg-pbtn {
  width: 30px; height: 30px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink3);
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; transition: color .16s, border-color .16s, background .16s, box-shadow .16s;
}
.sg-pbtn svg { width: 15px; height: 15px; }
.sg-pbtn:hover { color: var(--ink); border-color: var(--line2); }
.sg-pbtn.on {
  color: #22C55E;
  border-color: rgba(34,197,94,.38);
  background: rgba(34,197,94,.10);
  box-shadow: 0 4px 12px -6px rgba(34,197,94,.55);
}

/* 三栏面板本体：都必须是「列方向 flex + 内部可滚」 */
.studio-ai,
.studio-code,
.studio-prev {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  box-shadow: 0 10px 30px -22px rgba(16, 40, 90, .5);
}

/* ---------- 面板标题条（三栏统一高度） ---------- */
.sg-coltitle {
  font-size: 12px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: .2px;
  white-space: nowrap;
}
.sg-aihead, .sg-bar {
  flex: none;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: #FAFBFD;
}
.sg-aihead .muted, .sg-bar .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- 三栏之间的拖动条 ----------
   沙盒本身 gap:0 —— 面板之间的 12px 间距由拖动条本身占，
   这样加拖动条不会把源码栏挤窄。 */
.sg-split {
  flex: none; width: 12px; position: relative; z-index: 6;
  cursor: col-resize; touch-action: none; user-select: none;
}
.sg-split i {
  position: absolute; left: 50%; top: 14px; bottom: 14px; width: 3px; margin-left: -1.5px;
  border-radius: 3px; background: transparent; transition: background .15s;
}
.sg-split:hover i { background: var(--blue); }
body.sg-dragging { cursor: col-resize; }
body.sg-dragging .sg-split i { background: var(--blue); }
body.sg-dragging * { user-select: none; }

/* ---------- 目标形态切换 ---------- */
.sg-kinds { display: inline-flex; gap: 0; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: #fff; }
.sg-kind {
  padding: 7px 16px; border: 0; cursor: pointer; font-family: inherit;
  font-size: 13px; font-weight: 700; color: var(--ink3); background: transparent;
}
.sg-kind:hover { color: var(--ink); }
.sg-kind.on { background: linear-gradient(135deg, var(--blue), #2E85FF); color: #fff; }

/* ---------- ① AI 对话栏 ---------- */
.sg-aibody {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  display: flex;
  position: relative;
}
/* 沙盒里不留 chatbot 的会话列表栏（那是全屏工作台用的）——
   320px 的栏再塞 176px 的侧栏，消息流只剩 140px，文字会竖排成单字。
   需要看历史时用右上角按钮拉出抽屉。 */
.studio-ai .cb {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr);
  border: 0;
  border-radius: 0;
  background: #fff;
}
.studio-ai .cb-side { display: none; }
.studio-ai.sb-drawer .cb-side {
  display: flex;
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 190px;
  z-index: 30;
  box-shadow: 0 16px 38px -16px rgba(16, 40, 90, .45);
}
/* 欢迎区往下面放 —— 原来垂直居中，上面空一大片，看着像没加载出来 */
.studio-ai .cb-welcome { padding: 18px 14px 26px; justify-content: flex-end; }
.studio-ai .cb-hero { font-size: 22px; margin-bottom: 14px; }
.studio-ai .cb-quick { gap: 7px; margin-top: 14px; }
.studio-ai .cb-chip { height: 36px; padding: 0 12px; font-size: 12.5px; }
.studio-ai .cb-thread { padding: 14px 12px 4px; }
.studio-ai .cb-dock { padding: 6px 12px 12px; }
.studio-ai .cb-bubble { max-width: 88%; font-size: 13px; }
.studio-ai .cb-card { padding: 14px 14px; }
/* 语音输入按钮（沙盒侧插入，不改 chatbot.js） */
.studio-ai .cb-mic { left: 52px; }
.studio-ai .cb-mic.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.studio-ai .cb-mic.off { opacity: .38; cursor: not-allowed; }

/* ---------- ② 程序（源码）栏 ---------- */
.studio-code {
  display: grid;
  grid-template-columns: 172px minmax(0, 1fr);
  padding: 0;
}
.sg-tree {
  border-right: 1px solid var(--line); background: #FAFBFD; overflow-y: auto;
  padding: 8px 0; font-size: 12.5px;
}
.sg-file {
  padding: 6px 10px; cursor: pointer; color: var(--ink2); font-family: var(--mono);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sg-file:hover { background: rgba(0,102,255,.07); color: var(--blue); }
.sg-file.on { background: rgba(0,102,255,.12); color: var(--blue); font-weight: 700; }
.sg-dir { color: var(--ink3); }
.sg-caret { display: inline-block; width: 12px; font-size: 10px; }
.sg-name { font-family: var(--mono); }
.sg-kids { padding-bottom: 4px; }
.sg-code { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.sg-code .sb-head { flex: none; gap: 8px; }
.sg-code .sb-head .sg-cur {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sg-code .sb-head .muted { flex: none; white-space: nowrap; }
.sg-cur { font-family: var(--mono); font-size: 12.5px; font-weight: 700; color: var(--ink2); }

/* 代码区自己滚 —— min-height 必须清零，否则整页被顶出滚动条 */
.studio-code .sg-code .codearea {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  resize: none;
  overflow: auto;
}

/* ---------- ③ 演示（预览）栏 ---------- */
.sg-bar { flex: none; }
.sg-dots { display: inline-flex; gap: 5px; }
.sg-dots i { width: 9px; height: 9px; border-radius: 50%; background: #E3EAF6; }
.sg-run { font-size: 12px; color: var(--ink3); white-space: nowrap; }
.sg-ok { color: var(--green); }
/* 小程序预览的如实标注（教学简化版，不是微信官方引擎） */
.sg-mini-tag {
  flex: none; font-size: 10.5px; font-weight: 700; color: #A8440E; background: #FFF4E6;
  border: 1px solid #FFE0BF; border-radius: 999px; padding: 2px 9px; white-space: nowrap;
}
.sg-ico {
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer; flex: none;
  border: 1px solid var(--line); background: #fff; color: var(--ink3);
  display: inline-flex; align-items: center; justify-content: center;
}
.sg-ico:hover { border-color: var(--blue); color: var(--blue); }
.sg-ico svg { width: 14px; height: 14px; }

/* 舞台 = 演示区自己的滚动容器 */
.sg-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; background:
    radial-gradient(420px 260px at 80% 0%, rgba(0,102,255,.06), transparent 62%),
    radial-gradient(380px 240px at 10% 100%, rgba(250,219,20,.10), transparent 64%),
    #fff;
  overflow: auto;
}

/* 手机模拟器（小程序）—— 比例锁死
   ⚠️ 小程序内容按 **750rpx 宽**设计（mini_runtime.js 里 1rpx = 0.5px），
   屏幕区必须是 **375 × 710**（= 750rpx × 1420rpx），否则内容比屏幕宽
   → 出现横向滚动条、内容被切。
   手机壳外宽 = 375 + 边框 8×2 = **391**；屏高固定 710，
   舞台不够高就整体等比缩小（JS 里 scale）—— **屏幕缩放/窗口变矮都不会变形**。 */
.sg-phone-fit { flex: none; display: flex; justify-content: center; }
.sg-phone {
  width: 391px; flex: none; transform-origin: top center;
  border-radius: 34px; overflow: hidden;
  background: #12151C; box-shadow: 0 24px 50px -24px rgba(16,32,64,.5);
  border: 8px solid #1B1F29;
  display: flex; flex-direction: column;
}
.sg-phone-top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 14px; background: #1B1F29; color: #E6EAF2;
  font-size: 11px; font-family: var(--mono); flex: none;
}
.sg-phone-right { letter-spacing: 1px; opacity: .8; }
/* 屏幕区固定 375 × 710（= 750rpx × 1420rpx），里面用绝对定位铺满 iframe
   —— flex 里写 height:100% 会算成 0（高度循环依赖） */
.sg-screen { background: #fff; flex: none; height: 710px; position: relative; }
.sg-screen .preview-frame {
  position: absolute; inset: 0; width: 100%; height: 100%; border: 0; display: block;
}
.sg-phone-home {
  height: 22px; background: #1B1F29; position: relative; flex: none;
}
.sg-phone-home::after {
  content: ""; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 110px; height: 4px; border-radius: 2px; background: rgba(255,255,255,.42);
}

/* 浏览器窗口（网页） */
.sg-browser {
  width: 100%; height: 100%; min-height: 320px; border-radius: 12px; overflow: hidden;
  background: #fff; border: 1px solid var(--line); display: flex; flex-direction: column;
  box-shadow: 0 18px 40px -26px rgba(16,40,90,.4);
}
.sg-browser-bar {
  display: flex; align-items: center; gap: 7px; padding: 8px 12px;
  background: #F2F5FA; border-bottom: 1px solid var(--line); flex: none;
}
.sg-browser-bar .dot { width: 10px; height: 10px; border-radius: 50%; }
.sg-url {
  margin-left: 8px; font-size: 12px; color: var(--ink3);
  background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 2px 12px;
}
.sg-browser .preview-frame { flex: 1; width: 100%; border: 0; display: block; }

/* 演示区全屏：面板铺满整个视口 */
.studio-prev.sg-fs {
  position: fixed; inset: 0; z-index: 980; border: 0; border-radius: 0;
  box-shadow: none;
}

/* ---------- 窄屏：放弃「一屏固定」，回到常规滚动 ---------- */
@media (max-width: 1240px) {
  .main.sandbox-mode { height: auto; overflow: visible; }
  .studio {
    flex-direction: column;
    height: auto;
  }
  .sg-split { display: none; }   /* 竖排时没有左右可拖 */
  .studio-ai, .studio-code, .studio-prev { flex: 0 0 auto; }
  .studio-ai { min-height: 520px; }
  .studio-code { min-height: 460px; }
  .studio-prev { min-height: 480px; }
  .studio.sg-one > .studio-ai,
  .studio.sg-one > .studio-code,
  .studio.sg-one > .studio-prev { flex: 0 0 auto; }
  .studio.sg-nocode .studio-ai { flex: 0 0 auto; }
  .studio-code { grid-template-columns: 168px minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .studio-code { grid-template-columns: 1fr; }
  .sg-tree {
    display: flex; gap: 6px; overflow-x: auto; overflow-y: hidden;
    border-right: 0; border-bottom: 1px solid var(--line); padding: 6px 8px;
  }
  .sg-dir { display: none; }
  .sg-file { padding: 5px 10px; }
}
