/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-0:      #0a0a0a;   /* page background */
  --bg-1:      #111111;   /* sidebar */
  --bg-2:      #1a1a1a;   /* cards, chat bubble bg */
  --bg-3:      #222222;   /* input, hovered items */
  --bg-4:      #2a2a2a;   /* borders, dividers */

  --text-0:    #ffffff;   /* primary text */
  --text-1:    #d0d0d0;   /* secondary text */
  --text-2:    #888888;   /* muted text, hints */
  --text-3:    #555555;   /* very muted */

  --accent:    #e0e0e0;   /* interactive accent (subtle) */
  --border:    #2a2a2a;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;

  --sidebar-w: 260px;
  --topbar-h:  52px;
  --input-h:   80px;
}

html, body {
  height: 100%;
  background: var(--bg-0);
  color: var(--text-1);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ──────────────────────────────────────────────────────────────── */
body { display: flex; overflow: hidden; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.22s ease, opacity 0.22s ease;
  overflow: hidden;
}

.sidebar.collapsed { width: 0; opacity: 0; border: none; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text-0);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.logo svg { opacity: 0.85; }

.sidebar-section-label {
  padding: 18px 16px 6px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
}

.suggestion-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-4) transparent;
}

.suggestion-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 12.5px;
  text-align: left;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggestion-item:hover { background: var(--bg-3); color: var(--text-1); }

.suggestion-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: 1px dashed var(--border);
  color: var(--text-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  padding: 8px 10px;
  margin-top: 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.suggestion-toggle-btn:hover { 
  background: var(--bg-3); 
  color: var(--text-0);
  border-color: var(--text-3);
}

.suggestion-toggle-btn svg {
  opacity: 0.8;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.footer-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--text-2);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  flex-shrink: 0;
  transition: background 0.3s;
}
.dot.ok      { background: #4caf50; }
.dot.error   { background: #f44336; }
.dot.loading { background: #ff9800; }

/* ── Main ────────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-0);
}

.topbar-title {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-0);
  flex: 1;
}

.model-badge {
  font-size: 11px;
  color: var(--text-3);
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 3px 9px;
  border-radius: 99px;
  letter-spacing: 0.02em;
}

/* ── Icon button ─────────────────────────────────────────────────────────── */
.icon-btn {
  background: none;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-3); color: var(--text-0); }

/* ── Chat window ─────────────────────────────────────────────────────────── */
.chat-window {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-4) transparent;
  position: relative;
}

/* ── Welcome screen ──────────────────────────────────────────────────────── */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px 24px;
  text-align: center;
  gap: 12px;
}

.welcome-icon {
  color: var(--text-3);
  margin-bottom: 4px;
}

.welcome-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-0);
  letter-spacing: -0.02em;
}

.welcome-sub {
  font-size: 13.5px;
  color: var(--text-2);
  max-width: 360px;
}

.welcome-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
  max-width: 600px;
}

.chip {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-1);
  padding: 7px 14px;
  border-radius: 99px;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.chip:hover { background: var(--bg-3); border-color: var(--text-3); }

/* ── Messages ────────────────────────────────────────────────────────────── */
.messages { display: flex; flex-direction: column; gap: 0; }

.message-group {
  display: flex;
  flex-direction: column;
  padding: 10px 20px;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
  gap: 6px;
}

/* User bubble */
.bubble-user {
  align-self: flex-end;
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-0);
  padding: 10px 16px;
  border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
  max-width: 80%;
  font-size: 14px;
  word-break: break-word;
}

/* Assistant reply */
.bubble-assistant {
  align-self: flex-start;
  max-width: 100%;
}

.assistant-label {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

/* Summary message */
.result-message {
  font-size: 14px;
  color: var(--text-0);
  padding: 2px 0 8px;
  font-weight: 400;
}

/* ── SQL Block ────────────────────────────────────────────────────────────── */
.sql-block {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin: 6px 0;
}

.sql-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.sql-header:hover { background: var(--bg-3); }

.sql-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 7px;
}

.sql-label svg { opacity: 0.6; }

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

.copy-btn {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 7px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  font-family: var(--font);
}
.copy-btn:hover { color: var(--text-1); background: var(--bg-4); }

.chevron {
  color: var(--text-3);
  transition: transform 0.2s;
  display: flex;
}
.chevron.open { transform: rotate(180deg); }

.sql-body {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease;
}
.sql-body.open { max-height: 400px; }

.sql-code {
  display: block;
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 12.5px;
  color: #bfc7d5;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.7;
  overflow-x: auto;
}

/* SQL keyword highlighting */
.kw  { color: #c678dd; }
.fn  { color: #61afef; }
.str { color: #98c379; }
.num { color: #d19a66; }

/* ── Data Table ──────────────────────────────────────────────────────────── */
.table-block {
  margin: 6px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.table-meta {
  padding: 8px 14px;
  font-size: 11px;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.table-scroll { overflow-x: auto; max-height: 300px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--bg-4) transparent; }

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

thead { position: sticky; top: 0; z-index: 1; }

th {
  background: var(--bg-2);
  color: var(--text-2);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 9px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 8px 14px;
  color: var(--text-1);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-2); }

/* ── Chart Block ─────────────────────────────────────────────────────────── */
.chart-block {
  margin: 6px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-2);
}

.chart-meta {
  padding: 8px 14px;
  font-size: 11px;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.chart-container { padding: 8px; }

/* ── Error bubble ─────────────────────────────────────────────────────────── */
.bubble-error {
  background: var(--bg-2);
  border: 1px solid #3a1a1a;
  color: #ff7070;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

/* ── Loading ─────────────────────────────────────────────────────────────── */
.loading-dots {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 12px 16px;
}

.loading-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  animation: blink 1.4s infinite ease-in-out;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
  40%           { opacity: 1;   transform: scale(1); }
}

/* ── Input area ──────────────────────────────────────────────────────────── */
.input-area {
  padding: 12px 20px 10px;
  border-top: 1px solid var(--border);
  background: var(--bg-0);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 10px 10px 16px;
  transition: border-color 0.2s;
  max-width: 860px;
  margin: 0 auto;
}

.input-wrapper:focus-within { border-color: #444444; }

.question-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-0);
  font-family: var(--font);
  font-size: 14px;
  resize: none;
  max-height: 160px;
  line-height: 1.5;
  padding: 0;
  scrollbar-width: thin;
}

.question-input::placeholder { color: var(--text-3); }

.send-btn {
  background: var(--accent);
  border: none;
  color: #000000;
  cursor: pointer;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}

.send-btn:hover   { background: #cccccc; }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.input-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-3);
  margin-top: 6px;
  max-width: 860px;
  margin-left: auto;
  margin-right: auto;
}

.input-hint kbd {
  font-family: var(--mono);
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 10px;
  color: var(--text-2);
}

/* ── Timing badge ─────────────────────────────────────────────────────────── */
.timing {
  font-size: 11px;
  color: var(--text-3);
  padding-top: 4px;
}

/* ── Scrollbar styling ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a3a; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .sidebar { display: none; }
  .message-group { padding: 10px 14px; }
  .topbar { padding: 0 14px; }
  .input-area { padding: 10px 14px 8px; }
}
