:root {
  color-scheme: light;
  --bg: #f8f3e7;
  --panel: #ffffff;
  --text: #201a15;
  --muted: #667085;
  --line: #ded6ca;
  --user: #8f1d1d;
  --agent: #f8f1e5;
  --accent: #b91c1c;
  --accent-2: #b0892f;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --shadow: 0 18px 45px rgba(64, 43, 24, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78) 0%, rgba(248, 243, 231, 0.92) 100%),
    radial-gradient(circle at top left, rgba(185, 28, 28, 0.14), transparent 32%),
    var(--bg);
  display: grid;
  place-items: center;
  padding: 24px;
}

.chat-shell {
  width: min(920px, 100%);
  height: min(760px, calc(100vh - 48px));
  min-height: 560px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

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

h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
  font-weight: 750;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 12px;
  box-shadow: 0 8px 18px rgba(143, 29, 29, 0.18);
}

.chat-status {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  overflow-wrap: anywhere;
}

.session-label {
  color: #344054;
}

.messages {
  padding: 22px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #fbfcfe;
}

.message {
  max-width: 82%;
  border-radius: 8px;
  padding: 13px 15px;
  line-height: 1.55;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.message.user {
  align-self: flex-end;
  color: #ffffff;
  background: var(--user);
}

.message.agent {
  align-self: flex-start;
  background: var(--agent);
  border: 1px solid #eadfcf;
}

.answer {
  white-space: pre-wrap;
}

.message.error {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: #fecdca;
  font-weight: 650;
}

.loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid #cbd5e1;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: 0 0 auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

details {
  margin-top: 12px;
  border-top: 1px solid #d8dee9;
  padding-top: 10px;
}

summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
}

.sources {
  margin: 10px 0 0;
  padding-left: 18px;
  color: #344054;
  font-size: 14px;
}

.sources li + li {
  margin-top: 8px;
}

.sources strong {
  color: #201a15;
}

.sources p {
  margin: 5px 0;
  white-space: pre-wrap;
}

.sources a {
  color: var(--accent);
  font-weight: 700;
}

.source-meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.chat-form {
  border-top: 1px solid var(--line);
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  background: var(--panel);
}

textarea {
  width: 100%;
  min-height: 48px;
  max-height: 150px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  font: inherit;
  line-height: 1.45;
  outline: none;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

button {
  min-width: 104px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  padding: 0 18px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.secondary-button {
  min-height: 40px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--line);
}

.secondary-button:hover {
  border-color: #aeb8c7;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logout-form {
  padding: 0;
  border: 0;
  display: block;
}

.auth-shell {
  width: min(420px, 100%);
}

.auth-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-logo {
  width: 58px;
  height: 58px;
  border-radius: 14px;
  box-shadow: 0 8px 18px rgba(143, 29, 29, 0.18);
  margin-bottom: 14px;
}

.auth-copy {
  color: var(--muted);
  margin: 8px 0 22px;
}

.auth-error {
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid #fecdca;
  border-radius: 8px;
  margin: 0 0 16px;
  padding: 11px 12px;
  font-weight: 650;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-form label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-size: 14px;
  font-weight: 650;
}

.auth-form input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  outline: none;
}

.auth-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.auth-form button {
  min-height: 44px;
  margin-top: 4px;
}

@media (max-width: 640px) {
  body {
    padding: 0;
  }

  .chat-shell {
    min-height: 100vh;
    height: 100vh;
    border: 0;
    border-radius: 0;
  }

  .chat-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .message {
    max-width: 94%;
  }

  .chat-form {
    grid-template-columns: 1fr;
  }

  button {
    min-height: 44px;
  }

  .header-actions,
  .header-actions button,
  .logout-form,
  .logout-form button {
    width: 100%;
  }

  .header-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .auth-shell {
    padding: 18px;
  }
}
