/* ==========================================================================
   灯具 3D 展示 · 报价系统 —— 全局样式与主题
   主题通过 CSS 变量驱动，JS 动态设置 :root 上的变量实现「全页面配色交互」
   ========================================================================== */

/* 亮色兜底变量（JS 启动后会覆盖） */
:root {
  --bg: #f5f6f8;
  --bg-soft: #edeff3;
  --surface: #ffffff;
  --surface-2: #f1f3f7;
  --text: #17202a;
  --text-muted: #5f6b7a;
  --border: rgba(15, 23, 42, 0.12);
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
  --viewer-bg-top: #eef2f7;
  --viewer-bg-bottom: #dde4ee;
  --grid: rgba(100, 116, 139, 0.28);
  --ground: rgba(100, 116, 139, 0.10);
  --accent: #f59e0b;
  --accent-strong: #b45309;
  --accent-soft: rgba(245, 158, 11, 0.15);
  --accent-contrast: #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.3s ease, color 0.3s ease;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

.app { display: flex; flex-direction: column; height: 100vh; }

/* ============================== 顶栏 ===================================== */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 20;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-dot {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 4px 14px var(--accent-soft);
}
.brand h1 { font-size: 16px; font-weight: 700; letter-spacing: 0.5px; }
.brand p { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

.model-tabs { display: flex; gap: 6px; margin-left: auto; }
.tab {
  padding: 8px 18px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 14px;
  transition: all 0.2s ease;
}
.tab:hover { border-color: var(--accent); }
.tab.active {
  background: var(--accent); color: var(--accent-contrast);
  border-color: var(--accent); font-weight: 600;
  box-shadow: 0 4px 14px var(--accent-soft);
}

.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); font-size: 18px; line-height: 1;
  transition: all 0.2s ease;
}
.icon-btn:hover { border-color: var(--accent); transform: translateY(-1px); }

/* ============================== 主体布局 ================================= */
.main {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 1fr 360px;
}

/* 3D 视图区 */
.viewer { position: relative; min-width: 0; overflow: hidden; }
#stage {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, var(--viewer-bg-top), var(--viewer-bg-bottom));
  transition: background 0.3s ease;
}
#stage canvas.webgl { display: block; position: absolute; top: 0; left: 0; }
.label-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }

/* 尺寸标注标签 */
.dim-label {
  display: inline-flex; align-items: baseline; gap: 6px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 8px; padding: 3px 8px;
  font-size: 12px; white-space: nowrap;
  box-shadow: var(--shadow);
}
.dim-label .dim-key { color: var(--text-muted); font-size: 11px; }
.dim-label .dim-val { font-weight: 700; color: var(--accent); }

/* 浮动工具栏 */
.viewer-toolbar {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; gap: 6px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); z-index: 10;
}
.tool-btn {
  padding: 8px 14px; border-radius: 9px; border: none;
  background: transparent; color: var(--text-muted); font-size: 13px;
  transition: all 0.2s ease;
}
.tool-btn:hover { background: var(--surface-2); color: var(--text); }
.tool-btn.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* 尺寸读数面板 */
.dim-readout {
  position: absolute; top: 16px; left: 16px; z-index: 10;
  display: flex; flex-direction: column; gap: 6px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: 12px;
  box-shadow: var(--shadow); font-size: 13px; transition: opacity 0.2s ease;
}
.dim-readout.hidden { opacity: 0; pointer-events: none; }
.ro-item b { color: var(--text-muted); font-weight: 600; margin-right: 6px; }
.ro-item { color: var(--text); }

.hint {
  position: absolute; bottom: 18px; right: 16px; z-index: 5;
  font-size: 11px; color: var(--text-muted); opacity: 0.75;
}

/* 标价 / 定价 / 尺寸 标注卡片 */
.price-card {
  position: absolute; top: 16px; right: 16px; z-index: 10;
  display: flex; flex-direction: column; gap: 4px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-right: 3px solid var(--accent); border-radius: 12px;
  box-shadow: var(--shadow); font-size: 13px; min-width: 172px;
}
.pc-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.pc-label { color: var(--text-muted); font-size: 11px; font-weight: 600; }
.pc-list { color: var(--text-muted); text-decoration: line-through; font-size: 12px; }
.pc-price { color: var(--accent); font-weight: 700; font-size: 15px; }
.pc-size { color: var(--text); font-size: 12px; font-weight: 600; }

/* 3D 巡游展示条 */
.tour-overlay {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 15;
  display: none; align-items: center; gap: 12px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--accent); border-radius: 999px;
  box-shadow: var(--shadow); font-size: 13px;
}
.tour-overlay.show { display: flex; }
.tour-title { font-weight: 700; color: var(--accent); }
.tour-name { font-weight: 600; }
.tour-progress { color: var(--text-muted); font-size: 12px; }

/* 加载遮罩 */
.loading {
  position: absolute; inset: 0; z-index: 30;
  display: none; align-items: center; justify-content: center; flex-direction: column; gap: 16px;
  background: var(--bg); color: var(--text);
}
.loading.show { display: flex; }
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 4px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading p { font-size: 14px; }
.bar { width: 260px; height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s ease; }
.error-box { text-align: center; max-width: 420px; padding: 24px; }
.error-box p { margin-bottom: 10px; }
.error-hint { font-size: 12px; color: var(--text-muted); }
.error-hint code { background: var(--surface-2); padding: 2px 6px; border-radius: 5px; color: var(--accent); }

/* ============================== 报价侧栏 ================================ */
.sidebar {
  background: var(--surface); border-left: 1px solid var(--border);
  padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px;
}
.side-head { display: flex; align-items: center; justify-content: space-between; }
.side-head h2 { font-size: 17px; }
.badge {
  padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.field input[type="text"],
.field input[type="number"],
.field select {
  width: 100%; padding: 9px 11px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: 14px; transition: border 0.2s ease;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }

.stepper { display: flex; align-items: center; gap: 0; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.stepper button {
  width: 36px; height: 38px; border: none; background: var(--surface-2);
  color: var(--text); font-size: 18px; font-weight: 600;
}
.stepper button:hover { color: var(--accent); }
.stepper input {
  flex: 1; border: none; border-left: 1px solid var(--border); border-right: 1px solid var(--border);
  background: var(--surface); color: var(--text); text-align: center; font-size: 15px; height: 38px;
}
.stepper input:focus { outline: none; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

.extras { display: flex; flex-direction: column; gap: 8px; }
.extra {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2);
  cursor: pointer; transition: border 0.2s ease;
}
.extra:hover { border-color: var(--accent); }
.extra input { accent-color: var(--accent); }
.extra span { flex: 1; font-size: 13px; }
.extra em { font-style: normal; font-size: 12px; color: var(--accent); font-weight: 600; }

.summary {
  border: 1px solid var(--border); border-radius: 12px; padding: 14px;
  background: var(--surface-2);
}
.sum-row { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; color: var(--text); }
.sum-row.dim { color: var(--text-muted); }
.sum-total {
  display: flex; justify-content: space-between; margin-top: 8px; padding-top: 10px;
  border-top: 1px dashed var(--border); font-size: 17px; font-weight: 700;
}
.sum-total span:last-child { color: var(--accent); }

.actions { display: flex; gap: 10px; }
.btn {
  flex: 1; padding: 11px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 14px; font-weight: 600;
  transition: all 0.2s ease;
}
.btn:hover { border-color: var(--accent); }
.btn.primary {
  background: var(--accent); color: var(--accent-contrast); border-color: var(--accent);
  box-shadow: 0 4px 14px var(--accent-soft);
}
.btn.primary:hover { background: var(--accent-strong); }

.company { display: flex; flex-direction: column; gap: 6px; }

/* ============================== 主题弹层 ================================ */
.popover {
  position: fixed; top: 64px; right: 20px; z-index: 50;
  width: 240px; padding: 16px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  display: none; flex-direction: column; gap: 14px;
}
.popover.show { display: flex; }
.popover-title { font-size: 14px; font-weight: 700; }
.popover-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.popover-row > span { font-size: 12px; color: var(--text-muted); }
.seg { display: flex; gap: 4px; padding: 3px; background: var(--surface-2); border-radius: 9px; }
.seg button {
  padding: 6px 12px; border: none; border-radius: 7px; background: transparent;
  color: var(--text-muted); font-size: 12px;
}
.seg button.active { background: var(--surface); color: var(--accent); font-weight: 600; box-shadow: var(--shadow); }
.swatches { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.swatches button {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent;
  transition: transform 0.15s ease;
}
.swatches button:hover { transform: scale(1.15); }
.swatches button.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface); }

/* ============================== 报价单弹窗 ============================== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 14, 20, 0.55); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; padding: 24px;
}
.modal-overlay.show { display: flex; }
.modal-card {
  width: min(760px, 100%); max-height: 90vh; overflow-y: auto;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow);
  padding: 24px;
}
.modal-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-end; }

/* ============================== 报价单文档 ============================== */
.quote-sheet { display: none; }
.sheet {
  background: #ffffff; color: #1a1a1a; padding: 32px; font-size: 13px; line-height: 1.6;
}
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 3px solid #1a1a1a; padding-bottom: 16px; }
.sheet-brand { display: flex; gap: 12px; align-items: center; }
.sheet-logo {
  width: 44px; height: 44px; border-radius: 10px; background: #1a1a1a; color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700;
}
.sheet-brand h2 { font-size: 18px; }
.sheet-brand p { font-size: 11px; color: #666; }
.sheet-title { text-align: right; }
.sheet-title h1 { font-size: 26px; letter-spacing: 6px; }
.sheet-title p { font-size: 12px; color: #666; }
.sheet-meta {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px;
  padding: 14px 0; border-bottom: 1px solid #e5e5e5;
}
.sheet-meta div { display: flex; flex-direction: column; }
.sheet-meta span { font-size: 11px; color: #999; }
.sheet-table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.sheet-table th, .sheet-table td { border: 1px solid #ddd; padding: 9px 12px; text-align: left; }
.sheet-table th { background: #f2f2f2; font-weight: 600; }
.sheet-table td:nth-child(3), .sheet-table td:nth-child(4), .sheet-table td:nth-child(5),
.sheet-table th:nth-child(3), .sheet-table th:nth-child(4), .sheet-table th:nth-child(5) { text-align: right; }
.sheet-totals { margin-left: auto; width: 300px; }
.tot-line, .tot-grand { display: flex; justify-content: space-between; padding: 6px 0; }
.tot-grand { border-top: 2px solid #1a1a1a; margin-top: 6px; font-size: 16px; font-weight: 700; padding-top: 10px; }
.sheet-foot { margin-top: 20px; font-size: 11px; color: #666; }
.sheet-bom-note { font-size: 11px; color: #666; text-align: right; margin: 4px 0 12px; }
.sheet-table td:nth-child(6), .sheet-table th:nth-child(6) { text-align: right; }

/* ============================== 物料明细（侧栏） ======================== */
.bom-section {
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
  background: var(--surface-2);
}
.bom-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.bom-head h3 { font-size: 13px; font-weight: 700; }
.bom-total { color: var(--accent); font-weight: 700; font-size: 14px; }
.bom-line {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 0; border-bottom: 1px dashed var(--border); font-size: 12px;
}
.bom-line:last-child { border-bottom: none; }
.bom-name { display: flex; flex-direction: column; }
.bom-name em { font-style: normal; font-size: 10px; color: var(--text-muted); }
.bom-amt { color: var(--text); white-space: nowrap; }
.bom-empty { font-size: 12px; color: var(--text-muted); padding: 6px 0; }

/* ============================== 管理弹窗 ================================ */
.modal-card.wide { width: min(1040px, 100%); }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.admin-head .seg button { padding: 8px 18px; }
.admin-close { border: none; background: transparent; font-size: 20px; color: var(--text-muted); line-height: 1; }
.admin-close:hover { color: var(--text); }
.admin-tab { display: none; }
.admin-tab.active { display: block; }
.admin-body { max-height: 62vh; overflow: auto; padding-right: 4px; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th { text-align: left; font-size: 12px; color: var(--text-muted); font-weight: 600; padding: 6px; border-bottom: 2px solid var(--border); }
.admin-table td { padding: 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table input, .admin-table select {
  width: 100%; padding: 6px 8px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px;
}
.admin-table input:focus, .admin-table select:focus { outline: none; border-color: var(--accent); }
.admin-table .num { width: 76px; }
.cell-cost, .cell-amt { color: var(--accent); font-weight: 600; white-space: nowrap; text-align: right; }
.del-btn {
  border: none; background: var(--accent-soft); color: var(--accent);
  width: 26px; height: 26px; border-radius: 7px; font-size: 14px;
}
.del-btn:hover { background: var(--accent); color: var(--accent-contrast); }

/* 综合对比表 */
.compare-table { font-size: 14px; }
.compare-table th, .compare-table td { padding: 12px 10px; text-align: left; }
.compare-table tr.cur { background: var(--accent-soft); }
.cur-tag {
  font-style: normal; font-size: 10px; margin-left: 6px; padding: 1px 6px;
  border-radius: 999px; background: var(--accent); color: var(--accent-contrast);
}
.compare-table .c-list { color: var(--text-muted); text-decoration: line-through; }
.compare-table .c-price { color: var(--accent); font-weight: 700; }
.view-btn {
  padding: 6px 12px; border-radius: 7px; border: 1px solid var(--accent);
  background: transparent; color: var(--accent); font-size: 12px; font-weight: 600;
}
.view-btn:hover { background: var(--accent); color: var(--accent-contrast); }

.admin-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; }
.admin-hint { font-size: 12px; color: var(--text-muted); }
.add-btn {
  padding: 8px 16px; border-radius: 8px; border: 1px dashed var(--accent);
  background: transparent; color: var(--accent); font-size: 13px; margin-top: 10px;
}
.add-btn:hover { background: var(--accent-soft); }

/* 供应商卡片 */
.sup-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 14px; background: var(--surface-2); }
.sup-head { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.sup-head input {
  padding: 7px 9px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 13px;
}
.sup-head input:focus { outline: none; border-color: var(--accent); }
.sup-head input.sup-name { flex: 1; }
.sup-head input.sup-lead { width: 64px; }
.sup-head .lead-label { font-size: 12px; color: var(--text-muted); }
.sup-quotes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.sup-quotes label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--text-muted); }
.sup-quotes input {
  padding: 6px 8px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 13px;
}
.sup-quotes input:focus { outline: none; border-color: var(--accent); }

/* ============================== 响应式 ================================== */
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; grid-template-rows: 55vh 1fr; }
  .sidebar { border-left: none; border-top: 1px solid var(--border); }
  .model-tabs { margin-left: 0; order: 3; width: 100%; }
  .hint { display: none; }
}

/* ============================== 打印 ==================================== */
@media print {
  body { background: #fff; overflow: visible; }
  .app, .modal-overlay, .popover { display: none !important; }
  .quote-sheet { display: block !important; }
  .quote-sheet .sheet { padding: 0; }
}
