/* Sizing Solution Platform — app page (pages/appPage.js). Dark and minimal, in the look of the
   chat assistant: VAL blue as the one accent, translucent surfaces, soft motion. */

:root {
  --bg: #111213;
  --panel: #141617;
  --surface: rgba(255,255,255,.04);
  --surface-strong: rgba(255,255,255,.07);
  --surface-hover: rgba(255,255,255,.08);
  --border: rgba(255,255,255,.08);
  --border-strong: rgba(255,255,255,.14);
  --text: #d8d4ce;
  --text-strong: #f0ebe4;
  --muted: #8f8a84;
  --faint: #6f6a64;
  --accent: #0f31a1;
  --accent-hover: #1a44c9;
  --focus: #7aa2ff;
  --ease-sheet: cubic-bezier(.32, .72, 0, 1);
  --requirements-width: 380px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", "Open Sans", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body { overflow: hidden; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Layout: Requirements | splitter | Solution ---------- */

.app {
  display: grid;
  grid-template-columns: var(--requirements-width) 1px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}
/* Animated width change (e.g. switching to 3D); dragging the divider stays immediate. */
.app { transition: grid-template-columns .45s var(--ease-sheet); }
.app.is-resizing { cursor: col-resize; user-select: none; transition: none; }
/* Embedded content would swallow the pointer while the divider is dragged. */
.app.is-resizing model-viewer,
.app.is-resizing iframe { pointer-events: none; }

.panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.requirements { background: var(--panel); }
.solution { position: relative; background: var(--bg); }

.splitter {
  position: relative;
  z-index: 40;
  background: var(--border);
  cursor: col-resize;
  touch-action: none;
  transition: background-color .2s ease;
}
.splitter:focus-visible { outline: none; background: var(--focus); }
/* Wider invisible grab area than the 1px line. */
.splitter::before {
  content: "";
  position: absolute;
  inset: 0 -6px;
}
.splitter::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 36px;
  transform: translate(-50%, -50%);
  border-radius: 2px;
  background: rgba(255,255,255,.22);
  opacity: 0;
  transition: opacity .2s ease, background-color .2s ease;
}
.splitter:hover::after,
.app.is-resizing .splitter::after { opacity: 1; }
.app.is-resizing .splitter::after { background: var(--focus); }

.panel-header,
.filter-bar {
  flex: none;
  height: 60px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.panel-header {
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
}
.panel-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-strong);
}
.new-chat-requirement {
  flex: none;
  width: calc(100% - 24px);
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 10px 12px 0;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color .18s ease, color .18s ease, border-color .18s ease;
}
.new-chat-requirement:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  color: var(--text-strong);
}
.new-chat-requirement:disabled {
  opacity: .35;
  cursor: default;
}
.chat-list {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  padding: 10px 12px 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.16) transparent;
}
.chat-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 10px;
}
.chat-entry.is-active {
  border-color: var(--border);
  background: var(--surface);
}
.chat-entry-toggle {
  min-width: 0;
  overflow: hidden;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  color: var(--text-strong);
  font-size: 13px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.chat-entry-toggle:hover { color: #ffffff; }
.chat-entry-title-input {
  min-width: 0;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--focus);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-strong);
  font: inherit;
}
.chat-entry-actions {
  display: inline-flex;
  gap: 2px;
}
.chat-entry-action {
  padding: 4px 5px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  cursor: pointer;
}
.chat-entry-action:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text-strong);
}
.chat-entry-action--delete:hover:not(:disabled) { color: #ff8d8d; }
.chat-entry-action:disabled { opacity: .35; cursor: default; }
.chat-entry-action:focus-visible,
.request-card-toggle:focus-visible,
.request-action-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.chat-entry-summary {
  padding-right: 10px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.chat-entry-requests {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px 8px 18px;
}
.chat-entry-request {
  position: relative;
  padding: 5px 8px;
  padding-left: 22px;
  border: 0;
  border-left: 1px solid var(--border-strong);
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  text-align: left;
  cursor: pointer;
}
.chat-entry-request::before {
  content: "›";
  position: absolute;
  left: 8px;
  color: var(--faint);
  font-size: 16px;
  line-height: 12px;
  transform: rotate(0deg);
  transition: transform .18s ease, color .18s ease;
}
.chat-entry-request[aria-expanded="true"]::before {
  color: var(--focus);
  transform: rotate(90deg);
}
.chat-entry-request:hover { color: var(--text-strong); }

/* ---------- Shared controls ---------- */

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: rgba(255,255,255,.06);
  border-radius: 10px;
}
.segmented--full { display: flex; }
.segmented--full .segmented-btn { flex: 1; }
.segmented-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 28px;
  padding: 4px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color .2s ease, color .2s ease, box-shadow .2s ease;
}
.segmented-btn:hover:not(.is-active):not([aria-disabled="true"]) { color: var(--text-strong); }
.segmented-btn.is-active {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(0,0,0,.35);
}
.segmented-btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.segmented--icons .segmented-btn { padding: 4px 9px; }

.icon-btn {
  flex: none;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color .18s ease, color .18s ease;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-hover); color: var(--text-strong); }
.icon-btn:disabled { opacity: .3; cursor: default; }

.popover {
  position: absolute;
  z-index: 50;
  padding: 12px;
  background: rgba(28,30,33,.88);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  backdrop-filter: blur(30px) saturate(180%);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,.3), 0 18px 50px rgba(0,0,0,.5);
  animation: popover-in .22s var(--ease-sheet);
}
@keyframes popover-in {
  from { opacity: 0; transform: translateY(-4px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.popover-section + .popover-section { margin-top: 16px; }
.popover-label,
.form-label,
.welcome-label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--muted);
}
.popover-label { margin: 0 4px 8px; }
.popover-list { display: flex; flex-direction: column; gap: 2px; }
.popover-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-strong);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.popover-option:hover:not([aria-disabled="true"]) { background: var(--surface-hover); }
.popover-option[aria-disabled="true"] { color: var(--faint); cursor: default; }
.checkmark {
  flex: none;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  color: transparent;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.popover-option[aria-checked="true"] .checkmark {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
.popover-meta { margin-left: auto; font-size: 12px; color: var(--muted); }
.popover-soon {
  margin-left: auto;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-hover);
  color: var(--muted);
  font-size: 11px;
}

/* ---------- Requirements ---------- */

.requirements-form {
  flex: none;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.requirements-body {
  display: none;
}
.request-list { display: flex; flex-direction: column; gap: 12px; }
.request-card {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,.025);
}
.request-card.is-expanded { background: rgba(255,255,255,.015); }
.request-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 10px;
}
.request-card-toggle {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 0;
  background: transparent;
  color: var(--text-strong);
  text-align: left;
  cursor: pointer;
}
.request-card-toggle:hover { background: var(--surface-hover); }
.request-card-title { font-weight: 600; }
.request-card-status {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.request-card-title-input {
  min-width: 0;
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--focus);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-strong);
  font: inherit;
}
.request-card-header > .request-card-actions {
  flex: none;
  align-items: center;
}
.request-card-body-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}
.request-card-body { padding: 16px 14px 18px; border-top: 1px solid var(--border); }
.request-card.is-submitted .request-card-status { color: var(--focus); }
.request-card.is-error .request-card-status { color: #ff9a8f; }
.request-error {
  margin: 14px 0 0;
  padding: 9px 10px;
  border: 1px solid rgba(255,154,143,.35);
  border-radius: 8px;
  background: rgba(255,100,90,.08);
  color: #ffb0a7;
  font-size: 12px;
  line-height: 1.4;
}
.request-card-actions { display: inline-flex; gap: 2px; }
.request-action-btn {
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text-strong);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.request-action-btn:hover:not(:disabled) {
  border-color: var(--focus);
  background: var(--surface-hover);
}
.request-action-btn:disabled { opacity: .5; cursor: default; }
.request-card input:disabled,
.request-card button:disabled { opacity: .7; cursor: default; }
.new-request-btn {
  width: 100%;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  transition: background-color .18s ease, border-color .18s ease, color .18s ease;
}
.new-request-btn:hover {
  background: var(--surface-hover);
  border-color: var(--focus);
  color: var(--text-strong);
}
.form-group { display: flex; flex-direction: column; gap: 12px; }
.request-card-body > .form-group + .form-group { margin-top: 20px; }
.pill-group { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  padding: 7px 15px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}
.pill:hover:not(.is-active) { background: var(--surface-hover); }
.pill.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}
.parameter-fields { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.field-label { font-size: 13px; color: var(--text); }
.field-control {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color .2s ease, background-color .2s ease, box-shadow .2s ease;
}
.field-control:focus-within {
  border-color: rgba(120,150,255,.55);
  background: var(--surface-strong);
  box-shadow: 0 0 0 3px rgba(122,162,255,.12);
}
.field-control input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text-strong);
  font: inherit;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.field-control input::placeholder { color: var(--faint); }
.field-unit {
  flex: none;
  padding-right: 12px;
  color: var(--muted);
  font-size: 13px;
}
/* Short highlight on the fields the chat just filled in. */
.field.is-synced .field-control,
.field.is-synced .segmented { animation: field-synced 1.6s ease; }
@keyframes field-synced {
  0%, 25% { box-shadow: 0 0 0 3px rgba(122,162,255,.45); }
  100% { box-shadow: 0 0 0 3px rgba(122,162,255,0); }
}
.form-hint { margin: 0; font-size: 12px; color: var(--faint); }

/* 3D mode: the Generic Solutions scene takes the place of the form fields. */
.scene-view {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.requirements.is-scene-mode .panel-header {
  flex: none;
}
.requirements.is-scene-mode .scene-view {
  display: flex;
}
.requirements.is-scene-mode .requirements-form {
  flex: 1;
  min-height: 0;
}
.requirements.is-scene-mode .requirements-footer {
  flex: none;
}
.scene-frame {
  flex: 1;
  align-self: stretch;
  border: 0;
  background: #ffffff;
}
.scene-hint { margin: 0; padding: 24px; color: var(--muted); text-align: center; line-height: 1.7; }
.scene-hint code { color: var(--text-strong); }
.requirements-footer {
  flex: none;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
}
.primary-btn {
  width: 100%;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #ffffff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .2s ease, transform .18s var(--ease-sheet), opacity .2s ease;
}
.primary-btn svg { transition: transform .2s var(--ease-sheet); }
.primary-btn:hover:not(:disabled) { background: var(--accent-hover); }
.primary-btn:hover:not(:disabled) svg { transform: translateX(3px); }
.primary-btn:active:not(:disabled) { transform: scale(.98); }
.primary-btn:disabled { opacity: .45; cursor: default; }

/* ---------- Solution: filter bar ---------- */

.filter-bar {
  position: relative;
  z-index: 30;
  gap: 10px;
  padding: 0 14px 0 20px;
}
.popover-anchor { position: relative; flex: none; }
.filter-popover { top: calc(100% + 10px); left: 0; width: 290px; }
.drive-popover { top: calc(100% + 10px); left: 0; width: 280px; }
.filter-scroller {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 24px 4px 0;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent);
}
.filter-scroller::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 13px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}
.chip:hover { background: var(--surface-hover); }
.chip--menu { background: var(--surface); }
.chip-key { color: var(--muted); }
/* Manufacturer logos: colour = shown, pale grey = hidden. */
.logo-chip {
  flex: none;
  height: 34px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  transition: background-color .2s ease;
}
.logo-chip:hover { background: var(--surface-hover); }
.logo-chip-img {
  height: 18px;
  width: auto;
  max-width: 96px;
  transition: filter .25s ease, opacity .25s ease;
}
.logo-chip-img--emerson { height: 30px; }
.logo-chip-img--iefWerner { height: 22px; filter: invert(1) brightness(.94); }
.logo-chip[aria-pressed="false"] .logo-chip-img { filter: grayscale(1); opacity: .3; }
.logo-chip[aria-pressed="false"] .logo-chip-img--iefWerner { filter: invert(1) grayscale(1); }
.option-logo {
  flex: none;
  width: 56px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.option-logo-img { max-width: 100%; max-height: 14px; }
.option-logo-img--emerson { max-height: 22px; }
.option-logo-img--iefWerner { max-height: 16px; filter: invert(1) brightness(.94); }
.popover-option[aria-checked="false"] .option-logo-img { filter: grayscale(1); opacity: .4; }
.popover-option[aria-checked="false"] .option-logo-img--iefWerner { filter: invert(1) grayscale(1); }
.filter-divider {
  flex: none;
  width: 1px;
  height: 18px;
  margin: 0 2px;
  background: var(--border-strong);
}

/* ---------- Solution: chat stage with welcome backdrop ---------- */

.chat-stage { position: relative; flex: 1; min-height: 0; }
.welcome {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px 24px 72px;
  text-align: center;
  pointer-events: none;
  user-select: none;
  transition: opacity .6s ease, filter .6s ease;
}
/* Once the chat runs, the backdrop steps back — paler, but still in colour. */
.solution.has-messages .welcome { opacity: .22; filter: saturate(.75); }
.welcome-title {
  margin: 0 0 30px;
  color: var(--muted);
  font-size: clamp(15px, 1.6vw, 19px);
  font-weight: 400;
  line-height: 1.2;
}
.welcome-title span {
  display: block;
  margin-top: 8px;
  color: var(--text-strong);
  font-size: clamp(28px, 3.8vw, 46px);
  font-weight: 600;
  letter-spacing: -.02em;
}
.welcome-logos {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 20px 40px;
  max-width: 620px;
}
.welcome-logo {
  height: 26px;
  width: auto;
  max-width: 140px;
}
.welcome-logo--emerson { height: 44px; }
.welcome-logo--iefWerner { height: 32px; filter: invert(1) brightness(.94); }
.welcome-val {
  position: absolute;
  bottom: 22px;
  width: 170px;
  max-width: 45%;
  opacity: .8;
}

.chat-log {
  position: relative;
  z-index: 1;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px max(20px, calc((100% - 880px) / 2)) 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  /* Soft cut-off instead of content hitting the filter bar / composer edge. */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 20px, #000 calc(100% - 14px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 20px, #000 calc(100% - 14px), transparent 100%);
}
/* Messages keep their content height; an explicit min-height (typing bubble) would otherwise let the column squeeze them. */
.chat-log > * { flex-shrink: 0; }

/* Overlay-style scrollbars: no track, thin translucent thumb inset from the edge. */
.chat-log, .chat-md pre, .chat-md table, .results-table-wrap {
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.16) transparent;
}

.chat-msg {
  word-break: break-word;
  animation: chat-in .34s var(--ease-sheet) both;
}
@keyframes chat-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.chat-msg--user {
  align-self: flex-end;
  max-width: 82%;
  padding: 9px 14px;
  background-color: var(--accent);
  color: #ffffff;
  border-radius: 18px;
  border-bottom-right-radius: 6px;
  font-size: 15px;
  white-space: pre-wrap;
}
.chat-msg[data-request-id],
.chat-cards-wrap[data-request-id] { cursor: pointer; }
.chat-msg[data-request-id]:hover,
.chat-msg[data-request-id].is-request-linked {
  box-shadow: 0 0 0 2px rgba(122,162,255,.55);
}
.chat-msg[data-request-id]:focus-visible,
.chat-cards-wrap[data-request-id]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
.chat-msg--request strong { display: block; font-weight: 600; }
.chat-msg--request span { display: block; margin-top: 2px; font-size: 13px; opacity: .82; }
.chat-msg--bot {
  align-self: flex-start;
  max-width: 100%;
  padding: 12px 16px;
  background: rgba(24,26,28,.82);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  border: 1px solid var(--border);
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}
.chat-msg--bot:has(.chat-cards-wrap) { align-self: stretch; }
.chat-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 46px;
}
.chat-typing .chat-steps { flex: 1; margin: 0; }
.chat-live { display: inline-flex; align-items: center; gap: 5px; }
.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: chat-dot 1.4s infinite ease-in-out both;
}
.chat-typing span:nth-child(2) { animation-delay: .16s; }
.chat-typing span:nth-child(3) { animation-delay: .32s; }
.chat-typing em { margin-left: 8px; color: var(--muted); font-size: 13px; font-style: normal; }
@keyframes chat-dot {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}
.chat-stopped { align-self: flex-start; color: var(--muted); font-size: 13px; font-style: italic; }
.chat-file-card {
  align-self: flex-end;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  width: 150px;
  min-height: 110px;
  padding: 12px;
  background: rgba(24,26,28,.82);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  color: #e8e4de;
  line-height: 1.3;
}
.chat-file-card-name { overflow-wrap: anywhere; }
.chat-file-card-type {
  align-self: flex-start;
  padding: 2px 7px;
  background: var(--surface-hover);
  border-radius: 5px;
  color: #b8b3ac;
  font-size: 11px;
  letter-spacing: .04em;
}

/* ---------- Bot message Markdown ---------- */

.chat-md > :first-child { margin-top: 0; }
.chat-md > :last-child { margin-bottom: 0; }
.chat-md p { margin: 0 0 .7em; }
.chat-md h1, .chat-md h2, .chat-md h3,
.chat-md h4, .chat-md h5, .chat-md h6 {
  margin: 1.3em 0 .45em;
  color: var(--text-strong);
  font-weight: 600;
  line-height: 1.3;
}
.chat-md h1 { font-size: 20px; }
.chat-md h2 { font-size: 17px; }
.chat-md h3 { font-size: 15px; }
.chat-md h4, .chat-md h5, .chat-md h6 { font-size: 14px; color: #b3aea7; }
.chat-md a { color: var(--focus); text-decoration: none; }
.chat-md a:hover { text-decoration: underline; }
.chat-md strong { color: var(--text-strong); font-weight: 600; }
.chat-md hr { border: none; border-top: 1px solid var(--border); margin: 1.4em 0; }
.chat-md ul, .chat-md ol { margin: 0 0 .7em; padding-left: 1.35em; }
.chat-md li { margin: .2em 0; }
.chat-md li::marker { color: var(--muted); }
.chat-md blockquote {
  margin: .7em 0;
  padding: .1em 0 .1em .9em;
  border-left: 2px solid var(--border-strong);
  color: #a9a49d;
}
.chat-md code {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: .88em;
  background: var(--surface-hover);
  border-radius: 5px;
  padding: .15em .38em;
}
.chat-md pre {
  margin: .8em 0;
  padding: 12px 14px;
  background: #0d0f10;
  border: 1px solid rgba(255,255,255,.06);
  border-radius: 12px;
  overflow-x: auto;
}
.chat-md pre code { background: none; padding: 0; font-size: 13px; line-height: 1.5; }
.chat-md table:not(.results-table) {
  display: block;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: .8em 0;
  font-size: 13.5px;
}
.chat-md table:not(.results-table) th,
.chat-md table:not(.results-table) td { padding: 7px 10px; border-bottom: 1px solid var(--border); }
.chat-md table:not(.results-table) th { color: var(--text-strong); font-weight: 600; }
.chat-md img { max-width: 100%; border-radius: 8px; }

/* The 3D agent's log, collapsed above its answer. */
.chat-steps { margin: 0 0 .9em; }
.chat-steps summary {
  display: flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  user-select: none;
}
/* Disclosure chevron after the label instead of the default marker in front: right when closed, down when open. */
.chat-steps summary::-webkit-details-marker { display: none; }
.chat-steps summary::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .2s;
}
.chat-steps[open] summary::after { transform: rotate(45deg); }
.chat-steps[open] summary { margin-bottom: 8px; }
.chat-step {
  padding: 6px 0 6px 10px;
  border-left: 2px solid var(--border-strong);
}
.chat-step-heading { color: var(--text-strong); font-size: 13px; font-weight: 500; }
.chat-step-body {
  max-height: 180px;
  margin: 4px 0 0;
  overflow: auto;
  color: var(--muted);
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- Product cards (detail view) ---------- */

.chat-cards-wrap { margin-bottom: .8em; }
@property --cards-fade-l { syntax: "<length>"; inherits: false; initial-value: 0px; }
@property --cards-fade-r { syntax: "<length>"; inherits: false; initial-value: 0px; }
.chat-cards {
  display: flex;
  gap: 12px;
  margin: 0 -16px;
  padding: 0 16px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: 16px;
  scrollbar-width: none;
  /* Fade only the side that still has cards behind it (classes set while scrolling). */
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 var(--cards-fade-l), #000 calc(100% - var(--cards-fade-r)), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 var(--cards-fade-l), #000 calc(100% - var(--cards-fade-r)), transparent 100%);
  transition: --cards-fade-l .2s ease, --cards-fade-r .2s ease;
}
.chat-cards::-webkit-scrollbar { display: none; }
.chat-cards.has-prev { --cards-fade-l: 32px; }
.chat-cards.has-next { --cards-fade-r: 32px; }
.chat-cards.is-draggable { cursor: grab; }
.chat-cards.is-dragging { cursor: grabbing; user-select: none; scroll-snap-type: none; }
.chat-cards-nav { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.chat-cards-btn {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,.06);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color .18s ease, opacity .18s ease;
}
.chat-cards-btn:hover:not(:disabled) { background: rgba(255,255,255,.12); }
.chat-cards-btn:disabled { opacity: .32; cursor: default; }

.product-card {
  flex: 0 0 250px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  scroll-snap-align: start;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 14px;
  text-align: center;
}
.card-logo {
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.card-logo-img { max-height: 24px; max-width: 110px; width: auto; height: auto; }
/* Pure black wordmark — invisible on the dark card without the invert. */
.card-logo-img--iefWerner { filter: invert(1) brightness(.94); }
.card-image {
  height: 128px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  padding: 10px;
  background: #ffffff;
  border-radius: 8px;
}
.card-image--switchable { position: relative; margin-bottom: 6px; overflow: hidden; }
.card-product-img { max-height: 100%; max-width: 100%; object-fit: contain; }
.card-product-img--empty { width: 100%; height: 100%; background: #1c1f22; border-radius: 4px; }
.card-product-viewer { position: absolute; inset: 0; width: 100%; height: 100%; }
.card-product-viewer model-viewer { display: block; width: 100%; height: 100%; background: #ffffff; }
.card-viewer-status {
  position: absolute;
  z-index: 1;
  inset: auto 12px 12px;
  padding: 7px 10px;
  border-radius: 6px;
  background: rgba(17,18,19,.82);
  color: var(--text-strong);
  font-size: 12px;
}
.card-view-fullscreen {
  position: absolute;
  z-index: 2;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(17,18,19,.18);
  border-radius: 8px;
  background: rgba(255,255,255,.92);
  color: #26292b;
  cursor: pointer;
}
.card-image--switchable:fullscreen { width: 100vw; height: 100vh; margin: 0; padding: 0; border-radius: 0; }
.card-view-toggle {
  align-self: center;
  display: inline-flex;
  gap: 2px;
  margin: 0 0 12px;
  padding: 3px;
  border: 1px solid #34383a;
  border-radius: 20px;
  background: #202325;
}
.card-view-toggle-btn {
  min-width: 42px;
  padding: 4px 10px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  color: #aaa59e;
  font-size: 12px;
  cursor: pointer;
}
.card-view-toggle-btn.is-active { background: var(--accent); color: #ffffff; }
.card-name { margin-bottom: 10px; }
.card-name-line {
  color: #ffffff;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
  word-break: break-word;
}
.card-name-line--single { font-size: 15px; }
.card-name-label { color: var(--muted); font-weight: 500; }
.card-info {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  text-align: left;
}
.card-info-title {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .5px;
  text-transform: uppercase;
}
.card-info-list { margin: 0; }
.card-info-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255,255,255,.05);
}
.card-info-row:last-child { border-bottom: none; }
.card-info-row dt { color: var(--muted); font-size: 13px; }
/* Value and unit stay on one line ("2.70 Nm"); the label wraps instead. */
.card-info-row dd {
  flex-shrink: 0;
  margin: 0;
  color: var(--text-strong);
  font-size: 13px;
  font-weight: 500;
  text-align: right;
  white-space: nowrap;
}
.card-actions { margin-top: 12px; }
.card-info + .card-actions { margin-top: 12px; }
.card-name + .card-actions { margin-top: auto; }
.card-order {
  display: block;
  width: 100%;
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
button.card-order {
  cursor: not-allowed;
}

/* ---------- Filtering (client/app/chatPanel.js applyFilters) ---------- */

.chat-cards-wrap .is-filtered-out { display: none; }
.chat-cards-wrap.is-empty > :not(.chat-cards-empty) { display: none; }
.chat-cards-empty { margin: 0; color: var(--muted); font-size: 14px; }

/* ---------- Result views: tiles and table ---------- */

.results-table-wrap { display: none; }

.solution.view-tiles .chat-cards {
  flex-wrap: wrap;
  margin: 0;
  padding: 0;
  overflow: visible;
  scroll-snap-type: none;
  -webkit-mask-image: none;
  mask-image: none;
  cursor: auto;
}
.solution.view-tiles .product-card { flex: 0 0 156px; padding: 10px; }
.solution.view-tiles .card-logo { height: 22px; margin-bottom: 8px; }
.solution.view-tiles .card-logo-img { max-height: 16px; max-width: 84px; }
.solution.view-tiles .card-image { height: 86px; margin-bottom: 8px; padding: 6px; }
.solution.view-tiles .card-name { margin-bottom: 0; }
.solution.view-tiles .card-name-line { font-size: 12px; font-weight: 500; }
.solution.view-tiles .card-info,
.solution.view-tiles .card-view-toggle,
.solution.view-tiles .card-actions { display: none; }

.solution.view-table .chat-cards,
.solution.view-table .chat-cards-nav { display: none; }
.solution.view-table .results-table-wrap {
  display: block;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.results-table th,
.results-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.results-table tr:last-child > * { border-bottom: 0; }
.results-table thead th { background: rgba(255,255,255,.03); }
.results-table tbody th { color: var(--muted); font-weight: 500; }
.results-table td { color: var(--text-strong); font-variant-numeric: tabular-nums; }
.results-table tbody tr:hover > * { background: rgba(255,255,255,.025); }
.results-table .card-logo-img { max-height: 18px; max-width: 90px; }

/* ---------- Solution footer: view switch | composer | export in one row ---------- */

.solution-footer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 6px 14px 14px;
}
/* Bottom-aligned with the composer, then lifted to its centre line (composer 46px, switch 34px, button 40px). */
.view-switch { flex: none; margin-bottom: 6px; }
.export-anchor { margin-bottom: 3px; }
.chat-form { flex: 1; min-width: 0; max-width: 860px; margin: 0 auto; }
.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 6px;
  background: rgba(24,26,28,.9);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 24px;
  transition: border-color .2s ease, background-color .2s ease;
}
.chat-composer:focus-within { border-color: rgba(120,150,255,.45); }
.chat-input {
  flex: 1;
  min-width: 0;
  min-height: 32px;
  max-height: 132px;
  padding: 5px 4px;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: #e8e4de;
  font: inherit;
  font-size: 15px;
  line-height: 22px;
  overflow-y: auto;
  scrollbar-width: none;
}
.chat-input::-webkit-scrollbar { display: none; }
.chat-input::placeholder { color: #7c7770; }
.composer-btn {
  flex: none;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #b8b3ac;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color .2s ease, color .2s ease;
}
.composer-btn:hover:not([aria-disabled="true"]) { background: rgba(255,255,255,.09); color: #ffffff; }
.composer-btn[aria-disabled="true"] { color: var(--faint); cursor: not-allowed; }
.chat-send {
  flex: none;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background-color: var(--accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .18s var(--ease-sheet), background-color .2s ease;
}
.chat-send:hover:not(:disabled) { background-color: var(--accent-hover); transform: scale(1.06); }
.chat-send:active:not(:disabled) { transform: scale(.92); }
.chat-send:disabled { background-color: rgba(255,255,255,.09); color: rgba(255,255,255,.35); cursor: default; }
.chat-file-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  max-width: 100%;
  margin-bottom: 6px;
  padding: 4px 6px 4px 12px;
  background: var(--surface-strong);
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 14px;
  color: #e8e4de;
  font-size: 13px;
}
.chat-file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-file-remove {
  flex: none;
  width: 20px;
  height: 20px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #b8b3ac;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.chat-file-remove:hover { background: rgba(255,255,255,.12); color: #ffffff; }

.export-popover { right: 0; bottom: calc(100% + 10px); width: 230px; }
.round-btn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(15,49,161,.35);
  transition: background-color .2s ease, transform .18s var(--ease-sheet), box-shadow .2s ease;
}
.round-btn:hover:not(:disabled) { background: var(--accent-hover); transform: scale(1.05); }
.round-btn:disabled {
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.3);
  box-shadow: none;
  cursor: default;
}

/* ---------- Narrow screens: stack Requirements above Solution ---------- */

@media (max-width: 860px) {
  body { overflow: auto; }
  .app { display: flex; flex-direction: column; height: auto; }
  .splitter { display: none; }
  .requirements { border-bottom: 1px solid var(--border); }
  .requirements-body { overflow: visible; }
  .scene-view { height: 70vh; }
  .solution { height: 100vh; height: 100dvh; }
  .panel-header, .filter-bar { padding-left: 16px; padding-right: 12px; }
  .requirements-body, .requirements-footer { padding-left: 16px; padding-right: 16px; }
  .welcome-val { display: none; }
}
@media (max-width: 600px) {
  .chat-entry {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px;
  }
  .chat-entry-actions { gap: 0; }
  .chat-entry-action {
    min-width: 30px;
    min-height: 30px;
    padding: 5px 4px;
    overflow: hidden;
    font-size: 0;
  }
  .chat-entry-action::before {
    display: block;
    font-size: 13px;
    line-height: 1;
  }
  .chat-entry-action:not(.chat-entry-action--delete)::before { content: "R"; }
  .chat-entry-action--delete::before { content: "x"; font-size: 17px; }
  .chat-entry-summary {
    grid-column: 1 / -1;
    padding: 0 10px 6px;
  }
  .request-card-header {
    gap: 4px;
    padding-right: 6px;
  }
  .request-card-status { font-size: 11px; }
  .solution-footer { flex-wrap: wrap; align-items: center; }
  .chat-form { order: -1; flex-basis: 100%; }
  .view-switch, .export-anchor { margin-bottom: 0; }
  .export-anchor { margin-left: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
}
