/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f2f5;
  color: #2a2e1a;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
header {
  background: #2a2e1a;
  color: white;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

#header-sub {
  font-size: 0.85rem;
  opacity: 0.6;
  flex: 1;
}

.back-btn {
  background: rgba(255,255,255,0.12);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
  transition: background 0.2s;
}
.back-btn:hover { background: rgba(255,255,255,0.2); }

/* ── User Chip (header right) ── */
.user-info { display: flex; flex-direction: column; line-height: 1.2; }
.user-email { font-size: 10px; color: rgba(255,255,255,0.45); }
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(255,255,255,0.3);
}

#user-name {
  font-size: 0.82rem;
  opacity: 0.85;
  white-space: nowrap;
}

.btn-logout {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.75);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 0.78rem;
  text-decoration: none;
  white-space: nowrap;
  transition: all 0.2s;
}
.btn-logout:hover { background: rgba(255,255,255,0.18); color: white; }

/* ── Views ── */
.view { display: none; flex: 1; overflow: hidden; }
.view.active { display: flex; flex-direction: column; }

/* ── Products View ── */
.page-intro {
  padding: 24px 28px 12px;
}
.page-intro h2 { font-size: 1.2rem; font-weight: 600; margin-bottom: 4px; }
.page-intro p  { font-size: 0.9rem; color: #666; }

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 20px;
  padding: 16px 28px 28px;
  overflow-y: auto;
  align-content: start;
}

.product-card {
  background: white;
  border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  overflow: hidden;
  border: 2px solid transparent;
}
.product-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
  border-color: #7c7c3c;
}

.product-thumb {
  width: 100%;
  height: 150px;
  object-fit: cover;
  background: #e8edf3;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  color: #aaa;
}
.product-thumb img { width: 100%; height: 100%; object-fit: cover; }

.product-info { padding: 14px 16px; }
.product-info h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 4px; }
.product-info p  { font-size: 0.8rem; color: #888; }

.loading-card {
  grid-column: 1/-1;
  text-align: center;
  padding: 60px;
  color: #888;
  font-size: 0.95rem;
}

.error-card {
  grid-column: 1/-1;
  background: #fff5f5;
  border: 1px solid #fed7d7;
  border-radius: 10px;
  padding: 20px 24px;
  color: #c53030;
  font-size: 0.9rem;
  line-height: 1.6;
}

/* ── Configurator Layout ── */
.configurator-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Viewer ── */
.viewer-wrap {
  flex: 1;
  position: relative;
  background: #2a2e1a;
}

#aps-viewer {
  width: 100%;
  height: 100%;
  background: #2a2e1a;
}

#model-viewer {
  width: 100%;
  height: 100%;
  background: #2a2e1a;
}

.viewer-sample-banner {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  padding: 9px 16px;
  background: rgba(0,0,0,0.52);
  backdrop-filter: blur(6px);
  color: rgba(255,255,255,0.8);
  font-size: 0.78rem;
  text-align: center;
  pointer-events: none;
  letter-spacing: 0.01em;
}

.viewer-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2a2e1a;
  color: rgba(255,255,255,0.4);
  text-align: center;
}
.viewer-placeholder-inner { line-height: 1.8; }
.viewer-icon { font-size: 3rem; margin-bottom: 12px; }
.placeholder-contact {
  margin-top: 20px;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.35);
  line-height: 1.8;
}
.placeholder-contact a {
  color: rgba(255,255,255,0.55);
  text-decoration: none;
}
.placeholder-contact a:hover { color: rgba(255,255,255,0.85); }

/* ── Config Panel ── */
.config-panel {
  width: 360px;
  flex-shrink: 0;
  background: white;
  display: flex;
  flex-direction: column;
  box-shadow: -2px 0 10px rgba(0,0,0,0.06);
  overflow: hidden;
}

.product-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  gap: 12px;
}
.product-header h2 { font-size: 1rem; font-weight: 600; }
.release-label {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.75rem;
  background: #f4f9c8;
  color: #7c7c3c;
  padding: 2px 8px;
  border-radius: 20px;
}

/* ── Tabs ── */
.tabs { display: flex; border-bottom: 1px solid #eee; }
.tab {
  flex: 1;
  padding: 10px 0;
  border: none;
  background: none;
  font-size: 0.82rem;
  font-weight: 500;
  color: #888;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.tab.active { color: #7c7c3c; border-bottom-color: #7c7c3c; }
.tab:hover:not(.active) { color: #444; }

/* ── Tab Content ── */
.tab-content { display: none; flex: 1; overflow-y: auto; flex-direction: column; }
.tab-content.active { display: flex; }

/* ── Params Form ── */
.params-form {
  flex: 1;
  overflow-y: scroll;
  padding: 16px 20px;
  scrollbar-gutter: stable;
}
.params-form::-webkit-scrollbar { width: 6px; }
.params-form::-webkit-scrollbar-track { background: rgba(0,0,0,0.05); border-radius: 3px; }
.params-form::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.25); border-radius: 3px; }
.params-form::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.4); }

.param-group { margin-bottom: 16px; }
.param-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #444;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.param-group .param-unit {
  font-weight: 400;
  color: #aaa;
  text-transform: none;
  letter-spacing: 0;
}

.param-group input[type="number"],
.param-group input[type="text"],
.param-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: border-color 0.15s;
  background: #fafafa;
}
.param-group input:focus,
.param-group select:focus {
  outline: none;
  border-color: #7c7c3c;
  background: white;
}

.param-group .param-range {
  display: flex;
  gap: 8px;
  font-size: 0.75rem;
  color: #aaa;
  margin-top: 3px;
}

.param-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* ── Truss diagram ── */
.truss-diagram {
  grid-column: 1 / -1;
  margin-top: 10px;
  border-radius: 8px;
  overflow: hidden;
}
.truss-diagram img {
  display: block;
  width: 100%;
  height: auto;
}

/* ── Actions ── */
.actions {
  padding: 16px 20px;
  border-top: 1px solid #eee;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#downloads-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn-download {
  width: 100%;
  padding: 9px;
  border: 1px solid #22c55e;
  border-radius: 7px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  background: white;
  color: #15803d;
  transition: all 0.2s;
}
.btn-download:hover:not(:disabled) { background: #f0fdf4; }
.btn-download:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary, .btn-success, .btn-secondary {
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-primary  { background: #7c7c3c; color: white; }
.btn-primary:hover:not(:disabled)  { background: #5e5e2c; }
.btn-primary:disabled { background: #c8c8a8; cursor: not-allowed; }
.btn-success  { background: #22c55e; color: white; }
.btn-success:hover  { background: #16a34a; }
.btn-secondary { background: #f0f2f5; color: #333; padding: 9px 14px; flex: 1; }
.btn-secondary:hover:not(:disabled) { background: #e2e5ea; }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row-secondary { display: flex; gap: 8px; }

/* ── Status Box ── */
.status-box {
  padding: 10px 14px;
  border-radius: 7px;
  font-size: 0.85rem;
  line-height: 1.5;
}
.status-box.info     { background: #f4f9c8; color: #1d4ed8; border: 1px solid #bfdbfe; }
.status-box.success  { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.status-box.error    { background: #fff5f5; color: #c53030; border: 1px solid #fed7d7; }
.status-box.spinning::before { content: '⟳ '; animation: spin 1s linear infinite; display: inline-block; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── List Panels (Releases / History) ── */
.list-panel {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

.list-item {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid #eee;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
  background: white;
}
.list-item:hover { border-color: #7c7c3c; background: #fbfde8; }
.list-item.active { border-color: #7c7c3c; background: #f4f9c8; }
.list-item h4 { font-size: 0.88rem; font-weight: 600; margin-bottom: 3px; }
.list-item p  { font-size: 0.78rem; color: #888; }
.list-item .badge-status {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 20px;
  margin-top: 5px;
  font-weight: 600;
}
.badge-complete   { background: #dcfce7; color: #15803d; }
.badge-processing { background: #fef9c3; color: #a16207; }
.badge-failed     { background: #fee2e2; color: #b91c1c; }

.hint {
  color: #aaa;
  font-size: 0.85rem;
  padding: 20px 0;
  text-align: center;
}

/* ── Folder Bar ── */
.folder-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.88rem;
}
.folder-bar-label { color: #888; }
.folder-bar-name  { font-weight: 500; color: #ccc; flex: 1; }
.btn-outline {
  background: transparent;
  border: 1px solid #555;
  color: #ccc;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.82rem;
  white-space: nowrap;
}
.btn-outline:hover { border-color: #888; color: #fff; }
.btn-sm { padding: 2px 8px; font-size: 0.78rem; }

/* ── Folder Picker Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal {
  background: #1e2133;
  border: 1px solid #333;
  border-radius: 10px;
  width: 480px;
  max-width: 95vw;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #3a3e2a;
}
.modal-header h3 { margin: 0; font-size: 1rem; color: #e0e0e0; }
.modal-close {
  background: none;
  border: none;
  color: #888;
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.modal-close:hover { color: #fff; }
.folder-breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 8px 20px;
  border-bottom: 1px solid #3a3e2a;
  font-size: 0.82rem;
  min-height: 36px;
}
.crumb-btn {
  background: none;
  border: none;
  color: #4a9eff;
  cursor: pointer;
  padding: 2px 4px;
  font-size: 0.82rem;
}
.crumb-btn:hover { text-decoration: underline; }
.crumb-sep { color: #555; margin: 0 2px; }
.crumb-current { color: #ccc; padding: 2px 4px; }
.folder-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.folder-item {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  cursor: pointer;
  color: #ccc;
  font-size: 0.9rem;
  gap: 8px;
  border-bottom: 1px solid #1a1e30;
}
.folder-item:hover { background: #252a40; }
.folder-item-row { justify-content: space-between; cursor: default; }
.folder-item-name {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  flex: 1;
}
.folder-item-name:hover { color: #fff; }
.folder-icon { font-style: normal; flex-shrink: 0; }
.folder-item-main { display: flex; flex-direction: column; gap: 1px; }
.folder-item-sub { font-size: 11px; color: #6b7394; }
.folder-item-use-current {
  padding: 10px 20px;
  border-top: 1px solid #3a3e2a;
  text-align: right;
}

/* ── Optimize Button ── */
.btn-optimize {
  width: 100%;
  padding: 11px;
  border: 1px solid #7c7c3c;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: white;
  color: #7c7c3c;
}
.btn-optimize:hover:not(:disabled) { background: #f4f9c8; }
.btn-optimize:disabled { border-color: #c8c8a8; color: #c8c8a8; cursor: not-allowed; }

/* ── Optimize Modal ── */
.modal-wide { width: 580px; max-height: 82vh; }

.optimize-content {
  padding: 20px;
  overflow-y: auto;
  color: #e0e0e0;
}

.optimize-inputs {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 14px;
  padding: 10px 14px;
  background: #252a40;
  border-radius: 7px;
  margin-bottom: 18px;
  font-size: 0.82rem;
  color: #aaa;
}
.optimize-inputs strong { color: #e0e0e0; }
.load-combo { color: #4a9eff; }

.optimize-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-bottom: 16px;
}
.optimize-table th {
  text-align: left;
  color: #888;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 6px 8px;
  border-bottom: 1px solid #3a3e2a;
}
.optimize-table td {
  padding: 10px 8px;
  border-bottom: 1px solid #1e2235;
  color: #ccc;
}
.optimize-row-best td { background: #1a3050; color: #e0e0e0; }
.optimize-row-best .cost-cell { color: #4ade80; font-weight: 700; }
.cost-cell { font-weight: 600; }

.best-badge {
  display: inline-block;
  background: #1d6fa4;
  color: #90cdf4;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.optimize-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding: 10px 14px;
  background: #1a3050;
  border-radius: 7px;
  margin-bottom: 14px;
  font-size: 0.8rem;
  color: #90cdf4;
}
.breakdown-label {
  width: 100%;
  color: #aaa;
  font-size: 0.75rem;
  margin-bottom: 2px;
}

.optimize-note {
  font-size: 0.82rem;
  color: #777;
  line-height: 1.6;
}

.optimize-error {
  padding: 14px 16px;
  background: #2d1515;
  border: 1px solid #6b2020;
  color: #f87171;
  border-radius: 8px;
  font-size: 0.85rem;
}

/* ── Price Panel ── */
.price-panel {
  margin-top: 16px;
  border: 1px solid #3a3e2a;
  border-radius: 10px;
  overflow: hidden;
  font-size: 0.84rem;
}

.price-panel-header {
  background: #2a2e1a;
  color: #e0e0e0;
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 10px 14px 8px;
}

.price-meta-row {
  padding: 6px 14px 8px;
  font-size: 0.78rem;
  color: #888;
  background: #12141f;
  border-bottom: 1px solid #1e2235;
}

.price-section {
  padding: 10px 14px;
  border-bottom: 1px solid #1e2235;
  background: #12141f;
}
.price-section:last-of-type { border-bottom: none; }

.price-section-title {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #4a9eff;
  margin-bottom: 8px;
}

.price-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 3px 0;
  color: #bbb;
}
.price-row span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }

.price-meta { color: #666; font-size: 0.78rem; }

.price-subtotal {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #3a3e2a;
  color: #e0e0e0;
  font-weight: 600;
}

.price-total {
  margin-top: 4px;
  padding: 5px 0 2px;
  color: #4ade80;
  font-weight: 700;
  font-size: 0.9rem;
}

.price-divider { height: 8px; }

.price-na {
  color: #666;
  font-size: 0.82rem;
  padding: 4px 0;
}

.price-note {
  padding: 8px 14px;
  font-size: 0.76rem;
  color: #555;
  background: #12141f;
}

.price-loading {
  padding: 14px;
  color: #666;
  font-size: 0.82rem;
  text-align: center;
}

/* ── Price Summary (simplified modal) ── */
.price-summary {
  margin: 0 0 4px;
}
.price-summary-row {
  display: grid;
  grid-template-columns: 130px 1fr auto;
  align-items: baseline;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid #1e2235;
  color: #bbb;
}
.price-summary-row:first-child { border-top: 1px solid #1e2235; }
.price-summary-label {
  font-weight: 600;
  color: #ddd;
  white-space: nowrap;
}
.price-summary-note {
  font-size: 0.81rem;
  color: #777;
}
.price-summary-cost {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-weight: 600;
  color: #ddd;
  text-align: right;
}
.price-summary-divider {
  height: 1px;
  background: #2e3555;
  margin: 2px 0;
}
.price-summary-total {
  border-bottom: none;
}
.price-summary-total .price-summary-label,
.price-summary-total .price-summary-cost {
  color: #4ade80;
  font-size: 1rem;
  font-weight: 700;
}

/* ── Lock Form (optimizer modal) ── */
.modal-wide { width: 640px; }

.lock-form {
  padding: 14px 20px 10px;
  border-bottom: 1px solid #3a3e2a;
  background: #12141f;
}

.lock-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin-bottom: 12px;
}

.lock-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: #888;
}

.lock-field select {
  background: #1e2235;
  border: 1px solid #3a3e2a;
  color: #ddd;
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 0.82rem;
}

.lock-run-btn {
  width: 100%;
  margin-top: 4px;
}

/* ── Optimizer result cards ── */
.opt-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0;
  margin-bottom: 14px;
}

.opt-card {
  border: 1px solid #3a3e2a;
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  background: #12141f;
}

.opt-card:hover { border-color: #4a9eff; background: #16192a; }
.opt-card-active { border-color: #4ade80 !important; background: #0e1e14 !important; }

.opt-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.opt-card-cost {
  font-size: 1.05rem;
  font-weight: 700;
  color: #4ade80;
}

.alt-badge {
  display: inline-block;
  background: #252a40;
  color: #aaa;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.05em;
}

.opt-card-config {
  font-size: 0.92rem;
  color: #e0e0e0;
  margin-bottom: 3px;
}

.opt-card-deck, .opt-card-spacing {
  font-size: 0.82rem;
  color: #aaa;
  margin-bottom: 2px;
}

.opt-card-breakdown {
  font-size: 0.76rem;
  color: #666;
  margin-top: 6px;
  line-height: 1.5;
}

.opt-actions {
  padding-top: 4px;
  border-top: 1px solid #1e2235;
  margin-top: 4px;
}

.opt-actions .btn-primary { width: 100%; margin-bottom: 8px; }

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Optimizable parameter (checkbox stacked LEFT with Auto/Manual label above) ── */
.param-group.is-optimizable {
  display: grid;
  grid-template-columns: 56px 1fr;
  column-gap: 10px;
  align-items: end;
}
.param-group.is-optimizable > label {
  grid-column: 2;
  display: block;
}
.param-group.is-optimizable > select,
.param-group.is-optimizable > input,
.param-group.is-optimizable > .param-range {
  grid-column: 2;
}
.opt-toggle {
  grid-column: 1;
  grid-row: 1 / span 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding-top: 2px;
  cursor: pointer;
  user-select: none;
}
.opt-toggle-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #7c7c3c;
  padding: 1px 6px;
  border-radius: 9px;
  background: #f4f9c8;
  white-space: nowrap;
}
.opt-toggle.is-manual .opt-toggle-label {
  color: #888;
  background: #f0f2f5;
}
.opt-toggle .opt-check {
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
  accent-color: #7c7c3c;
}

/* When optimizer drives this param, the select looks "auto-managed" */
.param-group.is-optimizable:not(.is-locked) select {
  background: linear-gradient(to right, #f4f9c8, #fafafa 30%);
  border-color: #dde0bb;
  color: #555;
  font-style: italic;
}
.param-group.is-optimizable:not(.is-locked) select:focus {
  font-style: normal;
  background: white;
  border-color: #7c7c3c;
  color: #2a2e1a;
}

/* Section dividers in the params form */
.param-section-head {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #888;
  margin: 4px 0 12px;
  padding-top: 6px;
  border-top: 1px solid #eef0f4;
}
.param-section-head:first-child { border-top: none; padding-top: 0; }
.param-section-head .sub {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  color: #aaa;
  letter-spacing: 0;
  text-transform: none;
  margin-top: 3px;
}

/* ── Optimizer Modal ── */
.opt-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 25, 40, 0.55);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.opt-modal {
  background: white;
  border-radius: 12px;
  width: 640px;
  max-width: 100%;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,0.25);
}
.opt-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid #eef0f4;
}
.opt-modal-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: #2a2e1a;
}
.opt-modal-header .modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: #888;
  cursor: pointer;
  line-height: 1;
}
.opt-modal-header .modal-close:hover { color: #2a2e1a; }
.opt-modal-sub {
  padding: 8px 20px 14px;
  font-size: 0.78rem;
  color: #888;
  border-bottom: 1px solid #eef0f4;
  background: #fafbfc;
}
.opt-modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.opt-result-card {
  border: 2px solid #e3e7ee;
  border-radius: 10px;
  padding: 14px 16px;
  cursor: pointer;
  background: white;
  transition: all 0.15s;
  position: relative;
}
.opt-result-card:hover {
  border-color: #7c7c3c;
  background: #fbfde8;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,112,243,0.08);
}
.opt-result-card.is-best {
  border-color: #22c55e;
  background: #f0fdf4;
}
.opt-result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 6px;
}
.opt-result-config {
  font-size: 0.95rem;
  font-weight: 600;
  color: #2a2e1a;
}
.opt-result-cost {
  font-size: 1.1rem;
  font-weight: 700;
  color: #15803d;
  font-variant-numeric: tabular-nums;
}
.opt-result-meta {
  font-size: 0.78rem;
  color: #666;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.opt-result-meta .best-tag {
  background: #22c55e;
  color: white;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.05em;
}
.opt-result-meta .alt-tag {
  background: #e3e7ee;
  color: #555;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.05em;
}
.opt-modal-empty {
  padding: 30px;
  text-align: center;
  color: #888;
  font-size: 0.9rem;
}
.opt-modal-loading {
  padding: 40px;
  text-align: center;
  color: #888;
  font-size: 0.9rem;
}

/* ── Inline Price Readout ── */
.price-readout {
  border: 1px solid #e3e7ee;
  border-radius: 8px;
  background: #fafbfc;
  overflow: hidden;
  font-size: 0.83rem;
}
.price-readout-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 14px 8px;
  background: white;
  border-bottom: 1px solid #eef0f4;
}
.price-readout-head .price-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: #888;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.price-readout-head .price-grand {
  font-size: 1.15rem;
  font-weight: 700;
  color: #15803d;
  font-variant-numeric: tabular-nums;
}
.price-readout-head .price-grand.is-loading {
  color: #aaa;
  font-size: 0.85rem;
  font-weight: 500;
  font-style: italic;
}
.price-readout-head .price-grand.is-error {
  color: #c53030;
  font-size: 0.78rem;
  font-weight: 500;
}
.price-readout-rows {
  padding: 6px 14px 8px;
}
.price-readout-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 3px 0;
  color: #555;
  font-size: 0.78rem;
}
.price-readout-row .pr-label { color: #555; font-weight: 500; }
.price-readout-row .pr-note {
  flex: 1;
  color: #999;
  font-size: 0.74rem;
  text-align: right;
  padding-right: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.price-readout-row .pr-cost {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #333;
  white-space: nowrap;
}
.price-readout-meta {
  font-size: 0.7rem;
  color: #999;
  padding: 0 14px 10px;
  line-height: 1.5;
}

/* ── Inline Optimizer Alternatives ── */
.opt-alternatives {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.opt-alt-head {
  font-size: 0.7rem;
  font-weight: 600;
  color: #888;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.opt-alt-card {
  border: 1px solid #e3e7ee;
  border-radius: 7px;
  padding: 9px 11px;
  cursor: pointer;
  background: white;
  transition: all 0.15s;
  font-size: 0.8rem;
}
.opt-alt-card:hover {
  border-color: #7c7c3c;
  background: #fbfde8;
}
.opt-alt-card.is-best {
  border-color: #22c55e;
  background: #f0fdf4;
}
.opt-alt-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.opt-alt-config {
  font-weight: 600;
  color: #2a2e1a;
  font-size: 0.83rem;
}
.opt-alt-cost {
  font-weight: 700;
  color: #15803d;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.opt-alt-card.is-best .opt-alt-cost { color: #15803d; }
.opt-alt-meta {
  margin-top: 3px;
  font-size: 0.72rem;
  color: #888;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.opt-alt-meta .best-tag {
  background: #22c55e;
  color: white;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  letter-spacing: 0.05em;
}

/* Tweak the Optimize button to match the lighter, embedded look */
.btn-optimize {
  background: white;
  color: #7c7c3c;
  border: 1px solid #7c7c3c;
}
.btn-optimize:hover:not(:disabled) { background: #f4f9c8; }
.btn-optimize:disabled {
  border-color: #dde0bb;
  color: #c8c8a8;
  background: white;
  cursor: not-allowed;
}

/* ── Optimizable parameter rows: checkbox to the LEFT with stacked Auto/Manual label ── */
.param-group.is-optimizable {
  display: grid;
  grid-template-columns: 56px 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 4px;
  align-items: start;
}
.param-group.is-optimizable > label:not(.opt-toggle) {
  grid-column: 2;
  grid-row: 1;
}
.param-group.is-optimizable > select,
.param-group.is-optimizable > input:not(.opt-check) {
  grid-column: 2;
  grid-row: 2;
}
.param-group.is-optimizable .opt-toggle {
  grid-column: 1;
  grid-row: 1 / span 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 4px;
  padding-top: 2px;
  cursor: pointer;
  user-select: none;
}
.param-group.is-optimizable .opt-toggle-label {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #7c7c3c;
  background: #f4f9c8;
  padding: 2px 6px;
  border-radius: 3px;
  line-height: 1;
}
.param-group.is-optimizable .opt-toggle.is-manual .opt-toggle-label {
  color: #6b7280;
  background: #f3f4f6;
}
.param-group.is-optimizable .opt-check {
  width: 18px;
  height: 18px;
  accent-color: #7c7c3c;
  cursor: pointer;
  margin: 0;
}
.param-group.is-optimizable.is-locked > select,
.param-group.is-optimizable.is-locked > input:not(.opt-check) {
  border-color: #d1d5db;
  background: #fafbfc;
}

/* ── Optimizer Modal ── */
.opt-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 24px;
}
.opt-modal {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
.opt-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
}
.opt-modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: #2a2e1a;
}
.opt-modal-header .modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: #888;
  cursor: pointer;
  padding: 0 4px;
}
.opt-modal-header .modal-close:hover { color: #2a2e1a; }
.opt-modal-sub {
  padding: 0 20px 12px;
  font-size: 0.78rem;
  color: #6b7280;
}
.opt-modal-body {
  padding: 0 20px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.opt-modal-loading,
.opt-modal-empty {
  text-align: center;
  padding: 32px 16px;
  color: #6b7280;
  font-size: 0.85rem;
}
.opt-result-card {
  border: 1px solid #e3e7ee;
  border-radius: 8px;
  padding: 12px 14px;
  cursor: pointer;
  background: white;
  transition: all 0.15s;
}
.opt-result-card:hover {
  border-color: #7c7c3c;
  background: #fbfde8;
  transform: translateY(-1px);
}
.opt-result-card.is-best {
  border-color: #22c55e;
  background: #f0fdf4;
}
.opt-result-card.is-best:hover { background: #dcfce7; }
.opt-result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}
.opt-result-config {
  font-weight: 600;
  color: #2a2e1a;
  font-size: 0.9rem;
}
.opt-result-cost {
  font-weight: 700;
  color: #15803d;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.opt-result-meta {
  margin-top: 6px;
  font-size: 0.75rem;
  color: #6b7280;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.opt-result-meta .best-tag {
  background: #22c55e;
  color: white;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 3px;
  letter-spacing: 0.05em;
}
.opt-result-meta .alt-tag {
  background: #e5e7eb;
  color: #4b5563;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 3px;
  letter-spacing: 0.05em;
}

/* ── Check Design button variant (when 0 auto-checks) ── */
.btn-optimize.is-check-mode {
  color: #15803d;
  border-color: #22c55e;
}
.btn-optimize.is-check-mode:hover:not(:disabled) {
  background: #f0fdf4;
}

/* ── Check Design result card ── */
.check-result {
  text-align: center;
  padding: 8px 4px 4px;
}
.check-result-icon {
  font-size: 2.4rem;
  font-weight: 700;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  line-height: 1;
}
.check-result.is-pass .check-result-icon {
  background: #dcfce7;
  color: #15803d;
}
.check-result.is-fail .check-result-icon {
  background: #fee2e2;
  color: #b91c1c;
}
.check-result-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #2a2e1a;
  margin-bottom: 6px;
}
.check-result.is-pass .check-result-title { color: #15803d; }
.check-result.is-fail .check-result-title { color: #b91c1c; }
.check-result-sub {
  font-size: 0.85rem;
  color: #4b5563;
  margin-bottom: 12px;
}
.check-result-detail {
  font-size: 0.78rem;
  color: #6b7280;
  line-height: 1.5;
  background: #f9fafb;
  padding: 10px 12px;
  border-radius: 6px;
  text-align: left;
}


/* ── Cascadia brand palette (override variables) ── */
:root {
  --brand-olive: #7c7c3c;
  --brand-olive-dark: #5e5e2c;
  --brand-lime: #c4dc2c;
  --brand-lime-dark: #a8c020;
  --brand-warm-bg: #f4f4ec;
}

body { background: var(--brand-warm-bg); }

/* Header brandmark layout */
header {
  background: white;
  color: #2a2e1a;
  border-bottom: 1px solid #e4e4d4;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 16px;
}
header .brandmark {
  height: 36px;
  width: auto;
  display: block;
}
header .header-divider {
  width: 1px;
  height: 28px;
  background: #d4d4c0;
}
header .header-product {
  font-size: 1rem;
  font-weight: 500;
  color: #7c7c3c;
  letter-spacing: 0.01em;
}

/* Optimize button: use lime accent (the energetic "Structural" green) */
.btn-optimize {
  border-color: var(--brand-olive);
  color: var(--brand-olive);
}
.btn-optimize:hover:not(:disabled) {
  background: var(--brand-lime);
  border-color: var(--brand-lime);
  color: #2a2e1a;
}

/* BEST tag in lime, not generic green */
.opt-result-meta .best-tag,
.opt-alt-meta .best-tag,
.best-tag {
  background: var(--brand-lime) !important;
  color: #2a2e1a !important;
}
.opt-result-card.is-best {
  border-color: var(--brand-lime);
  background: #f4f9c8;
}
.opt-result-card.is-best:hover { background: #ecf3a3; }

/* Auto pill in olive (replaces blue) */
.param-group.is-optimizable .opt-toggle-label,
.opt-toggle-label {
  color: #7c7c3c;
  background: #eef0d9;
}

/* Price card: olive accent on the grand total when in brand context */
.price-readout-head .price-grand { color: var(--brand-olive-dark); }

/* Generate button stays primary olive */
.btn-primary { background: var(--brand-olive); }
.btn-primary:hover:not(:disabled) { background: var(--brand-olive-dark); }
.btn-primary:disabled { background: #c8c8a8; }

/* Viewer placeholder uses warm dark */
.viewer-wrap, .viewer-wrap > * {
  background: #2a2e1a;
}
.viewer-placeholder { color: rgba(255,255,255,0.55); }

/* ── Info icon (ℹ) with JS-positioned tooltip ── */
.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #d4d4c0;
  color: #6b7280;
  font-size: 9px;
  font-style: normal;
  font-weight: 700;
  cursor: help;
  vertical-align: middle;
  margin-left: 3px;
  flex-shrink: 0;
  user-select: none;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}
.info-icon:hover { background: #7c7c3c; color: white; }

/* Shared JS tooltip (injected at body level to escape overflow:hidden) */
#info-tooltip {
  position: fixed;
  z-index: 9000;
  background: #2a2e1a;
  color: #e0e0e0;
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.45;
  padding: 8px 11px;
  border-radius: 7px;
  max-width: 220px;
  pointer-events: none;
  white-space: normal;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  transition: opacity 0.12s;
  text-transform: none;
  letter-spacing: 0;
}

/* ── Snow Load: input + lookup button side by side ── */
.snow-lookup-row {
  display: flex;
  gap: 6px;
}
.snow-lookup-row input { flex: 1; min-width: 0; }
.btn-snow-lookup {
  flex-shrink: 0;
  padding: 7px 10px;
  font-size: 0.78rem;
  border: 1px solid #d4d4c0;
  border-radius: 6px;
  background: #f4f4ec;
  color: #7c7c3c;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
  transition: all 0.15s;
}
.btn-snow-lookup:hover { background: #eef0d9; border-color: #7c7c3c; }

/* ── Snow Load Modal ── */
.snow-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  padding: 24px;
}
.snow-modal {
  background: white;
  border-radius: 12px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
.snow-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid #eef0f4;
}
.snow-modal-header h3 { margin: 0; font-size: 1rem; font-weight: 700; color: #2a2e1a; }
.snow-modal-body { padding: 16px 20px 20px; }
.snow-modal-desc {
  font-size: 0.82rem;
  color: #6b7280;
  margin-bottom: 14px;
  line-height: 1.5;
}
.snow-addr-row { display: flex; gap: 8px; margin-bottom: 12px; }
.snow-addr-row input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.9rem;
}
.snow-addr-row input:focus { outline: none; border-color: #7c7c3c; }
.snow-addr-row button {
  padding: 8px 14px;
  background: #7c7c3c;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.snow-addr-row button:hover:not(:disabled) { background: #5e5e2c; }
.snow-addr-row button:disabled { background: #c8c8a8; cursor: not-allowed; }
.snow-result-pass {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.snow-result-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: #15803d;
  margin-bottom: 2px;
  font-variant-numeric: tabular-nums;
}
.snow-result-sub { font-size: 0.78rem; color: #4b5563; line-height: 1.4; }
.snow-result-addr { font-size: 0.7rem; color: #6b7280; margin-top: 6px; }
.snow-result-error {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  border-radius: 8px;
  padding: 10px 14px;
  color: #c53030;
  font-size: 0.82rem;
  margin-bottom: 12px;
}
.snow-apply-btn {
  width: 100%;
  padding: 10px;
  background: #7c7c3c;
  color: white;
  border: none;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 10px;
  transition: background 0.15s;
}
.snow-apply-btn:hover { background: #5e5e2c; }
.snow-steps {
  margin: 0 0 14px 18px;
  padding: 0;
  font-size: 0.82rem;
  color: #4b5563;
  line-height: 1.75;
}
.snow-open-btn {
  display: block;
  padding: 10px 14px;
  background: #f4f4ec;
  border: 1px solid #d4d4c0;
  border-radius: 7px;
  color: #7c7c3c;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  margin-bottom: 14px;
  transition: all 0.15s;
}
.snow-open-btn:hover { background: #eef0d9; border-color: #7c7c3c; }
.snow-entry-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #444;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.snow-disclaimer {
  font-size: 0.7rem;
  color: #9ca3af;
  line-height: 1.4;
  text-align: center;
}
