/* =========================================
   QUERYMIND — Design System
   Theme: Industrial Terminal meets Data Studio
   ========================================= */

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

:root {
  --bg-0:       #0a0b0d;
  --bg-1:       #111318;
  --bg-2:       #181c22;
  --bg-3:       #1f242d;
  --bg-4:       #272d38;
  --border:     #2a3040;
  --border-hi:  #3d4a60;
  --text-0:     #f0f2f5;
  --text-1:     #9ba8be;
  --text-2:     #5a6880;
  --accent:     #f5a623;
  --accent-dim: #a06810;
  --accent-glow:#f5a62330;
  --green:      #3ecf8e;
  --red:        #f56565;
  --blue:       #63b3ed;
  --purple:     #9f7aea;
  --mono:       'JetBrains Mono', monospace;
  --sans:       'DM Sans', sans-serif;
  --display:    'Syne', sans-serif;
  --radius:     6px;
  --radius-lg:  12px;
  --sidebar-w:  280px;
  --transition: 0.18s ease;
}

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

body {
  font-family: var(--sans);
  background: var(--bg-0);
  color: var(--text-0);
  font-size: 14px;
  line-height: 1.6;
}

/* ── APP LAYOUT ─────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── SIDEBAR ────────────────────────────── */
.sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-header {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--display);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-0);
}

.logo-icon {
  color: var(--accent);
  font-size: 22px;
  animation: pulse-hex 3s ease-in-out infinite;
}

@keyframes pulse-hex {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.logo-sub {
  font-size: 11px;
  color: var(--text-2);
  margin-top: 4px;
  font-family: var(--mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.sidebar-section {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.section-label {
  display: block;
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.15em;
  color: var(--text-2);
  margin-bottom: 10px;
  text-transform: uppercase;
}

/* API Key */
.api-key-wrapper {
  display: flex;
  gap: 6px;
}

.api-input {
  flex: 1;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  color: var(--text-0);
  font-family: var(--mono);
  font-size: 11px;
  outline: none;
  transition: border-color var(--transition);
}

.api-input:focus { border-color: var(--accent); }

.save-btn {
  background: var(--accent);
  color: var(--bg-0);
  border: none;
  border-radius: var(--radius);
  padding: 7px 12px;
  font-family: var(--display);
  font-weight: 700;
  font-size: 11px;
  cursor: pointer;
  transition: opacity var(--transition);
}
.save-btn:hover { opacity: 0.85; }

.hint-text {
  font-size: 10px;
  color: var(--text-2);
  margin-top: 6px;
  font-family: var(--mono);
}

/* DB Badge */
.db-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-bottom: 8px;
  font-family: var(--mono);
  font-size: 12px;
}

.db-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  flex-shrink: 0;
  animation: blink 2s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.schema-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-1);
  font-family: var(--mono);
  font-size: 10px;
  padding: 5px 10px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: all var(--transition);
}
.schema-toggle:hover { border-color: var(--accent); color: var(--accent); }

.schema-panel {
  display: none;
  margin-top: 10px;
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-1);
  line-height: 1.8;
  max-height: 200px;
  overflow-y: auto;
}

.schema-panel.open { display: block; }

.schema-table-name {
  color: var(--accent);
  font-weight: 600;
  margin-top: 8px;
}
.schema-table-name:first-child { margin-top: 0; }

.schema-col { color: var(--text-2); padding-left: 10px; }
.schema-col .col-type { color: var(--blue); }

/* Load Buttons */
.load-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.load-btn {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-1);
  font-family: var(--sans);
  font-size: 11px;
  padding: 7px 8px;
  cursor: pointer;
  text-align: center;
  transition: all var(--transition);
  display: block;
  width: 100%;
}

.load-btn:hover, .load-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

.upload-btn { cursor: pointer; }

/* Suggestions */
.suggestions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.suggestion-item {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 11px;
  color: var(--text-1);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  font-family: var(--sans);
  line-height: 1.4;
}

.suggestion-item:hover {
  border-color: var(--accent-dim);
  color: var(--accent);
  background: var(--accent-glow);
}

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

.gh-link {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-2);
  text-decoration: none;
  transition: color var(--transition);
}
.gh-link:hover { color: var(--accent); }

/* ── MAIN AREA ───────────────────────────── */
.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-0);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-1);
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.page-title {
  font-family: var(--display);
  font-size: 16px;
  font-weight: 700;
  color: var(--text-0);
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-1);
  font-size: 18px;
  cursor: pointer;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-2);
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.idle { background: var(--text-2); }
.status-dot.thinking { background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: blink 0.8s ease-in-out infinite; }
.status-dot.success { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.error { background: var(--red); box-shadow: 0 0 6px var(--red); }

.clear-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-2);
  font-family: var(--mono);
  font-size: 10px;
  padding: 5px 10px;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: 0.05em;
}
.clear-btn:hover { border-color: var(--red); color: var(--red); }

/* ── CHAT AREA ───────────────────────────── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.chat-area::-webkit-scrollbar { width: 5px; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Welcome Screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
  padding: 60px 20px;
  gap: 16px;
}

.welcome-icon {
  font-size: 56px;
  color: var(--accent);
  animation: float 4s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.welcome-screen h2 {
  font-family: var(--display);
  font-size: 28px;
  font-weight: 800;
  color: var(--text-0);
  letter-spacing: -0.5px;
}

.welcome-screen p {
  color: var(--text-1);
  max-width: 420px;
  font-size: 14px;
}

.welcome-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.example-pill {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  color: var(--text-1);
  font-family: var(--sans);
  font-size: 12px;
  padding: 7px 16px;
  cursor: pointer;
  transition: all var(--transition);
}
.example-pill:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

/* ── MESSAGES ────────────────────────────── */
.message {
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: slideUp 0.25s ease;
}

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

.message.user { align-items: flex-end; }
.message.assistant { align-items: flex-start; }

.msg-bubble {
  max-width: 680px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  font-size: 14px;
}

.message.user .msg-bubble {
  background: var(--accent);
  color: var(--bg-0);
  border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
  font-weight: 500;
}

.message.assistant .msg-bubble {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-0);
  border-radius: 4px var(--radius-lg) var(--radius-lg) var(--radius-lg);
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-2);
  padding: 0 4px;
}

.msg-meta .role-tag {
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.message.user .msg-meta { flex-direction: row-reverse; }
.message.user .role-tag { color: var(--accent-dim); }
.message.assistant .role-tag { color: var(--blue); }

/* SQL pill button */
.sql-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-3);
  border: 1px solid var(--border-hi);
  border-radius: 4px;
  padding: 3px 10px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--accent);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  margin-top: 4px;
}
.sql-pill:hover { background: var(--accent-glow); border-color: var(--accent); }

/* ── RESULTS TABLE ──────────────────────── */
.results-block {
  max-width: 100%;
  overflow-x: auto;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-top: 4px;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-2);
}

.results-count {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  color: var(--green);
  font-weight: 600;
}

.results-time { color: var(--text-2); }

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 12px;
}

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

th:first-child { border-radius: 0; }

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

tr:last-child td { border-bottom: none; }

tr:hover td { background: var(--bg-2); }

td.num { color: var(--blue); text-align: right; }
td.null { color: var(--text-2); font-style: italic; }

/* Chart container */
.chart-container {
  padding: 16px;
  border-top: 1px solid var(--border);
}

/* Thinking indicator */
.thinking-msg {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-1);
  font-size: 13px;
  max-width: 320px;
}

.thinking-dots span {
  display: inline-block;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: dot-bounce 1.2s ease-in-out infinite;
  margin: 0 1px;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* Error block */
.error-block {
  background: #1a0f0f;
  border: 1px solid #5a2020;
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  color: var(--red);
  font-family: var(--mono);
  font-size: 12px;
  max-width: 600px;
}

/* ── INPUT AREA ─────────────────────────── */
.input-area {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-1);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 16px;
  transition: border-color var(--transition);
}

.input-wrapper:focus-within { border-color: var(--accent); }

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-0);
  font-family: var(--sans);
  font-size: 14px;
  resize: none;
  line-height: 1.5;
  max-height: 140px;
  overflow-y: auto;
  padding-top: 3px;
}

.chat-input::placeholder { color: var(--text-2); }

.send-btn {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-end;
  transition: opacity var(--transition), transform var(--transition);
}

.send-btn:hover:not(:disabled) { opacity: 0.85; transform: scale(1.05); }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.send-icon { color: var(--bg-0); font-size: 16px; font-weight: 900; }

.input-hint {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-2);
  margin-top: 8px;
  padding-left: 2px;
}

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

/* ── SQL MODAL ──────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-1);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius-lg);
  width: min(640px, 90vw);
  overflow: hidden;
  animation: slideUp 0.2s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-1);
}

.modal-close {
  background: none; border: none;
  color: var(--text-2); cursor: pointer; font-size: 14px;
  transition: color var(--transition);
}
.modal-close:hover { color: var(--text-0); }

.modal-code {
  padding: 18px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--accent);
  background: var(--bg-0);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
  line-height: 1.7;
}

.modal-actions {
  display: flex;
  gap: 8px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
}

.modal-copy, .modal-run {
  padding: 8px 16px;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition);
}

.modal-copy {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-1);
}
.modal-copy:hover { border-color: var(--accent); color: var(--accent); }

.modal-run {
  background: var(--accent);
  border: none;
  color: var(--bg-0);
  font-weight: 700;
}
.modal-run:hover { opacity: 0.85; }

/* ── TOAST ──────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px; right: 24px;
  background: var(--bg-3);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-0);
  z-index: 200;
  animation: slideUp 0.2s ease;
  pointer-events: none;
}

/* ── RESPONSIVE ─────────────────────────── */
@media (max-width: 700px) {
  .app { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed; inset: 0; z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }

  .mobile-menu-btn { display: block; }

  .chat-area { padding: 16px; }
  .input-area { padding: 12px 16px 16px; }
  .topbar { padding: 0 16px; }
}

/* ── SCROLLBAR GLOBAL ───────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
