/* ========= 通用基础样式 ========= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    background: #f5f6f8;
    font-family: "Microsoft YaHei", sans-serif;
    display: flex;
    justify-content: center;
}

/* ========= 整体容器 ========= */
.app-container {
    width: 100%;
    max-width: 750px;
    min-height: 100vh;
    background: #fff;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 30px rgba(0,0,0,0.05);
    position: relative;
}

/* ========= 顶部导航 ========= */
.nav-bar {
    height: 50px;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    border-bottom: 1px solid #e5e7eb;
}
.nav-title {
    font-size: 18px;
    font-weight: bold;
    color: #111;
    flex: 1;
    text-align: center;
}
.nav-icon {
    width: 26px;
    height: 26px;
    display: flex;
    justify-content: center;
    border-radius: 50%;
    background: #f4f4f5;
    font-size: 13px;
    color: #333;
    cursor: pointer;
}

/* ========= 上半部分：画布 + 变体 + 工具栏 ========= */
.canvas-section {
    flex: 1;
    background: #f9fafb;
    padding: 10px 16px 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* 设计器挂载 div（SDK 用） */
#designBox {
    width: 100%;
    max-width: 680px;
    aspect-ratio: 1/1;
    background: #f8fafc;
    border-radius: 12px;
    border: 1.5px dashed #cbd5e1;
    position: relative;
    margin-top: 10px;
    overflow: hidden;
    box-shadow: inset 0 0 8px rgba(0,0,0,0.03);
}

/* 变体选择区域（颜色 / 尺寸） */
#variantBox {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    max-width: 680px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    padding: 16px 24px;
    margin: 16px auto 0;
    font-size: 14px;
    color: #374151;
    white-space: nowrap;
    gap: 80px;
}

.variant-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

#variantBox select {
    width: 120px;
    border: 1px solid #d1d5db;
    background: #fff;
    font-size: 14px;
    color: #111;
    padding: 4px 8px;
    border-radius: 6px;
    outline: none;
    transition: all 0.2s ease;
}
#variantBox select:focus {
    border-color: #facc15;
    box-shadow: 0 0 0 2px rgba(250,204,21,0.2);
}

/* 工具栏：添加图片 / 文字 / 图库 / 背景色 */
.tool-bar {
    width: 100%;
    max-width: 680px;
    margin-top: 14px;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    display: flex;
    justify-content: space-around;
    padding: 12px 0;
}

.tool-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 13px;
    color: #111;
}

.tool-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #f9fafb;
    border: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 6px;
    transition: all 0.25s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    cursor: pointer;
}

.tool-btn img {
    width: 28px;
    height: 28px;
}

.tool-btn:hover {
    background: #fff9c4;
    transform: translateY(-2px);
}

/* ========= 底部操作栏 ========= */
.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 750px;
    background: #fff;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 10px 0;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
    z-index: 100;
}

.bottom-btn {
    border: none;
    background: none;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-clear { color: #ef4444; }
.btn-main {
    background: #facc15;
    padding: 8px 18px;
    border-radius: 20px;
    font-weight: bold;
    color: #000;
    border: none;
    cursor: pointer;
}

.bottom-btn:hover,
.btn-main:hover {
    transform: scale(1.05);
}

/* ========= 预览弹窗（带进度条） ========= */
.preview-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}
.preview-modal.active { display: flex; }

.preview-card {
    background: #fff;
    border-radius: 16px;
    padding: 18px;
    width: 90%;
    max-width: 420px;
    position: relative;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}

.preview-close {
    position: absolute;
    top: 8px;
    right: 12px;
    font-size: 22px;
    border: none;
    background: none;
    color: #888;
    cursor: pointer;
}

#previewBox {
    font-size: 14px;
    color: #333;
    text-align: center;
    padding-top: 20px;
}

/* 预览 loading 文案 + 进度条 */
#previewLoading {
    padding: 16px;
    text-align: center;
    font-size: 13px;
    color: #6b7280;
}
.preview-progress-bar {
    margin-top: 10px;
    width: 100%;
    height: 4px;
    border-radius: 999px;
    background: #e5e7eb;
    overflow: hidden;
}
.preview-progress-inner {
    width: 0;
    height: 100%;
    border-radius: 999px;
    background: #3b82f6;
    transition: width 0.3s linear;
}

/* ========= 字体弹窗 ========= */
.font-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
}
.font-modal.active { display: flex; }

.font-card {
    background: #fff;
    border-radius: 16px;
    padding: 20px;
    width: 90%;
    max-width: 300px;
    box-shadow: 0 8px 20px rgba(0,0,0,0.25);
    position: relative;
}

.font-close {
    position: absolute;
    top: 8px;
    right: 12px;
    font-size: 20px;
    color: #777;
    border: none;
    background: none;
    cursor: pointer;
}

.font-card textarea {
    width: 100%;
    height: 80px;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 8px;
    margin-bottom: 10px;
    resize: none;
}

.font-card select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 8px;
    margin-bottom: 12px;
}

.btn-group {
    display: flex;
    gap: 10px;
}

.btn {
    flex: 1;
    padding: 10px 0;
    border-radius: 8px;
    color: #fff;
    font-weight: bold;
    border: none;
    cursor: pointer;
}
.btn-blue { background: #2563eb; }
.btn-dark { background: #111827; }

/* ========= 产品弹窗（两列卡片） ========= */
.product-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1600;
    display: none;
    align-items: center;
    justify-content: center;
}
.product-modal.active {
    display: flex;
}

.product-panel {
    background: #f9fafb;
    border-radius: 16px;
    padding: 12px;
    width: 90%;
    max-width: 520px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
}

.product-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.product-title {
    font-size: 15px;
    font-weight: 600;
    color: #111827;
}
.product-close {
    border: none;
    background: none;
    font-size: 20px;
    color: #6b7280;
    cursor: pointer;
}

.product-search-wrap {
    margin-bottom: 8px;
}
.product-search-input {
    width: 100%;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid #d1d5db;
    font-size: 13px;
    background: #ffffff;
    outline: none;
}
.product-search-input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 1px rgba(37,99,235,0.25);
}

.product-grid {
    flex: 1;
    margin-top: 4px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    max-height: 340px;
    overflow-y: auto;
}

.product-card {
    background: #ffffff;
    border-radius: 12px;
    padding: 6px;
    box-shadow: 0 1px 4px rgba(15,23,42,0.08);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.product-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(15,23,42,0.16);
}

.product-thumb-wrap {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 10px;
    overflow: hidden;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
}
.product-thumb {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.product-thumb.placeholder {
    font-size: 12px;
    color: #9ca3af;
}

.product-name {
    font-size: 13px;
    font-weight: 600;
    color: #111827;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.product-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    margin-top: 2px;
}
.product-price {
    color: #ef4444;
    font-weight: 600;
}
.product-id {
    color: #6b7280;
    font-size: 11px;
}

.product-empty {
    grid-column: 1 / -1;
    text-align: center;
    font-size: 13px;
    color: #9ca3af;
    padding: 20px 0;
}

/* ========= 图库弹层 ========= */
.gallery-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1500;
    display: none;
    align-items: center;
    justify-content: center;
}
.gallery-modal.active { display: flex; }

.gallery-card {
    background: #fff;
    border-radius: 16px;
    padding: 16px;
    width: 90%;
    max-width: 420px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    position: relative;
}
.gallery-close {
    position: absolute;
    top: 6px;
    right: 10px;
    border: none;
    background: none;
    font-size: 22px;
    color: #666;
    cursor: pointer;
}
.gallery-search {
    width: 100%;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    margin-bottom: 8px;
}
.gallery-search-btn {
    width: 100%;
    padding: 8px;
    border-radius: 8px;
    border: none;
    background: #2563eb;
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 10px;
}
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-height: 260px;
    overflow-y: auto;
}
.gallery-img {
    width: 100%;
    display: block;
    border-radius: 6px;
    cursor: pointer;
}
.gallery-pager {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}
.gallery-pager button {
    flex: 1;
    padding: 8px 0;
    border-radius: 8px;
    border: none;
    background: #111827;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
}

/* ========= 简单加载遮罩（可选） ========= */
.loading-mask {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.loading-mask.hidden {
    display: none;
}
.spinner {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 3px solid #e5e7eb;
    border-top-color: #2563eb;
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
/* ========= 响应式：小屏幕 ========= */
@media (max-width: 480px) {
  .tool-btn { width: 46px; height: 46px; }
  .tool-bar { padding: 8px 0; }
  .tool-item { font-size: 11px; }
  .nav-title { font-size: 16px; }
  .bottom-btn { font-size: 12px; }
  .btn-main { padding: 6px 14px; font-size: 13px; }
  #variantBox { gap: 20px; padding: 12px 14px; }
  #variantBox select { width: 90px; }
}
/* 安全区：适配刘海屏 */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-bar { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}
