:root {
  color-scheme: light;
  --bg: #f5f7f3;
  --surface: #ffffff;
  --surface-2: #f0f4f8;
  --ink: #14213d;
  --muted: #647084;
  --line: #dbe3ea;
  --accent: #0f766e;
  --accent-2: #e2532f;
  --accent-3: #f5b841;
  --danger: #b42318;
  --ready: #13795b;
  --shadow: 0 18px 48px rgba(20, 33, 61, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.10), transparent 32%),
    linear-gradient(315deg, rgba(226, 83, 47, 0.10), transparent 28%),
    var(--bg);
  color: var(--ink);
}

button,
textarea,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 16px;
  align-items: start;
}

.topbar,
.composer,
.providers-panel,
.final-panel,
.runs-panel {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar {
  grid-column: 1 / -1;
  min-height: 88px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  border-radius: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background:
    linear-gradient(135deg, var(--ink), #1d4e89 54%, var(--accent));
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.8);
}

.brand-mark span {
  font-weight: 900;
  font-size: 1.35rem;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 2vw, 2.1rem);
  line-height: 1.05;
}

.brand p,
.panel-heading p,
.status-line,
.result-head p,
.provider-copy small,
.counter {
  color: var(--muted);
}

.status-line {
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
  white-space: nowrap;
}

.composer,
.providers-panel,
.final-panel,
.runs-panel {
  border-radius: 8px;
  padding: 16px;
}

.composer {
  display: grid;
  gap: 12px;
}

.control-row,
.action-row,
.panel-heading,
.result-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}

.segment {
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
}

.segment:last-child {
  border-right: 0;
}

.segment.is-active {
  background: var(--ink);
  color: #fff;
}

.depth-control {
  min-width: 170px;
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.depth-control input {
  accent-color: var(--accent);
}

.prompt-label {
  color: var(--ink);
  font-weight: 750;
}

textarea {
  width: 100%;
  min-height: 210px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--ink);
  background: #fbfcfd;
  outline: none;
  line-height: 1.45;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.primary-button,
.ghost-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.primary-button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.button-icon {
  font-weight: 900;
  transform: translateY(-1px);
}

.ghost-button {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.ghost-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.providers-panel {
  grid-column: 2;
  grid-row: 2;
}

.provider-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.client-provider-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.client-provider {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.client-provider-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.remove-provider-button {
  min-height: 34px;
}

.provider-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.provider-form-grid label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.provider-form-grid label:nth-child(4),
.provider-form-grid label:nth-child(6) {
  grid-column: 1 / -1;
}

.provider-form-grid input,
.provider-form-grid select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.provider-form-grid input:focus,
.provider-form-grid select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.provider-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-height: 370px;
  overflow: auto;
  padding-right: 4px;
}

.provider-option {
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.provider-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.provider-copy strong,
.provider-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.provider-status {
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--surface-2);
}

.provider-status.ready {
  color: var(--ready);
  background: rgba(19, 121, 91, 0.12);
}

.provider-status.missing {
  color: var(--danger);
  background: rgba(180, 35, 24, 0.10);
}

.answer-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 16px;
}

.final-panel,
.runs-panel {
  min-height: 420px;
}

.answer-text,
.result-card pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

.answer-text {
  margin: 16px 0 0;
  min-height: 318px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fbfcfd;
}

.model-results {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  max-height: 620px;
  overflow: auto;
  padding-right: 4px;
}

.result-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.result-head h3 {
  font-size: 1rem;
}

.result-head span {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.78rem;
  background: rgba(245, 184, 65, 0.18);
  color: #705100;
}

.result-card.failed .result-head span {
  background: rgba(180, 35, 24, 0.10);
  color: var(--danger);
}

.result-card pre {
  margin: 12px 0 0;
  color: #20314f;
}

.empty-state {
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.5);
}

@media (max-width: 980px) {
  .shell {
    padding: 14px;
  }

  .workspace,
  .answer-grid {
    grid-template-columns: 1fr;
  }

  .providers-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .topbar,
  .control-row,
  .action-row,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    min-height: auto;
  }

  .status-line,
  .primary-button,
  .ghost-button {
    width: 100%;
  }

  .provider-actions {
    width: 100%;
  }

  .segmented {
    width: 100%;
  }

  .depth-control {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }

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

  .segment:nth-child(2) {
    border-right: 0;
  }

  .segment:nth-child(1),
  .segment:nth-child(2) {
    border-bottom: 1px solid var(--line);
  }

  .provider-option {
    grid-template-columns: minmax(0, 1fr);
  }

  .client-provider-head,
  .provider-actions {
    align-items: stretch;
    flex-direction: column;
  }

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

  .provider-form-grid label:nth-child(4),
  .provider-form-grid label:nth-child(6) {
    grid-column: auto;
  }

  .provider-status {
    width: fit-content;
  }
}
