:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #0f172a;
  --text-muted: #475569;
  --border: #cbd5e1;
  --border-subtle: #e2e8f0;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #f0fdfa;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --warning-soft: #fffbeb;
  --warning-border: #fcd34d;
  --warning-text: #78350f;
  --radius: 8px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  display: flex;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 860px;
  height: 100vh;
  height: 100dvh;
  background: var(--surface);
  border-inline: 1px solid var(--border-subtle);
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface);
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius);
  background: var(--accent);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

h1 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.3;
}

.scope {
  max-width: 36rem;
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.chat {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1rem;
  min-height: 0;
  padding: 1.25rem;
  overflow-y: auto;
}

.message {
  max-width: 88%;
}

.message-user {
  align-self: flex-end;
  padding: 0.75rem 1rem;
  border: 1px solid #ccfbf1;
  border-radius: var(--radius);
  background: var(--accent-soft);
}

.message-assistant {
  align-self: flex-start;
  width: 100%;
  max-width: 100%;
  padding: 1rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--surface);
}

.message-welcome {
  background: var(--surface-muted);
}

.message-meta {
  margin: 0 0 0.375rem;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.message-text {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.citation {
  color: var(--accent);
  font-size: 0.75em;
  font-weight: 700;
  text-decoration: none;
  vertical-align: super;
}

.citation:hover {
  text-decoration: underline;
}

.refusal-label {
  display: inline-block;
  margin: 0 0 0.5rem;
  padding: 0.125rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.75rem;
}

.sources {
  margin-top: 0.875rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-subtle);
}

.sources-heading {
  margin: 0 0 0.5rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.source-list {
  display: grid;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.source-card {
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.source-label {
  margin: 0 0 0.125rem;
  color: var(--accent);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.source-title {
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 600;
}

.source-section {
  margin: 0.125rem 0 0.375rem;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.source-link {
  font-size: 0.875rem;
  font-weight: 600;
}

.disclaimer {
  margin-top: 0.875rem;
  padding: 0.75rem;
  border: 1px solid var(--warning-border);
  border-radius: var(--radius);
  background: var(--warning-soft);
  color: var(--warning-text);
  font-size: 0.875rem;
}

.disclaimer strong {
  display: block;
  margin-bottom: 0.125rem;
}

.quote-cta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-top: 0.875rem;
  padding: 0.75rem;
  border: 1px solid #99f6e4;
  border-radius: var(--radius);
  background: var(--accent-soft);
}

.quote-cta p {
  flex: 1 1 12rem;
  margin: 0;
  font-size: 0.875rem;
}

.quote-cta a {
  font-size: 0.875rem;
  font-weight: 600;
}

.button {
  min-height: 2.5rem;
  padding: 0.5rem 0.875rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
}

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

.button-primary {
  background: var(--accent);
  color: #ffffff;
}

.button-primary:hover:not(:disabled) {
  background: var(--accent-strong);
}

.button-secondary {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

.button-secondary:hover:not(:disabled) {
  background: var(--surface-muted);
}

.suggestions {
  padding: 0;
}

.suggestions-title {
  margin: 0 0 0.5rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.suggestion-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.suggestion {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
}

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

.composer {
  padding: 0.75rem 1.25rem 1rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--surface);
}

.composer-label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 600;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

#message-input {
  flex: 1;
  min-height: 2.75rem;
  max-height: 10rem;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  resize: none;
}

#message-input:focus-visible {
  border-color: var(--accent);
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

.composer-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.375rem;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.composer-hint {
  margin: 0;
}

.char-count {
  flex: none;
  font-variant-numeric: tabular-nums;
}

.message-typing {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.typing-dots {
  letter-spacing: 0.15em;
  animation: pulse 1.2s infinite ease-in-out;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.4;
  }

  50% {
    opacity: 1;
  }
}

.message-error {
  border-color: #fecaca;
  background: var(--danger-soft);
}

.error-title {
  margin: 0 0 0.25rem;
  color: var(--danger);
  font-weight: 700;
}

.message-error .button {
  margin-top: 0.625rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.quote-dialog {
  width: min(560px, calc(100% - 2rem));
  max-height: min(90dvh, 720px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.quote-dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
}

.dialog-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface);
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.125rem;
}

.icon-button {
  padding: 0.375rem;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

.icon-button:hover {
  background: var(--surface-muted);
}

.lead-form,
.lead-success {
  padding: 1.25rem;
}

.dialog-intro {
  margin: 0 0 1rem;
  color: var(--text-muted);
  font-size: 0.9375rem;
}

.field {
  margin-bottom: 0.875rem;
}

.field label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.field input,
.field textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

.field textarea {
  min-height: 5rem;
  resize: vertical;
}

.field input:focus-visible,
.field textarea:focus-visible {
  border-color: var(--accent);
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

.field input[aria-invalid="true"],
.field textarea[aria-invalid="true"] {
  border-color: var(--danger);
}

.field-checkbox {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem;
}

.field-checkbox input {
  flex: none;
  width: 1.125rem;
  height: 1.125rem;
  margin-top: 0.15rem;
}

.field-checkbox label {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 400;
}

.field-checkbox .field-error {
  flex-basis: 100%;
}

.field-error {
  margin: 0.25rem 0 0;
  color: var(--danger);
  font-size: 0.8125rem;
}

.form-error {
  margin: 0 0 0.875rem;
  padding: 0.625rem 0.75rem;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.875rem;
}

.honeypot {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.disclosure {
  margin: 1rem 0;
  padding: 0.75rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.disclosure a {
  font-weight: 600;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.lead-success h3 {
  margin: 0 0 0.5rem;
  font-size: 1.125rem;
}

.lead-success p {
  margin: 0 0 0.75rem;
}

.lead-success a {
  font-weight: 600;
}

@media (max-width: 600px) {
  .app-shell {
    border-inline: 0;
  }

  .app-header {
    flex-wrap: wrap;
    padding: 0.875rem 1rem;
  }

  .app-header .button {
    width: 100%;
  }

  .messages {
    padding: 1rem;
  }

  .composer {
    padding: 0.75rem 1rem 1rem;
  }

  .composer-row {
    flex-wrap: wrap;
  }

  .composer-row .button {
    width: 100%;
  }

  .message {
    max-width: 100%;
  }

  .quote-dialog {
    width: calc(100% - 1rem);
    max-height: calc(100dvh - 1rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
