:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #1b2431;
  --muted: #5f6b7a;
  --line: #dfe4ec;
  --brand: #0f5ba7;
  --brand-dark: #0b4480;
  --user: #e8f0fb;
  --error: #b3261e;
  --radius: 12px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--brand);
  color: #fff;
}

.brand { font-weight: 600; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }

.logo {
  width: 18px; height: 18px; border-radius: 50%;
  background: conic-gradient(#fff 0 25%, transparent 25% 50%, #fff 50% 75%, transparent 75%);
  display: inline-block;
}

.tag {
  font-size: 0.7rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.06em;
  background: rgba(255, 255, 255, 0.2); padding: 2px 8px; border-radius: 999px;
}

.user { display: flex; gap: 12px; align-items: center; font-size: 0.9rem; }

button.link {
  background: none; border: none; color: #fff; text-decoration: underline; cursor: pointer; font: inherit; padding: 0;
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  padding: 16px;
  min-height: 0;
}

.side {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}

.side h2 { margin: 0; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.documents { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.documents li { display: flex; flex-direction: column; gap: 2px; font-size: 0.92rem; }
.documents .meta { color: var(--muted); font-size: 0.8rem; }

.hint { color: var(--muted); font-size: 0.82rem; margin: 0; }

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

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

.message { max-width: 85%; padding: 12px 16px; border-radius: var(--radius); line-height: 1.5; }
.message.user { align-self: flex-end; background: var(--user); white-space: pre-wrap; }
.message.assistant { align-self: flex-start; background: #f8f9fb; border: 1px solid var(--line); }
.message.error .content { color: var(--error); }

.content > :first-child { margin-top: 0; }
.content > :last-child { margin-bottom: 0; }
.content table { border-collapse: collapse; margin: 8px 0; font-size: 0.92rem; }
.content th, .content td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.content code { background: #eef1f5; padding: 1px 4px; border-radius: 4px; }

.citations { display: flex; flex-wrap: wrap; gap: 6px; }
.citations:not(:empty) { margin-top: 10px; }
.chip {
  font-size: 0.78rem; background: #fff; border: 1px solid var(--brand); color: var(--brand-dark);
  padding: 1px 8px; border-radius: 999px; cursor: help;
}

.footer { color: var(--muted); font-size: 0.75rem; }
.footer:not(:empty) { margin-top: 8px; }

.composer { display: flex; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); }
.composer textarea {
  flex: 1; resize: vertical; font: inherit; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px;
}
.composer textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }

button {
  font: inherit; background: var(--brand); color: #fff; border: none; border-radius: 8px;
  padding: 10px 18px; cursor: pointer; font-weight: 600;
}
button:hover:not(:disabled) { background: var(--brand-dark); }
button:disabled { opacity: 0.6; cursor: wait; }
button.secondary { background: #fff; color: var(--brand); border: 1px solid var(--brand); margin-top: auto; }

.status { padding: 0 16px 10px; min-height: 1.4em; color: var(--muted); font-size: 0.85rem; }
.status.error { color: var(--error); }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .side { order: 2; }
  .message { max-width: 100%; }
}
