:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --panel: #ffffff;
  --ink: #18221f;
  --muted: #5d6b66;
  --line: #d9e0dc;
  --accent: #0f7b63;
  --accent-strong: #075340;
  --warn: #b45500;
  --soft: #e9f4ef;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  border-radius: 6px;
  padding: 0.65rem 0.9rem;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 1rem;
  height: 100vh;
  padding: 1rem;
}

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

.topbar,
.sources-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid var(--line);
}

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

h1 {
  font-size: 1.25rem;
}

h2 {
  font-size: 1.05rem;
}

#status {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.profile-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  padding: 1rem;
  border-bottom: 1px solid var(--line);
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.75rem;
  color: var(--ink);
  background: white;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.message {
  max-width: 78%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.85rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

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

.message.loading {
  color: var(--muted);
}

.citation-list {
  margin-top: 0.75rem;
  display: grid;
  gap: 0.45rem;
}

.citation {
  border-top: 1px solid var(--line);
  padding-top: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  padding: 1rem;
  border-top: 1px solid var(--line);
}

.sources-panel {
  overflow: hidden;
}

.sources {
  overflow: auto;
  padding: 1rem;
  display: grid;
  gap: 0.75rem;
}

.source-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.85rem;
  background: #fff;
}

.source-card h3 {
  font-size: 0.98rem;
  margin-bottom: 0.35rem;
}

.source-card p,
.source-meta {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.source-card button {
  margin-top: 0.7rem;
  background: var(--soft);
  border-color: var(--line);
  color: var(--accent-strong);
}

.error {
  color: var(--warn);
}

dialog {
  width: min(900px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid var(--line);
}

#sourceMeta {
  padding: 1rem 1rem 0;
}

pre {
  margin: 0;
  padding: 1rem;
  white-space: pre-wrap;
  line-height: 1.45;
  font-family: Arial, Helvetica, sans-serif;
  overflow: auto;
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
  }

  .chat-panel {
    min-height: 75vh;
  }

  .profile-row {
    grid-template-columns: 1fr;
  }

  .message {
    max-width: 92%;
  }
}
