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

:root {
  --bg: #0d0d14;
  --sidebar-bg: #0a0a10;
  --card: #13131f;
  --card2: #1a1a28;
  --border: #1f1f35;
  --border2: #2a2a44;
  --accent: #7c6df0;
  --accent2: #a395f5;
  --accent-glow: rgba(124,109,240,0.18);
  --text: #e8e8f0;
  --muted: #6b6b8a;
  --muted2: #4a4a65;
  --green: #3ecf8e;
  --red: #f86868;
  --code-bg: #0f0f1a;
  --user-bubble: #1e1a3a;
  --user-border: #3a2f7a;
  --ai-bubble: #121220;
  --sidebar-w: 280px;
  --topbar-h: 58px;
  --input-h: 130px;
  --radius: 12px;
}

html, body { height: 100%; font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; overflow: hidden; }

/* ── LAYOUT ── */
body { display: flex; height: 100vh; }

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  transition: transform 0.25s ease, width 0.25s ease;
  z-index: 20;
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-w))); position: absolute; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px;
  border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon { font-size: 20px; }
.logo-text { font-size: 16px; font-weight: 700; background: linear-gradient(135deg, var(--accent2), var(--accent)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 10px 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--muted);
}
.sidebar-search input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.sidebar-search input::placeholder { color: var(--muted2); }

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
.conv-item {
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 1px 0;
  transition: background 0.15s;
  position: relative;
  group: true;
}
.conv-item:hover { background: var(--card); }
.conv-item.active { background: var(--accent-glow); border: 1px solid var(--border2); }
.conv-item-text { flex: 1; font-size: 13px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item-meta { font-size: 11px; color: var(--muted2); }
.conv-delete { opacity: 0; background: none; border: none; color: var(--red); cursor: pointer; padding: 2px 4px; border-radius: 4px; transition: opacity 0.15s; flex-shrink: 0; }
.conv-item:hover .conv-delete { opacity: 1; }

.conv-date-label { font-size: 11px; color: var(--muted2); text-transform: uppercase; letter-spacing: 0.8px; padding: 10px 10px 4px; }

.sidebar-footer {
  padding: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: all 0.15s;
  width: 100%;
}
.sidebar-btn:hover { background: var(--card2); color: var(--text); border-color: var(--border2); }
.sidebar-btn.danger:hover { color: var(--red); border-color: rgba(248,104,104,0.3); }

/* ── MAIN ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
  transition: margin-left 0.25s;
}

/* ── TOPBAR ── */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.topbar-title { flex: 1; font-size: 15px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.model-badge {
  font-size: 11px;
  color: var(--accent2);
  background: var(--accent-glow);
  border: 1px solid rgba(124,109,240,0.3);
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 500;
  white-space: nowrap;
}

/* ── ICON BTN ── */
.icon-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.icon-btn:hover { background: var(--card); color: var(--text); border-color: var(--border); }

/* ── MESSAGES ── */
.messages-wrap {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
.messages { max-width: 820px; margin: 0 auto; padding: 24px 20px; display: flex; flex-direction: column; gap: 20px; }

/* Welcome screen */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 20px;
  gap: 16px;
  animation: fadeIn 0.4s ease;
}
.welcome-icon { font-size: 48px; }
.welcome h1 { font-size: 32px; font-weight: 800; background: linear-gradient(135deg, var(--accent2), var(--accent)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.welcome p { color: var(--muted); max-width: 440px; font-size: 15px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.suggestion-chip {
  background: var(--card);
  border: 1px solid var(--border2);
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  transition: all 0.15s;
}
.suggestion-chip:hover { background: var(--card2); color: var(--text); border-color: var(--accent); }

/* Message bubbles */
.msg { display: flex; flex-direction: column; gap: 6px; animation: slideUp 0.2s ease; }
.msg-meta { display: flex; align-items: center; gap: 8px; }
.msg-avatar {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
.msg.user .msg-avatar { background: var(--user-border); color: var(--accent2); }
.msg.ai .msg-avatar { background: var(--accent-glow); color: var(--accent2); border: 1px solid rgba(124,109,240,0.3); }
.msg-role { font-size: 12px; font-weight: 600; }
.msg.user .msg-role { color: var(--accent2); }
.msg.ai .msg-role { color: var(--accent); }
.msg-time { font-size: 11px; color: var(--muted2); margin-left: auto; }

.msg-bubble {
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.7;
  position: relative;
}
.msg.user .msg-bubble { background: var(--user-bubble); border: 1px solid var(--user-border); margin-left: 36px; }
.msg.ai .msg-bubble { background: var(--ai-bubble); border: 1px solid var(--border); margin-left: 36px; }

/* Markdown inside bubbles */
.msg-bubble p { margin-bottom: 10px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble strong { color: var(--text); font-weight: 600; }
.msg-bubble em { color: var(--accent2); font-style: italic; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { color: var(--text); font-weight: 700; margin: 16px 0 8px; }
.msg-bubble h1 { font-size: 18px; } .msg-bubble h2 { font-size: 16px; } .msg-bubble h3 { font-size: 14px; }
.msg-bubble ul, .msg-bubble ol { margin: 8px 0 8px 20px; }
.msg-bubble li { margin: 3px 0; color: var(--text); }
.msg-bubble a { color: var(--accent2); text-decoration: none; } .msg-bubble a:hover { text-decoration: underline; }
.msg-bubble blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--muted); margin: 8px 0; }
.msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.msg-bubble table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 10px 0; }
.msg-bubble th { background: var(--card2); color: var(--accent2); padding: 8px 10px; text-align: left; }
.msg-bubble td { padding: 7px 10px; border-bottom: 1px solid var(--border); }

/* Code blocks */
.code-block { position: relative; margin: 10px 0; border-radius: 8px; overflow: hidden; }
.code-block-header { background: var(--card2); border: 1px solid var(--border); border-bottom: none; border-radius: 8px 8px 0 0; padding: 6px 14px; display: flex; align-items: center; justify-content: space-between; }
.code-lang { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; }
.copy-code-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 11px; font-family: inherit; padding: 2px 8px; border-radius: 4px; transition: all 0.15s; display: flex; align-items: center; gap: 4px; }
.copy-code-btn:hover { background: var(--border); color: var(--text); }
.code-block pre { background: var(--code-bg); border: 1px solid var(--border); border-radius: 0 0 8px 8px; padding: 14px; overflow-x: auto; margin: 0; }
.code-block code { font-family: 'JetBrains Mono', monospace; font-size: 13px; color: #c9d1d9; line-height: 1.6; }
.msg-bubble code:not(.code-block code) { background: var(--code-bg); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--accent2); }

/* Thinking animation */
.typing-indicator { display: flex; gap: 5px; padding: 6px 0; align-items: center; }
.typing-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: typing 1.2s infinite ease-in-out; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* Bubble actions */
.bubble-actions { display: flex; gap: 4px; margin-top: 6px; margin-left: 36px; opacity: 0; transition: opacity 0.15s; }
.msg:hover .bubble-actions { opacity: 1; }
.bubble-action-btn { background: none; border: 1px solid var(--border); color: var(--muted); padding: 3px 10px; border-radius: 6px; cursor: pointer; font-size: 11px; font-family: inherit; transition: all 0.15s; display: flex; align-items: center; gap: 4px; }
.bubble-action-btn:hover { background: var(--card); color: var(--text); }

/* ── INPUT AREA ── */
.input-area {
  padding: 12px 20px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: border-color 0.2s;
}
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.input-wrap textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  max-height: 180px;
  overflow-y: auto;
  scrollbar-width: thin;
}
.input-wrap textarea::placeholder { color: var(--muted2); }
.input-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.send-btn {
  background: var(--accent);
  border: none;
  color: white;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.send-btn:hover { background: var(--accent2); transform: scale(1.05); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.send-btn.stop { background: var(--red); }

.file-preview { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.file-chip { background: var(--card2); border: 1px solid var(--border2); border-radius: 6px; padding: 4px 10px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.file-chip-remove { background: none; border: none; color: var(--muted2); cursor: pointer; font-size: 14px; line-height: 1; }
.file-chip-remove:hover { color: var(--red); }

.input-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; padding: 0 2px; }
.char-count { font-size: 11px; color: var(--muted2); }
.hint { font-size: 11px; color: var(--muted2); }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--card);
  border: 1px solid var(--border2);
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  scrollbar-width: thin;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  animation: modalIn 0.2s ease;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 17px; font-weight: 700; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 4px; }

.setting-group { display: flex; flex-direction: column; gap: 6px; }
.setting-group label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; }
.setting-group input[type=text],
.setting-group input[type=password],
.setting-group input[type=number],
.setting-group select,
.setting-group textarea {
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 9px 12px;
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
}
.setting-group input:focus, .setting-group select:focus, .setting-group textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
.setting-group select { cursor: pointer; }
.setting-group textarea { resize: vertical; min-height: 100px; line-height: 1.6; }
.setting-group input[type=range] { padding: 0; border: none; background: none; box-shadow: none; accent-color: var(--accent); }
.input-row { display: flex; gap: 8px; align-items: center; }

.fetch-status { font-size: 12px; min-height: 16px; }
.fetch-status.loading { color: var(--accent2); }
.fetch-status.success { color: var(--green); }
.fetch-status.error { color: var(--red); }

.pill-btn {
  background: var(--card2);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.pill-btn:hover { background: var(--border); }
.pill-btn.accent { background: var(--accent); border-color: var(--accent); color: white; }
.pill-btn.accent:hover { background: var(--accent2); border-color: var(--accent2); }
.pill-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--card2);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s;
  z-index: 9999;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

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

/* ── ANIMATIONS ── */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 30% { transform: translateY(-5px); opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── TOGGLE SWITCH ── */
.toggle-switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: var(--border2); border-radius: 24px; transition: 0.2s; }
.toggle-slider:before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.2s; }
.toggle-switch input:checked + .toggle-slider { background: var(--accent); }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(18px); }

/* ── TOOL EVENTS ── */
.tool-event { margin: 4px 0 4px 36px; }
.tool-header { display: inline-flex; align-items: center; gap: 6px; background: var(--code-bg); border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; font-size: 12px; }
.tool-icon { font-size: 13px; }
.tool-name { color: var(--accent2); font-weight: 600; font-family: 'JetBrains Mono', monospace; }
.tool-input { color: var(--muted); max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── BRIDGE SECTION ── */
.bridge-section { background: rgba(62,207,142,0.04); border: 1px solid rgba(62,207,142,0.15); border-radius: 10px; padding: 14px; }
#bridgeFieldsGroup { border-left: 2px solid var(--accent); padding-left: 14px; margin-top: 4px; display: flex; flex-direction: column; gap: 14px; }

/* ── RESPONSIVE ── */
@media (max-width: 640px) {
  :root { --sidebar-w: 260px; }
  .sidebar { position: fixed; height: 100vh; }
  .hint { display: none; }
  .welcome h1 { font-size: 24px; }
  .suggestions { flex-direction: column; }
  .suggestion-chip { text-align: left; }
}
