/* Profonti user UI — chat-focused.
 * Hand-written; no Tailwind. CSS variables for theming.
 */

:root {
  --color-bg: #f9fafb;
  --color-surface: #ffffff;
  --color-surface-2: #f3f4f6;
  --color-border: #e5e7eb;
  --color-text: #111827;
  --color-text-muted: #6b7280;

  --color-sidebar-bg: #f3f4f6;
  --color-sidebar-border: #e5e7eb;

  --color-accent: #0d9488;       /* teal-600 — warmer than admin's blue */
  --color-accent-hover: #0f766e;
  --color-danger: #dc2626;

  --color-user-bubble: #0d9488;
  --color-assistant-bubble: #ffffff;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --font-system:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", Menlo, Consolas, monospace;
}

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

html,
body,
#root {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-system);
  font-size: 15px;
  line-height: 1.55;
  color: var(--color-text);
  background: var(--color-bg);
}

a {
  color: var(--color-accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font: inherit;
  cursor: pointer;
}

.muted {
  color: var(--color-text-muted);
}

/* ---------- App shell ---------- */

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}

.app-shell__sidebar {
  background: var(--color-sidebar-bg);
  border-right: 1px solid var(--color-sidebar-border);
  display: flex;
  flex-direction: column;
  padding: var(--space-4);
  overflow-y: auto;
}

.app-shell__brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-4);
}

.app-shell__brand-mark {
  color: var(--color-accent);
}

.app-shell__engagement {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
}

.app-shell__engagement-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 2px;
}

.app-shell__engagement-link {
  font-size: 12px;
  color: var(--color-text-muted);
  text-decoration: none;
}

.app-shell__engagement-link:hover {
  color: var(--color-accent);
}

.app-shell__engagement-links {
  display: flex;
  gap: 12px;
}

/* ----- Definitions page ----- */

.definitions-search {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0 8px;
}

.definitions-search input {
  flex: 1;
  font-size: 14px;
}

.definitions-search__count {
  font-size: 12px;
  white-space: nowrap;
}

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

.definition-card {
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-accent);
  border-radius: 6px;
  padding: 14px 16px;
  background: var(--color-bg, #fff);
}

.definition-card__head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.definition-card__term {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text);
}

.definition-card__meaning {
  margin: 4px 0 6px;
  line-height: 1.5;
}

.definition-card__goals {
  font-size: 13px;
  margin-bottom: 4px;
}

.definition-card__sql {
  margin-top: 8px;
  font-size: 13px;
}

.definition-card__sql summary {
  cursor: pointer;
  color: var(--color-accent);
}

.definition-card__sql pre {
  margin: 6px 0 0;
  padding: 8px 10px;
  background: var(--color-bg-soft, #f9fafb);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.45;
}

.maturity-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--color-bg-soft, #f3f4f6);
  color: var(--color-text-muted);
}

.maturity-badge--confirmed {
  background: rgba(13, 148, 136, 0.12);
  color: var(--color-accent);
}

.maturity-badge--proposed {
  background: rgba(59, 130, 246, 0.12);
  color: #1d4ed8;
}

.maturity-badge--sketched {
  background: rgba(217, 119, 6, 0.12);
  color: #b45309;
}

.maturity-badge--operational {
  background: rgba(16, 185, 129, 0.12);
  color: #047857;
}

/* ===========================================================
   Help system
   =========================================================== */

.help-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  min-height: calc(100vh - 96px);
}

.help-toc {
  border-right: 1px solid var(--color-border);
  padding-right: 16px;
  overflow-y: auto;
}

.help-toc__search {
  margin-bottom: 12px;
  position: sticky;
  top: 0;
  background: var(--color-bg, #fff);
  padding: 8px 0;
  z-index: 1;
}

.help-toc__list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 4px;
}

.help-toc__item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.help-toc__item:hover {
  background: var(--color-bg-soft, #f9fafb);
}

.help-toc__item--active {
  background: var(--color-accent-soft, rgba(13, 148, 136, 0.08));
  border-color: var(--color-accent);
}

.help-toc__title {
  font-weight: 600;
  font-size: 13px;
}

.help-toc__summary {
  font-size: 11px;
  line-height: 1.35;
  margin-top: 2px;
}

.help-toc__empty {
  padding: 8px 10px;
  font-size: 12px;
}

.help-main {
  padding: 8px 24px 32px 0;
  max-width: 720px;
}

.help-article h1 {
  margin-top: 0;
  font-size: 24px;
  font-weight: 700;
}

.help-article h2 {
  margin-top: 28px;
  font-size: 16px;
  font-weight: 700;
}

.help-article .help-lead {
  font-size: 15px;
  line-height: 1.55;
  border-left: 3px solid var(--color-accent);
  padding-left: 12px;
  margin: 12px 0 24px 0;
}

.help-article p,
.help-article li {
  font-size: 14px;
  line-height: 1.6;
}

.help-article pre {
  background: var(--color-bg-soft, #f9fafb);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.5;
  overflow-x: auto;
}

.help-article code {
  background: var(--color-bg-soft, #f9fafb);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12.5px;
}

.app-shell__engagement-picker {
  width: 100%;
  padding: 6px 8px;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 600;
  background: var(--color-bg, #fff);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm, 4px);
  color: inherit;
}

.app-shell__engagement-picker:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: -1px;
}

.app-shell__newchat {
  margin-bottom: var(--space-4);
}

.app-shell__sidebar-heading {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  font-weight: 600;
  margin-bottom: var(--space-2);
  padding: 0 var(--space-2);
}

.app-shell__sidebar-empty {
  font-size: 13px;
  color: var(--color-text-muted);
  padding: 0 var(--space-2);
}

.app-shell__conversations {
  flex: 1 1 auto;
  overflow-y: auto;
  margin-bottom: var(--space-4);
}

.conversation-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.conversation-list__item {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  margin-bottom: 2px;
}

.conversation-list__item:hover {
  background: var(--color-surface);
  text-decoration: none;
}

.conversation-list__item--active {
  background: var(--color-surface);
  border-left: 3px solid var(--color-accent);
}

.conversation-list__title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-list__meta {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.app-shell__user {
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.app-shell__user-info {
  flex: 1 1 auto;
  min-width: 0;
}

.app-shell__user-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-shell__user-email {
  font-size: 11px;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-shell__main {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--color-text);
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: white;
}

.btn--primary:hover:not(:disabled) {
  background: var(--color-accent-hover);
  border-color: var(--color-accent-hover);
  color: white;
}

.btn--small {
  padding: 4px var(--space-3);
  font-size: 12px;
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-text-muted);
}

.btn--ghost:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.04);
  color: var(--color-text);
  border-color: transparent;
}

.btn--block {
  width: 100%;
}

/* ---------- Chat page ---------- */

.chat-page {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-6);
  gap: var(--space-4);
}

.chat-empty {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: var(--space-8);
}

.chat-empty h1 {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-3);
}

.chat-empty p {
  max-width: 480px;
}

.chat-thinking {
  align-self: flex-start;
  color: var(--color-text-muted);
  font-style: italic;
  padding: var(--space-2) var(--space-4);
}

.chat-input-wrap {
  margin-top: auto;
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

.chat-input {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
}

.chat-input__textarea {
  flex: 1 1 auto;
  padding: var(--space-3);
  font: inherit;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  resize: vertical;
  min-height: 60px;
}

.chat-input__textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.15);
}

.chat-input__send {
  padding: var(--space-3) var(--space-4);
}

/* ---------- Messages ---------- */

.message-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.message {
  display: flex;
}

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

.message--assistant {
  justify-content: flex-start;
}

.message__bubble {
  max-width: 90%;
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-4);
}

.message--user .message__bubble {
  background: var(--color-user-bubble);
  color: white;
}

.message--assistant .message__bubble {
  background: var(--color-assistant-bubble);
  border: 1px solid var(--color-border);
}

.message__role {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: var(--space-1);
  opacity: 0.8;
}

.message__content {
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Inside the markdown-rendered body, we no longer want pre-wrap
   because the rendered HTML carries its own block-level layout. */
.message__content .md-body {
  white-space: normal;
}

/* ---------- Markdown rendering (assistant messages) ---------- */

.md-body {
  word-wrap: break-word;
}

.md-body > *:first-child {
  margin-top: 0;
}

.md-body > *:last-child {
  margin-bottom: 0;
}

.md-body p {
  margin: 0 0 var(--space-2) 0;
  line-height: 1.55;
}

.md-body h1,
.md-body h2,
.md-body h3,
.md-body h4 {
  margin: var(--space-3) 0 var(--space-1) 0;
  line-height: 1.25;
  font-weight: 700;
}

.md-body h1 { font-size: 18px; }
.md-body h2 { font-size: 16px; }
.md-body h3 { font-size: 14px; }
.md-body h4 { font-size: 13px; }

.md-body ul,
.md-body ol {
  margin: var(--space-1) 0 var(--space-2) 0;
  padding-left: var(--space-5);
}

.md-body li {
  margin-bottom: 2px;
  line-height: 1.5;
}

.md-body strong { font-weight: 700; }
.md-body em { font-style: italic; }

.md-body a {
  color: var(--color-accent);
  text-decoration: underline;
}

.md-body code {
  background: var(--color-bg-soft, #f3f4f6);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.md-body pre {
  background: var(--color-bg-soft, #f3f4f6);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 10px 12px;
  margin: var(--space-2) 0;
  font-size: 12.5px;
  line-height: 1.5;
  overflow-x: auto;
}

.md-body pre code {
  background: transparent;
  padding: 0;
  font-size: inherit;
}

.md-body table {
  border-collapse: collapse;
  margin: var(--space-2) 0;
  width: 100%;
  font-size: 13px;
}

.md-body th,
.md-body td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

.md-body th {
  background: var(--color-bg-soft, #f9fafb);
  font-weight: 700;
  border-bottom-width: 2px;
  border-bottom-color: var(--color-text-muted);
}

.md-body tr:last-child td {
  border-bottom: none;
}

.md-body blockquote {
  margin: var(--space-2) 0;
  padding: var(--space-1) var(--space-3);
  border-left: 3px solid var(--color-accent);
  color: var(--color-text-muted);
  font-style: italic;
}

.md-body hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-3) 0;
}

.message__citations {
  margin-top: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* ---------- Freshness panel ---------- */

.freshness-panel {
  margin-top: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.freshness-panel__agg {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: 13px;
}

.freshness-panel__summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  list-style: none;
}

.freshness-panel__summary::-webkit-details-marker { display: none; }

.freshness-panel__name {
  font-weight: 600;
}

.freshness-panel__when {
  color: var(--color-text-muted);
}

.freshness-panel__schedule {
  margin-left: auto;
  color: var(--color-text-muted);
}

.freshness-panel__table {
  width: 100%;
  margin-top: var(--space-2);
  border-collapse: collapse;
  font-size: 12px;
}

.freshness-panel__table th,
.freshness-panel__table td {
  text-align: left;
  padding: 4px 8px;
  border-top: 1px solid var(--color-border);
}

.freshness-panel__status--succeeded { color: var(--color-success, #2a8d2a); }
.freshness-panel__status--failed    { color: var(--color-danger,  #b33); }
.freshness-panel__status--running   { color: var(--color-warning, #b80); }
.freshness-panel__status--never     { color: var(--color-text-muted); }

/* ---------- Citation card ---------- */

.citation-card {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: 13px;
}

.citation-card--error {
  background: rgba(220, 38, 38, 0.06);
  border-color: rgba(220, 38, 38, 0.3);
}

.citation-card__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
}

.citation-card__summary {
  color: var(--color-text);
}

.citation-card__error {
  color: var(--color-danger);
}

.citation-card__toggle {
  background: transparent;
  border: none;
  color: var(--color-accent);
  font-size: 12px;
  padding: 0;
}

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

.citation-card__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.citation-card__csv,
.citation-card__pptx {
  color: var(--color-accent);
  text-decoration: none;
  font-size: 12px;
}

.citation-card__csv:hover,
.citation-card__pptx:hover {
  text-decoration: underline;
}

.chat-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 6px 4px 12px;
  border-bottom: 1px solid var(--color-border, #e5e7eb);
  margin-bottom: 12px;
}

.chat-toolbar__action {
  font-size: 12px;
  color: var(--color-accent);
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid var(--color-accent);
  border-radius: 4px;
}

.chat-toolbar__action:hover {
  background: var(--color-accent);
  color: #fff;
}

.citation-card__body {
  margin-top: var(--space-2);
}

.citation-card__sql-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  font-weight: 600;
  margin-top: var(--space-2);
  margin-bottom: var(--space-1);
}

.citation-card__sql {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  overflow-x: auto;
  white-space: pre;
  margin: 0;
}

.citation-card__rows {
  overflow-x: auto;
}

.citation-card__rows table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
}

.citation-card__rows th,
.citation-card__rows td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
}

.citation-card__rows th {
  font-weight: 600;
  background: var(--color-surface);
}

/* ---------- Login ---------- */

.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.login-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  width: 400px;
  text-align: center;
}

.login-card__title {
  margin: 0;
  font-size: 32px;
  font-weight: 700;
  color: var(--color-accent);
  letter-spacing: -0.02em;
}

.login-card__sub {
  margin: var(--space-1) 0 var(--space-6) 0;
  color: var(--color-text-muted);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.form-input {
  width: 100%;
  padding: var(--space-3);
  font: inherit;
  font-size: 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.form-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.15);
}

.form-error-banner {
  background: rgba(220, 38, 38, 0.08);
  color: var(--color-danger);
  border: 1px solid rgba(220, 38, 38, 0.3);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  font-size: 13px;
}

.login-card__sent {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  align-items: center;
}

/* ---------- Common page ---------- */

.page {
  padding: var(--space-6);
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.page__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-4);
}

.page h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
}

.page h2 {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 var(--space-3) 0;
}

.breadcrumbs {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

.breadcrumbs__sep {
  margin: 0 var(--space-1);
}

.breadcrumbs__current {
  color: var(--color-text);
}

.overview-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-6);
  margin-bottom: var(--space-4);
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}

.kv__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  font-weight: 600;
  margin-bottom: 2px;
}

.goal-readonly-list,
.source-readonly-list {
  margin: 0;
  padding-left: var(--space-6);
}

.goal-readonly-list li,
.source-readonly-list li {
  margin-bottom: var(--space-2);
}

/* ---------- States ---------- */

.loading-screen,
.loading-state,
.error-state {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-8);
  color: var(--color-text-muted);
}

.error-state {
  color: var(--color-danger);
}

/* Brand logo replacing the text wordmark in the sidebar. */
.app-shell__brand-logo {
  display: block;
  height: 32px;
  width: auto;
}


/* ===========================================================
   Mobile-responsive — collapse the desktop sidebar at < 768px,
   make chat / help readable on phones.
   =========================================================== */

@media (max-width: 768px) {
  /* App shell becomes a vertical stack — compact top bar + main */
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    height: auto;
    min-height: 100vh;
  }

  .app-shell__sidebar {
    border-right: none;
    border-bottom: 1px solid var(--color-sidebar-border);
    padding: var(--space-3);
    /* Cap the sidebar height on mobile so the main pane is reachable
       without scrolling past every conversation in the Recent list. */
    max-height: 50vh;
  }

  /* Inline the brand + engagement block side-by-side so the sidebar
     header doesn't eat half the screen. */
  .app-shell__brand {
    font-size: 16px;
    margin-bottom: var(--space-3);
  }

  .app-shell__brand-logo {
    height: 24px;
  }

  .app-shell__engagement {
    padding: var(--space-2);
    margin-bottom: var(--space-3);
  }

  .app-shell__engagement-links {
    flex-wrap: wrap;
    gap: 8px 12px;
  }

  .app-shell__newchat {
    margin-bottom: var(--space-3);
  }

  /* Conversation history compresses; users tap items by row */
  .conversation-list__item {
    padding: var(--space-2) var(--space-2);
  }

  /* Main pane — give it room. The chat/help/etc. each have their
     own padding rules; here we just make sure the container doesn't
     fight them. */
  .app-shell__main {
    overflow-x: hidden;
  }

  /* ---------- Pages ---------- */

  .page {
    padding: var(--space-3);
  }

  .page__header {
    margin-bottom: var(--space-3);
  }

  /* Chat layout — chat input stays anchored, messages scroll */
  .chat-page {
    padding: var(--space-3);
  }

  .chat-toolbar {
    flex-wrap: wrap;
    gap: 6px;
  }

  /* Message list — bubbles full width on mobile */
  .message {
    max-width: 100%;
  }

  .message__bubble {
    max-width: 100%;
  }

  /* Citation cards — table can scroll horizontally without
     overflowing the whole layout */
  .citation-card__rows {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Citation actions wrap when the row is narrow */
  .citation-card__head {
    flex-wrap: wrap;
    gap: 6px;
  }

  /* Help — stack the TOC above the article instead of left-rail */
  .help-shell {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .help-toc {
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    padding-right: 0;
    padding-bottom: 12px;
    max-height: 200px;
  }

  .help-main {
    padding: 8px 0 32px 0;
  }

  .help-article h1 {
    font-size: 20px;
  }

  /* Definitions cards stack comfortably */
  .definition-card {
    padding: 12px 12px;
  }

  /* Engagement overview — kv grid one column */
  .kv-grid {
    grid-template-columns: 1fr !important;
  }
}

/* Safe-area insets for iOS notch + bottom home indicator when the
   PWA runs full-screen via display:standalone. */
@supports (padding: max(0px)) {
  .app-shell__sidebar {
    padding-top: max(var(--space-4), env(safe-area-inset-top));
  }

  .chat-input-wrap {
    padding-bottom: max(var(--space-3), env(safe-area-inset-bottom));
  }
}
