:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-muted: #f4f5f7;
  --text: #202124;
  --text-soft: #4b5563;
  --text-muted: #7a818c;
  --text-faint: #a4a9b2;
  --border: #e5e7eb;
  --border-strong: #d5d9df;
  --accent: #30343b;
  --accent-hover: #1f2329;
  --brand-accent: #0e9fb3;
  --ok-bg: #f4faf6;
  --ok-txt: #47735a;
  --red-bg: #fff7f6;
  --red-txt: #a85a52;
  --font: "DM Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "Menlo", "Consolas", "Monaco", monospace;
  --r-sm: 5px;
  --r-md: 8px;
  --r-lg: 14px;
  --r-xl: 18px;
  --r-full: 999px;
  --shadow-input: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.05);
}

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

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

button,
textarea {
  font: inherit;
}

.header {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
  z-index: 40;
}

.header-inner {
  max-width: 1440px;
  height: 52px;
  margin: 0 auto;
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 14px;
}

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

.brand-org {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand-org span {
  color: var(--brand-accent);
}

.brand-divider {
  width: 1px;
  height: 18px;
  background: var(--border-strong);
}

.brand-title {
  font-size: 11px;
  font-weight: 650;
  color: var(--text-soft);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.header-sep {
  flex: 1;
}

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

.header-model {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  color: var(--text-faint);
}

.btn-header {
  color: var(--text-soft);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn-header:hover {
  background: var(--surface-muted);
  border-color: var(--border-strong);
  color: var(--text);
}

.chat-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 0 28px;
  min-width: 0;
}

.chat-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
  padding: 32px 0 12px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: #d6dae0;
  border-radius: 8px;
}

.welcome-card {
  width: min(620px, 100%);
  margin: 42px auto 0;
  padding: 0 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
}

.welcome-card h2 {
  display: inline-flex;
  align-items: center;
  color: var(--brand-accent);
  background: #f2fafb;
  border: 1px solid #d7eef2;
  border-radius: var(--r-md);
  padding: 7px 13px;
  font-size: 18px;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: 0;
  margin-bottom: 3px;
}

.welcome-card p {
  max-width: 560px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}

.example-questions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.example-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text-soft);
  padding: 6px 13px 6px 8px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.example-btn:hover {
  background: var(--surface-muted);
  border-color: var(--border-strong);
  color: var(--text);
}

.example-icon {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: #f7f8fa;
  border: 1px solid #eceff3;
  color: var(--text-muted);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.example-icon svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.example-btn:hover .example-icon {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text-soft);
}

.msg {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.msg-user {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 24px;
  height: 24px;
  margin-top: 2px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.msg-body {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.msg-user .msg-body {
  align-items: flex-end;
}

.msg-bubble {
  font-size: 14.5px;
  line-height: 1.7;
  word-break: break-word;
}

.msg-user .msg-bubble {
  max-width: min(620px, 78%);
  padding: 9px 13px;
  background: var(--surface-muted);
  border: 1px solid #edf0f3;
  border-radius: var(--r-lg);
  border-bottom-right-radius: var(--r-sm);
  color: var(--text);
}

.msg-assistant .msg-bubble {
  max-width: 760px;
  color: var(--text);
}

.msg-assistant .msg-bubble:empty {
  display: none;
}

.assistant-progress {
  max-width: 700px;
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.assistant-progress:empty {
  display: none;
}

.assistant-progress p {
  margin-bottom: 6px;
}

.assistant-progress p:last-child {
  margin-bottom: 0;
}

.assistant-progress code {
  font-family: var(--mono);
  font-size: 11.5px;
  background: #f1f2f4;
  border: 1px solid #eaecf0;
  border-radius: 4px;
  padding: 1px 4px;
}

.assistant-progress ul,
.assistant-progress ol {
  padding-left: 18px;
  margin: 6px 0;
}

.assistant-progress li {
  margin-bottom: 2px;
}

.assistant-progress .code-block {
  margin: 7px 0;
  padding: 8px 10px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.assistant-answer {
  margin-top: 1px;
}

.msg-bubble p {
  margin-bottom: 10px;
}

.msg-bubble p:last-child {
  margin-bottom: 0;
}

.msg-bubble strong {
  font-weight: 650;
}

.msg-bubble em {
  color: var(--text-soft);
}

.msg-bubble code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: #f0f1f3;
  border: 1px solid #e9ebee;
  border-radius: 4px;
  padding: 1px 5px;
}

.msg-bubble ul,
.msg-bubble ol {
  padding-left: 22px;
  margin: 8px 0 10px;
}

.msg-bubble li {
  margin-bottom: 4px;
}

.msg-bubble .compact-list {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 3px 18px;
  padding-left: 0;
  margin: 7px 0 12px;
}

.msg-bubble .compact-list li {
  position: relative;
  margin: 0;
  padding-left: 12px;
  color: var(--text-soft);
}

.msg-bubble .compact-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.78em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-faint);
}

.msg-bubble h3 {
  margin: 16px 0 7px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.35;
  font-weight: 650;
}

.code-block {
  margin: 10px 0;
  padding: 10px 12px;
  background: #f5f6f8;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  color: #30343b;
}

.thinking-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 2px 0;
  width: fit-content;
}

.t-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #aeb4bd;
  opacity: 0.45;
  animation: tPulse 1.2s ease-in-out infinite;
}

.t-dot:nth-child(2) {
  animation-delay: 0.16s;
}

.t-dot:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes tPulse {
  0%, 70%, 100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  35% {
    opacity: 0.9;
    transform: translateY(-2px);
  }
}

.tool-area {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}

.tool-activity {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  max-width: 100%;
  color: var(--text-muted);
  font-size: 11.5px;
  line-height: 1.3;
}

.tool-activity-icon {
  width: 10px;
  height: 10px;
  border: 1.5px solid #d2d6dc;
  border-top-color: var(--text-muted);
  border-radius: 50%;
  flex-shrink: 0;
}

.tool-activity.running .tool-activity-icon {
  animation: actSpin 0.9s linear infinite;
}

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

.tool-activity-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.steps-chip {
  max-width: 100%;
  display: inline-block;
}

.steps-chip summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  color: var(--text-muted);
  background: transparent;
  border: 0;
  border-radius: var(--r-full);
  padding: 1px 0;
  font-size: 11.5px;
  line-height: 1.35;
  font-weight: 500;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.steps-chip summary::-webkit-details-marker {
  display: none;
}

.steps-chip summary::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-1px);
  opacity: 0.65;
  transition: transform 0.15s;
}

.steps-chip[open] summary::after {
  transform: rotate(225deg) translate(-1px, -1px);
}

.steps-chip summary:hover {
  color: var(--text);
}

.steps-chip-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}

.steps-expanded {
  width: min(560px, 100%);
  margin-top: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}

.step-detail {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.step-detail-header {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.4;
}

.step-detail-header span:last-child {
  color: var(--text-muted);
}

.step-detail-sql {
  max-height: 120px;
  margin-left: 20px;
  padding: 7px 9px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: #f7f8fa;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: #555d68;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
}

.result-table-wrap {
  max-width: 100%;
  margin-top: 8px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}

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

.result-table th {
  padding: 7px 10px;
  background: #f8f9fa;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.result-table td {
  max-width: 240px;
  padding: 7px 10px;
  border-bottom: 1px solid #eef0f3;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-table tr:last-child td {
  border-bottom: 0;
}

.result-table tbody tr:hover {
  background: #fafafa;
}

.result-truncated {
  margin-top: 5px;
  color: var(--text-muted);
  font-size: 11.5px;
}

.chat-input-area {
  flex-shrink: 0;
  padding: 10px 0 22px;
}

.chat-input-inner {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  padding: 10px 10px 10px 16px;
  box-shadow: var(--shadow-input);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-input-inner:focus-within {
  border-color: #b9bec7;
  box-shadow: var(--shadow-input), 0 0 0 3px rgba(31, 35, 41, 0.05);
}

#chat-input {
  flex: 1;
  max-height: 160px;
  resize: none;
  overflow-y: auto;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 14px;
  line-height: 1.55;
}

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

#send-btn {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, transform 0.12s;
}

#send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

#send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.chat-footer {
  margin-top: 9px;
  color: var(--text-faint);
  text-align: center;
  font-size: 10.8px;
  line-height: 1.45;
}

.chat-footer p {
  margin: 1px 0;
}

.chat-footer a {
  color: var(--text-muted);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.chat-footer a:hover {
  color: var(--text);
  border-bottom-color: var(--border-strong);
}

.msg-error .msg-bubble {
  padding: 10px 12px;
  background: var(--red-bg);
  border: 1px solid #f0d1cd;
  border-radius: var(--r-md);
  color: var(--red-txt);
}

/* ── KPI Layout ─────────────────────────────────────────────────────────────── */

.app-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.kpi-sidebar {
  width: 520px;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 20px 14px;
  overflow-y: auto;
  border-right: 1px solid var(--border);
  background: var(--bg);
  align-content: start;
}

.kpi-insight {
  grid-column: 1 / -1;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand-accent);
  border-radius: var(--r-md);
  margin-bottom: 4px;
}

.kpi-insight__loading {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.kpi-insight__tldr {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 10px;
}

.kpi-insight__actions {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kpi-insight__actions li {
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1.4;
  padding-left: 16px;
  position: relative;
}

.kpi-insight__actions li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand-accent);
}

.kpi-rail__category {
  grid-column: 1 / -1;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  padding: 0 2px;
  margin-top: 4px;
}

.kpi-card {
  width: 100%;
  padding: 10px 11px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}

.kpi-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  border-color: var(--border-strong);
}

.kpi-card__title {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 3px;
}

.kpi-card__icon {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  background: #f2fafb;
  color: var(--brand-accent);
  font-size: 9px;
  font-weight: 700;
}

.kpi-card__hero {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  margin-bottom: 2px;
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.kpi-card__mtd-label {
  font-size: 9px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi-card__subs {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin-bottom: 4px;
}

.kpi-card__sub {
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1.3;
}

.kpi-card__sub span {
  font-weight: 600;
  color: var(--text-soft);
}

.kpi-card__deltas {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.kpi-card__delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1;
  padding: 2px 5px;
  border-radius: var(--r-sm);
}

.kpi-card__delta--up {
  color: #1a7a42;
  background: #eefbf3;
}

.kpi-card__delta--down {
  color: #b5423a;
  background: #fef4f3;
}

.kpi-card__yoy {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-faint);
}

/* ── KPI Detail Panel ──────────────────────────────────────────────────────── */

.kpi-detail-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.08);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.kpi-detail-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.kpi-detail-panel {
  position: fixed;
  top: 72px;
  left: 530px;
  width: 420px;
  max-height: calc(100vh - 92px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.12), 0 4px 12px rgba(15, 23, 42, 0.06);
  z-index: 100;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateX(-10px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.kpi-detail-panel.active {
  opacity: 1;
  transform: translateX(0) scale(1);
  pointer-events: auto;
}

.kpi-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.kpi-detail-title {
  font-size: 15px;
  font-weight: 650;
  color: var(--text);
}

.kpi-detail-close {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.kpi-detail-close:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.kpi-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.kpi-detail-chart-wrap {
  width: 100%;
  height: 200px;
  position: relative;
}

.kpi-detail-chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

.kpi-detail-comparisons h4,
.kpi-detail-locations h4 {
  font-size: 12px;
  font-weight: 650;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.kpi-detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.kpi-detail-table th {
  padding: 6px 8px;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 600;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kpi-detail-table td {
  padding: 7px 8px;
  border-bottom: 1px solid #f0f2f4;
  color: var(--text);
}

.kpi-detail-table tr:last-child td {
  border-bottom: 0;
}

.kpi-detail-table tbody tr:hover {
  background: #fafbfc;
}

@media (max-width: 1024px) {
  .kpi-sidebar {
    display: none;
  }
}

@media (max-width: 640px) {
  .header-inner,
  .chat-layout {
    padding-left: 16px;
    padding-right: 16px;
  }

  .header-model {
    display: none;
  }

  .brand-divider,
  .brand-title {
    display: none;
  }

  .chat-messages {
    gap: 20px;
    padding-top: 24px;
  }

  .welcome-card {
    margin-top: 28px;
  }

  .welcome-card h2 {
    font-size: 17px;
  }

  .msg {
    gap: 9px;
  }

  .msg-avatar {
    width: 22px;
    height: 22px;
  }

  .msg-user .msg-bubble {
    max-width: 86%;
  }

  .chat-input-area {
    padding-bottom: 14px;
  }

  .kpi-ticker__inner {
    padding: 6px 12px;
    gap: 4px;
  }

  .kpi-pill {
    padding: 4px 8px;
    gap: 5px;
  }

  .kpi-pill__label {
    display: none;
  }
}


