:root {
  --rta-red: #e30613;
  --rta-red-dark: #b3050f;
  --rta-red-soft: #fdecee;
  --ink: #1b1d22;
  --ink-soft: #555b66;
  --line: #e6e8ec;
  --bg: #f5f6f8;
  --card: #ffffff;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--card);
  border-bottom: 3px solid var(--rta-red);
  box-shadow: 0 2px 6px rgba(0,0,0,.04);
}

.brand { display: flex; align-items: center; gap: 14px; }
.logo { height: 44px; width: auto; }
.brand-text h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand-text p {
  margin: 2px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.status {
  font-size: 12px;
  color: var(--ink-soft);
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
}
.status.thinking { color: var(--rta-red); border-color: var(--rta-red); background: var(--rta-red-soft); }
.status.error { color: #fff; background: var(--rta-red-dark); border-color: var(--rta-red-dark); }

.layout {
  display: grid;
  grid-template-columns: minmax(380px, 1fr) minmax(420px, 1.4fr);
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 71px);
}
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; height: auto; }
}

.chat-pane {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.bubble {
  max-width: 86%;
  padding: 12px 14px;
  border-radius: 14px;
  line-height: 1.5;
  border: 1px solid var(--line);
  background: #fff;
}
.msg.user .bubble {
  background: var(--rta-red);
  color: #fff;
  border-color: var(--rta-red);
  border-top-right-radius: 4px;
}
.msg.bot .bubble { border-top-left-radius: 4px; }
.msg.bot.welcome .bubble { background: var(--rta-red-soft); border-color: #f6c8cc; }

.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre.sql {
  background: #0f1115;
  color: #e6e8ec;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12px;
  overflow-x: auto;
  margin-top: 8px;
}
.bubble details { margin-top: 8px; font-size: 12px; color: var(--ink-soft); }
.bubble details summary { cursor: pointer; user-select: none; }

.suggestions { padding: 0; margin: 6px 0 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: #fff;
  border: 1px solid var(--rta-red);
  color: var(--rta-red);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.chip:hover { background: var(--rta-red); color: #fff; }

.composer {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #fafbfc;
}
.composer textarea {
  flex: 1;
  resize: none;
  padding: 10px 12px;
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  outline: none;
  transition: border-color .15s;
}
.composer textarea:focus { border-color: var(--rta-red); }
.composer button {
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: var(--rta-red);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.composer button:hover { background: var(--rta-red-dark); }
.composer button:disabled { background: #c9ccd2; cursor: not-allowed; }

.dashboard {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 0;
}
.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.dash-header h2 { margin: 0; font-size: 16px; font-weight: 700; }
.ghost {
  background: none;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}
.ghost:hover { border-color: var(--rta-red); color: var(--rta-red); }

.charts {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.charts .empty {
  margin: auto;
  color: var(--ink-soft);
  text-align: center;
  font-size: 13px;
}
.chart-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 14px 8px;
  background: #fff;
}
.chart-card h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}
.chart-card .canvas-wrap { position: relative; height: 280px; }
.chart-card .meta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--ink-soft);
  display: flex;
  justify-content: space-between;
}

.spinner {
  display: inline-block;
  width: 10px; height: 10px;
  border: 2px solid var(--rta-red);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -1px;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
