/* ============================================================================
 * GF-SpecBuilder · 应用样式（交互/布局 · S3）
 * 硬约束：全程零金额元素；客户可见 EN；navy #1a2540 主色；mobile-first。
 * 打印样式独立在 print.css（media=print），本文件只负责屏幕。
 * ========================================================================== */

/* ---------- 设计令牌 ---------- */
:root {
  --navy: #1a2540;          /* MEG navy 主色 */
  --navy-2: #27365e;        /* navy hover */
  --navy-3: #35477a;
  --green: #6e9b3c;         /* MEG green（成功/计数点缀） */
  --ink: #24292f;           /* 正文 */
  --muted: #5b6472;         /* 次级文字 */
  --line: #d9dee5;          /* 边框 */
  --line-strong: #b6bfca;
  --bg: #f4f5f7;            /* 页面浅灰背景 */
  --card: #ffffff;
  --tint: #eef1f6;          /* 选中态浅 tint */
  --danger: #b3261e;
  --focus: #3f6bd6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(26, 37, 64, 0.06), 0 4px 12px rgba(26, 37, 64, 0.05);
  --toolbar-h: 56px;
  --scroll-offset: 112px;   /* 移动端 sticky 顶栏高度预留 */
  --page-gutter: clamp(14px, 3vw, 28px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
          "PingFang SC", "Microsoft YaHei", sans-serif;
}

/* ---------- Reset / 基础 ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 26px; line-height: 1.25; color: var(--navy); }
h2 { font-size: 19px; line-height: 1.3; color: var(--navy); }
img { max-width: 100%; display: block; }
button { font-family: inherit; }
svg { display: block; }

.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* 可访问性：跳过链接与焦点环 */
.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  padding: 10px 16px; background: var(--navy); color: #fff; border-radius: 0 0 8px 8px;
  text-decoration: none; transition: top 0.15s ease;
}
.skip-link:focus { top: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

/* 通用隐藏：屏幕切换靠 [hidden] */
[hidden] { display: none !important; }

/* ---------- 应用页眉 ---------- */
.app-header {
  background: var(--navy);
  color: #fff;
}
.app-header-inner {
  max-width: 1180px; margin: 0 auto;
  padding: 14px clamp(14px, 3vw, 28px);
}
.brand {
  display: inline-flex; align-items: baseline; gap: 10px;
  color: #fff; text-decoration: none;
}
.brand-name { font-size: 22px; font-weight: 800; letter-spacing: 0.02em; }
.brand-divider { color: rgba(255, 255, 255, 0.55); font-weight: 300; }
.brand-line { font-size: 14.5px; color: rgba(255, 255, 255, 0.92); letter-spacing: 0.01em; }

/* ---------- 主内容容器 ---------- */
.app-main {
  max-width: 1180px; margin: 0 auto;
  padding: 28px var(--page-gutter) 72px;
}

/* ---------- 屏幕公共：步骤横幅 ---------- */
.screen { animation: screen-in 0.18s ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.step-banner { margin: 4px 0 20px; }
.step-pill {
  display: inline-block; padding: 3px 10px; margin-bottom: 10px;
  font-size: 12.5px; font-weight: 700; letter-spacing: 0.04em; color: var(--navy);
  background: #e3e8f2; border-radius: 999px;
}
.step-pill-small { margin-bottom: 0; }
.step-intro { margin-top: 6px; color: var(--muted); max-width: 640px; }

/* ---------- 面板/表单 ---------- */
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.project-panel { padding: 22px clamp(16px, 3vw, 26px) 24px; max-width: 760px; }
.field-grid { display: grid; grid-template-columns: 1fr; gap: 16px 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-full { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: 14.5px; color: var(--navy); }
.opt-tag { font-weight: 400; color: var(--muted); }
.field input,
.field select {
  width: 100%; min-height: 46px; padding: 9px 12px;
  font: inherit; color: var(--ink);
  background: #fff; border: 1px solid var(--line-strong); border-radius: 8px;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.field input::placeholder { color: #98a0ab; }
.field input:focus,
.field select:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(26, 37, 64, 0.12); }
.field input[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(179, 38, 30, 0.12); }
.field-error { margin-top: 4px; font-size: 13.5px; color: var(--danger); }

/* 引用徽标（?ref=XX） */
.ref-label { font-weight: 600; font-size: 14.5px; color: var(--navy); }
.ref-badge {
  display: inline-flex; align-items: center; align-self: flex-start;
  padding: 4px 12px; font-weight: 700; color: #fff;
  background: var(--navy-3); border-radius: 999px; letter-spacing: 0.03em;
}
.ref-hint { display: block; margin-top: 4px; font-size: 13px; color: var(--muted); }

/* 隐私勾选（R7） */
.privacy-row {
  margin: 20px 0 4px; padding: 14px 16px;
  background: var(--tint); border: 1px solid var(--line); border-radius: 10px;
}
.privacy-check {
  display: flex; align-items: flex-start; gap: 10px; cursor: pointer;
  font-size: 15px; font-weight: 600; color: var(--navy);
}
.privacy-check input { position: absolute; opacity: 0; pointer-events: none; }
.privacy-box {
  flex: none; width: 24px; height: 24px; margin-top: -1px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--line-strong); border-radius: 6px; background: #fff;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.privacy-tick { width: 15px; height: 15px; color: #fff; opacity: 0; }
.privacy-check input:checked + .privacy-box { background: var(--navy); border-color: var(--navy); }
.privacy-check input:checked + .privacy-box .privacy-tick { opacity: 1; }
.privacy-check input:focus-visible + .privacy-box { outline: 3px solid var(--focus); outline-offset: 2px; }
.privacy-note { margin: 8px 0 0 34px; font-size: 13px; color: var(--muted); }

/* 操作按钮 */
.actions { margin-top: 22px; display: flex; gap: 12px; align-items: center; }
.actions-between { justify-content: space-between; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px;
  font-size: 15px; font-weight: 600; line-height: 1.2;
  border: 1px solid transparent; border-radius: 8px; cursor: pointer;
  text-decoration: none; transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-2); }
.btn-primary:disabled { background: #9aa3b3; cursor: not-allowed; }
.btn-primary:focus-visible { outline-color: #9db8ff; }
.btn-ghost { background: #fff; color: var(--navy); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--tint); border-color: var(--navy); }
.btn-icon { width: 42px; min-height: 42px; padding: 0; border-radius: 8px; font-size: 20px; }
.btn-lg { min-height: 50px; padding: 12px 26px; font-size: 16px; }

/* ---------- 选配屏：粘性工具栏 ---------- */
.select-toolbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px;
  margin: -28px calc(0px - var(--page-gutter)) 14px;
  padding: 10px var(--page-gutter);
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.toolbar-step { display: flex; align-items: center; gap: 8px; flex: 1 1 200px; }
.toolbar-title { font-weight: 700; color: var(--navy); font-size: 15px; }
.toolbar-right { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.sel-count { font-size: 14px; color: var(--muted); white-space: nowrap; }
.sel-count strong { color: var(--navy); font-size: 16px; }

/* 目录加载/失败 */
.catalog-state { padding: 40px 0; text-align: center; }
.catalog-loading p { color: var(--muted); margin-top: 12px; }
.spinner {
  display: inline-block; width: 30px; height: 30px;
  border: 3px solid #d5dbe4; border-top-color: var(--navy);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.catalog-error p { color: var(--ink); margin: 0 auto 16px; max-width: 420px; }

/* 选配布局：移动=顶部横向 chip 导航；桌面=左侧 rail */
.select-layout { display: block; }
.group-nav {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 10px 0; margin: 0 0 18px;
  -webkit-overflow-scrolling: touch; scrollbar-width: thin;
}
.group-nav::-webkit-scrollbar { height: 4px; }
.group-nav::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }
.group-chip {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  padding: 8px 13px; white-space: nowrap;
  font-size: 14px; font-weight: 600; color: var(--navy);
  background: #fff; border: 1px solid var(--line-strong); border-radius: 999px;
  text-decoration: none; transition: border-color 0.12s ease, background 0.12s ease;
}
.group-chip:hover { border-color: var(--navy); }
.group-chip .chip-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px;
  font-size: 12px; font-weight: 700; color: #fff; background: var(--green);
  border-radius: 999px;
}
.group-chip .chip-count.is-empty { display: none; }

/* 分组区块 */
.select-sections { scroll-margin-top: var(--scroll-offset); }
.cat-section {
  margin: 0 0 34px; padding: 20px 18px 18px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); scroll-margin-top: var(--scroll-offset);
}
.cat-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.cat-count { font-size: 13px; font-weight: 700; color: var(--green); }
.cat-count.is-empty { display: none; }
.cat-desc { margin: 4px 0 16px; color: var(--muted); font-size: 14px; }

/* 选项卡片网格 */
.option-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
}

/* 选项卡片 */
.option-card {
  display: flex; flex-direction: column;
  background: #fff; border: 1.5px solid var(--line); border-radius: 10px;
  overflow: hidden; transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.option-card:hover { border-color: var(--line-strong); }
.option-card.is-selected { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(26, 37, 64, 0.08); }

/* 图位：固定宽高比防 CLS */
.option-media { position: relative; width: 100%; aspect-ratio: 4 / 3; background: #e9ecf1; }
.media-btn {
  display: block; width: 100%; height: 100%; padding: 0;
  border: 0; background: transparent; cursor: zoom-in; overflow: hidden;
}
.option-thumb {
  width: 100%; height: 100%; object-fit: cover;
}
.thumb-placeholder {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; color: #a9b1bd; background: #e9ecf1;
}
.thumb-placeholder svg { width: 46px; height: 46px; }

/* 卡片主体 */
.option-body { display: flex; flex-direction: column; flex: 1; padding: 12px 14px 14px; }
.option-choice {
  display: flex; align-items: flex-start; gap: 10px; cursor: pointer; flex: 1;
}
.option-choice input { position: absolute; opacity: 0; pointer-events: none; }
.option-checkmark {
  flex: none; width: 22px; height: 22px; margin-top: 1px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--line-strong); border-radius: 6px; background: #fff;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.option-checkmark svg { width: 14px; height: 14px; color: #fff; opacity: 0; }
.option-choice input:checked + .option-checkmark { background: var(--navy); border-color: var(--navy); }
.option-choice input:checked + .option-checkmark svg { opacity: 1; }
.option-choice input:focus-visible + .option-checkmark { outline: 3px solid var(--focus); outline-offset: 2px; }
.option-copy { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.option-name { font-weight: 700; font-size: 15px; color: var(--ink); line-height: 1.35; }
.option-desc { font-size: 13.5px; color: var(--muted); line-height: 1.45; }

/* 数量步进（qty_editable，勾选后出现） */
.option-qty {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line);
}
.qty-label { font-size: 13.5px; font-weight: 600; color: var(--muted); }
.qty-stepper { display: inline-flex; align-items: center; gap: 4px; }
.qty-btn {
  width: 36px; height: 36px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1; color: var(--navy);
  background: #fff; border: 1px solid var(--line-strong); border-radius: 8px; cursor: pointer;
}
.qty-btn:hover { background: var(--tint); }
.qty-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.qty-val { min-width: 34px; text-align: center; font-weight: 700; font-size: 16px; color: var(--navy); }

/* ---------- 汇总屏 ---------- */
.summary-panel { margin-bottom: 16px; }
.summary-total {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 18px; margin: 18px 0;
  background: var(--tint); border: 1px solid var(--line); border-radius: var(--radius);
}
.summary-total strong { color: var(--navy); font-size: 17px; }
.summary-group { padding: 18px 18px 6px; }
.summary-group + .summary-group { border-top: 1px solid var(--line); }
.summary-group h3 {
  margin: 0 0 4px; font-size: 16px; color: var(--navy);
}
.summary-group .g-desc { margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.item-list { list-style: none; margin: 0; padding: 0 0 12px; }
.item-row {
  display: flex; align-items: baseline; gap: 10px;
  padding: 8px 0; border-bottom: 1px dashed var(--line);
}
.item-row:last-child { border-bottom: 0; }
.item-name { font-weight: 600; }
.item-desc { color: var(--muted); font-size: 13.5px; }
.item-qty { flex: none; margin-left: auto; font-size: 13px; font-weight: 700; color: var(--navy); white-space: nowrap; }
.empty-state { padding: 40px 18px; text-align: center; color: var(--muted); }
.empty-state p { max-width: 420px; margin: 0 auto; }
.summary-foot { margin-top: 22px; }
.save-hint { color: var(--muted); font-size: 13.5px; margin-bottom: 8px; }

/* ---------- R6 已选总览确认屏 ---------- */
.success-banner {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 16px 18px; margin-bottom: 20px;
  background: #f0f6e8; border: 1px solid #cfe0b4; border-radius: var(--radius);
}
.success-banner h1 { font-size: 21px; color: #33520f; margin-bottom: 4px; }
.success-banner p { color: #44551f; font-size: 14.5px; }
.success-tick {
  flex: none; width: 26px; height: 26px; padding: 4px; margin-top: 2px;
  color: #fff; background: var(--green); border-radius: 50%;
}
.overview-meta { padding: 16px 18px; margin-bottom: 18px; font-size: 14.5px; }
.overview-meta h2 { margin: 0 0 10px; font-size: 16px; color: var(--navy); }
.meta-grid { display: grid; grid-template-columns: 1fr; gap: 10px 24px; margin-top: 8px; }
.meta-row { display: flex; gap: 8px; flex-wrap: wrap; }
.meta-k { font-weight: 700; color: var(--navy); min-width: 96px; }
.meta-v { color: var(--ink); }
.meta-note { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); color: var(--muted); font-size: 13.5px; }

.overview-group {
  padding: 16px 18px 6px; margin-bottom: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.overview-group h3 { margin: 0 0 2px; font-size: 16px; color: var(--navy); }
.overview-group .g-desc { margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.ov-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 0; border-bottom: 1px dashed var(--line);
}
.ov-item:last-child { border-bottom: 0; }
.ov-thumb {
  flex: none; width: 56px; height: 42px; border-radius: 6px; overflow: hidden;
  background: #e9ecf1; display: flex; align-items: center; justify-content: center;
}
.ov-thumb img { width: 100%; height: 100%; object-fit: cover; }
.ov-thumb .thumb-placeholder { width: 56px; height: 42px; }
.ov-thumb .thumb-placeholder svg { width: 20px; height: 20px; }
.ov-copy { min-width: 0; flex: 1; }
.ov-copy .item-name { font-weight: 600; font-size: 15px; display: block; }
.ov-copy .item-desc { color: var(--muted); font-size: 13px; display: block; margin-top: 2px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; z-index: 90;
  transform: translate(-50%, 16px);
  max-width: min(92vw, 460px); padding: 12px 18px;
  color: #fff; background: var(--navy); border-radius: 10px;
  font-size: 14.5px; text-align: center;
  box-shadow: 0 8px 24px rgba(26, 37, 64, 0.28);
  opacity: 0; pointer-events: none; transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: #8a241e; }

/* ---------- Lightbox（图片放大预览，可选增强） ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  background: rgba(12, 16, 28, 0.82); padding: 24px;
}
.lightbox img {
  max-width: min(92vw, 860px); max-height: 86vh;
  border-radius: 10px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}
.lightbox-close {
  position: absolute; top: 14px; right: 14px;
  width: 44px; height: 44px; padding: 0;
  font-size: 26px; line-height: 1; color: #fff;
  background: rgba(255, 255, 255, 0.12); border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%; cursor: pointer;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.24); }

/* ---------- 页脚 ---------- */
.app-footer {
  padding: 18px 16px 26px; text-align: center;
  color: var(--muted); font-size: 13px;
}
.noscript-note { padding: 40px 16px; text-align: center; color: var(--muted); }

/* 打印规格书容器：屏幕隐藏，仅打印时由 print.css 显示 */
#spec-print { display: none; }

/* ---------- 断点：≥768px ---------- */
@media (min-width: 768px) {
  .field-grid { grid-template-columns: 1fr 1fr; }
  .meta-grid { grid-template-columns: 1fr 1fr; }
  .toolbar-right { flex: 0 0 auto; }
}

/* ---------- 断点：≥1024px（左侧 sticky rail） ---------- */
@media (min-width: 1024px) {
  :root { --scroll-offset: 68px; }
  .app-main { padding-top: 36px; }
  .select-toolbar { margin-top: -36px; flex-wrap: nowrap; }
  .select-layout {
    display: grid; grid-template-columns: 240px minmax(0, 1fr);
    gap: 26px; align-items: start;
  }
  .group-nav {
    position: sticky; top: calc(var(--toolbar-h) + 12px);
    flex-direction: column; align-items: stretch;
    overflow: visible; padding: 0; margin: 0;
    scrollbar-width: none;
  }
  .group-chip { justify-content: space-between; border-radius: 8px; }
  .select-sections { padding-top: 2px; }
}

/* ---------- 无障碍动效 ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation: none !important; transition: none !important; }
}
