/* Census Chat — dark, professional, no-build-step stylesheet. */

:root {
  --bg: #0b0e14;
  --bg-raised: #11151d;
  --surface: #161b26;
  --surface-2: #1c2230;
  --border: #262d3b;
  --border-strong: #343d4f;
  --text: #e7eaf0;
  --text-dim: #9aa4b5;
  --text-faint: #6b7587;
  --accent: #5ba7f7;
  --accent-strong: #3b82f6;
  --accent-soft: rgba(91, 167, 247, 0.14);
  --green: #3fb960;
  --green-soft: rgba(63, 185, 96, 0.12);
  --amber: #e0a93e;
  --amber-soft: rgba(224, 169, 62, 0.12);
  --red: #e5634f;
  --red-soft: rgba(229, 99, 79, 0.1);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono",
    monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: radial-gradient(
      1200px 500px at 50% -200px,
      rgba(59, 130, 246, 0.08),
      transparent
    ),
    var(--bg);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ------------------------------------------------------------------ header */

.app-header {
  flex: none;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 14, 20, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 10;
}

.header-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-mark {
  width: 26px;
  height: 26px;
  color: var(--accent);
  flex: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.brand-title {
  font-weight: 650;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.brand-sub {
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

/* ----------------------------------------------------------------- buttons */

.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 550;
  border-radius: 9px;
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s ease, border-color 0.15s ease,
    transform 0.05s ease;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.6;
  cursor: default;
  transform: none;
}

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

.btn-ghost:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-primary {
  background: var(--accent-strong);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #2f74e0;
}

.btn-spinner {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
  flex: none;
}

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

/* -------------------------------------------------------------- chat layout */

#chat-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: auto;
}

#messages {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* -------------------------------------------------------------- empty state */

.empty-state {
  margin: 9vh auto 0;
  max-width: 560px;
  text-align: center;
  animation: rise 0.4s ease both;
}

.hero-mark {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero-mark svg {
  width: 28px;
  height: 28px;
}

.empty-state h1 {
  font-size: 24px;
  font-weight: 650;
  margin: 0 0 10px;
  letter-spacing: -0.01em;
}

.empty-sub {
  color: var(--text-dim);
  font-size: 14.5px;
  margin: 0 0 24px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.chip {
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

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

/* ----------------------------------------------------------------- messages */

.msg {
  display: flex;
  animation: rise 0.25s ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

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

.bubble {
  border-radius: var(--radius);
  padding: 12px 16px;
  min-width: 0;
}

.bubble-user {
  max-width: 78%;
  background: var(--accent-strong);
  color: #fff;
  border-bottom-right-radius: 5px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.bubble-assistant {
  max-width: 94%;
  width: fit-content;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}

/* --------------------------------------------------------- markdown content */

.md-content {
  overflow-wrap: break-word;
}

.md-content p {
  margin: 0 0 10px;
}

.md-content p:last-child {
  margin-bottom: 0;
}

.md-content .md-heading {
  margin-top: 4px;
}

.md-content .md-quote {
  margin: 4px 0 10px;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--border, #2a3346);
  color: var(--muted, #8b93a7);
  font-size: 0.92em;
}

.md-content .md-table {
  margin: 6px 0 12px;
  border-collapse: collapse;
  font-size: 0.93em;
}

.md-content .md-table th,
.md-content .md-table td {
  padding: 5px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border, #2a3346);
}

.md-content .md-table th {
  color: var(--muted, #8b93a7);
  font-weight: 600;
}

.md-content .md-table td:not(:first-child),
.md-content .md-table th:not(:first-child) {
  font-variant-numeric: tabular-nums;
}

.md-content ul,
.md-content ol {
  margin: 4px 0 10px;
  padding-left: 22px;
}

.md-content li {
  margin: 3px 0;
}

.md-content code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
}

.md-content:empty {
  display: none;
}

.stream-cursor {
  display: inline-block;
  width: 8px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--accent);
  border-radius: 2px;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.error-note {
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid rgba(229, 99, 79, 0.4);
  background: var(--red-soft);
  border-radius: 10px;
  color: #f0b3a8;
  font-size: 14px;
}

.error-note:first-child {
  margin-top: 0;
}

/* ---------------------------------------------------------------- status chip */

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12.5px;
  width: fit-content;
}

.status-chip:first-child,
.md-content:empty + .status-chip {
  margin-top: 0;
}

.chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
  flex: none;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.35;
    transform: scale(0.75);
  }
}

/* --------------------------------------------------------------- result chart */

.chart-slot:empty {
  display: none;
}

/* Fixed preferred width so the fit-content bubble grows to hold the chart;
   max-width keeps it inside the bubble on narrow screens. */
.result-chart {
  margin-top: 12px;
  width: 520px;
  max-width: 100%;
}

.result-chart svg {
  display: block;
  width: 100%;
}

.chart-caption {
  font-size: 11.5px;
  color: var(--text-faint);
  margin-bottom: 6px;
}

.chart-label {
  fill: var(--text-dim);
  font-family: var(--font);
  font-size: 12px;
}

.chart-value {
  fill: var(--text);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chart-track {
  fill: var(--surface-2);
}

.chart-bar {
  fill: var(--accent-strong);
  transform-box: fill-box;
  transform-origin: left center;
  animation: bar-grow 0.45s ease-out both;
}

@keyframes bar-grow {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

.chart-more {
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--text-faint);
}

/* ------------------------------------------------------------------ cost chip */

.cost-slot:empty {
  display: none;
}

.cost-chip {
  margin-top: 10px;
  font-size: 11.5px;
  color: var(--text-faint);
  cursor: help;
  width: fit-content;
}

/* --------------------------------------------------------------- golden badge */

.golden-slot:empty {
  display: none;
}

.golden-badge {
  margin-top: 10px;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  border: 1px solid;
}

.golden-pass {
  background: var(--green-soft);
  border-color: rgba(63, 185, 96, 0.35);
  color: #8fd9a4;
}

.golden-fail {
  background: var(--amber-soft);
  border-color: rgba(224, 169, 62, 0.4);
  color: #ecc77f;
}

.golden-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 550;
}

.golden-icon {
  flex: none;
}

.golden-detail {
  margin-top: 5px;
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.5;
}

/* benchmark SQL shown on a mismatch, so the user can compare both queries */
.golden-sql {
  margin-top: 6px;
}

.golden-sql summary {
  list-style: none;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  user-select: none;
  text-decoration: underline dotted;
}

.golden-sql summary::-webkit-details-marker {
  display: none;
}

.golden-sql pre {
  margin: 6px 0 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-raised);
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ----------------------------------------------------------------- SQL panel */

.sql-panel {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-raised);
  overflow: hidden;
}

.sql-panel summary {
  list-style: none;
  cursor: pointer;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
  user-select: none;
}

.sql-panel summary::-webkit-details-marker {
  display: none;
}

.sql-panel summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 5px solid var(--text-faint);
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
  flex: none;
}

.sql-panel[open] summary::before {
  transform: rotate(90deg);
}

.sql-panel summary:hover {
  color: var(--text);
}

.sql-title {
  font-weight: 600;
  letter-spacing: 0.04em;
}

.sql-count {
  color: var(--text-faint);
}

.sql-attempts {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sql-attempt-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 12px;
}

.attempt-label {
  color: var(--text-dim);
  font-weight: 550;
}

.attempt-meta {
  color: var(--text-faint);
}

.pill {
  font-size: 10.5px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-radius: 999px;
  padding: 2px 8px;
  border: 1px solid;
}

.pill-ok {
  color: var(--green);
  border-color: rgba(63, 185, 96, 0.4);
  background: var(--green-soft);
}

.pill-repaired {
  color: var(--amber);
  border-color: rgba(224, 169, 62, 0.4);
  background: var(--amber-soft);
}

.pill-error {
  color: var(--red);
  border-color: rgba(229, 99, 79, 0.4);
  background: var(--red-soft);
}

.pill-running {
  color: var(--accent);
  border-color: rgba(91, 167, 247, 0.4);
  background: var(--accent-soft);
  animation: pulse 1.1s ease-in-out infinite;
}

.sql-attempt pre {
  margin: 0;
  padding: 10px 12px;
  background: #0a0d13;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
}

.sql-attempt code {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  color: #c4d4ef;
  white-space: pre;
}

.sql-error {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: #f0b3a8;
  background: var(--red-soft);
  border: 1px solid rgba(229, 99, 79, 0.3);
  border-radius: 8px;
  padding: 7px 10px;
  overflow-wrap: break-word;
}

/* ----------------------------------------------------------------- composer */

.composer {
  flex: none;
  border-top: 1px solid var(--border);
  background: rgba(11, 14, 20, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: 12px 20px calc(10px + env(safe-area-inset-bottom));
}

.composer-inner {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 10px 10px 16px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.composer-inner:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

#input {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  max-height: 160px;
  padding: 4px 0;
}

#input::placeholder {
  color: var(--text-faint);
}

.send-btn {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--accent-strong);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, transform 0.05s ease;
}

.send-btn svg {
  width: 18px;
  height: 18px;
}

.send-btn:hover:not(:disabled) {
  background: #2f74e0;
}

.send-btn:active {
  transform: translateY(1px);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.composer-hint {
  max-width: 860px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-faint);
}

/* ------------------------------------------------------------------- toasts */

#toasts {
  position: fixed;
  right: 20px;
  bottom: 96px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
  max-width: min(380px, calc(100vw - 40px));
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  border-left-color: var(--green);
}

.toast-error {
  border-left-color: var(--red);
}

.toast a {
  color: var(--accent);
  font-weight: 550;
  text-decoration: underline;
}

/* -------------------------------------------------------------- small screens */

@media (max-width: 640px) {
  .header-inner {
    padding: 10px 14px;
  }

  .brand-sub {
    display: none;
  }

  .btn {
    padding: 7px 11px;
    font-size: 12.5px;
  }

  #messages {
    padding: 16px 12px 8px;
  }

  .bubble-user {
    max-width: 88%;
  }

  .bubble-assistant {
    max-width: 100%;
  }

  .composer {
    padding-left: 12px;
    padding-right: 12px;
  }

  .empty-state {
    margin-top: 5vh;
  }
}

/* -------------------------------------------------------------- scrollbars */

#chat-scroll::-webkit-scrollbar,
.sql-attempt pre::-webkit-scrollbar {
  width: 10px;
  height: 8px;
}

#chat-scroll::-webkit-scrollbar-thumb,
.sql-attempt pre::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

#chat-scroll::-webkit-scrollbar-track,
.sql-attempt pre::-webkit-scrollbar-track {
  background: transparent;
}

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