:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #d8dee8;
  --soft: #eef2f7;
  --accent: #126a72;
  --accent-dark: #0b4e55;
  --indigo: #334eac;
  --warning: #9d6216;
  --danger: #b42318;
  --ok: #0f766e;
  --shadow: 0 10px 28px rgba(23, 32, 51, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

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

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

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

h1 {
  font-size: 21px;
  line-height: 1.15;
  margin-bottom: 3px;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
  margin-bottom: 0;
}

h3 {
  font-size: 15px;
  margin-bottom: 8px;
}

.subtle {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 0;
}

.top-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button,
.link-button {
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

button:hover,
.link-button:hover {
  border-color: #9aa6b8;
}

button.primary,
.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.nav-button.is-active {
  background: #e6f3f3;
  border-color: #9ccfd0;
  color: var(--accent-dark);
}

.app-shell {
  padding: 24px 28px 40px;
  max-width: 1480px;
  margin: 0 auto;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.two {
  grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
}

.lower {
  margin-top: 18px;
}

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

.panel-header {
  min-height: 54px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.status-stack {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.status.ok {
  color: var(--ok);
  border-color: #9bd6cc;
  background: #eefbf8;
}

.status.warn {
  color: var(--warning);
  border-color: #e5c188;
  background: #fff8ed;
}

.task-card {
  margin: 16px;
  padding: 16px;
  background: linear-gradient(135deg, #eef7f6, #f4f6ff);
  border: 1px solid #d5e3ef;
  border-radius: 8px;
}

.task-card p,
.task-card li {
  font-size: 14px;
  line-height: 1.5;
}

.compact-grid {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--text);
  background: #fff;
  padding: 9px 10px;
  min-height: 38px;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

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

.chat-form {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.form-actions,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.response-box {
  min-height: 190px;
  padding: 16px;
  line-height: 1.55;
  font-size: 14px;
}

.response-box strong {
  color: var(--accent-dark);
}

.source-list {
  padding: 12px 16px 16px;
  display: grid;
  gap: 10px;
  min-height: 170px;
}

.source-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 11px;
  background: #fcfdff;
}

.source-item button {
  margin-top: 8px;
}

.trace-preview {
  margin: 0;
  padding: 16px;
  min-height: 240px;
  overflow: auto;
  max-height: 470px;
  background: #101828;
  color: #e4e7ec;
  border-radius: 0 0 8px 8px;
  font-size: 12px;
  line-height: 1.5;
}

.summary-grid,
.instrument-grid {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

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

.metric b {
  display: block;
  font-size: 22px;
  color: var(--indigo);
}

.table-wrap {
  overflow: auto;
  max-height: 500px;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 760px;
  font-size: 13px;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #f1f4f9;
  color: #344054;
  z-index: 1;
}

td code {
  color: var(--accent-dark);
  font-size: 12px;
}

@media (max-width: 920px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
    padding: 16px;
  }

  .app-shell {
    padding: 16px;
  }

  .grid.two,
  .compact-grid,
  .summary-grid,
  .instrument-grid {
    grid-template-columns: 1fr;
  }

  table {
    min-width: 620px;
  }
}
