:root {
  --bg-1: #f4f6fb;
  --bg-2: #eef1f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --border: #e6e9f0;
  --border-strong: #d5dae6;
  --text: #0f1729;
  --text-2: #48526b;
  --muted: #8a93a6;
  --primary: #4f46e5;
  --primary-2: #6366f1;
  --primary-dark: #4338ca;
  --emerald: #10b981;
  --amber: #f59e0b;
  --rose: #f43f5e;
  --sky: #0ea5e9;
  --box-a: #6366f1;
  --box-b: #ec4899;
  --shadow-sm: 0 1px 2px rgba(15, 23, 41, 0.05);
  --shadow: 0 8px 24px rgba(15, 23, 41, 0.06);
  --shadow-lg: 0 20px 50px rgba(15, 23, 41, 0.10);
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

/* hidden 屬性優先於任何 display 規則（如 .viz 的 grid） */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Inter", "Noto Sans TC", -apple-system, BlinkMacSystemFont,
    "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 100% -10%, #e0e7ff 0%, transparent 55%),
    radial-gradient(1000px 500px at -10% 0%, #dbeafe 0%, transparent 50%),
    linear-gradient(180deg, var(--bg-1), var(--bg-2));
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 13px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary-2), var(--primary-dark));
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.35);
}
.brand-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.brand-text h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.3px;
  line-height: 1.15;
}
.subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.2px;
  text-transform: none;
  font-weight: 600;
}
.header-badge {
  font-size: 12px; font-weight: 600; color: var(--primary-dark);
  background: #eef2ff; border: 1px solid #e0e7ff;
  padding: 7px 13px; border-radius: 999px;
}
.header-actions { display: flex; align-items: center; gap: 12px; }

.lang-menu { position: relative; }
.lang-globe-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit; font-size: 12.5px; font-weight: 600;
  color: var(--text-2);
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px 6px 12px;
  cursor: pointer;
  transition: all .15s;
}
.lang-globe-btn svg { flex: none; color: var(--primary); }
.lang-globe-btn:hover {
  color: var(--text);
  background: #e8ecf5;
  border-color: var(--border-strong);
}
.lang-menu.open .lang-globe-btn {
  color: #fff;
  background: linear-gradient(135deg, var(--primary-2), var(--primary-dark));
  border-color: transparent;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.3);
}
.lang-menu.open .lang-globe-btn svg { color: #fff; }

.lang-menu-list {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  margin: 0;
  padding: 6px;
  list-style: none;
  min-width: 168px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 30;
}
.lang-menu-list li + li { margin-top: 2px; }
.lang-btn {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--text-2);
  background: transparent;
  border: none;
  padding: 8px 12px;
  border-radius: 9px;
  cursor: pointer;
  transition: all .15s;
}
.lang-btn:hover { color: var(--text); background: var(--panel-soft); }
.lang-btn.on {
  color: #fff;
  background: linear-gradient(135deg, var(--primary-2), var(--primary-dark));
}

/* ---------- Layout ---------- */
.layout {
  max-width: 1240px;
  margin: 28px auto;
  padding: 0 28px;
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 26px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.inputs {
  padding: 8px 22px 22px;
  align-self: start;
}

/* ---------- Sections ---------- */
.card-section {
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
}
.card-section:last-of-type { border-bottom: none; }
.section-head { display: flex; align-items: center; gap: 9px; margin-bottom: 15px; }
.section-icon { font-size: 16px; line-height: 1; }
.section-head h2 {
  font-size: 14px; font-weight: 700; margin: 0; color: var(--text);
  letter-spacing: 0.3px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

/* ---------- Fields ---------- */
.field {
  display: flex; flex-direction: column; gap: 7px;
  font-size: 12.5px; font-weight: 600; color: var(--text-2);
  margin-bottom: 12px;
}
.field:last-child { margin-bottom: 0; }
.grid-2 .field, .grid-3 .field { margin-bottom: 0; }
.grid-2, .grid-3 { margin-bottom: 12px; }
.card-section .grid-2:last-child, .card-section .grid-3:last-child { margin-bottom: 0; }

.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap input, .input-wrap select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600;
  color: var(--text);
  background: var(--panel-soft);
  transition: border-color .15s, box-shadow .15s, background .15s;
  appearance: none;
}
.input-wrap input:focus, .input-wrap select:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12);
}
.input-wrap input[type="number"] { padding-right: 42px; }
.input-wrap select { cursor: pointer; padding-right: 34px; }
/* 隱藏數字輸入框的上下箭頭 */
.input-wrap input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.input-wrap input[type="number"]::-webkit-outer-spin-button,
.input-wrap input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.unit-suffix {
  position: absolute; right: 12px;
  font-size: 12px; font-weight: 600; color: var(--muted);
  pointer-events: none;
}
.input-wrap:has(select)::after {
  content: ""; position: absolute; right: 14px;
  width: 8px; height: 8px; border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted); transform: rotate(45deg) translateY(-2px);
  pointer-events: none;
}

/* ---------- Unit toggle ---------- */
.unit-toggle {
  display: flex; gap: 5px;
  background: var(--panel-soft);
  padding: 5px; border-radius: 12px;
  border: 1px solid var(--border);
}
.unit-toggle label {
  flex: 1; text-align: center;
  padding: 9px 6px; border-radius: 8px;
  font-size: 13px; font-weight: 600; color: var(--text-2);
  cursor: pointer; transition: all .15s;
}
.unit-toggle input { display: none; }
.unit-toggle label:has(input:checked) {
  background: #fff; color: var(--primary-dark);
  box-shadow: var(--shadow-sm);
}

/* ---------- Mode toggle ---------- */
.mode-toggle {
  display: flex; gap: 5px;
  background: var(--panel-soft);
  padding: 5px; border-radius: 12px;
  border: 1px solid var(--border);
}
.mode-btn {
  flex: 1; text-align: center;
  font: inherit; font-size: 13px; font-weight: 700;
  color: var(--text-2);
  background: transparent;
  border: none; border-radius: 8px;
  padding: 10px 6px; cursor: pointer;
  transition: all .15s;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.on {
  color: #fff;
  background: linear-gradient(135deg, var(--primary-2), var(--primary-dark));
  box-shadow: var(--shadow-sm);
}

/* 貨櫃裝棧板：單一／混合棧板尺寸切換（字較長，加大字級與按鈕高度） */
.cp-mode-toggle {
  padding: 6px;
  gap: 6px;
}
.mode-btn.cp-mode-btn {
  font-size: 15px;
  line-height: 1.45;
  padding: 14px 10px;
  letter-spacing: 0.01em;
}

/* ---------- Calc-type toggle ---------- */
.calctype-toggle {
  display: flex; gap: 5px;
  background: var(--panel-soft);
  padding: 5px; border-radius: 12px;
  border: 1px solid var(--border);
}
.calctype-btn {
  flex: 1; text-align: center;
  font: inherit; font-size: 12px; font-weight: 700;
  color: var(--text-2);
  background: transparent;
  border: none; border-radius: 8px;
  padding: 10px 4px; cursor: pointer;
  transition: all .15s;
  line-height: 1.25;
}
.calctype-btn:hover { color: var(--text); }
.calctype-btn.on {
  color: #fff;
  background: linear-gradient(135deg, var(--primary-2), var(--primary-dark));
  box-shadow: var(--shadow-sm);
}

/* 頁首下方的全寬計算類型列 */
.calctype-bar {
  max-width: 1240px;
  margin: 20px auto 0;
  padding: 0 28px;
}
.calctype-bar .calctype-toggle {
  display: flex;
  width: 100%;
  gap: 6px;
  padding: 6px;
}
.calctype-bar .calctype-btn {
  flex: 1 1 0;
  font-size: 13.5px;
  padding: 11px 12px;
}
@media (max-width: 640px) {
  .calctype-bar { padding: 0 16px; }
  .calctype-bar .calctype-btn { padding: 10px 6px; font-size: 12px; }
}

/* ---------- Product list (mixed mode) ---------- */
.product-row {
  padding: 14px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}
.product-row .grid-3,
.product-row .grid-2 {
  margin-bottom: 0;
}
.product-row .field {
  margin-bottom: 0;
}
.product-row-top {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 12px;
}
.product-row-name {
  flex: 1;
}
.p-del {
  flex-shrink: 0;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #fff; color: var(--muted);
  cursor: pointer; font-size: 15px;
  transition: all .15s;
}
.p-del:hover { border-color: var(--rose); color: var(--rose); background: #fff1f2; }
.btn-add {
  width: 100%; margin-top: 6px;
  padding: 10px; border: 1.5px dashed var(--border-strong);
  border-radius: 10px; background: var(--panel-soft);
  color: var(--primary-dark); font: inherit; font-size: 13px; font-weight: 700;
  cursor: pointer; transition: all .15s;
}
.btn-add:hover { border-color: var(--primary); background: #eef2ff; }

/* ---------- Ranked placement options ---------- */
.result-options {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.options-head { font-size: 13px; font-weight: 700; color: var(--text-2); margin-bottom: 12px; }
.options-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}
.option-card {
  text-align: left;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--panel-soft);
  cursor: pointer;
  transition: all .15s;
  font: inherit;
}
.option-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.option-card.on {
  border-color: var(--primary);
  background: #eef2ff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}
.option-top { display: flex; align-items: center; gap: 7px; margin-bottom: 9px; }
.option-rank { font-size: 12px; font-weight: 800; color: var(--muted); }
.option-badge {
  font-size: 10px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--primary-2), var(--primary-dark));
  padding: 2px 7px; border-radius: 999px; letter-spacing: 0.3px;
}
.option-orient { font-size: 12.5px; font-weight: 700; color: var(--text); margin-left: auto; }
.option-stats { display: flex; justify-content: space-between; gap: 6px; }
.option-stats span { display: flex; flex-direction: column; gap: 2px; }
.option-stats strong { font-size: 15px; font-weight: 800; color: var(--text); }
.option-stats small { font-size: 10px; color: var(--muted); font-weight: 600; }
.option-vol strong { color: var(--primary-dark); }

/* ---------- Mixed results ---------- */
.mix-legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  margin-bottom: 6px;
}
.mix-legend-title { font-size: 12.5px; font-weight: 700; color: var(--muted); }
.mix-swatch { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.mix-swatch i { width: 13px; height: 13px; border-radius: 4px; display: inline-block; }
.pallet-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}
.pallet-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--panel-soft);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.pallet-card:hover { border-color: var(--primary); transform: translateY(-1px); }
.pallet-card:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.pallet-card.on {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary) inset, 0 6px 16px rgba(79, 70, 229, 0.15);
}
.mix-click-hint {
  font-size: 12px;
  color: var(--muted);
  margin: 2px 0 10px;
}
.pallet-svg { display: grid; place-items: center; min-height: 150px; }
.pallet-svg svg { max-width: 100%; height: auto; }
.pallet-title { font-size: 13px; font-weight: 800; color: var(--text); margin-top: 8px; }
.mix-layers {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mix-layers[hidden] { display: none; }
.mix-layers-hint { font-size: 11px; font-weight: 700; color: var(--muted); }
.mix-layer { display: grid; place-items: center; gap: 3px; }
.mix-layer-svg svg { max-width: 100%; height: auto; }
.mix-layer-cap { font-size: 11px; color: var(--text-2); line-height: 1.4; }
.layer-breakdown {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.layer-breakdown[hidden] { display: none; }
.layer-breakdown-hint { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 10px; }
.layer-breakdown-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
}
.layer-cell { display: grid; place-items: center; gap: 4px; }
.layer-cell svg { max-width: 100%; height: auto; }
.layer-cell-cap { font-size: 11.5px; color: var(--text-2); line-height: 1.4; text-align: center; max-width: 180px; }
.pallet-comp { font-size: 12px; color: var(--text-2); margin-top: 4px; line-height: 1.5; }
.pallet-meta { font-size: 11.5px; color: var(--muted); margin-top: 5px; }
.mix-table thead th {
  font-size: 11.5px; font-weight: 700; color: var(--muted);
  text-align: left; padding: 8px 10px;
  border-bottom: 2px solid var(--border);
  text-transform: uppercase; letter-spacing: 0.2px;
}
.mix-bad { color: var(--rose); font-weight: 700; }
.mix-note { font-size: 12.5px; color: var(--rose); margin: 10px 2px 0; font-weight: 600; }
.details .mix-table { margin-top: 16px; }
.details .mix-table td { padding: 9px 10px; text-align: left; font-size: 13px; }
.details .mix-table td:last-child { text-align: center; }
.details .mix-table td:first-child { font-weight: 700; color: var(--text); }

/* ---------- Switch rows ---------- */
.switch-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: 12px;
  cursor: pointer; transition: border-color .15s, background .15s;
}
.switch-row:last-child { margin-bottom: 0; }
.switch-row:hover { border-color: var(--border-strong); }
.switch-row input { display: none; }
.switch {
  flex: none; margin-top: 1px;
  width: 38px; height: 22px; border-radius: 999px;
  background: #d5dae6; position: relative; transition: background .18s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: var(--shadow-sm); transition: transform .18s;
}
.switch-row input:checked + .switch { background: var(--primary); }
.switch-row input:checked + .switch::after { transform: translateX(16px); }
.switch-label {
  font-size: 13.5px; font-weight: 600; color: var(--text);
  display: flex; flex-direction: column; gap: 2px; line-height: 1.35;
}
.switch-label em { font-style: normal; font-weight: 500; font-size: 12px; color: var(--muted); }

.up-axis-row { margin-top: 4px; padding-left: 50px; }

/* ---------- Button ---------- */
.btn-primary {
  width: 100%; margin-top: 20px;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  padding: 14px; border: none; border-radius: 12px;
  background: linear-gradient(135deg, var(--primary-2), var(--primary-dark));
  color: #fff; font-size: 15.5px; font-weight: 700; cursor: pointer;
  box-shadow: 0 10px 22px rgba(79, 70, 229, 0.35);
  transition: transform .1s, box-shadow .15s, filter .15s;
  font-family: inherit;
}
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.05); box-shadow: 0 14px 28px rgba(79, 70, 229, 0.42); }
.btn-primary:active { transform: translateY(0); }

/* ---------- Results ---------- */
.results { display: flex; flex-direction: column; gap: 22px; }
.results-toolbar { display: flex; align-items: center; }
.results-title { font-size: 17px; font-weight: 800; margin: 0; letter-spacing: -0.2px; }
.btn-print {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: inherit; font-size: 13.5px; font-weight: 700;
  color: var(--primary-dark);
  background: #fff; border: 1px solid var(--border-strong);
  border-radius: 10px; padding: 9px 15px; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: all .15s;
}
.btn-print:hover { border-color: var(--primary); background: #eef2ff; transform: translateY(-1px); }

.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.card {
  position: relative; overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 18px;
  box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: var(--accent, var(--primary));
}
.card .card-ico { font-size: 18px; margin-bottom: 8px; display: block; }
.card .value { font-size: 32px; font-weight: 800; letter-spacing: -1px; line-height: 1; color: var(--text); }
.card .value small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.card .label { font-size: 12.5px; color: var(--muted); margin-top: 7px; font-weight: 600; }
.card.c-indigo { --accent: linear-gradient(90deg, var(--primary-2), var(--primary-dark)); }
.card.c-sky    { --accent: linear-gradient(90deg, #38bdf8, var(--sky)); }
.card.c-emerald{ --accent: linear-gradient(90deg, #34d399, var(--emerald)); }
.card.c-amber  { --accent: linear-gradient(90deg, #fbbf24, var(--amber)); }
.card.c-violet { --accent: linear-gradient(90deg, #a78bfa, #7c3aed); }
.card.highlight .value { color: var(--primary-dark); }
.card.warn { grid-column: 1 / -1; }
.card.warn::before { background: var(--rose); }
.card.warn .value { color: var(--rose); font-size: 22px; }

/* ---------- Viz ---------- */
.viz { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.viz-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.viz-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.viz-head h3 { font-size: 14px; font-weight: 700; margin: 0; }
.svg-wrap {
  background:
    linear-gradient(var(--panel-soft), var(--panel-soft)) padding-box,
    repeating-linear-gradient(45deg, #eef1f8 0 10px, #f4f6fb 10px 20px);
  border: 1px dashed var(--border-strong);
  border-radius: 12px;
  padding: 14px;
  display: flex; justify-content: center; align-items: center;
  min-height: 240px;
}
.svg-wrap svg { max-width: 100%; height: auto; filter: drop-shadow(0 4px 8px rgba(15,23,41,0.08)); }
.viz-note { font-size: 12.5px; color: var(--muted); margin: 12px 0 0; text-align: center; font-weight: 500; }

.legend { display: flex; gap: 18px; justify-content: center; font-size: 12px; color: var(--text-2); margin-top: 12px; font-weight: 600; }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.swatch { width: 13px; height: 13px; border-radius: 4px; display: inline-block; }

/* ---------- 檢視選擇（整板 / 尾板）---------- */
.view-chooser {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
}
.view-chooser:empty { display: none; }
.chooser-label { font-size: 13.5px; font-weight: 700; color: var(--text-2); }
.chooser-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.seg {
  font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--text-2);
  background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: 10px; padding: 9px 15px; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: all .15s;
}
.seg:hover:not(:disabled) { border-color: var(--primary); color: var(--primary-dark); }
.seg:disabled { opacity: 0.45; cursor: not-allowed; }
.seg.seg-on {
  background: linear-gradient(135deg, var(--primary-2), var(--primary-dark));
  border-color: var(--primary-dark); color: #fff;
  box-shadow: 0 6px 14px rgba(79, 70, 229, 0.32);
}

/* ---------- 3D View ---------- */
.view3d-block { padding-bottom: 16px; }
.view3d-controls { display: flex; gap: 8px; }
.chip {
  font-family: inherit;
  font-size: 12.5px; font-weight: 600;
  color: var(--text-2);
  background: var(--panel-soft);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 6px 13px;
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { border-color: var(--primary); color: var(--primary-dark); }
.chip.chip-on {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}
.view3d-canvas {
  position: relative;
  width: 100%;
  height: 440px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: #eef1f8;
}
.view3d-canvas canvas { display: block; width: 100% !important; height: 100% !important; }
.view3d-loading {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--muted); font-size: 14px; font-weight: 600;
}

/* ---------- Details ---------- */
.details-block { padding-bottom: 8px; }
.details-actions {
  display: flex; align-items: center;
  gap: 10px; margin-top: 14px; flex-wrap: wrap;
}
.details-actions .btn-print { margin-left: auto; }
.btn-export-container {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: inherit; font-size: 13.5px; font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border: none;
  border-radius: 10px; padding: 10px 16px; cursor: pointer;
  box-shadow: 0 8px 18px rgba(79, 70, 229, 0.3);
  transition: transform .1s, box-shadow .15s, filter .15s;
}
.btn-export-container:hover { transform: translateY(-1px); filter: brightness(1.05); box-shadow: 0 12px 24px rgba(79, 70, 229, 0.4); }
.btn-export-container:active { transform: translateY(0); }
.details table { width: 100%; border-collapse: collapse; font-size: 14px; }
.details td { padding: 13px 4px; border-bottom: 1px solid var(--border); }
.details tr:last-child td { border-bottom: none; }
.details td:first-child { color: var(--text-2); font-weight: 500; }
.details td:last-child { text-align: right; font-weight: 700; color: var(--text); }

/* ---------- Footer ---------- */
.seo-about { max-width: 880px; margin: 12px auto 0; padding: 24px 20px 8px; color: var(--muted); }
.seo-about h2 { font-size: 16px; font-weight: 700; color: var(--text); margin: 0 0 8px; }
.seo-about h3 { font-size: 14px; font-weight: 700; color: var(--text); margin: 18px 0 8px; }
.seo-about p { font-size: 13px; line-height: 1.8; margin: 0; }
.seo-faq details { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; background: var(--panel); }
.seo-faq summary { font-size: 13.5px; font-weight: 600; color: var(--text); cursor: pointer; }
.seo-faq p { margin-top: 8px; }

.app-footer { text-align: center; color: var(--muted); font-size: 12.5px; padding: 8px 20px 34px; }

/* ---------- 列印報告 ---------- */
.report-print { display: none; }
.report-summary { display: block; }
.report-header { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 3px solid #4f46e5; padding-bottom: 12px; margin-bottom: 18px; }
.report-header h1 { margin: 0; font-size: 24px; font-weight: 800; color: #1e1b4b; }
.report-sub { margin: 2px 0 0; font-size: 12px; letter-spacing: 3px; text-transform: uppercase; color: #6b7280; }
.report-meta { text-align: right; font-size: 12px; color: #4b5563; line-height: 1.7; }
.report-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.rcard { border: 1px solid #d1d5db; border-radius: 10px; padding: 14px; text-align: center; }
.rcard .rc-val { font-size: 26px; font-weight: 800; color: #111827; }
.rcard .rc-lab { font-size: 11.5px; color: #6b7280; margin-top: 4px; }
.rcard.rc-hl { background: #eef2ff; border-color: #c7d2fe; }
.rcard.rc-hl .rc-val { color: #4338ca; }
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 18px; }
.report-box h3 { font-size: 13px; margin: 0 0 8px; color: #374151; border-left: 3px solid #4f46e5; padding-left: 8px; }
.report-box table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.report-box td { padding: 7px 4px; border-bottom: 1px solid #e5e7eb; }
.report-box td:first-child { color: #6b7280; }
.report-box td:last-child { text-align: right; font-weight: 700; color: #111827; }
.report-visuals { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; align-items: start; }
.report-visual-3d { display: flex; flex-direction: column; align-items: center; text-align: center; }
.report-visual-3d .report-iso-svg { width: auto; max-width: 100%; height: auto; margin: 0 auto; }
.report-section-title { font-size: 15px; margin: 0 0 12px; color: #1e1b4b; border-left: 4px solid #4f46e5; padding-left: 10px; }
.report-solutions { display: flex; flex-direction: column; gap: 0; }
.report-solution-page { margin: 0; }
.report-solution { border: 1px solid #e5e7eb; border-radius: 12px; padding: 16px; background: #fafafa; }
.report-solution-title { margin: 0 0 10px; font-size: 14px; font-weight: 800; color: #312e81; }
.report-solution-details table { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 14px; }
.report-solution-details td { padding: 6px 4px; border-bottom: 1px solid #e5e7eb; }
.report-solution-details td:first-child { color: #6b7280; width: 42%; }
.report-solution-details td:last-child { text-align: right; font-weight: 700; color: #111827; }
.report-solution .report-visual h5,
.report-solution .report-2d h5 { font-size: 12px; margin: 0 0 6px; color: #4b5563; font-weight: 700; }
.report-visual h3 { font-size: 13px; margin: 0 0 8px; color: #374151; border-left: 3px solid #4f46e5; padding-left: 8px; }
.report-visual img, .report-visual svg { max-width: 100%; height: auto; border: 1px solid #e5e7eb; border-radius: 8px; }
.report-2d { display: flex; flex-direction: column; gap: 14px; }
.report-2d .report-visual { text-align: center; }
.report-layer-breakdown { margin-top: 14px; }
.report-layer-breakdown > h5 {
  font-size: 12px; margin: 0 0 8px; color: #4b5563; font-weight: 700;
}
.report-layer-breakdown .layer-breakdown-grid {
  display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-start;
}
.report-layer-breakdown .layer-cell { max-width: 160px; }
.report-layer-breakdown .layer-cell-cap { font-size: 10.5px; }
.report-page-footer {
  margin-top: 16px;
  padding-top: 10px;
  border-top: 1px solid #e5e7eb;
  font-size: 13px;
  line-height: 1.4;
  color: #6b7280;
  text-align: center;
}

@media print {
  /* 底部邊距維持一致；免責句改由各頁內容內的 report-page-footer 顯示 */
  @page { size: A4; margin: 10mm; }
  html, body { background: #fff !important; }
  body > *:not(#report) { display: none !important; }
  #report { display: block !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* 第 1 頁：只放摘要，強制換頁後才開始方案明細 */
  .report-summary {
    break-after: page;
    page-break-after: always;
  }
  /* 各邏輯頁做成欄位排版，把頁內免責句推到該頁底部 */
  .report-summary,
  .report-solution-page {
    display: flex;
    flex-direction: column;
    min-height: 257mm; /* A4 約 297mm − 上下邊距 */
    box-sizing: border-box;
  }
  .report-header { margin-bottom: 12px; padding-bottom: 8px; }
  .report-header h1 { font-size: 20px; }
  .report-cards { gap: 8px; margin-bottom: 12px; }
  .rcard { padding: 10px; }
  .rcard .rc-val { font-size: 22px; }
  .report-grid { gap: 12px; margin-bottom: 0; }
  .report-box td { padding: 5px 4px; }
  .report-header, .report-cards, .report-grid { break-inside: avoid; page-break-inside: avoid; }

  /* flex 容器的子元素在桌面 Chrome／Edge 常忽略 break-before；列印時改為區塊排版 */
  .report-solutions { display: block; }
  /* 每個方案（整板／尾板）整塊不可跨頁，避免標題掉到上一頁底部 */
  .report-solution-page,
  .report-solution {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  /* 第 2 頁：整板（接在摘要 break-after 之後）；第 3 頁：尾板 */
  .report-solution-page-last {
    break-before: page;
    page-break-before: always;
  }
  .report-section-title { font-size: 13px; margin: 0 0 8px; }
  .report-solution {
    border-radius: 8px;
    padding: 10px 12px;
    background: #fafafa;
  }
  .report-solution-title { margin: 0 0 6px; font-size: 13px; }
  .report-solution-details {
    column-count: 2;
    column-gap: 16px;
    margin-bottom: 8px;
  }
  .report-solution-details table {
    width: 100%;
    font-size: 10.5px;
    margin-bottom: 0;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .report-solution-details td { padding: 3px 2px; }
  .report-solution-details td:first-child { width: 46%; }
  .report-visuals {
    grid-template-columns: 1.1fr 0.9fr;
    gap: 10px;
    align-items: start;
  }
  .report-solution .report-visual h5,
  .report-solution .report-2d h5 { font-size: 10.5px; margin: 0 0 4px; }
  .report-2d { gap: 8px; }
  .report-visual img {
    display: block;
    width: 100%;
    max-height: 220px;
    object-fit: contain;
    background: #eef1f8;
  }
  .report-visual-3d .report-iso-svg {
    display: block;
    width: auto;
    max-width: 100%;
    max-height: 240px;
    height: auto;
    margin: 0 auto;
  }
  .report-2d .report-visual svg {
    display: block;
    max-width: 100%;
    max-height: 150px;
    width: auto;
    height: auto;
    margin: 0 auto;
  }
  .report-layer-breakdown { margin-top: 8px; page-break-inside: avoid; }
  .report-layer-breakdown > h5 { font-size: 10.5px; margin: 0 0 4px; }
  .report-layer-breakdown .layer-breakdown-grid { gap: 6px; }
  .report-layer-breakdown .layer-cell svg { max-width: 110px; height: auto; }
  .report-layer-breakdown .layer-cell-cap { font-size: 9.5px; }
  /* 頁內免責句：落在每頁內容底部（箱子直接裝櫃等內容較滿時仍可見） */
  .report-page-footer {
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid #e5e7eb;
    font-size: 12.5px;
    line-height: 1.4;
    color: #4b5563;
    text-align: center;
    background: #fff;
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .inputs { position: static; }
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
  .viz { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .header-badge { display: none; }
  .summary-cards { grid-template-columns: 1fr 1fr; }
  .layout, .header-inner { padding-left: 16px; padding-right: 16px; }
}
