:root {
  color-scheme: dark;
  --bg: #0d0f12;
  --surface: #14171b;
  --surface-raised: #1a1e23;
  --surface-hover: #20252b;
  --border: #2a2f36;
  --border-soft: #20242a;
  --text: #edf0f4;
  --muted: #929aa5;
  --faint: #646d78;
  --accent: #7068e8;
  --accent-soft: rgba(112, 104, 232, 0.15);
  --green: #4db88a;
  --amber: #d7a54d;
  --red: #e06c75;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.topbar {
  height: 64px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: #111316;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto minmax(280px, 1fr);
  align-items: center;
  gap: 20px;
}
.title-group { min-width: 0; display: flex; align-items: center; gap: 12px; }
.back-link {
  width: 32px;
  height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 24px;
  line-height: 1;
}
.back-link:hover { background: var(--surface-hover); color: var(--text); }
.eyebrow { margin: 0 0 1px; color: var(--muted); font-size: 11px; }
h1 {
  max-width: 520px;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dataset-nav {
  display: flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #0d0f12;
}
.dataset-nav a {
  min-width: 88px;
  padding: 6px 12px;
  border-radius: 5px;
  color: var(--muted);
  text-align: center;
  text-decoration: none;
  font-size: 12px;
}
.dataset-nav a:hover { color: var(--text); }
.dataset-nav a[aria-current="page"] { background: var(--surface-raised); color: var(--text); }
.header-actions { justify-self: end; display: flex; align-items: center; gap: 12px; }
.status { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.status i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.status i[data-state="loading"] { background: var(--amber); animation: pulse 1s infinite; }
.status i[data-state="ready"] { background: var(--green); }
.status i[data-state="error"] { background: var(--red); }
@keyframes pulse { 50% { opacity: 0.35; } }
.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
}
.icon-button:hover { background: var(--surface-hover); color: var(--text); }

.preview-shell {
  height: calc(100vh - 64px);
  min-height: 0;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
}
.sample-sidebar {
  min-height: 0;
  border-right: 1px solid var(--border);
  background: #111316;
  display: flex;
  flex-direction: column;
}
.sidebar-heading {
  height: 48px;
  flex: none;
  padding: 0 14px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.sidebar-heading span:last-child {
  min-width: 26px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--surface-raised);
  color: var(--faint);
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
}
.sample-list { min-height: 0; flex: 1; overflow: auto; padding: 8px; }
.sample-item {
  width: 100%;
  min-height: 74px;
  margin-bottom: 4px;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  cursor: pointer;
  text-align: left;
}
.sample-item:hover { background: var(--surface); }
.sample-item.is-active { border-color: rgba(112, 104, 232, 0.38); background: var(--accent-soft); }
.sample-item strong { color: #d9dde3; font-size: 12px; }
.sample-item span {
  width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sample-item small { color: var(--faint); font-size: 10px; }
.load-more, .message-load-more {
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}
.load-more { margin: 8px; flex: none; }
.load-more:hover, .message-load-more:hover { background: var(--surface-hover); color: var(--text); }
.load-more:disabled { cursor: wait; opacity: 0.5; }

.sample-main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.sample-toolbar {
  min-height: 56px;
  flex: none;
  padding: 9px 18px;
  border-bottom: 1px solid var(--border);
  background: #111316;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.sample-toolbar > div:first-child { display: flex; align-items: center; gap: 12px; }
.section-label { color: var(--accent); font-size: 11px; font-weight: 700; }
#sample-position { color: var(--text); font-size: 13px; }
.sample-meta { min-width: 0; display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.sample-meta span {
  max-width: 230px;
  padding: 4px 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface);
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 18px clamp(16px, 3vw, 46px) 80px;
  scroll-behavior: smooth;
}
.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--faint);
  text-align: center;
}
.empty-state strong { color: var(--muted); font-size: 14px; }
.empty-state span { font-size: 12px; }
.empty-state.is-error strong { color: var(--red); }
.loading-state { animation: softPulse 1.3s infinite; }
@keyframes softPulse { 50% { opacity: 0.45; } }

.message {
  position: relative;
  width: 100%;
  max-width: none;
  margin: 0 auto 10px;
  padding: 10px 12px;
  border: 0;
  background: transparent;
}
.message-user {
  width: 100%;
  margin-left: 0;
  margin-right: 0;
  padding: 13px 15px;
  border: 1px solid #272b35;
  border-radius: 7px;
  background: #171921;
}
.message-developer,
.message-system {
  width: 100%;
  margin-left: 0;
  margin-right: 0;
  padding: 13px 15px;
  border: 1px solid #252a31;
  border-radius: 7px;
  background: #13161a;
}
.message-assistant,
.message-reasoning { margin-right: 0; padding-left: 4px; }
.message > header { margin-bottom: 9px; display: flex; align-items: center; gap: 7px; }
.message > header strong { color: var(--muted); font-size: 11px; }
.message > header small { margin-left: auto; color: var(--faint); font-size: 9px; }
.role-marker {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-hover);
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
}
.message-user .role-marker { background: var(--accent); color: white; }
.message-assistant .role-marker { background: #35404d; color: #dce4ee; }
.message-content { min-width: 0; }
.markdown-body {
  min-width: 0;
  color: #c8ced6;
  font-size: 13px;
  line-height: 1.75;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body p { margin: 0 0 10px; }
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 20px 0 9px;
  color: #edf0f4;
  font-weight: 650;
  line-height: 1.35;
}
.markdown-body h1 { padding-bottom: 8px; border-bottom: 1px solid var(--border); font-size: 20px; }
.markdown-body h2 { padding-bottom: 6px; border-bottom: 1px solid var(--border-soft); font-size: 17px; }
.markdown-body h3 { font-size: 15px; }
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 { font-size: 13px; }
.markdown-body strong { color: #eef1f5; font-weight: 700; }
.markdown-body em { color: #d6dbe2; }
.markdown-body a { color: #9c96f4; text-decoration: underline; text-underline-offset: 2px; }
.markdown-body code {
  padding: 2px 5px;
  border: 1px solid #30353d;
  border-radius: 4px;
  background: #0b0d10;
  color: #d9b878;
  font: 0.92em/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.markdown-body .markdown-code-block {
  margin: 12px 0;
  padding: 13px 15px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #090b0d;
}
.markdown-body .markdown-code-block code {
  padding: 0;
  border: 0;
  background: transparent;
  color: #cbd2dc;
  font-size: 12px;
  white-space: pre;
}
.markdown-body blockquote {
  margin: 12px 0;
  padding: 7px 12px;
  border-left: 3px solid var(--accent);
  background: rgba(112, 104, 232, 0.055);
  color: #aeb5bf;
}
.markdown-body ul,
.markdown-body ol { margin: 8px 0 12px; padding-left: 25px; }
.markdown-body li { margin: 3px 0; padding-left: 2px; }
.markdown-body li::marker { color: #8982ed; }
.markdown-body hr { height: 1px; margin: 18px 0; border: 0; background: var(--border); }
.markdown-table-scroll { max-width: 100%; margin: 12px 0; overflow-x: auto; }
.markdown-body table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: 12px; }
.markdown-body th,
.markdown-body td { padding: 8px 10px; border: 1px solid var(--border); text-align: left; vertical-align: top; }
.markdown-body th { background: var(--surface-raised); color: #e1e5eb; font-weight: 650; }
.markdown-body tr:nth-child(even) td { background: rgba(255, 255, 255, 0.018); }
.raw-content {
  margin: 0;
  overflow: auto;
  overflow-wrap: anywhere;
  color: #c8ced6;
  font: 12px/1.7 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.text-toggle {
  margin-top: 10px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #8d86f2;
  cursor: pointer;
  font-size: 11px;
}
.text-toggle:hover { color: #b3aff8; }
.tool-block {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0d0f12;
  overflow: hidden;
}
.thinking-block {
  margin: 0;
  border: 0;
  background: transparent;
}
.thinking-block summary {
  min-height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: #9690ee;
  font-size: 11px;
}
.thinking-block summary::marker { color: var(--accent); }
.thinking-block summary span { margin-left: auto; color: var(--faint); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; }
.thinking-block .message-content { margin-left: 4px; padding: 5px 0 4px 14px; border-left: 1px solid rgba(112, 104, 232, 0.35); }
.tool-block summary {
  min-height: 38px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 11px;
}
.tool-block summary::marker { color: var(--green); }
.tool-block summary span { margin-left: auto; color: var(--faint); }
.tool-block .message-content { padding: 12px; border-top: 1px solid var(--border-soft); }
.tool-event { width: 100%; max-width: none; margin: 0 0 8px; }
.tool-event-block {
  border: 1px solid #292d32;
  border-radius: 6px;
  background: #1a1d20;
  overflow: hidden;
}
.tool-event-block summary {
  min-height: 34px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: #9299a2;
  font-size: 11px;
}
.tool-event-block summary::marker { color: #737b85; }
.tool-event-block summary span { margin-left: auto; color: #69717b; }
.tool-event-block summary small { min-width: 34px; color: #555d67; text-align: right; }
.tool-event-block .message-content { max-height: 440px; padding: 12px 14px; overflow: auto; border-top: 1px solid #282c31; background: #0e1113; }
.context-event-block { border-color: #30333a; background: #17191d; }
.context-event-block summary { color: #8d96a3; }
.context-event-block summary::marker { color: #6f7884; }
.message-load-more { width: min(420px, 100%); margin: 16px auto 0; display: block; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  padding: 20px;
  background: rgba(5, 7, 9, 0.78);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
}
.modal-backdrop[hidden] { display: none; }
.auth-modal {
  width: min(400px, 100%);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #15181c;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
}
.modal-mark {
  width: 36px;
  height: 36px;
  margin-bottom: 18px;
  border-radius: 6px;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  color: #9b95f3;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  font-weight: 700;
}
.auth-modal h2 { margin: 0 0 7px; font-size: 20px; }
.auth-modal > p { margin: 0 0 22px; color: var(--muted); font-size: 12px; }
.auth-modal label { margin-bottom: 14px; display: block; }
.auth-modal label span { margin-bottom: 6px; display: block; color: var(--muted); font-size: 11px; font-weight: 600; }
.auth-modal input {
  width: 100%;
  height: 42px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0e1013;
  color: var(--text);
  outline: 0;
}
.auth-modal input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.primary-button {
  width: 100%;
  height: 42px;
  margin-top: 3px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 600;
}
.primary-button:hover { background: #7b73ee; }
.primary-button:disabled { cursor: wait; opacity: 0.55; }
.auth-modal .error-message { min-height: 18px; margin: 12px 0 0; color: var(--red); }

@media (max-width: 820px) {
  .topbar { grid-template-columns: minmax(0, 1fr) auto; }
  .dataset-nav { display: none; }
  .preview-shell { grid-template-columns: 190px minmax(0, 1fr); }
  .status span { display: none; }
  .sample-meta span:nth-child(n+3) { display: none; }
  .message-user, .message-system, .message-developer { width: 100%; margin-left: 0; }
}

@media (max-width: 560px) {
  .topbar { height: 56px; padding-inline: 10px; }
  .preview-shell { height: calc(100vh - 56px); display: flex; flex-direction: column; }
  .sample-sidebar { position: relative; height: 118px; flex: none; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar-heading { height: 34px; }
  .sample-list { display: flex; overflow-x: auto; overflow-y: hidden; padding: 6px 102px 6px 6px; }
  .sample-item { width: 142px; min-width: 142px; min-height: 70px; margin: 0 4px 0 0; padding: 7px 9px; }
  .sample-item small { display: none; }
  .load-more { position: absolute; right: 6px; bottom: 6px; z-index: 2; width: 90px; height: 70px; margin: 0; }
  .sample-toolbar { min-height: 48px; padding: 7px 10px; }
  .section-label, .sample-meta { display: none; }
  .conversation { padding: 10px 8px 60px; }
  .message { padding: 11px; }
  h1 { max-width: calc(100vw - 150px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
