/* ========================================
   Aibao 移动端响应式样式 — 全量改造
   触发条件：html.is-mobile (width < 768px)
             html.is-tablet (768px ≤ width < 1024px)
   配合 app.js 自动检测设备类型给 html 加 class
   一套代码、一套数据库、纯 CSS / JS 无 localStorage
   ======================================== */

/* ==========================================
   第一部分：手机端 (html.is-mobile, <768px)
   ========================================== */

/* ----- 通用：容器、间距、字体 ----- */
html.is-mobile .container,
html.is-mobile .container-sm { padding: 0 12px; }
html.is-mobile .section { padding: 28px 0; }
html.is-mobile .section-title { margin-bottom: 24px; }
html.is-mobile .section-title h2 { font-size: 20px; }
html.is-mobile .section-title p { font-size: 13px; }

html.is-mobile body { font-size: 14px; }

/* 按钮缩小 */
html.is-mobile .btn { padding: 8px 16px; font-size: 13px; }
html.is-mobile .btn-lg { padding: 12px 20px; font-size: 14px; }
html.is-mobile .btn-sm { padding: 5px 12px; font-size: 12px; }

/* ----- 导航栏：横向条目常驻显示 ----- */
html.is-mobile .nav-toggle { display: none !important; }
html.is-mobile .nav-links { display: flex !important; flex-direction: row; gap: 12px; align-items: center; }
html.is-mobile .nav-links a { font-size: 12px; padding: 4px 0; }
html.is-mobile .nav-links a.active::after { bottom: -8px; }
html.is-mobile .navbar-inner { height: 48px; padding: 0 10px; }
html.is-mobile .logo-icon { width: 28px; height: 28px; }
html.is-mobile .logo-text { font-size: 14px; }
html.is-mobile .navbar { top: 0; }

/* ----- 首页 Hero ----- */
html.is-mobile .hero { padding: 32px 0 40px; }
html.is-mobile .hero h1 { font-size: 20px; margin-bottom: 10px; }
html.is-mobile .hero p { font-size: 13px; margin-bottom: 24px; padding: 0 8px; }
html.is-mobile .hero-buttons { gap: 8px; }

/* ----- 特性卡片 ----- */
html.is-mobile .feature-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 12px; }
/* ★ 但「注意事项」页面的卡片要单列 */
html.is-mobile .feature-grid[style*="grid-template-columns:1fr"],
html.is-mobile .feature-grid[style*="grid-template-columns: 1fr"] { grid-template-columns: 1fr !important; }
/* ★ 注意事项页面：卡片内文字不要单字换行 */
html.is-mobile .feature-card { word-break: break-word; overflow-wrap: break-word; }
html.is-mobile .feature-card h3 { word-break: keep-all; }
html.is-mobile .feature-card { padding: 24px 18px; }
html.is-mobile .feature-card h3 { font-size: 15px; }
html.is-mobile .feature-card p { font-size: 12px; }

/* ----- 模板展厅 ----- */
html.is-mobile .template-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
html.is-mobile .template-card { border-radius: 10px; }
html.is-mobile .template-info { padding: 10px; }
html.is-mobile .template-info h3 { font-size: 13px; }
html.is-mobile .template-info p { font-size: 11px; }
html.is-mobile .template-price .price { font-size: 14px; }
html.is-mobile .template-price .pages { font-size: 11px; }

/* 分类按钮横向滚动 */
html.is-mobile .category-bar { gap: 6px; margin-bottom: 20px; }
html.is-mobile .category-bar .cat-row {
  flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
  justify-content: flex-start; padding-bottom: 6px; max-width: 100%;
}
html.is-mobile .category-bar button { padding: 5px 14px; font-size: 12px; flex-shrink: 0; }

/* ----- 模板预览页 ----- */
html.is-mobile #tpl-pages-preview-grid {
  grid-template-columns: repeat(2, 1fr) !important; gap: 8px;
}

/* ----- 登录页 ----- */
html.is-mobile .login-page { min-height: calc(100vh - 52px); padding: 20px 12px; }
html.is-mobile .login-card { padding: 24px 16px; border-radius: 14px; }
html.is-mobile .login-card h2 { font-size: 18px; }
html.is-mobile .login-card .subtitle { font-size: 12px; margin-bottom: 20px; }
html.is-mobile .tab-group button { padding: 8px; font-size: 13px; }
html.is-mobile .form-group { margin-bottom: 14px; }
html.is-mobile .form-group input,
html.is-mobile .form-group select,
html.is-mobile .form-group textarea { font-size: 14px; padding: 10px 12px; }
html.is-mobile .balance-card { padding: 14px; }
html.is-mobile .balance-card .balance-amount { font-size: 24px; }

/* ----- 我的作品 ----- */
html.is-mobile .works-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
html.is-mobile .work-actions { flex-wrap: wrap; }
html.is-mobile .work-actions .btn { flex: 1; font-size: 12px; padding: 6px 10px; }

/* ==========================================
   第二部分：制作编辑页 (workbench) — 重点优化
   ========================================== */

/* 顶栏精简 */
html.is-mobile .workbench-header { position: sticky; top: 0; z-index: 900; }
html.is-mobile .workbench-header-inner {
  flex-wrap: wrap; gap: 6px; padding: 8px 12px; height: auto;
}
html.is-mobile .workbench-header-inner h2 { font-size: 14px; }
html.is-mobile .workbench-header-inner .code-info { font-size: 10px; width: 100%; }
html.is-mobile .workbench-header-inner > div:last-child { width: 100%; display: flex; gap: 6px; justify-content: flex-end; }
html.is-mobile .workbench-header-inner > div:last-child .btn { font-size: 11px; padding: 4px 8px; }

/* 制作页主体：单列堆叠 + 折叠面板 */
html.is-mobile .workbench-body {
  grid-template-columns: 1fr !important;
  padding: 8px !important; gap: 8px;
  max-width: 100vw !important;
  overflow-x: hidden;
  display: flex !important;
  flex-direction: column !important;
}
html.is-mobile .workbench-body > * { max-width: 100% !important; width: 100% !important; box-sizing: border-box !important; flex-shrink: 0 !important; }
html.is-mobile .workbench { overflow-x: hidden; }
html.is-mobile .workbench .container { max-width: 100% !important; }

/* 左侧面板（儿童信息 + 按钮 + 参考图）→ 排第一，默认展开 */
html.is-mobile .workbench-body .panel.left-panel { order: 1; }
/* ★ 手机端：参考图示例 + 儿童信息 横向并排 */
html.is-mobile .mobile-ref-info-row { display: flex !important; gap: 8px; align-items: flex-start; }
html.is-mobile .mobile-ref-col { width: 45%; flex-shrink: 0; }
html.is-mobile .mobile-info-col { flex: 1; min-width: 0; }
/* 参考图示例：图片按框显示 + 单列大图 */
html.is-mobile .mobile-ref-col [id^="ref-example-grid"] { display: flex !important; flex-direction: column !important; gap: 4px !important; padding: 6px !important; }
html.is-mobile .mobile-ref-col [id^="ref-example-grid"] > div { width: 100% !important; aspect-ratio: 1/1; max-width: 100% !important; overflow: hidden; }
html.is-mobile .mobile-ref-col [id^="ref-example-grid"] > div img { width: 100% !important; height: 100% !important; max-width: 100% !important; max-height: 100% !important; object-fit: cover; }
/* 人物信息标题：纯文字（不可折叠） */
html.is-mobile .mobile-info-title { font-size: 12px !important; padding-bottom: 4px !important; margin-bottom: 4px !important; }
/* ★ 字段紧凑：双列 2x2 网格布局 */
html.is-mobile .mobile-info-fields { display: grid !important; grid-template-columns: 1fr 1fr; gap: 4px 6px !important; }
html.is-mobile .mobile-info-fields > .mobile-field { margin-bottom: 0 !important; }
html.is-mobile .mobile-info-fields > .mobile-field input,
html.is-mobile .mobile-info-fields > .mobile-field select { width: 100% !important; font-size: 10px !important; padding: 3px 4px !important; }
html.is-mobile .mobile-info-fields > .mobile-field label { font-size: 9px !important; margin-bottom: 1px !important; }
/* 称呼和保存按钮跨整行 */
html.is-mobile .mobile-info-fields > #child-name,
html.is-mobile .mobile-info-fields > input#child-name,
html.is-mobile .mobile-info-fields > .form-group:first-child { grid-column: 1 / -1; }
html.is-mobile .mobile-info-fields > button[onclick*="saveChildInfo"] { grid-column: 1 / -1; padding: 4px !important; font-size: 11px !important; }
/* 参考图和人物信息两栏等高 */
html.is-mobile .mobile-ref-info-row { align-items: stretch !important; }
html.is-mobile .mobile-ref-col,
html.is-mobile .mobile-info-col { align-self: stretch; }
html.is-mobile .workbench-body .panel.left-panel .panel-title {
  cursor: pointer; user-select: none; margin-bottom: 0;
}
html.is-mobile .workbench-body .panel.left-panel .panel-title::after {
  content: ' ▼'; font-size: 10px; opacity: 0.5;
}
html.is-mobile .workbench-body .panel.left-panel.collapsed .panel-title::after {
  content: ' ▶'; 
}
html.is-mobile .workbench-body .panel.left-panel.collapsed > *:not(.panel-title) {
  display: none;
}

/* 右侧面板 → 排第二 */
html.is-mobile .workbench-body .panel.right-panel { order: 2; padding: 12px 10px; }
html.is-mobile .workbench-body .panel.right-panel .panel-title {
  cursor: pointer; user-select: none; margin-bottom: 0; font-size: 13px; padding-bottom: 8px;
}
html.is-mobile .workbench-body .panel.right-panel .panel-title::after {
  content: ' ▼'; font-size: 10px; opacity: 0.5;
}
html.is-mobile .workbench-body .panel.right-panel.collapsed .panel-title::after {
  content: ' ▶';
}
/* ★ 右面板：本页操作区（#page-operation-panel）永远不折叠 */
html.is-mobile .workbench-body .panel.right-panel.collapsed #page-operation-panel { display: block !important; }
html.is-mobile .workbench-body .panel.right-panel.collapsed > *:not(.panel-title):not(#page-operation-panel) { display: none; }
/* ★ 手机端：#page-operation-panel 紧凑布局 */
html.is-mobile .workbench-body .panel.right-panel button { max-width: 100% !important; }
html.is-mobile .workbench-body .panel.right-panel div[style*="display:flex"] { gap: 6px !important; flex-wrap: wrap !important; }
html.is-mobile #page-operation-panel button { font-size: 12px !important; padding: 8px 10px !important; max-width: 100% !important; }
html.is-mobile #page-operation-panel > div[style*="display:flex"] { gap: 6px !important; }
html.is-mobile #page-operation-panel > div[style*="display:flex"] > button { flex: 1 1 0 !important; min-width: 0 !important; word-break: break-all !important; }
/* ★ 缩略图在右面板内：横滑单行 */
html.is-mobile .workbench-body .panel.right-panel .thumb-list { display: flex !important; overflow-x: auto !important; -webkit-overflow-scrolling: touch; padding: 4px 0 8px 0; gap: 8px; }
html.is-mobile .workbench-body .panel.right-panel .thumb-list .thumb-item { flex: 0 0 auto !important; width: 64px; }
/* ★ 手机端：选择页面标题不折叠（不响应点击） */
html.is-mobile .panel-title.mobile-thumb-title { cursor: default !important; pointer-events: none !important; padding-bottom: 4px !important; margin-bottom: 4px !important; font-size: 12px !important; }
html.is-mobile .panel-title.mobile-thumb-title::after { content: '' !important; }
/* ★ 手机端：所有标题前的 emoji 图案隐藏 */
html.is-mobile .panel-title,
html.is-mobile .mobile-actions-group button,
html.is-mobile #page-operation-panel > div:first-child,
html.is-mobile #page-operation-panel button { font-size: 12px !important; }
/* ★ 缩略图下方加横向滚动滑条 */
html.is-mobile .workbench-body .panel.right-panel .thumb-list { scrollbar-width: thin !important; scrollbar-color: var(--primary-light) transparent !important; }
html.is-mobile .workbench-body .panel.right-panel .thumb-list::-webkit-scrollbar { height: 4px !important; display: block !important; }
html.is-mobile .workbench-body .panel.right-panel .thumb-list::-webkit-scrollbar-track { background: rgba(0,0,0,0.05); border-radius: 2px; }
html.is-mobile .workbench-body .panel.right-panel .thumb-list::-webkit-scrollbar-thumb { background: var(--primary-light); border-radius: 2px; }
/* ★ 手机端：所有文字标题前的 emoji 图案去掉 */
html.is-mobile .workbench-body #gen-all-btn,
html.is-mobile .workbench-body button[onclick*="uploadGlobalRef"],
html.is-mobile .workbench-body button[onclick*="uploadRefImage"] { font-size: 12px !important; }
html.is-mobile .workbench-body #gen-all-btn { padding: 10px !important; }
html.is-mobile .workbench-body button[onclick*="uploadGlobalRef"] { padding: 8px !important; }
html.is-mobile .workbench-body button[onclick*="uploadRefImage"] { padding: 8px !important; }
html.is-mobile .workbench-body .panel.right-panel .panel-title {
  cursor: pointer; user-select: none; margin-bottom: 0;
}
html.is-mobile .workbench-body .panel.right-panel .panel-title::after {
  content: ' ▼'; font-size: 10px; opacity: 0.5;
}
html.is-mobile .workbench-body .panel.right-panel.collapsed .panel-title::after {
  content: ' ▶';
}
html.is-mobile .workbench-body .panel.right-panel.collapsed > *:not(.panel-title) {
  display: none;
}

/* 中间画布 */
html.is-mobile .canvas-area { order: 3; padding: 10px; min-height: auto; overflow: hidden; max-width: 100vw !important; }
html.is-mobile .canvas-main,
html.is-mobile .canvas-main > div,
html.is-mobile .canvas-done-wrapper { max-width: 100% !important; overflow: hidden !important; width: 100% !important; box-sizing: border-box !important; }
html.is-mobile .canvas-main [style*="display:flex"],
html.is-mobile .canvas-main [style*="display:flex"] > * { min-width: 0 !important; }
/* 图片：只加高度上限，宽度保持内联 width:100% */
html.is-mobile .canvas-main img,
html.is-mobile .canvas-done-wrapper img { max-height: 60vh !important; }
/* 历史版本缩略图不缩放 */
html.is-mobile .history-strip img,
html.is-mobile .hist-thumb-wrap img { max-height: none !important; }
html.is-mobile .canvas-toolbar { padding-bottom: 8px; margin-bottom: 8px; flex-wrap: wrap; gap: 6px; }
html.is-mobile .canvas-toolbar .btn { font-size: 11px; padding: 4px 6px; }

/* 缩略图：底部横滑条 */
html.is-mobile .thumb-list {
  display: flex !important;
  gap: 8px; overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
  flex-wrap: nowrap;
}
html.is-mobile .thumb-list .thumb-item {
  flex: 0 0 auto;
  width: 65px;
}
html.is-mobile .thumb-list::-webkit-scrollbar { display: none; }
html.is-mobile .thumb-item .thumb-img-wrap { border-width: 2px; }
html.is-mobile .thumb-item .thumb-label { font-size: 10px; margin-top: 4px; }

/* 全局参考图区域收起 */
html.is-mobile .global-ref-section { max-height: 80px; overflow: hidden; }

/* 底部固定操作栏（手机） */
html.is-mobile .workbench-body::after {
  content: '';
  display: block; height: 64px; order: 4;
}

/* ==========================================
   第三部分：通用组件
   ========================================== */

/* 模态框 → 全屏 */
html.is-mobile .modal-overlay { padding: 0 !important; }
html.is-mobile .modal {
  max-width: 100% !important; width: 100% !important;
  max-height: 100vh !important; border-radius: 0 !important;
  padding: 14px 16px;
}
html.is-mobile .modal-header h3 { font-size: 16px; }
html.is-mobile .modal-footer { gap: 8px; flex-wrap: wrap; }

/* Toast 靠底 */
html.is-mobile .toast-container {
  top: auto; bottom: 16px; right: 8px; left: 8px;
  align-items: stretch;
}
html.is-mobile .toast { min-width: 0; font-size: 13px; padding: 12px 14px; }

/* 警告提示 */
html.is-mobile .alert { font-size: 12px; padding: 8px 10px; }

/* 表格 → 横滚 */
html.is-mobile table.data-table { font-size: 11px; }
html.is-mobile table.data-table th,
html.is-mobile table.data-table td { padding: 6px 4px; white-space: nowrap; }
html.is-mobile .table-wrap { margin: 0 -12px; padding: 0 12px; }

/* 统计卡片 */
html.is-mobile .stat-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
html.is-mobile .stat-card { padding: 12px; }
html.is-mobile .stat-card .stat-value { font-size: 20px; }
html.is-mobile .stat-card .stat-icon { width: 36px; height: 36px; font-size: 18px; }

/* 底部 */
html.is-mobile .footer { padding: 32px 0 16px; }
/* ★ 手机端：底部 footer 的快捷入口/帮助中心/联系我们等栏目隐藏，只保留版权信息 */
html.is-mobile .footer-grid > * { display: none; }
html.is-mobile .footer-grid { grid-template-columns: 1fr !important; gap: 16px; }
html.is-mobile .footer-bottom { font-size: 11px; }

/* 加载动画 */
html.is-mobile .loading-overlay p { font-size: 13px; }

/* 图片查看器适配 */
html.is-mobile .image-viewer-overlay { padding: 8px !important; }
html.is-mobile .image-viewer-overlay img { max-height: 80vh !important; }

/* 通用：强制内联 3+ 列或多列 grid 缩为双列 */
html.is-mobile div[style*="grid-template-columns:1fr 1fr 1fr"],
html.is-mobile div[style*="grid-template-columns: 1fr 1fr 1fr"],
html.is-mobile div[style*="grid-template-columns:1fr 350px"],
html.is-mobile div[style*="grid-template-columns: 1fr 350px"],
html.is-mobile div[style*="grid-template-columns:repeat(auto-fill"] {
  grid-template-columns: repeat(2, 1fr) !important;
}

/* ==========================================
   第四部分：后台管理侧边栏 → 顶部横栏
   ========================================== */
html.is-mobile #app > div[style*="min-height:100vh"] {
  flex-direction: column !important;
}
html.is-mobile #app > div > aside[style*="position:fixed"] {
  position: static !important;
  width: 100% !important; height: auto !important;
  display: flex !important; flex-direction: column !important;
}
html.is-mobile #app > div > aside > div:first-child {
  display: flex !important; align-items: center !important;
  padding: 6px 10px !important; border-bottom: none !important;
}
html.is-mobile #app > div > aside nav {
  display: flex !important; flex-wrap: wrap !important; gap: 2px !important;
  padding: 2px 8px !important; overflow-x: auto !important;
  -webkit-overflow-scrolling: touch !important;
}
html.is-mobile #app > div > aside nav > a {
  flex: 0 0 auto !important; padding: 3px 7px !important;
  font-size: 10px !important; margin: 1px !important;
  border-radius: 4px !important;
}
html.is-mobile #app > div > aside > div:last-child {
  position: static !important; display: flex !important;
  align-items: center !important; gap: 6px !important;
  padding: 4px 10px 6px !important;
  border-top: 1px solid rgba(255,255,255,0.1) !important;
  font-size: 11px !important;
}
html.is-mobile #app > div > aside > div:last-child .btn {
  width: auto !important; font-size: 10px !important; padding: 3px 8px !important;
}
html.is-mobile #app > div > main[style*="margin-left:220px"] {
  margin-left: 0 !important; padding: 10px !important;
}

/* ==========================================
   第五部分：平板端 (html.is-tablet, 768-1024px)
   保留左右分栏但缩小尺寸
   ========================================== */
html.is-tablet .container,
html.is-tablet .container-sm { padding: 0 16px; }
html.is-tablet .template-grid { grid-template-columns: repeat(3, 1fr) !important; }
html.is-tablet .works-grid { grid-template-columns: repeat(2, 1fr) !important; }
html.is-tablet .feature-grid { grid-template-columns: repeat(2, 1fr) !important; }

/* 平板制作页 */
html.is-tablet .workbench-body {
  grid-template-columns: 200px 1fr !important; gap: 12px; padding: 12px;
}
html.is-tablet .workbench-body .panel.right-panel {
  grid-column: 1 / -1 !important;
}

/* 平板导航 */
html.is-tablet .nav-links { gap: 16px; }
html.is-tablet .nav-links a { font-size: 13px; }
html.is-tablet .logo-text { font-size: 18px; }

/* 平板后台 */
html.is-tablet #app > div > aside { width: 160px !important; }
html.is-tablet #app > div > main[style*="margin-left:220px"] {
  margin-left: 160px !important;
}

/* ==========================================
   第六部分：小手机 (<380px)
   ========================================== */
@media (max-width: 380px) {
  html.is-mobile .template-grid { grid-template-columns: repeat(2, 1fr) !important; }
  html.is-mobile #tpl-pages-preview-grid { grid-template-columns: repeat(2, 1fr) !important; }
  html.is-mobile .workbench-header-inner > div:last-child .btn { font-size: 10px; padding: 3px 6px; }
}
