:root {
  color-scheme: light;
  --bg: #f7f6f1;
  --surface: #ffffff;
  --surface-soft: #f0f3f1;
  --ink: #151716;
  --muted: #68706c;
  --line: #d9ddd8;
  --accent: #126b58;
  --accent-dark: #0a4236;
  --danger: #9b2c2c;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  padding: 0.75rem 1rem;
}

button:hover {
  background: var(--accent-dark);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0.78rem 0.85rem;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 0.92rem;
  line-height: 1.55;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 64px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 246, 241, 0.92);
  backdrop-filter: blur(14px);
  padding: 0 2rem;
}

.brand {
  font-size: 1.05rem;
  font-weight: 800;
}

.nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.nav a:hover,
.secondary-link:hover,
.link-button:hover {
  color: var(--accent);
}

.guest {
  color: var(--ink);
  font-weight: 700;
}

.link-button {
  background: transparent;
  color: var(--muted);
  padding: 0;
}

.link-button:hover {
  background: transparent;
}

.main-shell {
  width: min(1280px, calc(100% - 2rem));
  margin: 2rem auto 4rem;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.login-panel,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 2rem;
  padding: 2rem;
}

.panel {
  padding: 1.25rem;
}

.workspace,
.chat-layout,
.tests-layout {
  display: grid;
  align-items: start;
  gap: 1rem;
}

.workspace {
  grid-template-columns: minmax(0, 1fr) 420px;
}

.chat-layout {
  grid-template-columns: minmax(0, 1fr) 340px;
}

.tests-layout {
  grid-template-columns: 430px minmax(0, 1fr);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.section-heading.compact {
  margin-bottom: 0.75rem;
}

.section-heading h1,
.section-heading h2,
.login-panel h1 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1.05;
}

.section-heading h1,
.login-panel h1 {
  font-size: clamp(2rem, 4vw, 4rem);
}

.section-heading h2 {
  font-size: 1.05rem;
}

.eyebrow {
  margin: 0 0 0.45rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.muted,
.empty {
  color: var(--muted);
}

.empty {
  margin: 0;
}

.secondary-link {
  color: var(--muted);
  font-weight: 800;
}

.stack {
  display: grid;
  gap: 1rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.form-grid.tight {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.full {
  grid-column: 1 / -1;
}

.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.list {
  display: grid;
  gap: 0.3rem;
}

.list-row {
  display: grid;
  gap: 0.3rem;
  border-radius: 8px;
  padding: 0.75rem;
}

.list-row:hover {
  background: var(--surface-soft);
}

.list-row span,
.result-row small,
.message-meta {
  color: var(--muted);
  font-size: 0.84rem;
}

.messages {
  display: grid;
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.message {
  display: grid;
  gap: 0.55rem;
  border-left: 3px solid var(--line);
  background: #fbfbf8;
  padding: 0.85rem 1rem;
}

.message.user {
  border-left-color: #6e7781;
}

.message.assistant {
  border-left-color: var(--accent);
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.composer {
  display: grid;
  gap: 0.8rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

.context-panel {
  position: sticky;
  top: 84px;
}

.context-panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.details {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 0.55rem;
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
}

.details dt {
  color: var(--muted);
}

.details dd {
  margin: 0;
  word-break: break-word;
}

.system-prompt {
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 0.85rem;
}

.model-picker {
  display: grid;
  gap: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  padding: 0.8rem;
}

.model-picker legend {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  padding: 0 0.35rem;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--ink);
  font-weight: 650;
}

.check-row input {
  width: auto;
}

.result-list {
  display: grid;
  gap: 0.55rem;
}

.result-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.result-row summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  cursor: pointer;
  padding: 0.8rem 1rem;
}

.result-row summary span:first-child {
  display: grid;
  gap: 0.2rem;
}

.metric {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.86rem;
}

.metric.error {
  color: var(--danger);
}

.result-body {
  display: grid;
  gap: 0.7rem;
  border-top: 1px solid var(--line);
  padding: 1rem;
}

.result-body h3 {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
}

.flash {
  margin-bottom: 1rem;
  border-radius: 8px;
  padding: 0.85rem 1rem;
  font-weight: 700;
}

.flash-error {
  border: 1px solid #e2b0b0;
  background: #fff0f0;
  color: var(--danger);
}

.flash-notice {
  border: 1px solid #9ed2c6;
  background: #edf8f5;
  color: var(--accent-dark);
}

@media (max-width: 980px) {
  .workspace,
  .chat-layout,
  .tests-layout {
    grid-template-columns: 1fr;
  }

  .context-panel {
    position: static;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .topbar {
    align-items: start;
    flex-direction: column;
    padding: 1rem;
  }

  .nav {
    flex-wrap: wrap;
  }

  .main-shell {
    width: min(100% - 1rem, 1280px);
    margin-top: 0.5rem;
  }

  .panel,
  .login-panel {
    padding: 1rem;
  }

  .section-heading,
  .actions,
  .result-row summary {
    align-items: stretch;
    flex-direction: column;
  }
}
