@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  --bg:        #0c0c10;
  --surface:   #13131a;
  --surface2:  #1a1a24;
  --surface3:  #22222f;
  --border:    #2a2a3a;
  --border2:   #333345;
  --accent:    #6366f1;
  --accent2:   #818cf8;
  --accent-glow: rgba(99,102,241,.18);
  --text:      #e2e8f0;
  --text2:     #94a3b8;
  --text3:     #4b5563;
  --user-bg:   linear-gradient(135deg,#4f46e5,#6366f1);
  --bot-bg:    #1a1a28;
  --danger:    #ef4444;
  --success:   #22c55e;
  --radius:    14px;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Scrollbar ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ── Header ────────────────────────────────────────────────────────────── */
header {
  height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 20;
}

.header-left { display: flex; align-items: center; gap: 11px; }
.header-logo {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 14px var(--accent-glow);
}
.header-title    { font-size: 15px; font-weight: 700; letter-spacing: -.2px; }
.header-subtitle { font-size: 11px; color: var(--text2); margin-top: 1px; }

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

.status-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px 4px 8px;
  font-size: 12px; color: var(--text2);
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--danger);
  transition: background .4s;
}
.status-dot.ok { background: var(--success); animation: pulse 2.4s infinite; }
@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(34,197,94,.4); }
  50%      { box-shadow: 0 0 0 5px rgba(34,197,94,0); }
}

.hdr-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text2);
  padding: 6px 13px; border-radius: 8px;
  cursor: pointer; font-size: 12px; font-weight: 500;
  font-family: inherit;
  transition: all .18s;
}
.hdr-btn:hover { background: var(--surface3); color: var(--text); border-color: var(--border2); }

/* ── Layout ────────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────────────────────────────── */
#sidebar {
  width: 230px;
  min-width: 230px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 14px 10px;
  gap: 6px;
}

.sidebar-section { margin-bottom: 6px; }
.sidebar-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text3);
  padding: 6px 8px 4px;
}

.fn-btn {
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text2);
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 12.5px;
  font-family: inherit;
  font-weight: 500;
  text-align: left;
  display: flex; align-items: center; gap: 9px;
  transition: all .16s;
}
.fn-btn:hover {
  background: var(--surface2);
  border-color: var(--border);
  color: var(--text);
}
.fn-btn:active { background: var(--surface3); }
.fn-btn.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent2);
}
.fn-icon {
  width: 26px; height: 26px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  background: var(--surface2);
  flex-shrink: 0;
  transition: background .16s;
}
.fn-btn:hover .fn-icon  { background: var(--surface3); }
.fn-btn.active .fn-icon { background: var(--accent-glow); }

/* ── Chat ──────────────────────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

#chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

/* ── Message groups ────────────────────────────────────────────────────── */
.msg-group {
  display: flex; flex-direction: column; gap: 3px;
  margin-bottom: 10px;
  animation: msgIn .22s ease-out;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg-group.user { align-items: flex-end; }
.msg-group.bot  { align-items: flex-start; }

.msg-row {
  display: flex; align-items: flex-end; gap: 8px;
  max-width: 80%;
}
.msg-group.user .msg-row { flex-direction: row-reverse; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.avatar.bot  { background: var(--accent); color: #fff; box-shadow: 0 0 10px var(--accent-glow); }
.avatar.user { background: #312e81; color: #a5b4fc; }

.bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-group.user .bubble {
  background: var(--user-bg);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 12px rgba(79,70,229,.3);
}
.msg-group.bot .bubble {
  background: var(--bot-bg);
  color: var(--text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.msg-time {
  font-size: 10px; color: var(--text3);
  padding: 0 4px; margin-top: 1px;
}

/* ── Tool badge ────────────────────────────────────────────────────────── */
.tool-badge {
  align-self: flex-start;
  display: flex; align-items: center; gap: 7px;
  font-size: 11.5px; color: var(--text2);
  padding: 5px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  margin-left: 38px; margin-bottom: 3px;
  animation: msgIn .18s ease-out;
}
.tool-spinner {
  width: 11px; height: 11px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Typing ────────────────────────────────────────────────────────────── */
.typing-wrap {
  display: flex; align-items: flex-end; gap: 8px;
  margin-bottom: 10px;
  animation: msgIn .22s ease-out;
}
.typing {
  display: flex; gap: 5px; align-items: center;
  padding: 12px 15px;
  background: var(--bot-bg);
  border-radius: 16px; border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text3);
  animation: tdot 1.3s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: .18s; }
.typing span:nth-child(3) { animation-delay: .36s; }
@keyframes tdot {
  0%,60%,100% { transform: translateY(0); background: var(--text3); }
  30%         { transform: translateY(-6px); background: var(--accent); }
}

/* ── Input bar ─────────────────────────────────────────────────────────── */
#input-bar {
  padding: 14px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; align-items: flex-end; gap: 10px;
  flex-shrink: 0;
}
.input-wrapper {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 13px;
  transition: border-color .2s, box-shadow .2s;
}
.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
#msg-input {
  width: 100%; border: none; background: transparent;
  padding: 11px 14px;
  font-size: 13.5px; font-family: inherit;
  color: var(--text); resize: none;
  height: 46px; max-height: 130px; outline: none; line-height: 1.5;
}
#msg-input::placeholder { color: var(--text3); }

#send-btn {
  width: 46px; height: 46px; flex-shrink: 0;
  background: var(--accent);
  color: white; border: none; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; cursor: pointer;
  transition: all .18s;
  box-shadow: 0 2px 10px var(--accent-glow);
}
#send-btn:hover    { background: var(--accent2); transform: scale(1.06); }
#send-btn:active   { transform: scale(.96); }
#send-btn:disabled { background: var(--surface3); box-shadow: none; cursor: default; transform: none; }

/* ── Overlay / Modal ───────────────────────────────────────────────────── */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn .18s;
}
.overlay.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 30px;
  width: 440px;
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
  animation: modalIn .2s ease-out;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-hdr {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 22px;
}
.modal-hdr-icon {
  width: 40px; height: 40px; border-radius: 11px;
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  display: flex; align-items: center; justify-content: center; font-size: 19px;
}
.modal-hdr h2 { font-size: 16px; font-weight: 700; }
.modal-hdr p  { font-size: 12px; color: var(--text2); margin-top: 2px; }

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--text2); text-transform: uppercase;
  letter-spacing: .5px; margin-bottom: 6px;
}
.form-group .field {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 13.5px; font-family: inherit;
  color: var(--text); outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.form-group .field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.form-group .field option { background: var(--surface2); }

.modal-btns { display: flex; gap: 9px; margin-top: 22px; justify-content: flex-end; }
.modal-btns button {
  padding: 9px 22px; border-radius: 9px; border: none;
  cursor: pointer; font-size: 13px; font-family: inherit; font-weight: 600;
  transition: all .18s;
}
.btn-cancel { background: var(--surface2); color: var(--text2); border: 1px solid var(--border); }
.btn-cancel:hover { background: var(--surface3); color: var(--text); }
.btn-go {
  background: var(--accent); color: white;
  box-shadow: 0 2px 10px var(--accent-glow);
}
.btn-go:hover { background: var(--accent2); transform: translateY(-1px); }

/* ── SQL editor ──────────────────────────────────────────────────────────── */
.sql-editor {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
  min-height: 140px;
}

/* ── SQL results table ───────────────────────────────────────────────────── */
.sql-result {
  margin-top: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  animation: msgIn .22s ease-out;
  align-self: flex-start;
  max-width: 100%;
  width: calc(100% - 0px);
}
.sql-result-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 14px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px; color: var(--text2);
}
.sql-badge {
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  color: var(--accent2);
  font-size: 10px; font-weight: 700;
  padding: 2px 8px; border-radius: 10px;
}
.sql-table-wrap { overflow-x: auto; max-height: 320px; overflow-y: auto; }
.sql-table { width: 100%; border-collapse: collapse; font-size: 12.5px; white-space: nowrap; }
.sql-table thead th {
  position: sticky; top: 0;
  background: var(--surface2); color: var(--accent2);
  font-weight: 600; padding: 7px 12px; text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
}
.sql-table tbody tr { border-bottom: 1px solid var(--border); transition: background .12s; }
.sql-table tbody tr:last-child { border-bottom: none; }
.sql-table tbody tr:hover { background: var(--surface2); }
.sql-table td { padding: 6px 12px; color: var(--text); max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.sql-table td.null-val { color: var(--text3); font-style: italic; }
.sql-no-rows { padding: 18px; text-align: center; color: var(--text3); font-size: 13px; }
