:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f4f7;
  --ink: #172026;
  --muted: #65727d;
  --line: #dce3e8;
  --accent: #107c5e;
  --accent-2: #0e6f93;
  --danger: #b42318;
  --shadow: 0 14px 40px rgba(23, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

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

button {
  min-height: 42px;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  padding: 0 16px;
  font-weight: 650;
  cursor: pointer;
}

button:hover {
  background: #0d6d53;
}

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

button.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

button.secondary:hover {
  background: var(--panel-2);
}

.button-link {
  display: inline-grid;
  min-height: 42px;
  place-items: center;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  padding: 0 16px;
  font-weight: 650;
  text-decoration: none;
}

.button-link:hover {
  background: #0d6d53;
}

.button-link.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.button-link.secondary:hover {
  background: var(--panel-2);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(220px, 290px) minmax(320px, 1fr) minmax(340px, 430px);
  min-width: 920px;
  min-height: 100vh;
}

.context-panel {
  display: flex;
  flex-direction: column;
  gap: 22px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 24px;
}

.brand-block {
  display: flex;
  gap: 14px;
  align-items: center;
}

.mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.2;
}

h2 {
  font-size: 21px;
  line-height: 1.25;
}

p,
#statusText,
#requestInfo {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.context-form {
  display: grid;
  gap: 14px;
}

.runtime-card {
  display: grid;
  gap: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 14px;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-title h2 {
  font-size: 15px;
}

.section-title span {
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.section-title span.ready {
  background: rgba(16, 124, 94, 0.12);
  color: var(--accent);
}

.runtime-grid {
  display: grid;
  gap: 11px;
}

#runtimeInfo {
  min-height: 18px;
}

label {
  display: grid;
  gap: 7px;
  color: #33424d;
  font-size: 13px;
  font-weight: 650;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(14, 111, 147, 0.14);
}

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

summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
}

details label {
  margin-top: 12px;
}

.quick-actions {
  display: grid;
  gap: 10px;
  margin-top: auto;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  padding: 24px;
}

.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 20px;
}

.health-pill {
  min-width: 94px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 7px 11px;
  text-align: center;
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.health-pill.online {
  border-color: rgba(16, 124, 94, 0.25);
  background: rgba(16, 124, 94, 0.1);
  color: var(--accent);
}

.health-pill.error {
  border-color: rgba(180, 35, 24, 0.25);
  background: rgba(180, 35, 24, 0.08);
  color: var(--danger);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: 24px 4px;
}

.empty-state {
  max-width: 620px;
  color: var(--muted);
  line-height: 1.55;
}

.message {
  display: grid;
  gap: 6px;
  max-width: min(760px, 88%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 13px 15px;
  box-shadow: var(--shadow);
}

.message.user {
  align-self: flex-end;
  border-color: rgba(14, 111, 147, 0.22);
  background: #eef7fa;
}

.message.assistant {
  align-self: flex-start;
}

.message.error {
  border-color: rgba(180, 35, 24, 0.22);
  background: #fff4f2;
}

.message-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.message-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.5;
}

.composer {
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.composer textarea {
  min-height: 84px;
  max-height: 220px;
  background: #fff;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-top: 12px;
}

.trace-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  max-height: 100vh;
  border-left: 1px solid var(--line);
  background: #fbfcfd;
  padding: 24px 20px;
}

.trace-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
}

.trace-header h2 {
  font-size: 18px;
}

.trace-header button {
  min-height: 36px;
  padding: 0 12px;
}

.side-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}

.tab-button {
  min-height: 34px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  padding: 0 10px;
}

.tab-button:hover,
.tab-button.active {
  border-color: rgba(16, 124, 94, 0.26);
  background: rgba(16, 124, 94, 0.1);
  color: var(--accent);
}

.hidden {
  display: none !important;
}

.trace-events {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 18px 2px;
}

.trace-event {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.trace-event.agent-production {
  border-left-color: var(--accent);
}

.trace-event.agent-query {
  border-left-color: var(--accent-2);
}

.trace-event h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.3;
}

.trace-meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.trace-event pre {
  max-height: 260px;
  overflow: auto;
  margin: 0;
  border-radius: 7px;
  background: #f6f7f9;
  color: #25323b;
  padding: 10px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  line-height: 1.45;
}

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

.learning-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
}

.learning-toolbar button {
  min-height: 34px;
  padding: 0 12px;
}

.learning-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 2px 2px 18px;
}

.learning-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent-2);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.learning-card.approved {
  border-left-color: var(--accent);
}

.learning-card.rejected {
  border-left-color: var(--danger);
}

.learning-card h3 {
  margin: 0;
  font-size: 14px;
  line-height: 1.3;
}

.learning-meta,
.learning-evidence {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.learning-details {
  display: grid;
  gap: 6px;
  color: #25323b;
  font-size: 13px;
  line-height: 1.45;
}

.learning-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.learning-actions button {
  min-height: 34px;
  padding: 0 12px;
}

.learning-actions .danger {
  border: 1px solid rgba(180, 35, 24, 0.25);
  background: #fff;
  color: var(--danger);
}

.learning-actions .danger:hover {
  background: #fff4f2;
}

.logs-page {
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.logs-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.logs-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 14px 20px;
}

.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.logs-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.toggle-row {
  display: flex;
  width: auto;
  align-items: center;
  grid-template-columns: auto 1fr;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.toggle-row input {
  width: auto;
}

.logs-filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
  padding: 12px 14px;
}

.logs-filters label {
  gap: 5px;
  font-size: 12px;
}

.logs-filters input,
.logs-filters select {
  padding: 9px 10px;
}

.logs-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.runs-list-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

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

.panel-title h2 {
  font-size: 17px;
}

.panel-title span {
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.runs-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding: 12px;
}

.run-card {
  display: grid;
  height: auto;
  min-height: 96px;
  gap: 6px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  background: #fff;
  color: var(--ink);
  padding: 10px;
  text-align: left;
}

.run-card:hover,
.run-card.active {
  border-color: rgba(16, 124, 94, 0.3);
  border-left-color: var(--accent);
  background: rgba(16, 124, 94, 0.07);
}

.run-card.failed {
  border-left-color: var(--danger);
}

.run-card.running {
  border-left-color: var(--accent-2);
}

.run-card-top,
.run-meta-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.run-card-top strong {
  color: var(--ink);
  text-transform: uppercase;
}

.run-question {
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.run-meta-line {
  justify-content: flex-start;
  flex-wrap: wrap;
  line-height: 1.45;
}

.run-mini-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.run-mini-metrics span {
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 4px 7px;
  font-size: 11px;
  font-weight: 800;
}

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

.run-header-detail {
  display: grid;
  gap: 10px;
  max-height: 31vh;
  overflow-y: auto;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fbfcfd 0%, #f6f8fa 100%);
  padding: 12px 16px;
}

.run-header-detail h2 {
  max-width: 980px;
  overflow-wrap: anywhere;
}

.run-facts {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.run-facts span,
.status-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 750;
}

.run-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 8px;
}

.summary-card {
  position: relative;
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  background: #fff;
  padding: 9px 12px;
}

.summary-card:nth-child(1) {
  border-left-color: var(--accent);
}

.summary-card:nth-child(2) {
  border-left-color: #7357c8;
}

.summary-card:nth-child(3) {
  border-left-color: var(--accent-2);
}

.summary-card:nth-child(4) {
  border-left-color: var(--danger);
}

.summary-card span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.summary-card strong {
  color: var(--ink);
  font-size: 22px;
  line-height: 1.1;
}

.summary-card small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.metrics-collapse {
  border-top: 0;
  padding-top: 0;
}

.metrics-collapse summary {
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 750;
}

.metrics-collapse-content {
  display: grid;
  gap: 8px;
  padding-top: 8px;
}

.summary-card.danger {
  border-color: rgba(180, 35, 24, 0.24);
  border-left-color: var(--danger);
  background: #fff7f5;
}

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

.metrics-panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.metrics-panel-heading div {
  display: grid;
  gap: 2px;
}

.metrics-panel-heading span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.metrics-panel-heading strong {
  color: var(--ink);
  font-size: 17px;
  line-height: 1.2;
}

.metrics-panel-heading small {
  color: var(--muted);
  font-size: 12px;
}

.token-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(100px, 1fr));
  gap: 8px;
}

.token-grid span {
  display: grid;
  gap: 4px;
  border-radius: 7px;
  background: #f6f8fa;
  padding: 8px;
}

.token-grid small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.token-grid strong {
  color: var(--ink);
  font-size: 15px;
}

.breakdown-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px 12px;
}

.breakdown-row::before {
  content: "Agentes";
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.breakdown-row.tools::before {
  content: "Ferramentas";
}

.breakdown-row span {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f6f8fa;
  color: var(--muted);
  padding: 9px 10px;
  font-size: 12px;
  line-height: 1.35;
}

.breakdown-row strong {
  display: block;
  color: var(--ink);
  margin-bottom: 2px;
}

.status-badge.completed {
  border-color: rgba(16, 124, 94, 0.25);
  background: rgba(16, 124, 94, 0.1);
  color: var(--accent);
}

.status-badge.failed {
  border-color: rgba(180, 35, 24, 0.25);
  background: rgba(180, 35, 24, 0.08);
  color: var(--danger);
}

.status-badge.running {
  border-color: rgba(14, 111, 147, 0.25);
  background: rgba(14, 111, 147, 0.1);
  color: var(--accent-2);
}

.run-timeline {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 12px 16px 20px;
}

.log-event {
  position: relative;
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
}

.log-event.production {
  border-left-color: var(--accent);
}

.log-event.query {
  border-left-color: var(--accent-2);
}

.log-event.error,
.log-event.tool_error,
.log-event.agent_error {
  border-left-color: var(--danger);
}

.log-event.type-ia {
  border-left-color: #7357c8;
}

.log-event.type-ferramenta,
.log-event.type-sql {
  border-left-color: var(--accent-2);
}

.log-event.type-agente {
  border-left-color: var(--accent);
}

.log-event.type-erro {
  border-left-color: var(--danger);
}

.log-event-meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.log-event h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.event-badge {
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.event-badge.type-ia {
  border-color: rgba(115, 87, 200, 0.25);
  background: rgba(115, 87, 200, 0.1);
  color: #6046b0;
}

.event-badge.type-ferramenta,
.event-badge.type-sql {
  border-color: rgba(14, 111, 147, 0.24);
  background: rgba(14, 111, 147, 0.1);
  color: var(--accent-2);
}

.event-badge.type-agente {
  border-color: rgba(16, 124, 94, 0.24);
  background: rgba(16, 124, 94, 0.1);
  color: var(--accent);
}

.event-badge.type-erro {
  border-color: rgba(180, 35, 24, 0.25);
  background: rgba(180, 35, 24, 0.08);
  color: var(--danger);
}

.event-details {
  border-top: 0;
  padding-top: 0;
}

.event-details summary {
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 750;
}

.log-event pre {
  max-height: 420px;
  overflow: auto;
  margin: 0;
  border-radius: 7px;
  background: #f6f7f9;
  color: #25323b;
  padding: 11px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .context-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-panel {
    min-height: 70vh;
    padding: 22px;
  }

  .trace-panel {
    padding: 22px;
  }

  .chat-header {
    align-items: stretch;
    flex-direction: column;
  }

  .health-pill {
    width: fit-content;
  }

  .message {
    max-width: 100%;
  }

  .logs-topbar,
  .logs-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .logs-filters,
  .logs-grid {
    grid-template-columns: 1fr;
  }

  .run-summary-grid {
    grid-template-columns: 1fr 1fr;
  }

  .runs-list-panel {
    max-height: 42vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
