:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --line: #dfded8;
  --text: #20201d;
  --muted: #6f6d66;
  --accent: #1f6f5b;
  --accent-dark: #185746;
  --user: #e7f1ed;
  --assistant: #ffffff;
  --shadow: 0 12px 40px rgba(30, 30, 20, 0.08);
}

* {
  box-sizing: border-box;
}

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

.app {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 22px;
  background: #fbfbf9;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  color: white;
  background: var(--accent);
  font-weight: 700;
}

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

p {
  margin: 0;
}

mark {
  border-radius: 4px;
  background: #ffe86b;
  color: inherit;
  padding: 0 2px;
}

#status {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.filters {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

select,
textarea,
button {
  font: inherit;
}

select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  padding: 0 10px;
}

.chat-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 100vh;
}

.messages {
  overflow: auto;
  padding: 28px min(5vw, 70px);
}

.message {
  display: flex;
  margin: 0 auto 18px;
  max-width: 980px;
}

.message.user {
  justify-content: flex-end;
}

.bubble {
  max-width: min(760px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--assistant);
  box-shadow: var(--shadow);
  padding: 16px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.user .bubble {
  background: var(--user);
  box-shadow: none;
}

.sources {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.warning {
  margin-bottom: 12px;
  border: 1px solid #e4c77a;
  border-radius: 8px;
  background: #fff8df;
  color: #5b4514;
  padding: 10px 12px;
  font-size: 14px;
  white-space: normal;
}

.source {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfbf9;
  white-space: normal;
}

.source-header {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
}

.tag {
  border-radius: 999px;
  background: #ecebe6;
  color: #4f4d46;
  padding: 3px 8px;
}

.source-title {
  font-weight: 650;
}

a.source-title {
  color: inherit;
  text-decoration: none;
}

a.source-title:hover {
  text-decoration: underline;
}

.source-publisher {
  display: inline-block;
  margin: 0 6px 0 2px;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 2px 7px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.source-text {
  color: #35342f;
  font-size: 14px;
  line-height: 1.5;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 18px min(5vw, 70px);
  border-top: 1px solid var(--line);
  background: rgba(251, 251, 249, 0.94);
}

textarea {
  width: 100%;
  max-height: 160px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  outline: none;
  background: white;
  color: var(--text);
}

textarea:focus {
  border-color: var(--accent);
}

button {
  min-width: 86px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 650;
  cursor: pointer;
}

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

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

@media (max-width: 820px) {
  .app {
    grid-template-columns: 1fr;
  }

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

  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chat-panel {
    min-height: calc(100vh - 230px);
  }
}

@media (max-width: 520px) {
  .filters,
  .composer {
    grid-template-columns: 1fr;
  }

  button {
    min-height: 42px;
  }
}
