* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #0f1419;
  color: #e6edf3;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  gap: 12px;
}
.brand { font-weight: 700; font-size: 16px; }
.brand .tag {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  font-size: 11px; border-radius: 4px; background: #3a2a00; color: #f6c343; border: 1px solid #5a4300;
}
.session { display: flex; align-items: center; gap: 8px; }
.session label { font-size: 12px; color: #9aa4af; }
.session input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: #0d1117;
  color: #e6edf3;
  border: 1px solid #30363d;
  padding: 4px 6px;
  border-radius: 4px;
  width: 220px;
}

.btn-secondary {
  background: #21262d;
  color: #e6edf3;
  border: 1px solid #30363d;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.btn-secondary:hover { background: #30363d; }

.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 12px 16px 0;
  min-height: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  border-radius: 8px;
  padding: 10px 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
  border: 1px solid #30363d;
  background: #161b22;
}
.msg.user {
  align-self: flex-end;
  max-width: 75%;
  background: #1f3a5f;
  border-color: #2f5a90;
}
.msg.assistant {
  align-self: flex-start;
  max-width: 90%;
  background: #161b22;
}
.msg.error {
  align-self: flex-start;
  max-width: 95%;
  background: #2d0f0f;
  border-color: #8b1a1a;
  color: #ffb4b4;
}
.msg .role {
  font-size: 11px;
  color: #9aa4af;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.msg .answer-text {
  font-size: 14px;
  line-height: 1.45;
}

.table-wrap {
  margin-top: 8px;
  overflow-x: auto;
  border: 1px solid #30363d;
  border-radius: 6px;
  background: #0d1117;
}
table.data {
  border-collapse: collapse;
  font-size: 12px;
  width: 100%;
  min-width: 600px;
}
table.data th, table.data td {
  padding: 6px 10px;
  border-bottom: 1px solid #21262d;
  text-align: left;
  vertical-align: top;
}
table.data th {
  background: #161b22;
  color: #9aa4af;
  font-weight: 600;
  position: sticky;
  top: 0;
}
table.data tr:hover td { background: #131a23; }

.chart-wrap {
  margin-top: 8px;
  padding: 10px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
}

details.debug {
  margin-top: 8px;
  font-size: 12px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 6px 8px;
}
details.debug summary {
  cursor: pointer;
  color: #9aa4af;
  user-select: none;
}
details.debug pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #010409;
  border: 1px solid #30363d;
  padding: 8px;
  border-radius: 4px;
  margin: 6px 0;
  font-size: 11px;
  max-height: 320px;
  overflow: auto;
}
details.debug .kv {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 4px 8px;
  margin-top: 6px;
}
details.debug .kv .k { color: #9aa4af; }
details.debug .kv .v { color: #e6edf3; word-break: break-all; }

.composer {
  display: flex;
  gap: 8px;
  padding: 10px 0 16px;
  border-top: 1px solid #30363d;
  margin-top: 8px;
}
.composer textarea {
  flex: 1;
  background: #0d1117;
  color: #e6edf3;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
  resize: vertical;
  min-height: 44px;
  max-height: 160px;
  font-family: inherit;
}
.composer button {
  background: #238636;
  color: #fff;
  border: 1px solid #2ea043;
  border-radius: 6px;
  padding: 0 16px;
  font-size: 14px;
  cursor: pointer;
}
.composer button:hover { background: #2ea043; }
.composer button:disabled { opacity: 0.6; cursor: not-allowed; }

.footer {
  display: flex;
  justify-content: space-between;
  padding: 6px 16px;
  font-size: 11px;
  background: #161b22;
  border-top: 1px solid #30363d;
  color: #9aa4af;
}
.led {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 4px;
}
.led-on { background: #3fb950; box-shadow: 0 0 6px #3fb950; }
.led-off { background: #f85149; box-shadow: 0 0 6px #f85149; }
.led-warn { background: #d29922; }
