/* ===== RESET & VARIABLES ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-base: #070810;
  --bg-surface: #0d0f1a;
  --bg-card: #12141f;
  --bg-input: #181b28;
  --border: rgba(255,255,255,0.06);
  --border-hover: rgba(255,255,255,0.12);
  --accent: #5B6EF5;
  --accent-2: #9B59F5;
  --accent-glow: rgba(91,110,245,0.3);
  --text-primary: #E8EAF6;
  --text-secondary: #7B80A0;
  --text-muted: #454860;
  --user-bubble: #1e2140;
  --ai-bubble: #0f1120;
  --success: #4ade80;
  --error: #f87171;
  --sidebar-w: 280px;
  --topbar-h: 60px;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
}

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

body {
  font-family: 'Syne', sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ===== BACKGROUND EFFECTS ===== */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image: 
    linear-gradient(rgba(91,110,245,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(91,110,245,0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  pointer-events: none;
  z-index: 0;
}

.bg-orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  z-index: 0;
}
.orb-1 {
  width: 600px; height: 600px;
  top: -200px; left: -150px;
  background: radial-gradient(circle, rgba(91,110,245,0.12) 0%, transparent 70%);
}
.orb-2 {
  width: 500px; height: 500px;
  bottom: -150px; right: -100px;
  background: radial-gradient(circle, rgba(155,89,245,0.1) 0%, transparent 70%);
}
.orb-3 {
  width: 300px; height: 300px;
  top: 50%; left: 50%;
  background: radial-gradient(circle, rgba(91,110,245,0.06) 0%, transparent 70%);
}

/* ===== LAYOUT ===== */
.main-layout {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  margin-left: var(--sidebar-w);
  transition: margin-left 0.3s ease;
}

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform 0.3s ease;
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.logo-icon svg { width: 18px; height: 18px; }

.logo-text {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fff 30%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.2s;
}
.sidebar-close:hover { background: var(--border); color: var(--text-primary); }

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px;
  padding: 11px 16px;
  background: linear-gradient(135deg, rgba(91,110,245,0.15), rgba(155,89,245,0.1));
  border: 1px solid rgba(91,110,245,0.3);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: 'Syne', sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s;
  letter-spacing: 0.2px;
}
.new-chat-btn:hover {
  background: linear-gradient(135deg, rgba(91,110,245,0.25), rgba(155,89,245,0.2));
  border-color: rgba(91,110,245,0.5);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--accent-glow);
}
.new-chat-btn .btn-icon {
  width: 22px; height: 22px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
}

.sidebar-section {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
}

.section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 6px 8px;
}

.history-empty {
  padding: 24px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
}
.history-item:hover { background: var(--border); color: var(--text-primary); }
.history-item .hist-icon { font-size: 14px; flex-shrink: 0; }
.history-item .hist-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

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

.model-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.model-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.model-badge span { font-size: 12px; color: var(--text-secondary); font-weight: 500; }
.version-text { font-size: 11px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace; }

/* ===== TOPBAR ===== */
.topbar {
  height: var(--topbar-h);
  background: rgba(7,8,16,0.8);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.menu-btn {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: background 0.2s;
}
.menu-btn:hover { background: var(--border); }
.menu-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text-secondary);
  border-radius: 2px;
  transition: all 0.3s;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 10px var(--success);
  animation: pulse 2s infinite;
}

.clear-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
}
.clear-btn:hover { border-color: var(--error); color: var(--error); background: rgba(248,113,113,0.05); }

/* ===== CHAT CONTAINER ===== */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar { width: 4px; }
.chat-container::-webkit-scrollbar-track { background: transparent; }
.chat-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ===== WELCOME SCREEN ===== */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--topbar-h) - 140px);
  padding: 40px 24px;
  text-align: center;
  animation: fadeUp 0.6s ease;
}

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

.welcome-icon {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  margin-bottom: 24px;
  box-shadow: 0 8px 32px var(--accent-glow);
  animation: float 3s ease-in-out infinite;
}
.welcome-icon svg { width: 32px; height: 32px; }

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

.welcome-title {
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 800;
  letter-spacing: -1px;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.gradient-text {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-sub {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 40px;
  max-width: 380px;
  font-weight: 400;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: 480px;
  width: 100%;
}

.suggestion-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  text-align: left;
  transition: all 0.25s;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-family: 'Syne', sans-serif;
}
.suggestion-card:hover {
  border-color: rgba(91,110,245,0.4);
  background: rgba(91,110,245,0.06);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(91,110,245,0.1);
}
.sug-icon { font-size: 22px; }
.sug-text { font-size: 13px; font-weight: 600; color: var(--text-secondary); line-height: 1.4; }

/* ===== MESSAGES ===== */
.messages-wrapper {
  padding: 0 max(24px, calc(50% - 380px));
}

.message {
  display: flex;
  gap: 14px;
  margin-bottom: 24px;
  animation: messageIn 0.3s ease;
}

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

.message-avatar {
  flex-shrink: 0;
  padding-top: 2px;
}

.avatar-ai, .avatar-user {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
}

.avatar-ai {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  box-shadow: 0 4px 12px var(--accent-glow);
}
.avatar-ai svg { width: 16px; height: 16px; }

.avatar-user {
  background: var(--user-bubble);
  border: 1px solid rgba(91,110,245,0.3);
  color: var(--accent);
  font-size: 13px;
}

.pulse-avatar { animation: avatarPulse 1.5s infinite; }
@keyframes avatarPulse {
  0%, 100% { box-shadow: 0 4px 12px var(--accent-glow); }
  50% { box-shadow: 0 4px 24px rgba(91,110,245,0.6); }
}

.message-body { flex: 1; min-width: 0; }
.message-name {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
}

.message-bubble {
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 14.5px;
  line-height: 1.75;
  font-weight: 400;
  word-wrap: break-word;
}

.ai-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  color: var(--text-primary);
}

.user-bubble {
  background: linear-gradient(135deg, rgba(91,110,245,0.15), rgba(155,89,245,0.1));
  border: 1px solid rgba(91,110,245,0.25);
  border-radius: var(--radius) 4px var(--radius) var(--radius);
  color: var(--text-primary);
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  font-family: 'JetBrains Mono', monospace;
}

/* User message layout */
.user-message {
  flex-direction: row-reverse;
}
.user-message .message-name { text-align: right; }
.user-message .message-time { text-align: right; }

/* Error bubble */
.error-bubble {
  background: rgba(248,113,113,0.08);
  border-color: rgba(248,113,113,0.25);
  color: var(--error);
}
.error-avatar {
  background: rgba(248,113,113,0.15) !important;
  box-shadow: none !important;
  color: var(--error) !important;
  font-size: 16px !important;
}

/* Code formatting */
.message-content pre {
  background: #0a0b14;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  overflow-x: auto;
  margin: 12px 0;
}
.message-content .code-block {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.6;
  color: #a8b5e8;
}
.message-content .inline-code {
  background: rgba(91,110,245,0.12);
  border: 1px solid rgba(91,110,245,0.2);
  border-radius: 5px;
  padding: 1px 7px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--accent);
}
.message-content h1, .message-content h2, .message-content h3 {
  font-weight: 700;
  margin: 16px 0 8px;
  color: var(--text-primary);
}
.message-content h1 { font-size: 20px; }
.message-content h2 { font-size: 17px; }
.message-content h3 { font-size: 15px; }
.message-content ul { padding-left: 20px; margin: 8px 0; }
.message-content li { margin: 4px 0; }
.message-content strong { font-weight: 700; color: var(--text-primary); }
.message-content em { font-style: italic; color: var(--text-secondary); }
.message-content p { margin: 8px 0; }
.message-content p:first-child { margin-top: 0; }
.message-content p:last-child { margin-bottom: 0; }

/* ===== TYPING INDICATOR ===== */
.typing-bubble {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 16px 20px;
}
.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotBounce 1.4s infinite ease-in-out;
}
.dot:nth-child(1) { animation-delay: 0s; }
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes dotBounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.typing-indicator {
  padding: 0 max(24px, calc(50% - 380px));
}

/* ===== INPUT AREA ===== */
.input-area {
  flex-shrink: 0;
  padding: 16px max(24px, calc(50% - 400px)) 20px;
  background: rgba(7,8,16,0.85);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
}

.input-form { width: 100%; }

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 4px 4px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-wrapper:focus-within {
  border-color: rgba(91,110,245,0.4);
  box-shadow: 0 0 0 3px rgba(91,110,245,0.08);
}

.chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: 'Syne', sans-serif;
  font-size: 14.5px;
  font-weight: 400;
  line-height: 1.6;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  padding: 10px 0;
  overflow-y: auto;
}
.chat-input::placeholder { color: var(--text-muted); }
.chat-input::-webkit-scrollbar { width: 3px; }
.chat-input::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.send-btn {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  border-radius: 10px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  box-shadow: 0 4px 12px var(--accent-glow);
  margin-bottom: 4px;
}
.send-btn:hover { transform: scale(1.05); box-shadow: 0 6px 20px var(--accent-glow); }
.send-btn:active { transform: scale(0.97); }
.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  padding: 0 4px;
}
.char-count {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
}
.input-hint {
  font-size: 11px;
  color: var(--text-muted);
}

/* ===== OVERLAY ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
  backdrop-filter: blur(4px);
}

/* ===== UTILS ===== */
.hidden { display: none !important; }

/* ===== HTMX LOADING STATE ===== */
.htmx-request .send-btn { opacity: 0.6; pointer-events: none; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-close { display: flex; }
  .main-layout { margin-left: 0; }
  .menu-btn { display: flex; }

  .suggestion-grid {
    grid-template-columns: 1fr 1fr;
    max-width: 360px;
  }
  .welcome-title { font-size: 26px; }
  .input-hint { display: none; }
  .messages-wrapper { padding: 0 16px; }
  .typing-indicator { padding: 0 16px; }
  .input-area { padding: 12px 16px 16px; }
}

@media (max-width: 480px) {
  .suggestion-grid { grid-template-columns: 1fr; }
}
