:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --surface: #fffdf8;
  --surface-2: #f0eee7;
  --surface-3: #e8e4d8;
  --ink: #25231f;
  --muted: #69645b;
  --line: #d8d2c4;
  --accent: #2f6f59;
  --accent-2: #945f2f;
  --accent-3: #365f7e;
  --danger: #9f3d38;
  --ok: #2f6f59;
  --warn: #9b6a1f;
  --shadow: 0 14px 42px rgba(41, 36, 27, 0.12);
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  letter-spacing: 0;
}

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

button {
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(230px, 280px) minmax(0, 1fr) minmax(290px, 360px);
  height: 100vh;
  min-height: 720px;
  overflow: hidden;
}

.sidebar,
.inspector {
  background: var(--surface);
  border-color: var(--line);
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
}

.inspector {
  border-left: 1px solid var(--line);
  padding: 12px;
  overflow-y: auto;
}

.workspace {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  overflow: hidden;
}

.brand-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 18px 16px 10px;
}

.brand-row h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
}

.brand-row p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 12px 10px;
  padding: 0 10px;
  height: 38px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius);
}

.search-box:focus-within {
  border-color: var(--accent);
  background: #fff;
}

.search-box svg {
  width: 16px;
  height: 16px;
  color: var(--muted);
  flex: 0 0 auto;
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  min-width: 0;
}

.conversation-list {
  padding: 0 8px 8px;
  overflow-y: auto;
  flex: 1;
}

.conversation-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  width: 100%;
  padding: 10px;
  margin: 3px 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  border-radius: var(--radius);
  cursor: pointer;
}

.conversation-item:hover,
.conversation-item.active {
  background: var(--surface-2);
}

.conversation-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 650;
}

.conversation-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.sidebar-footer {
  border-top: 1px solid var(--line);
  padding: 12px;
}

.sidebar-footer .text-button {
  justify-content: flex-start;
  width: 100%;
}

.muted-line {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: rgba(255, 253, 248, 0.9);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.tab-group,
.target-strip {
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 3px;
  flex: 0 0 auto;
}

.tab-button,
.segment-button {
  min-height: 32px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
}

.tab-button.active,
.segment-button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.model-select-label {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 180px;
  flex: 1 1 auto;
  color: var(--muted);
}

.model-select-label select {
  min-width: 0;
}

select,
input,
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  outline: 0;
}

select,
input {
  height: 36px;
  padding: 0 10px;
}

textarea {
  width: 100%;
  padding: 10px;
  resize: vertical;
  line-height: 1.45;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 89, 0.12);
}

.view {
  display: none;
  min-height: 0;
  overflow: hidden;
}

.view.active {
  display: flex;
}

#chatView {
  flex-direction: column;
}

.diagnostic-banner {
  margin: 10px 14px 0;
  padding: 10px 12px;
  border: 1px solid rgba(155, 106, 31, 0.38);
  background: #fff7e8;
  color: #624113;
  border-radius: var(--radius);
  font-size: 13px;
}

.hidden {
  display: none !important;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px clamp(16px, 4vw, 56px);
}

.empty-chat {
  max-width: 660px;
  margin: 12vh auto 0;
  text-align: center;
  color: var(--muted);
}

.empty-chat h2 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 30px;
}

.message-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 820px);
  gap: 16px;
  align-items: start;
  margin: 0 auto 18px;
  max-width: 980px;
}

.message-role {
  color: var(--muted);
  font-size: 13px;
  padding-top: 9px;
  text-align: right;
}

.message-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}

.message-card.user {
  background: #f8fbf6;
  border-color: #cfdcc8;
}

.message-card.assistant {
  background: #fffdf8;
}

.message-card.error {
  border-color: rgba(159, 61, 56, 0.35);
  background: #fff3f2;
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}

.message-actions,
.context-actions {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  flex: 0 0 auto;
}

.mini-button {
  min-height: 26px;
  padding: 0 7px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}

.mini-button:hover {
  color: var(--ink);
  background: var(--surface-3);
}

.mini-button.danger {
  color: var(--danger);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.pill.ok {
  color: var(--ok);
  border-color: rgba(47, 111, 89, 0.25);
  background: rgba(47, 111, 89, 0.08);
}

.pill.warn {
  color: var(--warn);
  border-color: rgba(155, 106, 31, 0.28);
  background: rgba(155, 106, 31, 0.1);
}

.pill.danger {
  color: var(--danger);
  border-color: rgba(159, 61, 56, 0.28);
  background: rgba(159, 61, 56, 0.08);
}

.message-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.message-editor {
  display: grid;
  gap: 8px;
}

.message-editor textarea {
  min-height: 120px;
}

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

.composer {
  margin: 0 clamp(12px, 3vw, 40px) 16px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.composer-settings {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.composer-settings label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.composer-settings input[type="number"] {
  width: 82px;
  height: 30px;
}

.composer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: end;
}

.composer-row textarea {
  min-height: 70px;
  max-height: 260px;
  resize: vertical;
}

.icon-button,
.send-button,
.tool-button,
.primary-button,
.secondary-button,
.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 36px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}

.icon-button {
  width: 36px;
  background: var(--surface-2);
  color: var(--ink);
}

.send-button {
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: #fff;
}

.tool-button,
.secondary-button {
  padding: 0 12px;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
}

.primary-button {
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
}

.text-button {
  background: transparent;
  color: var(--accent-3);
  min-height: 30px;
  padding: 0 6px;
}

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

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

i[data-fallback] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 17px;
  min-height: 17px;
  font-style: normal;
  font-size: 11px;
  line-height: 1;
  font-weight: 700;
}

i[data-fallback]::before {
  content: attr(data-fallback);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}

.panel.tight {
  margin-bottom: 12px;
  padding: 12px;
}

.panel h2,
.panel h3 {
  margin: 0 0 12px;
}

.panel h2 {
  font-size: 16px;
}

.panel h3 {
  font-size: 13px;
  color: var(--muted);
}

.panel label {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
}

.toggle-line {
  display: flex !important;
  grid-template-columns: none !important;
  flex-direction: row;
  align-items: center;
  gap: 8px !important;
  color: var(--ink) !important;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  padding: 0;
}

.full-width {
  width: 100%;
  margin-bottom: 12px;
}

.context-stats {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.context-preview,
.report-preview,
.run-log {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
  background: #fbfaf7;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: auto;
  white-space: pre-wrap;
}

.context-preview {
  max-height: 260px;
  padding: 10px;
}

.context-list {
  display: grid;
  gap: 8px;
  white-space: normal;
  font-family: var(--sans);
}

.context-item {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 6px;
  padding: 8px;
}

.context-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.context-item-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.35;
  color: var(--ink);
}

.benchmark-grid,
.reports-grid {
  display: grid;
  gap: 14px;
  padding: 14px;
  width: 100%;
  overflow: hidden;
}

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

.reports-grid {
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
}

.grow-panel,
.report-preview-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

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

.field-grid label:first-child {
  grid-column: 1 / -1;
}

.list-header,
.progress-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
}

.check-list {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfaf7;
  max-height: 250px;
  overflow: auto;
  padding: 6px;
}

.check-list.compact {
  max-height: 180px;
}

.check-item {
  display: grid !important;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px !important;
  align-items: center;
  padding: 7px 6px;
  margin: 0 !important;
  color: var(--ink) !important;
  border-radius: 6px;
}

.check-item:hover {
  background: var(--surface-2);
}

.check-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.availability {
  color: var(--muted);
  font-size: 11px;
}

.button-row,
.button-column {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.button-column {
  flex-direction: column;
}

progress {
  width: 100%;
  height: 12px;
  accent-color: var(--accent);
}

.summary-table {
  margin: 12px 0;
  overflow: auto;
}

.summary-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.summary-table th,
.summary-table td {
  border-bottom: 1px solid var(--line);
  padding: 7px 8px;
  text-align: left;
  vertical-align: top;
}

.summary-table th {
  color: var(--muted);
  font-weight: 650;
}

.run-log {
  flex: 1;
  min-height: 220px;
  padding: 10px;
}

.report-list-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#reportRunSelect {
  width: 100%;
  min-height: 260px;
  flex: 1;
}

.report-preview {
  flex: 1;
  min-height: 0;
  padding: 14px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: #25231f;
  color: #fff;
  border-radius: 6px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  max-width: min(620px, calc(100vw - 32px));
  z-index: 30;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: minmax(210px, 250px) minmax(0, 1fr);
  }

  .inspector {
    display: none;
  }
}

@media (max-width: 840px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: 100vh;
  }

  .sidebar {
    display: none;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .model-select-label {
    grid-column: 1 / -1;
    flex-basis: 100%;
  }

  .benchmark-grid,
  .reports-grid {
    grid-template-columns: 1fr;
    overflow: auto;
  }

  .message-row {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .message-role {
    text-align: left;
    padding-top: 0;
  }

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