/* Design Builder (design-builder.html). Loaded after site.css (D18).
   Reuses site.css tokens and builder-* classes; adds db-* wizard, diagram,
   decision-log and print styles. Do not move these into site.css. */

/* —— Layout: wizard | diagram | decision log —— */
.builder-layout.db-layout {
  grid-template-columns: minmax(300px, 1.2fr) minmax(280px, 1fr) minmax(280px, 0.95fr);
}
@media (min-width: 1181px) {
  .db-diagram-panel { position: sticky; top: 84px; }
}
@media (max-width: 1180px) {
  .builder-layout.db-layout { grid-template-columns: 1fr 1fr; }
  .db-log-panel { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .builder-layout.db-layout { grid-template-columns: 1fr; }
}

.db-scenario {
  margin: 0.6rem 0 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  max-width: 52rem;
}

.db-visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Keyboard focus, visible on every control in the builder */
.builder-page a:focus-visible,
.builder-page button:focus-visible,
.builder-page input:focus-visible,
.builder-page textarea:focus-visible,
.builder-page summary:focus-visible,
.db-step-title:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 2px;
}
.db-step-title:focus:not(:focus-visible) { outline: none; }

/* —— Send to BOM Builder —— */
.db-send { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; }
.db-send-hint { font-size: 0.8rem; color: var(--text-muted); }
.db-send-hint:empty { display: none; }
.db-send-warn { color: #fbbf24; }
.db-send .btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* —— Step chips (reuse builder-cat-btn) —— */
.db-steps { margin: 0 0 1.1rem; }
.db-step-chip { text-decoration: none; }
.db-step-chip:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }
.db-step-chip.done { border-color: rgba(122, 240, 192, 0.45); }
.db-chip-count {
  margin-left: 0.25rem;
  font-size: 0.7rem;
  color: var(--text-muted);
}
.db-step-chip.done .db-chip-count { color: var(--mint); }

/* —— Notices —— */
.db-notices { display: flex; flex-direction: column; gap: 0.5rem; margin: -0.5rem 0 1rem; }
.db-notices:empty { display: none; }
.db-notice {
  position: relative;
  padding: 0.7rem 2.4rem 0.7rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  font-size: 0.85rem;
}
.db-notice ul { margin: 0.35rem 0 0; padding-left: 1.1rem; color: var(--text-muted); }
.db-notice-warn { border-color: rgba(251, 191, 36, 0.55); }
.db-notice-warn strong { color: #fbbf24; }
.db-notice-error { border-color: rgba(248, 113, 113, 0.6); }
.db-notice-error strong { color: #f87171; }
.db-notice-info strong { color: var(--mint); }
.db-notice-close {
  position: absolute;
  top: 0.35rem; right: 0.4rem;
  width: 1.8rem; height: 1.8rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
}
.db-notice-close:hover { color: var(--text); background: var(--accent-soft); }

/* —— Wizard —— */
.db-step-count {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.builder-panel h2.db-step-title { margin: 0.15rem 0 0.35rem; font-size: 1.2rem; }
.db-step-summary { margin: 0 0 0.6rem; font-size: 0.9rem; }
.db-divergence {
  margin: 0 0 0.6rem;
  padding: 0.5rem 0.7rem 0.5rem 1.6rem;
  font-size: 0.82rem;
  background: var(--accent-soft);
  border-radius: 8px;
}
.db-meta { margin: 0 0 0.45rem; font-size: 0.82rem; color: var(--text-muted); }
.db-meta-k {
  display: inline-block;
  margin-right: 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text);
}
.db-assumptions { margin: 0.25rem 0 0; padding-left: 1.1rem; }
.db-sketch,
.db-pending {
  margin: 0.5rem 0;
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
  border-radius: 8px;
  border: 1px dashed var(--border-strong);
}
.db-sketch strong { color: var(--mint); }
.db-pending { border-color: rgba(251, 191, 36, 0.55); color: var(--text); }

.db-decision {
  margin: 1rem 0 0;
  padding: 0.8rem 0.85rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-card);
  min-width: 0;
}
.db-decision legend {
  padding: 0 0.35rem;
  font-weight: 600;
  font-size: 0.95rem;
}
.db-dec-hint { margin: 0 0 0.5rem; font-size: 0.75rem; color: var(--text-muted); }
.db-na-note { margin: 0 0 0.5rem; font-size: 0.82rem; color: #fbbf24; }

.db-option {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0 0.6rem;
  padding: 0.5rem 0.55rem;
  margin-top: 0.35rem;
  border: 1px solid transparent;
  border-radius: 8px;
}
.db-option:hover { background: var(--bg-card-hover); }
.db-option.is-selected { border-color: var(--accent); background: var(--accent-soft); }
.db-option input { margin: 0.25rem 0 0; width: 1rem; height: 1rem; accent-color: var(--accent); }
.db-option label { font-size: 0.88rem; font-weight: 600; cursor: pointer; }
.db-option.is-disabled label { color: var(--text-muted); font-weight: 500; cursor: not-allowed; }
.db-option.is-disabled:hover { background: transparent; }
.db-opt-summary { margin: 0.15rem 0 0; font-size: 0.8rem; color: var(--text-muted); }
.db-opt-why { margin: 0.2rem 0 0; font-size: 0.78rem; color: #fbbf24; }
.db-opt-link { margin: 0.15rem 0 0; font-size: 0.78rem; }
.db-tag {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--mint);
  background: var(--mint-soft);
  vertical-align: 0.1em;
}
.db-flag {
  margin: 0.5rem 0 0;
  padding: 0.45rem 0.6rem;
  font-size: 0.8rem;
  border-left: 3px solid #fbbf24;
  background: rgba(251, 191, 36, 0.08);
  border-radius: 0 6px 6px 0;
}
.db-flag strong { color: #fbbf24; }

.db-dec-foot { margin-top: 0.6rem; }
.db-clear { margin-bottom: 0.5rem; }
.db-note { display: block; font-size: 0.78rem; color: var(--text-muted); }
.db-note-hint { opacity: 0.85; }
.db-note textarea {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  resize: vertical;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  font: inherit;
  font-size: 0.85rem;
}
.db-step-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 1.1rem;
}
.db-step-nav .btn-primary { margin-left: auto; }
.db-error { color: #f87171; font-size: 0.88rem; margin: 0; }

/* —— Diagram —— */
.db-diagram-box {
  min-height: 220px;
  max-height: min(75vh, 900px);
  overflow: auto;
  padding: 0.75rem;
  border-radius: 10px;
  background: #ffffff;
  border: 1px solid var(--border);
  color: #0b1220;
}
.db-diagram-box svg { display: block; margin: 0 auto; max-width: 100%; height: auto; }
.db-diagram-msg { margin: 0; font-size: 0.85rem; color: #334155; }
.db-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1rem;
  margin: 0.55rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.db-legend li { display: inline-flex; align-items: center; gap: 0.35rem; }
.db-legend svg line { stroke: var(--text-muted); }
.db-legend svg path { fill: var(--text-muted); }
.db-diagram-text { margin-top: 0.75rem; font-size: 0.8rem; color: var(--text-muted); }
.db-diagram-text summary { cursor: pointer; color: var(--text); }
.db-diagram-text ul { margin: 0.35rem 0; padding-left: 1.1rem; }
.db-diagram-text p { margin: 0.5rem 0 0; }

/* —— Decision log —— */
.db-log {
  max-height: min(80vh, 1100px);
  overflow: auto;
  padding-right: 0.25rem;
  font-size: 0.8rem;
}
.db-log-step { padding: 0.15rem 0 0.6rem; border-bottom: 1px solid var(--border); }
.db-log-step + .db-log-step { padding-top: 0.6rem; }
.db-log-step h3 { margin: 0 0 0.3rem; font-size: 0.92rem; }
.db-log-step h3 a { color: var(--text); }
.db-log-meta { margin: 0 0 0.3rem; color: var(--text-muted); }
.db-log-meta ul { margin: 0.15rem 0 0; padding-left: 1.1rem; }
.db-log-row {
  margin: 0.45rem 0 0;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
}
.db-log-row.is-decided { border-left: 3px solid var(--mint); }
.db-log-row h4 { margin: 0 0 0.3rem; font-size: 0.84rem; }
.db-log-row dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.2rem 0.6rem;
  margin: 0;
}
.db-log-row dt {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding-top: 0.12rem;
}
.db-log-row dd { margin: 0; min-width: 0; }
.db-log-row dd ul { margin: 0; padding-left: 1rem; }
.db-alt-tag { color: var(--text-muted); }
.db-flag-dd { color: #fbbf24; }
.db-note-text { white-space: pre-wrap; }
.db-muted { color: var(--text-muted); }
.db-arrow { color: var(--text-muted); }

/* —— Print to PDF: diagram + decision log on a light page —— */
.db-print-only { display: none; }

@media print {
  :root {
    --bg: #ffffff;
    --bg-elevated: #ffffff;
    --bg-card: #ffffff;
    --bg-card-hover: #ffffff;
    --border: #c9d2dc;
    --border-strong: #8a99a8;
    --text: #111111;
    --text-muted: #444b55;
    --accent: #0b4f8a;
    --accent-soft: transparent;
    --mint: #0b6b4a;
    --mint-soft: transparent;
    --shadow: none;
  }
  @page { margin: 14mm; }
  html, body { background: #ffffff !important; color: #111111; }
  body { font-size: 10.5pt; }
  .glow,
  header,
  footer,
  .breadcrumb,
  .eyebrow,
  .builder-hero .lead,
  .builder-toolbar,
  .db-notices,
  .db-steps,
  .db-wizard,
  .db-no-print,
  .builder-panel-sub { display: none !important; }
  .db-print-only { display: block; }
  .db-print-head p { margin: 0 0 0.2rem; }
  .builder-hero { padding: 0; }
  .builder-hero h1 { margin: 0 0 0.25rem; font-size: 18pt; }
  .db-scenario { color: #444b55; }
  .wrap { width: 100%; }
  .builder-layout.db-layout { display: block; }
  .builder-panel {
    box-shadow: none;
    border: none;
    padding: 0;
    margin: 0.8rem 0 0;
    background: #ffffff;
  }
  .db-diagram-panel { position: static; }
  .db-diagram-box {
    max-height: none;
    overflow: visible;
    border: 1px solid #c9d2dc;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .db-diagram-box svg { max-height: 230mm; width: auto; }
  .db-log-panel { break-before: page; page-break-before: always; }
  .db-log { max-height: none; overflow: visible; font-size: 9.5pt; }
  .db-log-step h3 { break-after: avoid; page-break-after: avoid; }
  .db-log-row { break-inside: avoid; page-break-inside: avoid; }
  .db-log-row.is-decided { border-left-color: #0b6b4a; }
  .db-flag-dd, .db-notice-warn strong { color: #8a5a00; }
  a { color: inherit; text-decoration: none; }
  .builder-disclaimer {
    break-inside: avoid;
    page-break-inside: avoid;
    color: #444b55;
    background: #ffffff;
  }
}
