/* ============================================================
   Tre-Creator 公共样式 V1.3
   移动端优先 / 桌面端自适应 / 现代化设计系统
   ============================================================
   设计原则：
   1. 手机端全屏体验，桌面端居中卡片式
   2. 手机 <768px 全宽；平板 768-1024 居中 480px；桌面 >1024 居中适配
   3. 管理后台桌面端自动展开侧边栏，手机端变底部 Tab
   ============================================================ */
:root {
  /* 主色系 — 清爽商务蓝（单色、高对比、朴素克制的初始风格） */
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #dbeafe;
  --primary-gradient: linear-gradient(135deg, #3b82f6, #2563eb);
  --primary-soft: #f8fafc;
  --accent: #60a5fa;
  --accent-gradient: #60a5fa;
  --success: #52c41a;
  --warning: #faad14;
  --danger: #ef4444;
  --info: #6b7280;
  /* 文字 */
  --text-primary: #1f2937;
  --text-secondary: #4b5563;
  --text-tertiary: #6b7280;
  --text-placeholder: #9ca3af;
  /* 背景 */
  --bg-page: #f5f6fa;
  --bg-page-soft: #f9fafb;
  --bg-card: #ffffff;
  --bg-hover: #f3f4f6;
  --bg-input: #fafafa;
  /* 边框 - 统一去除黑边/灰边效果 */
  --border-color: transparent;
  --border-light: transparent;
  /* 阴影 */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 6px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.10);
  --shadow-xl: 0 24px 48px rgba(0, 0, 0, 0.12);
  /* 圆角 */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  /* 间距阶（4px 基准） */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 20px;
  --space-2xl: 24px;
  --space-3xl: 32px;
  /* 组件专用间距 */
  --space-card: 16px;
  --space-section: 20px;
  --space-hero: 24px;
  --gap-grid: 8px;
  --gap-inline: 6px;
  /* 组件级阴影 */
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-hero: 0 8px 32px rgba(0, 0, 0, 0.12);
  --shadow-hover: 0 8px 24px rgba(59, 130, 246, 0.15);
  /* 安全区 */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* 过渡 */
  --transition: 0.25s ease;
  --transition-slow: 0.4s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
html, body { height: 100%; width: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-dark); }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font-family: inherit; font-size: 14px; }
img { display: block; max-width: 100%; }

/* ============================================================
   容器：手机全宽 / 平板居中 / 桌面宽屏
   ============================================================ */
.container { width: 100%; max-width: 480px; margin: 0 auto; padding: 16px; }
.container-wide { width: 100%; max-width: 1200px; margin: 0 auto; padding: 20px; }
.container-fluid { width: 100%; padding: 16px; }

/* ============================================================
   卡片
   ============================================================ */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); border-color: var(--border-color); transform: translateY(-1px); }
.card-flat { background: var(--bg-card); border-radius: var(--radius-md); padding: 16px; margin-bottom: 12px; border: 1px solid var(--border-color); }

/* ============================================================
   按钮 — 淡雅圆角 + 柔和悬浮
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 20px; border-radius: 999px;
  font-size: 14px; font-weight: 500; transition: all var(--transition);
  background: var(--primary-gradient); color: #fff;
  white-space: nowrap; user-select: none;
  letter-spacing: 0.2px;
  border: none;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); filter: brightness(1.03); }
.btn:active { transform: scale(0.98); }
.btn-block { display: flex; width: 100%; }
.btn-lg { padding: 13px 30px; font-size: 15px; }
.btn-sm { padding: 6px 14px; font-size: 12px; border-radius: 999px; }
.btn-xs { padding: 4px 10px; font-size: 11px; border-radius: 999px; }
.btn-outline {
  background: #fff !important; color: var(--primary);
  border: 1px solid var(--border-color) !important;
  box-shadow: var(--shadow-xs) !important;
  filter: none !important;
}
.btn-outline:hover { border-color: var(--primary) !important; background: var(--primary-soft) !important; color: var(--primary-dark); }
.btn-ghost { background: var(--primary-light); color: var(--primary); box-shadow: none; filter: none; }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-danger { background: linear-gradient(135deg, #c48b8b, #b57777); filter: none; }
.btn-danger:hover { box-shadow: var(--shadow-md); }
.btn-success { background: linear-gradient(135deg, #8ba888, #749271); filter: none; }
.btn-success:hover { box-shadow: var(--shadow-md); }
.btn-warning { background: linear-gradient(135deg, #c9a96b, #b89556); filter: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

/* ============================================================
   表单 — 淡雅描边 + 柔和聚焦
   ============================================================ */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; font-weight: 500; }
.form-input, .form-textarea, .form-select {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); background: var(--bg-input); color: var(--text-primary);
  transition: all var(--transition); outline: none;
  -webkit-appearance: none; appearance: none;
}
.form-input:hover, .form-textarea:hover, .form-select:hover { border-color: #dcdfe4; background: #fff; }
.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--primary); background: #fff;
  box-shadow: 0 0 0 4px rgba(138, 147, 166, 0.10);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-placeholder); }
.form-textarea { min-height: 80px; resize: vertical; line-height: 1.65; }

/* ============================================================
   头部 — 淡雅渐变 + 柔光光斑
   ============================================================ */
.page-header {
  background: linear-gradient(135deg, rgba(165,180,201,0.92) 0%, rgba(138,147,166,0.92) 100%);
  color: #fff;
  padding: calc(var(--safe-top) + 20px) 24px 24px;
  position: relative; overflow: hidden;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  box-shadow: 0 8px 24px rgba(138, 147, 166, 0.18);
}
.page-header::before {
  content: ''; position: absolute; top: -80px; left: -60px;
  width: 200px; height: 200px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.18), transparent 65%);
  pointer-events: none;
}
.page-header::after {
  content: ''; position: absolute; bottom: -50px; right: -30px;
  width: 180px; height: 180px; border-radius: 50%;
  background: radial-gradient(circle, rgba(212,165,165,0.28), transparent 65%);
  pointer-events: none;
}
.page-header-title { font-size: 21px; font-weight: 700; position: relative; z-index: 1; letter-spacing: 0.3px; }
.page-header-subtitle { font-size: 13px; opacity: 0.9; margin-top: 6px; position: relative; z-index: 1; }

/* ============================================================
   列表
   ============================================================ */
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 0; border-bottom: 1px solid var(--border-light);
  transition: background var(--transition), padding-left var(--transition);
}
.list-item:last-child { border-bottom: none; }
.list-item:hover { background: var(--bg-hover); }

/* ============================================================
   空状态
   ============================================================ */
.empty-state { text-align: center; padding: 70px 20px; color: var(--text-tertiary); }
.empty-icon { font-size: 52px; margin-bottom: 14px; opacity: 0.5; }
.empty-text { font-size: 14px; letter-spacing: 0.2px; }

/* ============================================================
   标签 — 淡雅浅色
   ============================================================ */
.tag {
  display: inline-flex; align-items: center; padding: 3px 11px;
  border-radius: 100px; font-size: 11px; font-weight: 500; line-height: 1.6;
  letter-spacing: 0.2px;
}
.tag-primary { background: var(--primary-light); color: var(--primary-dark); }
.tag-success { background: #eaf0ea; color: var(--success); }
.tag-warning { background: #f8f0e3; color: var(--warning); }
.tag-danger  { background: #f6e9e9; color: var(--danger); }
.tag-info    { background: var(--primary-soft); color: var(--info); }

/* ============================================================
   Toast — 更大圆角 + 磨砂玻璃
   ============================================================ */
.toast {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.94);
  background: rgba(58, 63, 75, 0.88); color: #fff; padding: 12px 22px;
  border-radius: 999px; font-size: 14px; z-index: 99999;
  opacity: 0; transition: all var(--transition); pointer-events: none;
  max-width: 86%; text-align: center; backdrop-filter: saturate(180%) blur(12px);
  white-space: pre-wrap; word-break: break-all;
  box-shadow: var(--shadow-md);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ============================================================
   弹窗 — 更大圆角 + 柔和阴影 + 缩放动画
   ============================================================ */
.modal-mask {
  position: fixed; inset: 0; background: rgba(58, 63, 75, 0.42);
  backdrop-filter: saturate(180%) blur(8px);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  display: flex; align-items: center; justify-content: center; z-index: 9998;
  opacity: 0; transition: opacity var(--transition);
}
.modal-mask.show { opacity: 1; }
.modal {
  background: #fff; border-radius: var(--radius-lg); width: 90%; max-width: 420px;
  max-height: 82vh; overflow: auto; box-shadow: var(--shadow-xl);
  transform: translateY(14px) scale(0.96);
  transition: transform var(--transition-slow);
  border: 1px solid var(--border-light);
}
.modal-mask.show .modal { transform: translateY(0) scale(1); }
.modal-header {
  padding: 18px 22px; border-bottom: 1px solid var(--border-light);
  font-weight: 600; font-size: 16px; color: var(--text-primary);
  letter-spacing: 0.2px;
}
.modal-body { padding: 20px 22px; }
.modal-footer {
  padding: 14px 22px; border-top: 1px solid var(--border-light);
  display: flex; gap: 10px; justify-content: flex-end;
}

/* ============================================================
   加载动画 — 柔和配色
   ============================================================ */
.spinner {
  width: 30px; height: 30px; border: 3px solid var(--border-color);
  border-top-color: var(--primary); border-radius: 50%;
  animation: spin 0.9s cubic-bezier(0.4,0,0.2,1) infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton {
  background: linear-gradient(90deg, #f1f2f0 25%, #e8e9e7 50%, #f1f2f0 75%);
  background-size: 200% 100%; animation: shimmer 1.6s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* 红包雨下落动画 */
@keyframes _rpFall {
  0%   { transform: translateY(-40px) rotate(0deg); opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { transform: translateY(200px) rotate(15deg); opacity: 0; }
}

/* ============================================================
   滚动条美化 — 淡色隐形
   ============================================================ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(180, 186, 197, 0.5);
  border-radius: 100px;
  transition: background var(--transition);
}
::-webkit-scrollbar-thumb:hover { background: rgba(138, 147, 166, 0.7); }
* { scrollbar-width: thin; scrollbar-color: rgba(180, 186, 197, 0.5) transparent; }

/* ============================================================
   响应式断点
   ============================================================ */

/* 平板 768px+：居中卡片式 */
@media (min-width: 768px) {
  .container { max-width: 480px; }
  .container-wide { max-width: 1024px; }
  .page-header { border-radius: 0 0 var(--radius-xl) var(--radius-xl); margin-bottom: 8px; }
}

/* 桌面 1024px+：宽屏适配 */
@media (min-width: 1024px) {
  .container { max-width: 520px; }
  .container-wide { max-width: 1200px; }
}

/* 大屏 1440px+ */
@media (min-width: 1440px) {
  .container-wide { max-width: 1400px; }
}

/* ============================================================
   编辑端组件 hover 交互态
   ============================================================ */
.comp-wrap { transition: box-shadow 0.25s ease, transform 0.25s ease; }
.comp-wrap:hover { box-shadow: var(--shadow-hover) !important; }
.comp-wrap.comp-selected { box-shadow: 0 0 0 2px var(--primary), var(--shadow-md) !important; }

/* 卡片类组件悬浮微动 */
.comp-wrap[data-type="card"]:hover,
.comp-wrap[data-type="goodsList"]:hover,
.comp-wrap[data-type="cardList"]:hover { transform: translateY(-2px); }

/* ============================================================
   编辑器三栏布局（桌面端 ≥1024px）
   ============================================================ */
@media (min-width: 1024px) {
  .editor-layout {
    display: grid;
    grid-template-columns: 280px 1fr 320px;
    gap: 0;
    height: calc(100vh - var(--topbar-h, 56px));
    overflow: hidden;
  }
  .editor-left-panel {
    position: sticky;
    top: var(--topbar-h, 56px);
    height: calc(100vh - var(--topbar-h, 56px));
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 1px solid var(--border-light);
    background: var(--bg-card);
    scrollbar-width: thin;
  }
  .editor-left-panel::-webkit-scrollbar { width: 6px; }
  .editor-left-panel::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

  .editor-canvas-wrap {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px 16px;
    overflow-y: auto;
    background: var(--bg-page);
  }
  .editor-canvas-inner {
    width: 100%;
    max-width: 420px;
  }
  .editor-right-panel {
    position: sticky;
    top: var(--topbar-h, 56px);
    height: calc(100vh - var(--topbar-h, 56px));
    overflow-y: auto;
    border-left: 1px solid var(--border-light);
    background: var(--bg-card);
    scrollbar-width: thin;
  }
  .editor-right-panel::-webkit-scrollbar { width: 6px; }
  .editor-right-panel::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }
}

/* ============================================================
   移动端编辑器底部工具栏（≤768px）
   ============================================================ */
@media (max-width: 768px) {
  .editor-bottom-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    display: flex;
    background: rgba(255,255,255,0.96);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-light);
    padding: 8px 8px calc(8px + var(--safe-bottom, 0px));
    z-index: 40;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.06);
  }
  .editor-bottom-bar .ebb-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 4px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: color var(--transition);
  }
  .editor-bottom-bar .ebb-btn.active { color: var(--primary); }
  .editor-bottom-bar .ebb-btn .ebb-icon { font-size: 20px; }
}

/* ============================================================
   骨架屏 loading + 磨砂玻璃 + 通用美化
   ============================================================ */
.skeleton-loading {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.glass-panel {
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.6);
}

/* 骨架库卡片美化 */
.skel-card {
  border-radius: var(--radius-lg, 14px);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
  border: 1px solid var(--border-light);
  overflow: hidden;
  background: var(--bg-card);
}
.skel-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary-light);
}

/* 编辑器工具栏按钮（替代 inline style） */
.util-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md, 8px);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
  gap: 4px;
}
.util-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}
.util-btn:active { transform: scale(0.97); }

/* 渐变主按钮 */
.btn-primary-gradient {
  background: var(--primary-gradient);
  color: #fff;
  border: none;
  border-radius: var(--radius-md, 8px);
  padding: 8px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(59,130,246,0.25);
}
.btn-primary-gradient:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(59,130,246,0.4);
}

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-placeholder);
  font-size: 13px;
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }

/* ============================================================
   P3 移动端增强（触摸优化 + 模态框适配 + 表单优化）
   ============================================================ */
@media (max-width: 768px) {
  /* 全局触摸行为：禁止双击缩放，保留平移/捏合 */
  html { touch-action: manipulation; }
  body { -webkit-text-size-adjust: 100%; }

  /* 可点击元素的触摸目标至少 44×44px（iOS HIG） */
  .btn, .btn-sm, .util-btn, .comp-item, .book-page-btn,
  .tpl-card, .skel-card, .modal-footer button {
    min-height: 44px;
    min-width: 44px;
  }

  /* 表单输入框触摸优化 */
  .form-input, .form-select, textarea.form-input {
    font-size: 16px; /* ≥16px 避免 iOS 自动缩放 */
    padding: 12px 14px;
    min-height: 44px;
  }

  /* 模态框移动端适配：全屏化 + 安全区 */
  .modal-mask.show .modal {
    width: 94vw !important;
    max-width: 480px !important;
    max-height: 88vh;
    margin: 0 auto;
    border-radius: 16px 16px 0 0;
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal-body {
    padding: 16px;
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .modal-footer {
    position: sticky;
    bottom: 0;
    background: var(--bg-card, #fff);
    padding: 12px 16px calc(12px + var(--safe-bottom, 0px));
    border-top: 1px solid var(--border-light);
  }

  /* 顶部安全区适配 */
  .topbar, .modal-header {
    padding-top: calc(var(--safe-top, 0px) + 8px);
  }

  /* 隐藏桌面端 hover 效果（移动端无 hover） */
  .comp-item:hover, .tpl-card:hover, .skel-card:hover,
  .util-btn:hover, .btn:hover {
    transform: none;
    box-shadow: none;
  }

  /* 激活态反馈替代 hover */
  .comp-item:active, .tpl-card:active, .skel-card:active {
    background: var(--primary-light, #eff6ff);
    transform: scale(0.98);
  }

  /* Toast 居中偏下，避免被底部栏遮挡 */
  .toast {
    bottom: calc(72px + var(--safe-bottom, 0px)) !important;
    max-width: 90vw;
  }

  /* 表格横向滚动 */
  .form-records-table, table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
}

/* 极小屏（≤380px）紧凑布局 */
@media (max-width: 380px) {
  .modal { width: 98vw !important; }
  .form-grid { grid-template-columns: 1fr !important; }
  .comp-grid { grid-template-columns: repeat(2, 1fr) !important; }
}

/* 横屏优化 */
@media (max-width: 768px) and (orientation: landscape) {
  .modal-mask.show .modal {
    max-height: 94vh;
  }
  .editor-mobile-bar { height: 44px; }
}
