/* 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: #4b5563;   /* gray-600 — secondary text stays readable */
  --color-accent-soft: #ccfbf1;  /* teal-100 — active place, rule notes */

  --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-5: 20px;
  --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;
  flex-wrap: wrap;
  gap: 12px;
}

/* A service add-on's mount (v0.12.20) sits with the engagement links but
   leaves the app — the arrow in the label says so. */
.app-shell__engagement-link--addon {
  font-style: italic;
}

/* ----- 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;
}

/* Row = link + a delete control that appears on hover; two clicks to
   delete (the first arms the row). */
.conversation-list__row {
  position: relative;
}

.conversation-list__row .conversation-list__item {
  padding-right: 28px;
}

.conversation-list__delete {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 14px;
  line-height: 1;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0;
}

.conversation-list__row:hover .conversation-list__delete,
.conversation-list__row:focus-within .conversation-list__delete,
.conversation-list__row--armed .conversation-list__delete {
  opacity: 1;
}

.conversation-list__delete:hover,
.conversation-list__row--armed .conversation-list__delete {
  color: #b91c1c;
  background: var(--color-surface);
  font-size: 11px;
  font-weight: 600;
}

.conversation-list__delete:disabled {
  opacity: 0.5;
  cursor: default;
}

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

/* ===========================================================
   Pinned dashboard tiles
   =========================================================== */

.page__header-actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--space-4);
  align-items: start;
}

.tile-card {
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-accent);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  min-width: 0;
}

.tile-card--stale {
  border-left-color: #b45309;
}

.tile-card--busy {
  opacity: 0.7;
}

.tile-card__head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.tile-card__titles {
  min-width: 0;
}

.tile-card__name {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.tile-card__question {
  font-size: 12px;
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.tile-badge {
  flex-shrink: 0;
  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-surface-2);
  color: var(--color-text-muted);
}

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

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

.tile-badge--paused {
  background: var(--color-surface-2);
  color: var(--color-text-muted);
}

.tile-card__body {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

.tile-card__empty {
  font-size: 13px;
  padding: var(--space-4) 0;
  text-align: center;
}

.tile-card__stale-note {
  font-size: 12px;
  color: #b45309;
  margin-top: var(--space-2);
}

.tile-card__stale-note--error {
  color: var(--color-danger);
}

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

.tile-card__meta {
  font-size: 11px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-card__actions {
  display: flex;
  gap: var(--space-1);
  flex-shrink: 0;
}

.tile-card__confirm {
  color: var(--color-danger);
  border-color: var(--color-danger);
}

/* Tile table */
.tile-table table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
}

.tile-table th,
.tile-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  white-space: nowrap;
}

.tile-table th {
  font-weight: 600;
  color: var(--color-text-muted);
}

.tile-table__note,
.tile-list__note,
.tile-chart__note {
  font-size: 11px;
  margin-top: var(--space-1);
}

/* Tile list */
.tile-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tile-list__item {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 4px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
}

.tile-list__primary {
  overflow-wrap: anywhere;
}

.tile-list__secondary {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* Tile chart (inline SVG) */
.tile-chart__svg {
  width: 100%;
  height: auto;
  display: block;
}

.tile-chart__axis {
  stroke: var(--color-border);
  stroke-width: 1;
}

.tile-chart__tick {
  fill: var(--color-text-muted);
  font-size: 10px;
  font-family: var(--font-system);
}

.tile-chart__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-1);
}

.tile-chart__legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--color-text-muted);
}

.tile-chart__swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

.tile-chart__empty {
  font-size: 12px;
  padding: var(--space-4) 0;
  text-align: center;
}

/* Pie: circle + labeled legend, side by side (wraps to stacked on narrow) */
.tile-chart__pie {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4);
}

.tile-chart__pie-svg {
  width: 180px;
  max-width: 100%;
  height: auto;
  flex-shrink: 0;
}

.tile-chart__pie-legend {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-width: 160px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tile-chart__pie-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.tile-chart__pie-name {
  flex: 1;
  overflow-wrap: anywhere;
}

.tile-chart__pie-value {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* US/Canada map */
.tile-map__svg {
  width: 100%;
  height: auto;
  display: block;
}

.tile-map__status {
  font-size: 12px;
  padding: var(--space-6) 0;
  text-align: center;
}

.tile-map__label {
  fill: var(--color-text);
  font-size: 9px;
  font-family: var(--font-system);
  paint-order: stroke;
  stroke: var(--color-surface, #fff);
  stroke-width: 2px;
}

.tile-map__legend {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 11px;
  margin-top: var(--space-1);
}

.tile-map__scale {
  display: inline-block;
  width: 80px;
  height: 8px;
  border-radius: 2px;
  background: linear-gradient(to right, #e5efee, var(--color-accent));
}

/* Pin affordance on a citation */
.citation-card__pin {
  position: relative;
  display: inline-block;
}

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

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

.citation-card__pinned {
  font-size: 12px;
}

.pin-form {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 10;
  width: 240px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

.pin-form__label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.pin-form__input {
  font-size: 13px;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 400;
  color: var(--color-text);
}

.pin-form__consequence {
  margin: var(--space-2) 0;
  font-size: 13px;
  max-width: 60ch;
}

.pin-form__error {
  font-size: 12px;
  color: var(--color-danger);
}

.pin-form__actions {
  display: flex;
  justify-content: flex-end;
}

.pin-form__as {
  font-size: 11px;
}

/* Chart view toggle + inline visualization on a citation */
.citation-card__views {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: var(--space-2);
}

.citation-card__view {
  font-size: 12px;
  padding: 3px 10px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
}

.citation-card__view:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.citation-card__view--active {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #fff;
}

.citation-card__viz {
  margin-top: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  overflow-x: auto;
}

.citation-card__viz-note {
  font-size: 11px;
  margin-top: var(--space-1);
}

/* The viewer's pin form (v0.12.19) is 260px wide on a desktop. This base
   rule sits ABOVE the 640px block below on purpose (D3b, lane O / lane T,
   2026-10-11): the phone sheet in that block sets `width: auto` at the same
   specificity, and when this rule came later in the file it won the
   cascade — the sheet rendered 260px wide at the left edge instead of 16px
   from each edge. Source order is the only thing that keeps the sheet. */
.report-pin .pin-form {
  width: 260px;
}

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

  .pin-form {
    right: auto;
    left: 0;
  }

  /* D3 (lane H, 2026-10-11): the viewer's 260px form anchored at its
     button (x≈160 at 375px) ran to x=420 and was clipped on the right. On a
     phone it is a sheet across the bottom of the viewport instead. */
  .report-pin .pin-form {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 16px;
    top: auto;
    width: auto;
  }
}

/* ---------- Prospondi help widget ---------- */

/* Docked bottom-right by the widget itself (`:host` inside its shadow
   root; a document rule on the element outranks it). Lift it clear of the
   chat composer once the 780px chat column reaches the viewport edge. */
@media (max-width: 900px) {
  prospondi-widget {
    bottom: 5.25rem;
  }
}

/* ---------- Reports (v0.12.14) ---------- */

.page--wide {
  max-width: 1400px;
}

.badge {
  display: inline-block;
  margin-left: var(--space-2);
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 500;
  vertical-align: middle;
  line-height: 1.6;
}

.badge--verified {
  border-color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 10%, var(--color-surface));
  color: var(--color-accent-hover);
}

.badge--shared {
  border-color: #c7d2fe;
  background: #eef2ff;
  color: #4338ca;
}

.badge--pinned {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #15803d;
}

/* Pin-to-dashboard control on the report viewer (v0.12.19) */
.report-pin {
  position: relative;
  display: inline-flex;
}


.form-input--inline {
  width: auto;
  padding: 4px 8px;
  font-size: 12px;
}

.btn--danger {
  border-color: var(--color-danger);
  background: var(--color-danger);
  color: #fff;
}

.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--color-accent);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
}

.reports-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.reports-toolbar__search {
  max-width: 360px;
}

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

.report-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: inherit;
  text-decoration: none;
}

.report-row:hover {
  border-color: var(--color-accent);
}

.report-row__main {
  min-width: 0;
}

.report-row__name {
  font-weight: 600;
}

.report-row__desc {
  font-size: 13px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.report-row__meta {
  display: flex;
  gap: var(--space-3);
  font-size: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

.report-row__failed {
  color: var(--color-danger);
}

.report-compose {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.report-compose__row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

.report-compose__label {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: 13px;
  font-weight: 500;
}

.report-compose__sql {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  resize: vertical;
}

.report-compose__hint {
  font-size: 12px;
}

.report-compose__actions {
  display: flex;
  gap: var(--space-2);
}

.report-view__header {
  align-items: flex-start;
  /* Let the action row drop below the title when both cannot fit,
     instead of squeezing the title/metadata into a narrow column. */
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
}

.report-view__title {
  flex: 1 1 420px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.report-view__title h1 {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.report-view__provenance {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  font-size: 12px;
  margin-top: var(--space-1);
}

.report-view__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  justify-content: flex-end;
  /* Overrides .page__header-actions flex-shrink: 0 so the row can wrap internally. */
  flex: 0 1 auto;
  min-width: 0;
  margin-left: auto;
}

.report-view__export {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: 12px;
  margin-right: var(--space-2);
}

.report-view__notice {
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--color-accent) 10%, var(--color-surface));
  color: var(--color-accent-hover);
  font-size: 13px;
}

.report-params {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  background: var(--color-surface-2);
  border-radius: var(--radius-md);
}

.report-params__field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  font-size: 12px;
  font-weight: 500;
}

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

.report-columns__head {
  display: flex;
  gap: var(--space-3);
  align-items: baseline;
  font-size: 13px;
  margin-bottom: var(--space-2);
}

.report-columns__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--space-1) var(--space-4);
}

.report-columns__item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  font-size: 13px;
  padding: 2px 0;
}

.report-columns__toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.report-columns__key {
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.report-columns__tools {
  display: inline-flex;
  gap: 2px;
  align-items: center;
  flex-shrink: 0;
}

.report-columns__width {
  width: 72px;
  padding: 2px 6px;
  font-size: 12px;
}

.report-columns__actions {
  display: flex;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.report-view__bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.report-view__status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 13px;
}

.report-view__running {
  color: var(--color-accent);
}

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

.report-table {
  overflow: auto;
  max-height: calc(100vh - 260px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.report-table--stale {
  opacity: 0.6;
}

.report-view__failed {
  margin: var(--space-3) 0;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  background: #fef2f2;
  border: 1px solid #fecaca;
}

.report-view__failed-note {
  margin: 0 0 var(--space-3);
  font-size: 14px;
  color: #991b1b;
}

.report-table thead th {
  position: sticky;
  top: 0;
  background: var(--color-surface);
  z-index: 1;
}

.report-table__filters th {
  top: 27px;
  padding-top: 2px;
  padding-bottom: 4px;
}

.report-table__th--sortable {
  cursor: pointer;
  user-select: none;
}

.report-table__th--sortable:hover {
  color: var(--color-text);
}

.report-table__sort {
  margin-left: 4px;
  font-size: 10px;
}

.report-table__filter {
  width: 100%;
  min-width: 90px;
  padding: 2px 6px;
  font-size: 12px;
  font-weight: 400;
}

.report-pager {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
  font-size: 13px;
}

.report-pager__size {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-left: auto;
}

.report-pager__size .form-input {
  width: auto;
  padding: 2px 6px;
}

/* ---------- Manage (v0.12.15) ---------- */

.manage__picker {
  width: auto;
  min-width: 220px;
  padding: 6px 8px;
  font-size: 13px;
  white-space: pre;
}

.manage__section h2 {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin: 0;
}

.manage__section h3 {
  margin: var(--space-4) 0 var(--space-2);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.manage__section-head {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
  font-size: 13px;
}

.manage__children {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  font-size: 13px;
}

.manage__children .link-btn {
  text-decoration: none;
  padding: 2px 8px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
}

.manage__children .link-btn:hover {
  border-color: var(--color-accent);
}

.manage__inline-form {
  margin-top: var(--space-2);
}

.manage__row-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.manage__row-form .form-input {
  width: auto;
  flex: 1 1 260px;
  max-width: 420px;
  padding: 6px 8px;
  font-size: 13px;
}

.manage__row-form .form-input.manage__role,
.manage__row-form .form-input.manage__month {
  flex: 0 0 auto;
  width: auto;
}

.manage__usage-controls {
  margin-top: 0;
  margin-bottom: var(--space-3);
}

.manage__definitions {
  margin: 0;
}

.manage__definition {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-surface-2);
}

.manage__definition dt {
  font-weight: 600;
}

.manage__definition dd {
  margin: var(--space-1) 0 0;
  font-size: 14px;
}

.manage__error {
  margin-top: var(--space-2);
  font-size: 13px;
  color: var(--color-danger);
}

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

.manage__table table {
  font-size: 13px;
}

.manage__table tfoot td {
  border-bottom: none;
  border-top: 2px solid var(--color-border);
}

.manage__cell-actions {
  text-align: right;
  white-space: nowrap;
}

.manage__cell-actions .btn + .btn {
  margin-left: var(--space-1);
}

.manage__num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.manage__engagement {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-2);
}

.manage__engagement-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: 13px;
}

.manage__engagement-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.manage__caret {
  width: 1em;
  color: var(--color-text-muted);
}

.manage__engagement-body {
  padding: 0 var(--space-3) var(--space-3);
  border-top: 1px solid var(--color-border);
}

.manage__engagement-body h3:first-child {
  margin-top: var(--space-3);
}

/* Manage → AI budget (v0.12.16) */

.manage__budget-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2);
  font-size: 14px;
}

.manage__budget-state {
  margin-left: auto;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted, #666);
}

.manage__budget-state--ok { color: var(--color-success, #2a8d2a); border-color: currentColor; }
.manage__budget-state--soft { color: var(--color-warning, #b80); border-color: currentColor; }
.manage__budget-state--over { color: var(--color-danger); border-color: currentColor; }

.manage__budget-bar {
  height: 8px;
  margin-top: var(--space-2);
  border-radius: 999px;
  background: var(--color-border);
  overflow: hidden;
}

.manage__budget-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--color-success, #2a8d2a);
  transition: width 200ms ease;
}

.manage__budget-fill--soft { background: var(--color-warning, #b80); }
.manage__budget-fill--over { background: var(--color-danger); }

.manage__budget-detail {
  margin-top: var(--space-1);
  font-size: 13px;
}

.manage__budget-next {
  margin-top: var(--space-2);
  font-size: 13px;
}

.manage__budget-keys,
.manage__budget-admin {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}

.manage__budget-keys h3,
.manage__budget-admin h3 {
  margin: 0 0 var(--space-1);
  font-size: 14px;
}

.manage__budget-hint {
  font-size: 13px;
  padding: 2px 6px;
  border-radius: var(--radius-sm, 4px);
  background: var(--color-surface-2, rgba(0, 0, 0, 0.04));
}

.manage__row-form .form-input.manage__budget-cap {
  flex: 0 0 auto;
  width: 160px;
}

.manage__row-form .form-input.manage__budget-pct {
  flex: 0 0 auto;
  width: 72px;
}

.manage__budget-check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
}

/* Manage → Add-ons (v0.12.20) */

.manage__addons {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.manage__addon {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.manage__addon--unavailable {
  opacity: 0.7;
}

.manage__addon-main {
  flex: 1 1 320px;
  min-width: 0;
}

.manage__addon-name {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-2);
  font-size: 14px;
}

.manage__addon-state {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  color: var(--color-text-muted, #666);
}

.manage__addon-state--on { color: var(--color-success, #2a8d2a); border-color: currentColor; }
.manage__addon-state--off { color: var(--color-text-muted, #666); }
.manage__addon-state--unavailable { border-style: dashed; }

.manage__addon-desc,
.manage__addon-why {
  margin: var(--space-1) 0 0;
  font-size: 13px;
}

.manage__addon-switch {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 13px;
}

.manage__addon-switch .form-input {
  width: auto;
  padding: var(--space-1) var(--space-2);
}

.chat-budget-notice {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-warning, #b80);
  border-radius: var(--radius-sm);
  background: rgba(187, 136, 0, 0.08);
  color: var(--color-text);
  font-size: 13px;
}

.chat-budget-notice span {
  flex: 1 1 auto;
}

/* Manage → Sources (v0.12.17) */

.manage__sources h4 {
  margin: var(--space-3) 0 var(--space-1);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}

.manage__source-detail-row > td {
  padding: 0 var(--space-3) var(--space-3);
  background: var(--color-surface-2);
}

.manage__source-detail {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0 var(--space-4);
  font-size: 13px;
}

.manage__source-detail > .manage__source-tables {
  grid-column: 1 / -1;
}

.manage__source-detail > .manage__source-upload {
  grid-column: 1 / -1;
}

@media (max-width: 800px) {
  .manage__source-detail {
    grid-template-columns: minmax(0, 1fr);
  }
}

.manage__source-table-list {
  list-style: none;
  margin: 0;
  padding: 0;
  columns: 2;
  column-gap: var(--space-4);
}

.manage__source-table-list li {
  break-inside: avoid;
  padding: 2px 0;
}

.manage__source-table-list label {
  cursor: pointer;
}

.manage__backing--env {
  border-color: var(--color-border);
}

.manage__backing--db {
  border-color: var(--color-accent);
  background: color-mix(in srgb, var(--color-accent) 10%, var(--color-surface));
  color: var(--color-accent-hover);
}

.manage__backing--none {
  border-color: var(--color-danger);
  color: var(--color-danger);
}

.manage__row-form--tight {
  margin-top: var(--space-2);
}

.manage__ok { color: var(--color-success, #2a8d2a); }
.manage__bad { color: var(--color-danger); }

.manage__notice {
  margin-top: var(--space-2);
  font-size: 13px;
}

.manage__wizard {
  margin-top: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.manage__wizard--new {
  margin-top: var(--space-3);
}

.manage__fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-2) var(--space-3);
}

.manage__field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.manage__field--wide {
  grid-column: 1 / -1;
}

.manage__field .form-input {
  padding: 6px 8px;
  font-size: 13px;
}

.manage__field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-muted);
}

.manage__field-hint {
  font-size: 11px;
}

.manage__req {
  color: var(--color-danger);
}

.manage__check {
  display: block;
  margin-top: var(--space-2);
  font-size: 13px;
  cursor: pointer;
}

.manage__json {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px;
  resize: vertical;
}

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

.manage__upload-result {
  margin-top: var(--space-2);
  font-size: 13px;
}

.manage__upload-result p {
  margin: 0 0 var(--space-1);
}

/* ---- Manage → Privacy (v0.12.21) ---------------------------------------- */

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

.manage__privacy-panel {
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.manage__privacy-panel h4 {
  margin: 0 0 var(--space-1);
  font-size: 14px;
}

.manage__privacy-panel h5 {
  margin: var(--space-3) 0 var(--space-1);
  font-size: 13px;
  font-weight: 600;
}

.manage__privacy-panel > p.muted {
  margin: 0 0 var(--space-2);
  font-size: 13px;
}

.manage__privacy-panel code {
  font-size: 12px;
}

.manage__identifiers {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-2) var(--space-3);
}

.manage__identifiers textarea.form-input {
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 12px;
  resize: vertical;
  min-height: 48px;
}

.manage__privacy-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.manage__privacy-actions .form-input {
  width: auto;
  padding: 6px 8px;
  font-size: 13px;
}

.manage__privacy-sep {
  flex: 0 0 1px;
  align-self: stretch;
  background: var(--color-border);
  margin: 0 var(--space-1);
}

.manage__check--inline {
  display: inline-block;
  margin-top: 0;
}

.manage__retention-form {
  margin-top: var(--space-2);
}

.manage__masks {
  margin: 0 0 var(--space-2);
  padding-left: 1.2em;
  font-size: 13px;
}

.manage__masks li {
  margin: 2px 0;
}

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

.manage__register td:first-child code {
  white-space: nowrap;
}

/* The DSAR progress affordance. Determinate when a previous request on
   this engagement gave a scale; an animated sweep when it did not. */
.manage__progress-wrap {
  margin-top: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
}

.manage__progress {
  position: relative;
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: var(--color-border);
}

.manage__progress-bar {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: 4px;
  background: var(--color-accent);
  transition: width 250ms linear;
}

.manage__progress-bar--indeterminate {
  width: 30%;
  animation: manage-progress-sweep 1.6s ease-in-out infinite;
}

@keyframes manage-progress-sweep {
  0% { left: -30%; }
  100% { left: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .manage__progress-bar--indeterminate {
    animation: none;
    left: 0;
    width: 100%;
    opacity: 0.5;
  }
  .manage__progress-bar {
    transition: none;
  }
}

.manage__progress-label {
  margin: var(--space-1) 0 var(--space-2);
  font-size: 12px;
}

/* New-build banner (v0.12.24) — src/components/UpdateBanner.tsx */

.update-banner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-3) var(--space-4) 0;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-sm);
  background: rgba(13, 148, 136, 0.08);
  color: var(--color-text);
  font-size: 13px;
}

.update-banner span {
  flex: 1 1 auto;
}

/* ---------- Today / Ask / Library (Shoreline first slice) ---------- */

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* The three daily places, above the engagement's other pages. */
.app-shell__primary-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: var(--space-3) 0;
}

.app-shell__primary-link {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
}

.app-shell__primary-link:hover {
  background: var(--color-surface);
}

.app-shell__primary-link:focus-visible,
.today-ask__input:focus-visible,
.today-card__open:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.app-shell__primary-link--active {
  background: var(--color-accent-soft);
  color: var(--color-accent-hover);
}

.today {
  max-width: 1040px;
  padding: var(--space-8) var(--space-8) 48px;
}

.today__header {
  margin-bottom: var(--space-6);
}

.today__company {
  font-size: 14px;
  margin-bottom: var(--space-1);
}

.today__title {
  font-size: 28px;
  font-weight: 650;
  margin: 0;
}

.today-ask {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
}

.today-ask__input {
  flex: 1;
  min-width: 0;
  padding: 12px 16px;
  font-size: 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.today-observation {
  font-size: 13px;
  margin: 0 0 var(--space-4);
}

.today-others {
  margin-top: var(--space-2);
}

.today-others > summary {
  cursor: pointer;
  font-size: 14px;
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
}

.today-card__viz {
  margin: 0 0 var(--space-3);
}

.today-cards {
  display: grid;
  gap: var(--space-6);
}

.today-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

.today-card--headline {
  border-left: 4px solid var(--color-accent);
}

.today-card__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
}

.today-card__title {
  font-size: 18px;
  margin: 0;
}

.today-card__open {
  font-size: 14px;
  color: var(--color-accent-hover);
  white-space: nowrap;
}

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

.today-card__summary {
  font-size: 16px;
  margin: 0 0 var(--space-4);
}

.today-card__meta {
  font-size: 13px;
  margin: var(--space-3) 0 0;
}

/* Declared totals under a card's row count (v0.3.74): one label / figure
   pair per declared-additive column of the held snapshot. */
.today-card__totals {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
  margin: calc(-1 * var(--space-2)) 0 var(--space-4);
}

.today-card__total {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}

.today-card__total dt {
  font-size: 13px;
  color: var(--color-text-muted);
}

.today-card__total dd {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* A listed column whose total is not shown: the reason sits in the
   figure's place, quietly ("total not shown: a value is missing"). */
.today-card__total--suppressed dd {
  font-size: 13px;
  font-weight: 400;
  color: var(--color-text-muted);
}

/* The viewer's one line of declared totals above the table. */
.report-view__totals {
  margin: 0 0 var(--space-3);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.today-card__rule {
  margin: var(--space-4) 0 0;
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--color-accent-soft);
  font-size: 14px;
  color: var(--color-text-muted);
}

.today-card__rule-term {
  font-weight: 600;
  color: var(--color-text);
}

.today-table-wrap {
  overflow-x: auto;
}

.today-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.today-table th.num {
  text-align: right;
}

.today-table th {
  text-align: left;
  font-weight: 600;
  color: var(--color-text-muted);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
}

.today-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-surface-2);
}

.today-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.today-state {
  padding: var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
}

.today-state p {
  margin: var(--space-1) 0 0;
}

.today-state--error {
  background: #fef2f2;
  border: 1px solid #fecaca;
}

.report-audience {
  margin: var(--space-1) 0 var(--space-2);
  font-size: 14px;
}

@media (max-width: 768px) {
  .today {
    padding: var(--space-4);
  }

  .today-dates {
    grid-template-columns: 1fr;
    gap: var(--space-2);
  }

  .app-shell__primary-nav {
    flex-direction: row;
    margin: var(--space-2) 0;
  }

  /* Narrow screens: each row becomes a card with every field labeled, so
     annual value and open issues stay readable on a phone. */
  .today-table thead {
    display: none;
  }

  .today-table,
  .today-table tbody,
  .today-table tr,
  .today-table td {
    display: block;
    width: 100%;
  }

  .today-table tr {
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border);
  }

  .today-table td {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 2px 0;
    border: none;
    text-align: right;
  }

  .today-table td::before {
    content: attr(data-label);
    color: var(--color-text-muted);
    text-align: left;
  }

  .today-table td:first-child {
    font-weight: 600;
  }

  .today-card {
    padding: var(--space-4);
  }
}

/* ---------- Report viewer: rule, dates, consequences before action ---------- */

.report-rule {
  margin: var(--space-2) 0;
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--color-accent-soft);
  font-size: 14px;
  color: var(--color-text-muted);
}

.report-rule__term {
  font-weight: 600;
  color: var(--color-text);
}

.report-dates {
  margin: var(--space-1) 0 var(--space-2);
  font-size: 14px;
}

/* The Recalculate note takes its own line under the run status. */
.report-view__status {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.report-view__recalc-note {
  display: block;
  flex-basis: 100%;
  font-size: 13px;
  text-align: right;
}

.action-confirm {
  margin: var(--space-3) 0;
  padding: var(--space-4);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  max-width: 640px;
}

.action-confirm p {
  margin: var(--space-2) 0 var(--space-3);
  font-size: 14px;
}

.action-confirm__buttons {
  display: flex;
  gap: var(--space-2);
}

/* ---------- Report viewer: source failure and "Send for help" ---------- */
/* The explanation sits under the dates line; the review panel is the
   ActionConfirm panel with room for the context and a note. Long ids and
   masked addresses wrap, so nothing scrolls sideways at 375 px. */

.source-problem,
.source-help {
  margin: var(--space-2) 0 var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-danger);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  max-width: 640px;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.source-help {
  border-left-color: var(--color-border);
}

.source-problem p,
.source-help p {
  margin: var(--space-1) 0;
}

.source-problem__help {
  margin-top: var(--space-2);
}

.help-review {
  overflow-wrap: anywhere;
}

.help-review__status:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.help-review__title:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.help-review__to,
.help-review__reply {
  font-weight: 600;
}

.help-review__reply--missing,
.help-review__state--error strong {
  color: var(--color-danger);
}

.help-review__context {
  margin: 0 0 var(--space-2);
  padding-left: var(--space-4);
  font-size: 14px;
}

.help-review__disclosure,
.help-review__banner,
.help-review__existing,
.help-review__unconfigured,
.help-review__state {
  margin: var(--space-2) 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  font-size: 14px;
}

.help-review__banner {
  border: 1px solid var(--color-accent);
}

.help-review__state p,
.help-review__existing p {
  margin: var(--space-1) 0 0;
}

.help-review__note {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin: var(--space-2) 0;
  font-size: 14px;
}

.help-review__note textarea {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
}

.help-review__count {
  font-size: 12px;
}

.help-review__buttons {
  flex-wrap: wrap;
}

@media (max-width: 640px) {
  .help-review__buttons .btn {
    flex: 1 1 100%;
    min-height: 44px;
  }
  .source-problem__help .btn,
  .source-help .btn {
    width: 100%;
    min-height: 44px;
  }
}

/* ---------- Report viewer: Sources & calculation (the run record) ---------- */
/* A native <details>: Enter / Space / tap open it; no hover anywhere. */

.report-evidence {
  margin: 0 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.report-evidence > summary {
  cursor: pointer;
  padding: var(--space-2) var(--space-3);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-1) var(--space-2);
  font-size: 14px;
}

.report-evidence > summary:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
  border-radius: var(--radius-md);
}

.report-evidence__title {
  font-weight: 600;
}

.report-evidence__line {
  font-size: 13px;
}

.report-evidence__body {
  padding: 0 var(--space-3) var(--space-3);
  font-size: 14px;
}

.report-evidence__facts {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: var(--space-1) var(--space-3);
  margin: var(--space-2) 0;
}

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

.report-evidence__facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

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

.report-evidence__list {
  margin: 0 0 var(--space-2);
  padding-left: 1.2em;
}

.report-evidence__sql {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 320px;
  overflow: auto;
  margin-bottom: var(--space-2);
}

.report-evidence__changed {
  margin: var(--space-2) 0;
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid var(--color-accent);
}

.report-evidence__failed {
  margin: var(--space-2) 0;
  color: #991b1b;
}

.report-evidence__scope {
  margin: var(--space-2) 0;
}

.report-evidence__history {
  list-style: none;
  margin: var(--space-1) 0 0;
  padding: 0;
}

.report-evidence__history li {
  border-top: 1px solid var(--color-border);
}

.report-evidence__run {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  padding: var(--space-2) var(--space-1);
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.report-evidence__run[aria-pressed="true"] {
  background: color-mix(in srgb, var(--color-accent) 8%, var(--color-surface));
}

.report-evidence__run:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}

.report-evidence__run-outcome--failed {
  color: #991b1b;
}

@media (max-width: 640px) {
  .report-evidence__facts {
    grid-template-columns: minmax(0, 1fr);
  }
  .report-evidence__facts dt {
    margin-top: var(--space-1);
  }
}
