.trial-layout {
  display: grid;
  grid-template-columns: minmax(0, 4fr) minmax(0, 5fr);
  align-items: center;
  align-content: center;
  min-block-size: calc(100svh - var(--mobile-header-height));
  gap: clamp(32px, 5vw, 76px);
  padding-block: clamp(32px, 5vw, 72px);
}

@media (min-width: 1024px) {
  .trial-layout { min-block-size: calc(100svh - var(--desktop-header-height)); }
}

.trial-back {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  margin-bottom: 20px;
  color: var(--muted);
  font-size: 14px;
}

.trial-intro h1 { margin: 0 0 22px; text-wrap: balance; }

.trial-panel {
  min-width: 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 16px 36px #0d0d0d0c;
  font-size: 16px;
  --panel-padding: clamp(18px, 3vw, 32px);
}

.trial-panel [hidden] { display: none; }

.trial-panel .panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.trial-panel .panel-head {
  justify-content: start;
  align-items: center;
  padding: 19px var(--panel-padding) 15px;
  font-size: 14px;
}

.trial-panel .progress { background: var(--sand); }
.trial-panel .progress { height: 2px; }
.trial-panel #progress-fill { height: 100%; width: 0; background: var(--accent); }

.trial-panel .chat-thread,
.trial-panel .results { padding: var(--panel-padding); }

.trial-panel .chat-thread {
  display: grid;
  align-content: start;
  gap: 14px;
  min-height: 330px;
  max-height: min(560px, 72svh);
  overflow: auto;
  scroll-margin-top: 30px;
  scrollbar-width: thin;
}

.trial-panel .chat-thread:has(.chat-opening) { max-height: none; }
.trial-panel .chat-thread:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.trial-panel .chat-message { display: flex; align-items: flex-start; gap: 8px; min-width: 0; }
.trial-panel .user-message { justify-content: flex-end; }

.trial-panel .chat-avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font: 600 11px/1 Montserrat, sans-serif;
}

.trial-panel .chat-bubbles {
  position: relative;
  display: grid;
  justify-items: start;
  gap: 6px;
  max-width: min(100% - 40px, 52ch);
}

.trial-panel .chat-bubble {
  margin: 0;
  padding: 10px 14px;
  border-radius: 6px 16px 16px;
  background: var(--sand);
  font-size: 15px;
  line-height: 1.5;
}

.trial-panel .user-message .chat-bubble {
  max-width: 86%;
  border-radius: 16px 16px 6px 16px;
  background: #4f2448;
  color: #fff;
}

.trial-panel .chat-bubble .question {
  margin: 0;
  font: 700 16px/1.45 'DM Sans', sans-serif;
}

.trial-panel .chat-bubble.chat-detail { color: var(--muted); font-size: 14px; }
.trial-panel .chat-turn { display: grid; gap: 16px; }
.trial-panel .chat-composer { justify-self: end; width: min(100%, 28rem); }
.trial-panel .chat-composer .actions { margin-top: 0; justify-content: end; }
.trial-panel .chat-composer:has(.report-open) { justify-self: stretch; width: auto; margin-inline-start: 40px; }
.trial-panel .chat-composer .report-open { justify-content: start; }
.trial-panel .chat-composer .controls { margin-top: 4px; justify-content: end; }
.trial-panel .chat-input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
.trial-panel .chat-input-row .button { border-radius: 18px; padding-inline: 14px; }

.trial-panel .chat-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.trial-panel .chat-typing { display: none; }

@media (prefers-reduced-motion: no-preference) {
  .trial-panel .chat-turn { --reply-delay: 240ms; }
  .trial-panel .chat-opening { --reply-delay: 540ms; }

  .trial-panel .chat-thread:has(.chat-opening) > .assistant-message {
    animation: trial-message-in 180ms ease-out both;
  }

  .trial-panel .chat-thread:has(.chat-opening) > .assistant-message:nth-child(2) {
    animation-delay: 140ms;
  }

  .trial-panel .chat-current .chat-bubble,
  .trial-panel .chat-composer {
    animation: trial-message-in 200ms ease-out var(--reply-delay) both;
  }

  .trial-panel .chat-current .chat-detail,
  .trial-panel .chat-composer { animation-delay: calc(var(--reply-delay) + 110ms); }

  .trial-panel .chat-typing {
    position: absolute;
    inset: 0 auto auto 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 13px;
    border-radius: 6px 16px 16px;
    background: var(--sand);
    pointer-events: none;
    animation: trial-typing 230ms ease-out both;
    animation-delay: calc(var(--reply-delay) - 230ms);
  }

  .trial-panel .chat-typing i {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--muted);
    animation: trial-dot 230ms ease-in-out both;
    animation-delay: inherit;
  }

  .trial-panel .chat-typing i:nth-child(2) { animation-delay: calc(var(--reply-delay) - 190ms); }
  .trial-panel .chat-typing i:nth-child(3) { animation-delay: calc(var(--reply-delay) - 150ms); }
}

@keyframes trial-message-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes trial-typing {
  0%, 85% { opacity: 1; }
  100% { opacity: 0; visibility: hidden; }
}
@keyframes trial-dot {
  50% { transform: translateY(-3px); }
}

.trial-panel h2 { font-size: clamp(24px, 3vw, 36px); margin-bottom: 14px; scroll-margin-top: 28px; }
.trial-panel h3 { font-size: clamp(21px, 2.2vw, 26px); margin-bottom: 10px; }
.trial-panel h2:focus { outline: none; }
.trial-panel p { margin-bottom: 14px; }
.trial-panel p:last-child, .trial-panel p.chat-bubble { margin-bottom: 0; }

.trial-panel .notice,
.trial-panel .result-note { color: var(--muted); }

.trial-panel .actions,
.trial-panel .controls,
.trial-panel .export {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin-top: 18px;
}

.trial-panel .controls { justify-content: space-between; }
.trial-panel .actions + .notice, .trial-panel .cta .button + .notice { margin-top: 14px; }
.trial-panel .button { border: 1px solid var(--ink); cursor: pointer; }
.trial-panel .button.secondary { background: #fff; color: var(--ink); }
.trial-panel .button.secondary:hover { background: var(--paper); }

.trial-panel .text-button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

.trial-panel .text-button:hover { color: var(--accent); }

.trial-panel .panel-foot {
  padding: 12px var(--panel-padding);
  background: var(--paper);
  border-block-start: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.trial-panel summary { cursor: pointer; font-weight: 600; }

.trial-panel .field { margin: 0 0 15px; min-width: 0; }
.trial-panel .field label { display: block; margin-bottom: 6px; font-weight: 600; }
.trial-panel :is(input, textarea) {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 9px 11px;
  background: #fff;
  border: 1px solid #777975;
  border-radius: 3px;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}

.trial-panel :is(input, textarea):focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.trial-panel .chat-input-row input { border-radius: 18px; padding-inline: 14px; }
.trial-panel :is(.notice, .result-note, .error, #status) { font-size: 14px; }
.trial-panel .error { color: #962d20; }
.trial-panel :is(.error, #status):empty { display: none; }

.trial-panel .finding, .trial-panel .sim { background: var(--paper); border: 1px solid var(--line); padding: clamp(14px, 3vw, 24px); margin-block: 20px; }
.trial-panel .method { margin-top: 20px; font-size: 14px; }
.trial-panel .method summary { margin-bottom: 8px; }
.trial-panel .sim-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; gap: 12px; }
.trial-panel .cta { padding-top: 18px; border-top: 1px solid var(--line); }

@media (max-width: 767px) {
  .trial-layout { grid-template-columns: 1fr; gap: 24px; padding-block: 28px; }
  .trial-panel .chat-thread { min-height: 0; }
  .trial-back { margin-bottom: 10px; }
  .trial-intro h1 { margin-bottom: 14px; }
}

@media (max-width: 440px) {
  .trial-panel .sim-grid { grid-template-columns: 1fr; gap: 0; }
  .trial-panel .panel-head { gap: 8px; }
  .trial-panel .chat-thread { padding-block: 14px; }
}

.trial-panel .chat-replies {
  display: grid;
  justify-items: end;
  gap: 7px;
}

.trial-panel .chat-replies .button {
  min-height: 44px;
  padding: 9px 15px;
  border: 1px solid #9b878f;
  border-radius: 24px;
  background: #fff;
  color: var(--ink);
  font: 600 14px/1.35 'DM Sans', sans-serif;
  letter-spacing: 0;
  text-align: right;
}

.trial-panel .chat-replies .button:hover {
  border-color: var(--accent);
  background: #fbf3f9;
}

.report-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}

.report-header nav {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px 12px;
  min-height: var(--desktop-header-height);
  padding: 12px clamp(16px, 3vw, 36px);
}

.report-header .report-new { justify-self: start; font-weight: 700; }
.report-header .report-links { display: flex; gap: 8px; }
.report-header .button { border: 1px solid var(--ink); cursor: pointer; }
.report-header #share-report { background: transparent; color: var(--ink); }
.report-header #share-report:hover { background: var(--sand); }
.report-header #share-report[hidden], .report-header #share-link[hidden],
.report-header #status:empty { display: none; }
.report-header #status, .report-header #share-link { grid-column: 1 / -1; justify-self: end; }
.report-header #status { margin: 0; color: var(--muted); font-size: 13px; }
.report-header #share-link { width: min(100%, 540px); font: inherit; }

.trial-report {
  width: min(1080px, calc(100% - 32px));
  margin: clamp(16px, 5vw, 64px) auto;
  --panel-padding: clamp(16px, 5vw, 48px);
}

.trial-report h1 { margin: 0 0 16px; font-size: clamp(32px, 5vw, 52px); }
.trial-report h2 { font-size: clamp(25px, 3vw, 34px); }
.trial-report .report-metrics, .trial-report .sim-metrics {
  display: grid;
  gap: 12px;
  margin-block: 24px;
}

.trial-report .report-metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.trial-report .sim-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.trial-report .report-metric, .trial-report .sim-metrics > div {
  padding: clamp(10px, 1.8vw, 18px);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
}

.trial-report .report-metric-total, .trial-report .sim-metrics > .report-metric-total {
  border-color: #cdb3ca;
  background: #faf1f8;
  color: #4f2448;
}

.trial-report dt { font-weight: 700; line-height: 1.4; }
.trial-report dd { margin: 0; overflow-wrap: anywhere; }
.trial-report .report-metric strong, .trial-report .sim-metrics dd {
  display: block;
  margin-block: 5px;
  font-size: clamp(20px, 3vw, 32px);
  font-weight: 700;
  line-height: 1.2;
}
.trial-report .report-metric span { display: block; color: var(--muted); font-size: 13px; }
.trial-report .report-section { border-radius: 12px; padding: clamp(14px, 3vw, 28px); }
.trial-report .finding { border-color: #cdb3ca; background: #faf1f8; }
.trial-report .priority-details { display: grid; gap: 10px; margin-bottom: 0; }
.trial-report .priority-details > div { padding: 12px 14px; border-radius: 8px; background: #fff; }
.trial-report .priority-details dd { margin-top: 4px; }
.trial-report .priority-stage + .priority-stage { margin-top: 24px; }
.trial-report .sim-grid { align-items: start; }
.trial-report #lift { padding: 0; border: 0; accent-color: var(--accent); background: transparent; }
.trial-report #lift-label { display: block; color: #4f2448; font-size: 14px; font-weight: 700; }
.trial-panel .chat-skip { margin-top: 8px; }

@media (max-width: 760px) {
  .report-header nav { min-height: var(--mobile-header-height); }
  .trial-report .report-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 480px) {
  .report-header .report-new { font-size: 13px; }
  .report-header .button { padding: 8px; letter-spacing: 0; }
  .trial-report .sim-metrics { grid-template-columns: 1fr; }
}
