.demo-page {
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.demo-page main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.demo-section {
  flex: 1;
  min-height: 0;
  padding: 1.25rem 0;
  display: flex;
  flex-direction: column;
}

.demo-inner {
  width: min(1280px, calc(100% - 3rem));
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.demo-layout {
  display: grid;
  grid-template-columns: minmax(340px, 440px) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: stretch;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.demo-sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
  padding: 1.75rem 1.85rem 1.75rem 2rem;
  background: var(--surface-soft);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.demo-header h2 {
  font-size: clamp(1.8rem, 3.2vw, 2.5rem);
  margin: 0;
  line-height: 1.15;
}

.demo-features {
  position: relative;
}

.demo-features-toggle {
  appearance: none;
  display: inline;
  margin: 0 0 0 0.08em;
  padding: 0;
  border: 0;
  background: transparent;
  font: inherit;
  letter-spacing: inherit;
  line-height: inherit;
  color: var(--text-muted);
  cursor: pointer;
  vertical-align: baseline;
}

.demo-features-toggle:hover,
.demo-features.is-open .demo-features-toggle {
  color: var(--accent);
}

.demo-lead {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 0.45rem);
  z-index: 5;
  margin: 0;
  padding: 0.85rem 1rem 0.85rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(26, 35, 50, 0.12);
  color: var(--text-muted);
  font-size: 0.9rem;
}

.demo-features:hover .demo-lead,
.demo-features:focus-within .demo-lead,
.demo-features.is-open .demo-lead {
  display: block;
}

.demo-lead li {
  margin: 0.35rem 0;
}

.demo-controls {
  margin: 1.25rem 0 0;
}

.demo-field + .demo-field {
  margin-top: 1.1rem;
}

.demo-label {
  display: block;
  margin-bottom: 0.5rem;
  font-family: var(--font-sans);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--text);
}

.demo-select,
.demo-prompt-input {
  width: 100%;
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  box-sizing: border-box;
}

.demo-prompt-input {
  min-height: 8.5rem;
  resize: vertical;
  line-height: 1.5;
  padding-right: 2.75rem;
}

.demo-select:focus,
.demo-prompt-input:focus {
  outline: none;
  border-color: var(--accent-light);
}

.chat-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 1.35rem 1.5rem;
  background: #eef1f5;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.chat-empty {
  margin: auto;
  max-width: 36rem;
  width: 100%;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.chat-empty-title {
  margin: 0 0 0.4rem;
  font-family: var(--font-sans);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

.chat-empty-lead {
  margin: 0;
  font-style: italic;
}

.chat-empty[hidden] {
  display: none;
}

.chat-starters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.65rem;
  margin-top: 1.1rem;
  text-align: left;
}

.chat-starter {
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  margin: 0;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: inherit;
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.chat-starter:hover,
.chat-starter:focus-visible {
  border-color: var(--accent-light);
  outline: none;
}

.chat-starter-title {
  --sparkle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke-width='1.75' stroke='black'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='M9.813 15.904 9 18.75l-.813-2.846a4.5 4.5 0 0 0-3.09-3.09L2.25 12l2.846-.813a4.5 4.5 0 0 0 3.09-3.09L9 5.25l.813 2.846a4.5 4.5 0 0 0 3.09 3.09L15.75 12l-2.846.813a4.5 4.5 0 0 0-3.09 3.09ZM18.259 8.715 18 9.75l-.259-1.035a3.375 3.375 0 0 0-2.455-2.456L14.25 6l1.036-.259a3.375 3.375 0 0 0 2.455-2.456L18 2.25l.259 1.035a3.375 3.375 0 0 0 2.455 2.456L21.75 6l-1.036.259a3.375 3.375 0 0 0-2.455 2.456ZM16.894 20.567 16.5 21.75l-.394-1.183a2.25 2.25 0 0 0-1.423-1.423L13.5 18.75l1.183-.394a2.25 2.25 0 0 0 1.423-1.423l.394-1.183.394 1.183a2.25 2.25 0 0 0 1.423 1.423l1.183.394-1.183.394a2.25 2.25 0 0 0-1.423 1.423Z'/%3E%3C/svg%3E");
  display: flex;
  align-items: center;
  gap: 0.4em;
  font-size: 0.95rem;
  font-weight: 650;
  color: var(--text);
  letter-spacing: -0.02em;
}

.chat-starter-title::before {
  content: "";
  flex: none;
  width: 0.95em;
  height: 0.95em;
  background: currentColor;
  -webkit-mask: var(--sparkle) center / contain no-repeat;
  mask: var(--sparkle) center / contain no-repeat;
}

.chat-starter-preview {
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--text-muted);
}

.chat-msg {
  padding: 0.85rem 1.1rem;
  border-radius: 8px;
  max-width: 90%;
  font-size: 0.95rem;
  line-height: 1.6;
  word-wrap: break-word;
}

.chat-msg.user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}

.chat-msg.ai {
  background: transparent;
  color: var(--text);
  align-self: flex-start;
  width: 100%;
  max-width: 100%;
  padding: 0;
}

.chat-msg.error {
  background: rgba(220, 38, 38, 0.08);
  color: #9f1239;
  border: 1px solid rgba(220, 38, 38, 0.18);
  align-self: flex-start;
}

.chat-thought {
  margin: 0 0 0.85rem;
  padding: 0.7rem 0.9rem;
  background: #e0e5ec;
  border: 1px solid rgba(26, 35, 50, 0.12);
  border-radius: 10px;
  color: var(--text-muted);
}

.chat-thought summary {
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  list-style: none;
}

.chat-thought summary::-webkit-details-marker {
  display: none;
}

.chat-thought summary::before {
  content: "▸ ";
  font-size: 0.65rem;
}

.chat-thought[open] summary::before {
  content: "▾ ";
}

.chat-thought-body {
  margin-top: 0.4rem;
  max-height: 10rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.chat-answer p {
  margin: 0 0 0.75rem;
}

.chat-answer p:last-child {
  margin-bottom: 0;
}

.chat-answer h1,
.chat-answer h2,
.chat-answer h3,
.chat-answer h4 {
  margin: 1rem 0 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.35;
  color: var(--text);
}

.chat-answer h1 { font-size: 1.15rem; }
.chat-answer h2 { font-size: 1.08rem; }

.chat-answer ul,
.chat-answer ol {
  margin: 0 0 0.75rem;
  padding-left: 1.25rem;
}

.chat-answer li {
  margin: 0.2rem 0;
}

.chat-msg.ai pre {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 0.85rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0.75rem 0;
}

.chat-msg.ai code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.875rem;
  color: var(--accent);
}

.chat-model-tag {
  display: block;
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  font-family: ui-monospace, monospace;
  color: var(--text-muted);
}

.demo-input-area {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: auto;
}

.demo-prompt-wrap {
  position: relative;
}

.demo-file-label {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-light);
  cursor: pointer;
}

.demo-file-label:hover {
  color: var(--accent);
}

.demo-file-icon {
  width: 1.35rem;
  height: 1.35rem;
}

.demo-file-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.demo-file-status {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 0;
}

.demo-file-input {
  display: none;
}

.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.demo-actions .btn {
  flex: 1;
  min-width: 7rem;
}

.chat-typing {
  color: var(--text-muted);
  font-size: 0.9rem;
  align-self: flex-start;
}

@media (max-width: 860px) {
  .demo-page {
    height: auto;
    overflow: auto;
  }

  .demo-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .chat-box {
    height: min(60vh, 28rem);
    max-height: 60vh;
  }
}

@media (max-width: 640px) {
  .demo-section {
    padding-top: 1.25rem;
  }
}
