/* ============================================================
   小面包拼豆 · desktop-layout.css
   图片生成板块桌面端工作台（≥900px 生效）

   设计口径（2026-11-10 用户确认，效果图 design-explorations/ui-layout-v1.html v1.1）：
   - A 方案：图纸满幅做主体，原图缩成可拖动的参照小窗
   - 各种数据调节统一放左栏，右侧大面积给预览
   - 固定高度，整页不滚动，只有左栏与画布各自内部滚动
   - 小窗可拖动 / 颜色清单默认展开 / 结果区生成后出现 / 选色替换浮在左侧

   加载顺序：style.css → outbound.css → skin.css → desktop-layout.css（本文件最后）
   作用域：全部规则都包在 @media (min-width:900px) + body.dl-on 之下，
           dl-on 由 js/desktop-layout.js 在 ≥900px 时添加；<900px 与「出库助手」
           分栏下本文件不产生任何效果，DOM 与样式保持原样。
   禁止事项：不要在本文件里给 .result-section / #previewSection / #editPanel
           声明 display（这些由 app.js 写行内 style 控制显隐）。
   ============================================================ */

@media (min-width: 900px) {

  /* ---------- 1. 固定视口：整页不滚动 ---------- */
  body.dl-on:not(.ob-mode) {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    padding-bottom: 0;
  }
  /* 底部导出栏是 fixed，生成后给它留出高度，避免盖住画布 */
  body.dl-on.dl-has-result:not(.ob-mode) { padding-bottom: 72px; }

  body.dl-on:not(.ob-mode) .header {
    position: relative;
    top: auto;
    flex: 0 0 52px;
  }
  body.dl-on:not(.ob-mode) .mode-switcher {
    position: relative;
    top: auto;
    flex: 0 0 46px;
  }
  body.dl-on:not(.ob-mode) .app-version {
    position: fixed;
    right: 8px;
    bottom: 2px;
    z-index: 1;
    font-size: 10px;
    pointer-events: none;
  }

  /* ---------- 2. 两栏：左 328px 控件栏 / 右自适应预览台 ---------- */
  body.dl-on:not(.ob-mode) .main-layout {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 12px 14px;
    gap: 12px;
    display: grid;
    grid-template-columns: 328px minmax(0, 1fr);
    align-items: stretch;
  }

  /* 左栏：独立滚动，原来的 sticky 垂直居中全部取消 */
  body.dl-on .left-panel {
    position: relative;
    top: auto;
    transform: none;
    flex: none;
    width: auto;
    max-width: none;
    max-height: none;
    height: 100%;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding-right: 4px;
  }
  body.dl-on .left-panel::-webkit-scrollbar { width: 6px; }
  body.dl-on .left-panel::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }
  body.dl-on .left-panel::-webkit-scrollbar-track { background: transparent; }

  /* 原本包住上传卡的空壳里只剩隐藏的拍立得/缩放预览卡，桌面端不占位 */
  body.dl-on .left-panel > .preview-sticky { display: none; }

  body.dl-on .left-panel > .card,
  body.dl-on .left-panel > .generate-btn,
  body.dl-on .left-panel > .dl-result-group { margin-bottom: 10px; }

  /* 右栏：预览台 */
  body.dl-on .right-panel {
    position: relative;
    min-width: 0;
    min-height: 0;
    height: 100%;
    width: auto;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    overflow: hidden;
  }
  /* 已下线的两个模式卡片都带行内 display:none，这里不额外处理 */

  /* ---------- 3. 预览台工具条 ---------- */
  .dl-stagebar {
    flex: 0 0 38px;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 0 11px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
  }
  .dl-stagebar::-webkit-scrollbar { height: 0; }
  .dl-stagebar .dl-title { font-family: var(--font-ui); font-size: 11.5px; font-weight: 650; flex: 0 0 auto; }
  .dl-stagebar .dl-badge {
    font-family: var(--font-mono); font-size: 10px; color: var(--ink-3);
    background: #F5F3F7; border-radius: 4px; padding: 2px 6px; flex: 0 0 auto;
  }
  .dl-stagebar .dl-sep { width: 1px; height: 18px; background: var(--line); flex: 0 0 auto; }
  .dl-stagebar .dl-hint {
    font-size: 10.5px; color: var(--ink-3); flex: 0 0 auto; margin-left: auto;
  }
  body.dl-on:not(.dl-state-gen) .dl-stagebar .dl-hint { display: none; }

  .dl-stagebar-controls { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
  body.dl-on:not(.dl-has-result) .dl-stagebar-controls { display: none; }

  /* 从 #resultSection 搬上来的两组开关，压成一行工具条（有行内 style，需 !important） */
  body.dl-on .dl-stagebar-controls .display-options {
    margin: 0 !important;
    gap: 7px !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
  }
  body.dl-on .dl-stagebar-controls .switch-group { padding: 0; gap: 5px; }
  body.dl-on .dl-stagebar-controls .switch-label { font-size: 11px; }
  body.dl-on .dl-stagebar-controls .bg-mode-selector { gap: 2px; }
  body.dl-on .dl-stagebar-controls .bg-mode-btn { padding: 3px 8px; font-size: 11px; }
  body.dl-on .dl-stagebar-controls .dl-edit-switch-wrap {
    margin-left: 0 !important;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
  }
  body.dl-on .dl-stagebar-controls .dl-edit-switch-wrap #editModeSwitch { margin-left: 0 !important; }

  /* ---------- 4. 画布区：图纸满幅 ---------- */
  .dl-canvaswrap {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 14px;
    overflow: auto;
    background-color: var(--bench);
    background-image: radial-gradient(circle at 1px 1px, rgba(36, 33, 43, .06) 1px, transparent 0);
    background-size: 18px 18px;
  }
  .dl-canvaswrap::-webkit-scrollbar { width: 7px; height: 7px; }
  .dl-canvaswrap::-webkit-scrollbar-thumb { background: rgba(36, 33, 43, .2); border-radius: 4px; }

  body.dl-on .dl-canvaswrap > #resultSection {
    width: 100%;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    position: relative;
  }
  /* 卡片标题里的编辑开关已移到工具条，标题本身在桌面端不占位 */
  body.dl-on .dl-canvaswrap > #resultSection > .card-title { display: none; }

  body.dl-on #resultPreview {
    height: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 12px;
    border-radius: 0;
    background: transparent;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    position: relative;
    overflow: hidden;
  }
  /* v2026.11.23a 无限画布：world canvas 绝对定位，视口平移/缩放由
     app.js previewView 用 transform 控制（transform-origin:0 0），
     初始视口由 locatePatternView 对准内容包围盒居中。 */
  body.dl-on #resultPreview > canvas {
    position: absolute;
    left: 0;
    top: 0;
    max-width: none;
    max-height: none;
    width: auto;
    height: auto;
    margin: 0;
    border-radius: 4px;
    box-shadow: var(--sh-2);
    transform-origin: 0 0;
  }
  body.dl-on .dl-canvaswrap #editTip {
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    margin: 0;
    background: rgba(255, 255, 255, .9);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
  }

  /* 空状态：与效果图一致，右侧同一块位置显示上传提示 */
  .dl-empty-hint { display: none; }
  body.dl-on.dl-state-empty .dl-empty-hint {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;
    margin: auto;
    width: min(70%, 560px);
    min-height: 260px;
    border: 1.5px dashed var(--line-strong);
    border-radius: var(--r);
    background: rgba(255, 255, 255, .6);
    color: var(--ink-2);
    text-align: center;
  }
  .dl-empty-hint b { font-size: 15px; font-weight: 600; color: var(--ink); }
  .dl-empty-hint span { font-size: 11.5px; color: var(--ink-3); }
  .dl-empty-hint button {
    margin-top: 5px;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    border-radius: var(--r-xs);
    padding: 7px 14px;
    font-size: 11.5px;
    cursor: pointer;
  }
  .dl-empty-hint button:hover { border-color: var(--ink-3); }

  /* ---------- 5. 浮层承载层：不随画布滚动 ---------- */
  .dl-stage-float {
    position: absolute;
    left: 0;
    right: 0;
    top: 38px;
    bottom: 0;
    z-index: 6;
    overflow: hidden;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .dl-stage-float > * { pointer-events: auto; }

  /* 未生成：原图占满预览台 */
  body.dl-on.dl-state-upload .dl-stage-float > #previewSection {
    width: min(80%, 900px);
    height: min(88%, 760px);
    margin: 0;
    padding: 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--r);
    background: var(--surface);
    box-shadow: var(--sh-2);
    box-sizing: border-box;
  }
  body.dl-on.dl-state-upload #previewSection .card-title { margin-bottom: 8px; }
  body.dl-on.dl-state-upload #previewSection .preview-original {
    height: calc(100% - 38px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
  }
  body.dl-on.dl-state-upload #previewSection .preview-original img {
    max-width: 100%;
    max-height: calc(100% - 30px);
    width: auto;
    height: auto;
    object-fit: contain;
  }
  body.dl-on.dl-state-upload #previewSection .change-btn { margin-top: 6px; }

  /* 已生成：原图缩为可拖动小窗（标题栏是拖动手柄） */
  body.dl-on.dl-state-gen .dl-stage-float > #previewSection {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 212px;
    height: auto;
    margin: 0;
    padding: 0;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-sm);
    background: var(--surface);
    box-shadow: var(--sh-3);
    overflow: hidden;
    z-index: 5;
  }
  body.dl-on.dl-state-gen #previewSection .card-title {
    margin: 0;
    padding: 5px 8px;
    border-bottom: 1px solid var(--line);
    background: #FDFCFB;
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: 600;
    gap: 5px;
    cursor: grab;
    user-select: none;
    touch-action: none;
  }
  body.dl-on.dl-state-gen #previewSection .card-title .icon { font-size: 12px; }
  body.dl-on.dl-state-gen #previewSection .crop-btn {
    margin-left: auto !important;
    padding: 2px 6px !important;
    font-size: 10.5px !important;
    background: var(--surface) !important;
    color: var(--ink-2) !important;
    border: 1px solid var(--line) !important;
  }
  body.dl-on.dl-state-gen #previewSection .preview-original { padding: 6px; text-align: center; }
  body.dl-on.dl-state-gen #previewSection .preview-original img { max-height: 140px; max-width: 100%; }
  body.dl-on.dl-state-gen #previewSection .change-btn { margin-top: 4px; font-size: 11px; }

  .dl-pip-grip, .dl-pip-btn, .dl-pip-resize { display: none; }
  body.dl-on .dl-pip-grip { display: inline; font-size: 10px; color: var(--ink-3); letter-spacing: -1px; }
  body.dl-on .dl-pip-btn {
    display: inline-block;
    border: 0;
    background: transparent;
    color: var(--ink-3);
    font-size: 11px;
    line-height: 1;
    padding: 2px 4px;
    border-radius: 3px;
    cursor: pointer;
    margin-left: 2px;
  }
  body.dl-on .dl-pip-btn:hover { background: var(--line); color: var(--ink); }
  body.dl-on.dl-state-gen #previewSection.dl-pip-free { right: auto; bottom: auto; }
  body.dl-on.dl-state-gen #previewSection.dl-pip-folded { height: 30px; }
  body.dl-on.dl-state-gen #previewSection.dl-dragging {
    z-index: 9;
    box-shadow: 0 28px 70px rgba(36, 33, 43, .30);
  }
  body.dl-on.dl-state-gen #previewSection.dl-dragging .card-title { cursor: grabbing; background: #FFF6DF; }

  /* 自由缩放：右下角手柄 + 尺寸固化后图片随容器放大 */
  body.dl-on.dl-state-gen .dl-pip-resize {
    display: block;
    position: absolute;
    right: 0;
    bottom: 0;
    width: 15px;
    height: 15px;
    z-index: 8;
    cursor: nwse-resize;
    touch-action: none;
    border-bottom-right-radius: var(--r-sm);
    background:
      linear-gradient(135deg, transparent 0 45%, var(--ink-3) 45% 54%, transparent 54% 64%,
        var(--ink-3) 64% 73%, transparent 73% 82%, var(--ink-3) 82% 91%, transparent 91%);
    opacity: .55;
  }
  body.dl-on.dl-state-gen .dl-pip-resize:hover { opacity: 1; }
  body.dl-on.dl-state-gen #previewSection.dl-pip-folded .dl-pip-resize { display: none; }
  body.dl-on.dl-state-gen #previewSection.dl-pip-resizing { user-select: none; }
  body.dl-on.dl-state-gen #previewSection.dl-pip-resizing .dl-pip-resize { opacity: 1; }
  body.dl-on.dl-state-gen #previewSection.dl-pip-sized .preview-original {
    height: calc(100% - 30px);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 6px;
  }
  body.dl-on.dl-state-gen #previewSection.dl-pip-sized .preview-original img {
    flex: 1 1 auto;
    min-height: 0;
    max-height: 100%;
    max-width: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
  }
  body.dl-on.dl-state-gen #previewSection.dl-pip-sized .preview-original .change-btn {
    flex: 0 0 auto;
  }

  /* 选色替换：浮在预览台左侧，不占左栏常驻位 */
  body.dl-on .dl-stage-float > #editPanel {
    position: absolute;
    left: 14px;
    top: 14px;
    width: 244px;
    max-height: calc(100% - 28px);
    overflow-y: auto;
    margin: 0;
    padding: 10px;
    border-color: var(--line-strong);
    border-radius: var(--r-sm);
    box-shadow: var(--sh-3);
    z-index: 7;
  }
  body.dl-on .dl-stage-float > #editPanel .card-title { font-size: 12px; margin-bottom: 8px; }
  body.dl-on .dl-stage-float > #editPanel .edit-colors { gap: 6px; }

  /* 编辑浮层内置的一份显示开关（代理，不改 app.js 的原控件与绑定） */
  .dl-mini-opts {
    margin: 10px 0 2px;
    padding: 8px 0 2px;
    border-top: 1px dashed var(--line-strong);
  }
  .dl-mini-head {
    font-family: var(--font-ui);
    font-size: 10.5px;
    font-weight: 600;
    color: var(--ink-3);
    margin-bottom: 7px;
  }
  .dl-mini-row { display: flex; align-items: flex-start; gap: 7px; margin-bottom: 6px; }
  .dl-mini-row > span {
    flex: 0 0 28px;
    font-size: 10.5px;
    color: var(--ink-3);
    line-height: 20px;
  }
  .dl-mini-bg {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: var(--r-xs);
    overflow: hidden;
    background: #F7F5F8;
  }
  .dl-mini-bg button {
    border: 0;
    border-right: 1px solid var(--line);
    background: transparent;
    color: var(--ink-2);
    font-family: var(--font-ui);
    font-size: 10.5px;
    padding: 3px 8px;
    cursor: pointer;
  }
  .dl-mini-bg button:last-child { border-right: 0; }
  .dl-mini-bg button.on { background: var(--cta); color: var(--cta-fg); font-weight: 650; }
  .dl-mini-bg button:hover:not(.on) { background: var(--line); }
  .dl-mini-toggles { display: flex; flex-wrap: wrap; gap: 4px; }
  .dl-mini-toggles button {
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--ink-3);
    border-radius: 999px;
    font-family: var(--font-ui);
    font-size: 10.5px;
    padding: 3px 9px;
    cursor: pointer;
  }
  .dl-mini-toggles button.on { background: var(--ink); border-color: var(--ink); color: #fff; }
  .dl-mini-toggles button:hover:not(.on) { border-color: var(--ink-3); }

  /* ---------- 6. 左栏结果区：只在生成后出现 ---------- */
  body.dl-on .dl-result-group { display: none; }
  body.dl-on.dl-has-result .dl-result-group { display: block; }
  .dl-result-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: var(--font-ui);
    font-size: 11.5px;
    font-weight: 650;
    color: var(--ink-2);
    padding: 2px 2px 8px;
  }
  .dl-result-sub { font-size: 10.5px; font-weight: 400; color: var(--ink-3); }
  body.dl-on .dl-result-group > .card { margin-bottom: 10px; }
  /* 统计放左栏后收成三格小卡 */
  body.dl-on .dl-result-group > .stats { gap: 6px; margin-bottom: 10px; }
  body.dl-on .dl-result-group > .stats .stat-item {
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    padding: 7px 4px;
  }
  /* 颜色清单默认展开：不折叠、不设 height 上限以外的隐藏 */
  body.dl-on .dl-result-group .color-list { max-height: 220px; }

  /* 生成按钮固定在左栏控件流里，保持奶油黄唯一主行动 */
  body.dl-on .left-panel > .generate-btn { flex: 0 0 auto; }

  /* ---------- 7. 竖版布局：图纸高 > 宽时工具列移到页面右侧 ----------
     setOrientation() 把工具条开关、选色面板、本次结果组搬进 .dl-aside，
     中间预览台整列让给竖图完整显示（左右两侧放工具及按钮）。 */
  body.dl-on:not(.dl-vertical) .dl-aside { display: none; }

  body.dl-on.dl-vertical:not(.ob-mode) .main-layout {
    grid-template-columns: 300px minmax(0, 1fr) 280px;
  }
  body.dl-on.dl-vertical:not(.ob-mode) .dl-aside {
    display: block;
    min-height: 0;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding-right: 4px;
  }
  body.dl-on.dl-vertical .dl-aside::-webkit-scrollbar { width: 6px; }
  body.dl-on.dl-vertical .dl-aside::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 3px; }
  body.dl-on.dl-vertical .dl-aside::-webkit-scrollbar-track { background: transparent; }

  /* 工具条开关：从预览台顶部横排改为右栏竖排 */
  body.dl-on.dl-vertical .dl-aside > .dl-stagebar-controls {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 10px;
    padding: 10px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
  }
  body.dl-on.dl-vertical .dl-aside > .dl-stagebar-controls .display-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
  }
  /* 竖版时预览台顶部只剩标题/徽章，提示文案收进右栏没必要占一行 */
  body.dl-on.dl-vertical .dl-stagebar .dl-hint { display: none; }

  /* 选色面板：从浮层 absolute 改为右栏静态卡片 */
  body.dl-on.dl-vertical .dl-aside > #editPanel {
    width: auto;
    max-height: none;
    overflow: visible;
    margin: 0 0 10px;
    padding: 10px;
    border-radius: var(--r-sm);
  }

  /* 本次结果组：左栏 → 右栏 */
  body.dl-on.dl-vertical .dl-aside > .dl-result-group { margin-bottom: 10px; }
  body.dl-on.dl-vertical .dl-aside .color-list { max-height: 320px; }

  /* ---------- 8. 动效降级 ---------- */
  @media (prefers-reduced-motion: reduce) {
    body.dl-on .dl-result-group { animation: none !important; }
  }
  body.dl-on.dl-has-result .dl-result-group { animation: dlRiseIn .3s var(--ease) both; }
  @keyframes dlRiseIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
  }
}
