:root {
  --bg: #eef2f5;
  --surface: #ffffff;
  --surface-alt: #f7f9fb;
  --surface-soft: #f3f6f9;
  --border: #d7dfe8;
  --text: #132130;
  --text-muted: #5e7286;
  --accent: #0b8f5d;
  --accent-soft: #e9fff4;
  --accent-hover: rgba(11, 143, 93, 0.08);
  --shadow: 0 18px 42px rgba(19, 33, 48, 0.08);
  --font-sans: "Inter", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
}

body {
  padding: 18px;
}

body[data-surface="sheet"] {
  padding: 0;
  background: var(--surface);
}

.app-shell {
  min-height: calc(100dvh - 36px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

body[data-surface="sheet"] .app-shell {
  min-height: 100dvh;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(circle at top right, color-mix(in srgb, var(--accent-soft) 72%, transparent 28%), transparent 44%),
    linear-gradient(180deg, color-mix(in srgb, var(--surface-soft) 84%, white 16%) 0%, var(--surface) 100%);
}

.app-header-main {
  display: grid;
  gap: 8px;
}

.app-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.app-header-actions {
  display: grid;
  justify-items: end;
  gap: 10px;
  min-width: 200px;
}

.eyebrow,
.section-label,
.status-line,
.source-label {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}

.app-header h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.app-summary,
.app-boundary,
.trust-note,
.composer-help {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}

.app-summary {
  max-width: 68ch;
}

.app-boundary {
  max-width: 68ch;
}

.starter-panel {
  display: grid;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-soft) 64%, white 36%);
}

.message-log {
  min-height: 0;
  padding: 20px;
  overflow: auto;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface-soft) 56%, white 44%) 0%, var(--surface) 120px);
  display: grid;
  align-content: start;
  gap: 18px;
}

.message-log[hidden] {
  display: none;
}

.message {
  display: grid;
  gap: 8px;
}

.message-user {
  justify-items: end;
}

.message-assistant {
  justify-items: start;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  max-width: min(100%, 56rem);
}

.message-role {
  margin: 0;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
}

.message-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.bubble {
  max-width: min(100%, 56rem);
  padding: 14px 16px;
  border-radius: 18px;
  line-height: 1.6;
  white-space: pre-wrap;
  border: 1px solid var(--border);
}

.message-user .bubble {
  max-width: min(82%, 44rem);
  background: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 72%, black 28%);
  color: #fff;
}

.message-assistant .bubble {
  background: var(--surface);
}

.source-block {
  display: grid;
  gap: 8px;
  max-width: min(100%, 56rem);
}

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

.source-item {
  display: block;
}

.source-chip {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
}

.source-chip:hover {
  background: var(--accent-hover);
}

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

.source-meta {
  color: var(--text-muted);
  font-size: 12px;
}

.followups {
  display: grid;
  gap: 10px;
  padding: 0;
}

.followups[hidden] {
  display: none;
}

.followups {
  padding: 14px 20px 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.example-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.example-button,
.button {
  border: 1px solid var(--border);
  border-radius: 999px;
  font: inherit;
  cursor: pointer;
}

.example-button {
  min-height: 38px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--text);
}

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

.composer {
  display: grid;
  gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
  font: inherit;
  color: var(--text);
  background: var(--surface-soft);
  resize: vertical;
}

.chat-input:focus-visible,
.button:focus-visible,
.example-button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 36%, white 64%);
  outline-offset: 2px;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.action-row {
  display: flex;
  gap: 10px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  background: var(--surface);
  color: var(--text);
}

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

.button.subtle {
  background: var(--surface-soft);
}

.button:disabled {
  opacity: 0.56;
  cursor: default;
}

.button[hidden],
.status-line[hidden] {
  display: none;
}

.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;
}

@media (max-width: 860px) {
  .app-header,
  .composer-actions {
    display: grid;
  }

  .app-header-actions {
    justify-items: start;
    min-width: 0;
  }

}

body[data-surface="sheet"] .app-header {
  display: none;
}

@media (max-width: 720px) {
  body {
    padding: 10px;
  }

  body[data-surface="sheet"] {
    padding: 0;
  }

  .app-shell {
    min-height: calc(100dvh - 20px);
    border-radius: 22px;
  }

  body[data-surface="sheet"] .app-shell {
    min-height: 100dvh;
    border-radius: 0;
  }

  .app-header,
  .starter-panel,
  .message-log,
  .followups,
  .composer {
    padding-left: 16px;
    padding-right: 16px;
  }

  .app-header h1 {
    font-size: 22px;
  }

  .message-log {
    padding-top: 16px;
    padding-bottom: 16px;
  }

  .composer-actions {
    justify-items: stretch;
  }

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

  .button {
    width: 100%;
  }

  .message-user .bubble,
  .message-assistant .bubble,
  .message-meta,
  .source-block {
    max-width: 100%;
  }
}
