:root {
  --bg: #0f1420;
  --panel: #161d2c;
  --panel-soft: #1d2637;
  --border: #27324a;
  --text: #e8edf7;
  --text-muted: #96a3bd;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.14);
  --good: #35c98a;
  --warn: #f0b429;
  --bad: #ef6461;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 15% -10%, #1b2740 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  max-width: 1240px;
  height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.chat,
.inspector {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

.chat__identity {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat__avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.chat__header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.chat__subtitle {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 12px;
}

.chat__meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.pill--muted {
  background: var(--panel-soft);
  color: var(--text-muted);
}

.pill--ok {
  background: rgba(53, 201, 138, 0.16);
  color: var(--good);
}

.pill--bad {
  background: rgba(239, 100, 97, 0.16);
  color: var(--bad);
}

.ghost-button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
}

.ghost-button:hover {
  color: var(--text);
  border-color: var(--accent);
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  max-width: 78%;
  padding: 11px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message--user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message--bot {
  align-self: flex-start;
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message--error {
  align-self: flex-start;
  background: rgba(239, 100, 97, 0.12);
  border: 1px solid rgba(239, 100, 97, 0.4);
  color: #ffd9d8;
}

.message code {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(79, 140, 255, 0.16);
  font-size: 0.92em;
}

.message--typing {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding-top: 14px;
  padding-bottom: 14px;
}

.loader {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.loader span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: loader-bounce 0.9s infinite ease-in-out;
}

.loader span:nth-child(2) {
  animation-delay: 0.15s;
}

.loader span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes loader-bounce {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 18px 12px;
}

.suggestion {
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  text-align: left;
}

.suggestion:hover {
  border-color: var(--accent);
}

.composer {
  display: flex;
  gap: 10px;
  padding: 14px 18px 16px;
  border-top: 1px solid var(--border);
}

.composer__input {
  flex: 1;
  max-height: 140px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-soft);
  color: var(--text);
  font: inherit;
  resize: none;
}

.composer__input:focus {
  outline: none;
  border-color: var(--accent);
}

.send-button {
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.send-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.inspector__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.inspector__header h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sources {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.source {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-soft);
  overflow: hidden;
}

.source__summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
}

.source__summary::-webkit-details-marker {
  display: none;
}

.source__title {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source__kind {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.source__score {
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score--high {
  color: var(--good);
}

.score--mid {
  color: var(--warn);
}

.score--low {
  color: var(--bad);
}

.source__text {
  margin: 0;
  padding: 0 12px 12px;
  color: var(--text-muted);
  font-size: 12.5px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.empty {
  color: var(--text-muted);
  font-size: 13px;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .chat {
    min-height: 70vh;
  }

  .inspector {
    max-height: 50vh;
  }
}
