/* ═══════════════════════════════════════════════════════════════════════════
   BankRAG — AI Banking Assistant  |  Theme System + Full UI
   ═══════════════════════════════════════════════════════════════════════════ */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ── Theme tokens ───────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg-0: #090b10;
  --bg-1: #0f1219;
  --bg-2: #161a24;
  --bg-3: #1e2230;
  --bg-4: #272c3a;
  --bg-hover: #252a38;
  --text-0: #f0f1f4;
  --text-1: #c8cad0;
  --text-2: #8b8f9a;
  --text-3: #5c6070;
  --accent: #4f8ff7;
  --accent-soft: rgba(79, 143, 247, 0.12);
  --accent-hover: #3a7be8;
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.12);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.12);
  --orange: #fb923c;
  --border: rgba(255,255,255,0.06);
  --border-strong: rgba(255,255,255,0.1);
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --glass: rgba(15, 18, 25, 0.8);
}

[data-theme="light"] {
  --bg-0: #ffffff;
  --bg-1: #f8f9fb;
  --bg-2: #f0f1f5;
  --bg-3: #e8eaef;
  --bg-4: #dcdfe6;
  --bg-hover: #eceef3;
  --text-0: #111318;
  --text-1: #3b3f4a;
  --text-2: #6b7080;
  --text-3: #9a9eab;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.08);
  --accent-hover: #1d4ed8;
  --green: #059669;
  --green-soft: rgba(5, 150, 105, 0.08);
  --red: #dc2626;
  --red-soft: rgba(220, 38, 38, 0.08);
  --orange: #ea580c;
  --border: rgba(0,0,0,0.06);
  --border-strong: rgba(0,0,0,0.1);
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
  --glass: rgba(255, 255, 255, 0.85);
}

:root {
  --sidebar-w: 290px;
  --topbar-h: 56px;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

html, body { height: 100%; font-family: var(--font); background: var(--bg-0); color: var(--text-0); overflow: hidden; }
body { display: flex; }

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ═══════════ SIDEBAR ═══════════ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s var(--ease);
  z-index: 100;
  overflow: hidden;
}
.sidebar-top { flex: 1; overflow-y: auto; padding: 16px 14px; }
.sidebar-bottom { padding: 12px 14px 16px; }
.sidebar-divider { height: 1px; background: var(--border); margin-bottom: 12px; }
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 99; backdrop-filter: blur(2px);
}

/* Logo */
.logo { display: flex; align-items: center; gap: 10px; padding: 4px 6px; margin-bottom: 18px; }
.logo-icon {
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent); border-radius: var(--radius-sm);
}
.logo-text { font-size: 18px; font-weight: 800; letter-spacing: -0.02em; }
.logo-badge {
  font-size: 10px; font-weight: 700; padding: 2px 7px;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  color: white; border-radius: 20px; letter-spacing: 0.04em;
}

/* New chat button */
.new-chat-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 10px 14px;
  background: var(--accent-soft); border: 1px solid transparent;
  border-radius: var(--radius-sm); color: var(--accent);
  font: 600 13px var(--font); cursor: pointer;
  transition: all 0.2s var(--ease); margin-bottom: 20px;
}
.new-chat-btn:hover {
  background: var(--accent); color: white;
  box-shadow: 0 4px 16px rgba(79,143,247,0.25);
  transform: translateY(-1px);
}

/* Sidebar sections */
.sidebar-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-3);
  padding: 0 6px; margin-bottom: 8px;
}
.suggestion-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; background: transparent; border: none;
  border-radius: var(--radius-xs); color: var(--text-2);
  font: 400 13px var(--font); text-align: left; cursor: pointer;
  transition: all 0.15s var(--ease); margin-bottom: 2px;
}
.suggestion-btn:hover { background: var(--bg-hover); color: var(--text-0); }
.suggestion-icon { font-size: 15px; flex-shrink: 0; }

/* Theme toggle */
.theme-toggle {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 12px; background: transparent; border: none;
  border-radius: var(--radius-xs); color: var(--text-2);
  font: 400 13px var(--font); cursor: pointer;
  transition: all 0.15s var(--ease); margin-bottom: 10px;
}
.theme-toggle:hover { background: var(--bg-hover); color: var(--text-0); }

/* ═══════════ CHAT HISTORY ═══════════ */
.history-list {
  max-height: 240px; overflow-y: auto;
  margin-bottom: 6px;
}
.history-empty {
  padding: 16px 10px; text-align: center;
  font-size: 12px; color: var(--text-3);
}
.history-item {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 8px 10px; background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-xs); cursor: pointer;
  transition: all 0.15s var(--ease); margin-bottom: 2px;
}
.history-item:hover { background: var(--bg-hover); }
.history-item.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.history-item-body { flex: 1; min-width: 0; }
.history-item-title {
  font-size: 13px; font-weight: 500; color: var(--text-1);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-item.active .history-item-title { color: var(--accent); font-weight: 600; }
.history-item-meta {
  font-size: 11px; color: var(--text-3); margin-top: 1px;
}
.history-del-btn {
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: var(--radius-xs);
  color: var(--text-3); cursor: pointer; flex-shrink: 0;
  opacity: 0; transition: all 0.15s;
}
.history-item:hover .history-del-btn { opacity: 1; }
.history-del-btn:hover { background: var(--red-soft); color: var(--red); }

.clear-history-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; padding: 7px 10px;
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius-xs); color: var(--text-3);
  font: 500 11px var(--font); cursor: pointer;
  transition: all 0.15s var(--ease); margin-top: 4px;
}
.clear-history-btn:hover {
  background: var(--red-soft); border-color: var(--red);
  color: var(--red);
}

/* Status bar */
.status-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; font-size: 12px; color: var(--text-3);
  background: var(--bg-2); border-radius: var(--radius-xs);
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-3); transition: background 0.3s;
  flex-shrink: 0;
}
.status-dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.offline { background: var(--red); }

/* ═══════════ MAIN ═══════════ */
.main {
  flex: 1; display: flex; flex-direction: column; height: 100vh; min-width: 0;
  background: var(--bg-0);
}

/* Top bar */
.topbar {
  height: var(--topbar-h); min-height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; border-bottom: 1px solid var(--border);
  background: var(--glass); backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title h1 { font-size: 15px; font-weight: 700; line-height: 1.2; }
.topbar-sub { font-size: 12px; color: var(--text-3); }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.menu-btn, .icon-btn {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: var(--radius-xs);
  color: var(--text-2); cursor: pointer; transition: all 0.15s;
}
.menu-btn:hover, .icon-btn:hover { background: var(--bg-3); color: var(--text-0); }

.doc-badge {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 10px; font-size: 12px; font-weight: 600;
  color: var(--accent); background: var(--accent-soft);
  border-radius: 20px;
}

/* ═══════════ CHAT AREA ═══════════ */
.chat-area {
  flex: 1; overflow-y: auto; position: relative;
  scroll-behavior: smooth;
}

/* Scroll-to-bottom button */
.scroll-btn {
  position: sticky; bottom: 16px; left: 50%; transform: translateX(-50%);
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  background: var(--bg-3); border: 1px solid var(--border-strong);
  border-radius: 50%; color: var(--text-2); cursor: pointer;
  box-shadow: var(--shadow); transition: all 0.2s; z-index: 10;
}
.scroll-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }

/* ═══════════ WELCOME ═══════════ */
.welcome {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; min-height: 100%; padding: 40px 24px 60px;
  position: relative;
}
.welcome-glow {
  position: absolute; top: 20%; left: 50%; transform: translateX(-50%);
  width: 300px; height: 300px;
  background: radial-gradient(circle, var(--accent-soft) 0%, transparent 70%);
  pointer-events: none; opacity: 0.6;
}
.welcome-avatar {
  width: 64px; height: 64px; display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 20px; margin-bottom: 20px;
  position: relative; z-index: 1;
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
.welcome-title {
  font-size: 26px; font-weight: 800; margin-bottom: 10px;
  background: linear-gradient(135deg, var(--text-0) 30%, var(--accent));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  position: relative; z-index: 1;
}
.welcome-desc {
  font-size: 14px; color: var(--text-2); line-height: 1.7;
  max-width: 460px; margin-bottom: 36px;
  position: relative; z-index: 1;
}
.welcome-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; width: 100%; max-width: 680px;
  position: relative; z-index: 1;
}
.welcome-card {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px; background: var(--bg-2);
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; transition: all 0.2s var(--ease);
  text-align: left;
}
.welcome-card:hover {
  border-color: var(--accent); background: var(--accent-soft);
  transform: translateY(-2px); box-shadow: 0 8px 24px rgba(79,143,247,0.1);
}
.wc-icon { font-size: 22px; flex-shrink: 0; margin-top: 1px; }
.wc-body { min-width: 0; }
.wc-title { font-size: 13px; font-weight: 700; margin-bottom: 3px; color: var(--text-0); }
.wc-desc { font-size: 12px; color: var(--text-2); line-height: 1.5; }
.welcome-card:hover .wc-desc { color: var(--text-1); }

/* ═══════════ MESSAGES ═══════════ */
.messages {
  max-width: 820px; width: 100%; margin: 0 auto;
  display: flex; flex-direction: column; gap: 0;
  padding: 16px 24px 32px;
}
.message {
  display: flex; gap: 14px; padding: 20px 0;
  border-bottom: 1px solid var(--border);
  animation: msgIn 0.35s var(--ease);
}
.message:last-child { border-bottom: none; }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg-avatar {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 2px; font-size: 14px; font-weight: 700;
}
.message.user .msg-avatar { background: var(--accent); color: white; }
.message.assistant .msg-avatar {
  background: var(--green-soft); color: var(--green);
  border: 1px solid rgba(52,211,153,0.2);
}
.msg-body { flex: 1; min-width: 0; }
.msg-header {
  display: flex; align-items: center; gap: 8px; margin-bottom: 6px;
}
.msg-name { font-size: 13px; font-weight: 700; }
.message.user .msg-name { color: var(--accent); }
.message.assistant .msg-name { color: var(--green); }
.msg-time { font-size: 11px; color: var(--text-3); }

.msg-content {
  font-size: 14px; line-height: 1.75; color: var(--text-1);
  word-wrap: break-word; overflow-wrap: break-word;
}
.msg-content p { margin-bottom: 10px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content ul, .msg-content ol { padding-left: 22px; margin-bottom: 10px; }
.msg-content li { margin-bottom: 4px; }
.msg-content strong { font-weight: 600; color: var(--text-0); }
.msg-content code {
  background: var(--bg-3); padding: 2px 7px; border-radius: 4px;
  font: 13px var(--mono);
}
.msg-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 6px 14px; margin: 8px 0;
  background: var(--accent-soft); border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
  color: var(--text-1);
}
.msg-content h1, .msg-content h2, .msg-content h3 {
  font-weight: 700; margin: 16px 0 8px; color: var(--text-0);
}
.msg-content h1 { font-size: 18px; }
.msg-content h2 { font-size: 16px; }
.msg-content h3 { font-size: 14px; }

/* Sources & actions */
.msg-footer { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.source-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 500; padding: 4px 10px;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 20px; color: var(--text-2);
  transition: all 0.15s;
}
.source-tag:hover { border-color: var(--accent); color: var(--accent); }

.msg-actions { display: flex; gap: 4px; margin-top: 8px; }
.action-btn {
  width: 30px; height: 30px; display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; border-radius: var(--radius-xs);
  color: var(--text-3); cursor: pointer; transition: all 0.15s;
}
.action-btn:hover { background: var(--bg-3); color: var(--text-0); }
.action-btn.copied { color: var(--green); }

/* Typing indicator */
.typing-dots { display: flex; gap: 5px; padding: 12px 0; }
.typing-dots span {
  width: 8px; height: 8px; background: var(--text-3); border-radius: 50%;
  animation: pulse 1.4s infinite ease-in-out both;
}
.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes pulse {
  0%, 80%, 100% { transform: scale(0.5); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ═══════════ INPUT ═══════════ */
.input-container { padding: 0 24px 18px; }
.input-form { max-width: 820px; margin: 0 auto; }
.input-box {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 14px 10px 20px;
  background: var(--bg-2); border: 1px solid var(--border-strong);
  border-radius: 18px; transition: all 0.25s var(--ease);
}
.input-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow);
}
textarea {
  flex: 1; border: none; background: none; color: var(--text-0);
  font: 400 14px var(--font); resize: none; outline: none;
  max-height: 160px; padding: 6px 0; line-height: 1.6;
}
textarea::placeholder { color: var(--text-3); }

.input-actions { display: flex; align-items: center; gap: 6px; }
.char-count { font-size: 11px; color: var(--text-3); min-width: 20px; text-align: right; }
.send-btn {
  width: 38px; height: 38px; border-radius: 12px; border: none;
  background: var(--accent); color: white; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all 0.2s var(--ease);
}
.send-btn:hover:not(:disabled) {
  background: var(--accent-hover); transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(79,143,247,0.3);
}
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.input-footer {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  font-size: 11px; color: var(--text-3); margin-top: 8px;
  flex-wrap: wrap;
}
.input-footer strong { font-weight: 600; color: var(--text-2); }
.dot-sep { width: 3px; height: 3px; background: var(--text-3); border-radius: 50%; margin: 0 4px; }

/* ═══════════ ERROR TOAST ═══════════ */
.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  padding: 12px 22px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; z-index: 1000;
  animation: toastIn 0.3s var(--ease), toastOut 0.3s 3.5s forwards;
}
.toast.error { background: var(--red-soft); border: 1px solid var(--red); color: var(--red); }
.toast.success { background: var(--green-soft); border: 1px solid var(--green); color: var(--green); }
@keyframes toastIn { from { transform: translateX(-50%) translateY(16px); opacity: 0; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(-50%) translateY(-8px); pointer-events: none; } }

/* ═══════════ RESPONSIVE ═══════════ */
@media (max-width: 900px) {
  .welcome-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar.open + .sidebar-overlay { display: block; }
  .welcome-grid { grid-template-columns: 1fr; max-width: 360px; }
  .chat-area { padding: 0; }
  .messages { padding: 12px 16px 24px; }
  .input-container { padding: 0 12px 12px; }
  .topbar { padding: 0 12px; }
}
@media (max-width: 480px) {
  .welcome-title { font-size: 22px; }
  .welcome-desc { font-size: 13px; }
  .message { gap: 10px; }
  .msg-avatar { width: 28px; height: 28px; font-size: 12px; }
}
