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

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-sidebar: #0f1525;
  --bg-input: #1e2a45;
  --bg-user-msg: #1e2a45;
  --bg-hover: #1e2a4580;
  --bg-active: #2a3a5c;
  --text-primary: #e8eaf0;
  --text-secondary: #8892a8;
  --text-muted: #5a6480;
  --accent: #7c6aef;
  --accent-hover: #9584ff;
  --accent-glow: #7c6aef40;
  --border: #ffffff0d;
  --border-light: #ffffff15;
  --success: #4ade80;
  --error: #f87171;
  --gradient-1: linear-gradient(135deg, #7c6aef 0%, #a78bfa 100%);
  --gradient-2: linear-gradient(135deg, #1e2a45 0%, #16213e 100%);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.15);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.25);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.35);
  --shadow-glow: 0 0 30px var(--accent-glow);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body, html {
  height: 100%;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

/* ============ LAYOUT ============ */
#app-container {
  display: flex;
  height: 100vh; /* fallback */
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
}

/* ============ SIDEBAR ============ */
#sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  transition: var(--transition);
  position: relative;
  z-index: 10;
}

#sidebar::after {
  content: '';
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 1px;
  background: linear-gradient(to bottom, transparent, var(--accent-glow), transparent);
  pointer-events: none;
}

.sidebar-header {
  padding: 20px 16px;
}

#new-chat-btn {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--gradient-2);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0.01em;
}

#new-chat-btn:hover {
  background: var(--bg-active);
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

#new-chat-btn i {
  font-size: 0.8rem;
  color: var(--accent);
}

.sidebar-label {
  padding: 16px 16px 8px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

#conversations-list {
  flex-grow: 1;
  overflow-y: auto;
  padding: 4px 10px;
}

.conv-item {
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: var(--transition);
  position: relative;
}

.conv-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.conv-item.active {
  background: var(--bg-active);
  color: var(--text-primary);
  font-weight: 500;
}

.conv-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

/* ============ MAIN CONTENT ============ */
#main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-primary);
  overflow: hidden;
}

/* Subtle background pattern */
#main-content::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 0%, var(--accent-glow) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

/* ============ HEADER ============ */
header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  backdrop-filter: blur(20px);
  background: rgba(26, 26, 46, 0.8);
  z-index: 5;
  position: relative;
}

#model-select {
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  padding: 8px 36px 8px 14px;
  border-radius: var(--radius-md);
  font-family: 'Inter', sans-serif;
  font-size: 0.825rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238892a8' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

#model-select:hover {
  border-color: var(--accent);
}

#model-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#model-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

#chat-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

/* ============ CHAT WINDOW ============ */
#chat-window {
  flex-grow: 1;
  overflow-y: auto;
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 1;
  position: relative;
  scroll-behavior: smooth;
}

/* Welcome state */
.welcome-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 16px;
  animation: fadeInUp 0.6s ease;
}

.welcome-logo {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  background: var(--gradient-1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: white;
  box-shadow: var(--shadow-glow);
}

.welcome-title {
  font-size: 1.6rem;
  font-weight: 700;
  background: var(--gradient-1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  max-width: 400px;
  text-align: center;
  line-height: 1.5;
}

/* ============ MESSAGES ============ */
.message-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 20px 24px;
  animation: fadeInUp 0.35s ease;
}

.message-wrapper.user {
  background: transparent;
}

.message-wrapper.ai {
  background: rgba(255,255,255,0.02);
}

.message-content {
  max-width: 780px;
  width: 100%;
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.8rem;
  transition: var(--transition);
}

.user .avatar {
  background: var(--gradient-1);
  color: white;
  box-shadow: 0 2px 10px rgba(124,106,239,0.3);
}

.ai .avatar {
  background: linear-gradient(135deg, #10b981 0%, #34d399 100%);
  color: white;
  box-shadow: 0 2px 10px rgba(16,185,129,0.3);
}

.text {
  line-height: 1.7;
  word-wrap: break-word;
  overflow-x: auto;
  flex-grow: 1;
  font-size: 0.925rem;
  color: var(--text-primary);
  min-width: 0;
}

.text p { margin-bottom: 12px; }
.text p:last-child { margin-bottom: 0; }

.text ul, .text ol {
  padding-left: 24px;
  margin-bottom: 12px;
}

.text li { margin-bottom: 4px; }

.text strong { color: #fff; font-weight: 600; }

.text a {
  color: var(--accent-hover);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: var(--transition);
}

.text a:hover { border-bottom-color: var(--accent-hover); }

/* ============ CODE BLOCKS ============ */
.text pre {
  background-color: #0c1222;
  padding: 0;
  border-radius: var(--radius-md);
  margin: 16px 0;
  position: relative;
  border: 1px solid var(--border-light);
  overflow: hidden;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #141c30;
  padding: 8px 16px;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  font-weight: 500;
  letter-spacing: 0.02em;
}

.copy-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  font-family: 'Inter', sans-serif;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  transition: var(--transition);
}

.copy-btn:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.08);
}

.text code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  padding: 14px 18px;
  display: block;
  overflow-x: auto;
  line-height: 1.6;
}

.text p code, .text li code {
  display: inline;
  padding: 2px 7px;
  background: rgba(124,106,239,0.15);
  border-radius: 5px;
  font-size: 0.84em;
  color: var(--accent-hover);
  border: 1px solid rgba(124,106,239,0.2);
}

/* ============ TYPING CURSOR ============ */
.typing-cursor::after {
  content: "▋";
  animation: blink 0.8s infinite;
  margin-left: 2px;
  color: var(--accent);
  font-size: 0.9rem;
}

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

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

/* ============ ZIP BUTTON ============ */
.zip-btn {
  margin-top: 14px;
  padding: 8px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: var(--transition);
}

.zip-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
  box-shadow: var(--shadow-glow);
}

/* ============ INPUT AREA ============ */
#input-container {
  padding: 16px 24px 24px;
  display: flex;
  justify-content: center;
  z-index: 5;
  position: relative;
}

.input-wrapper {
  max-width: 780px;
  width: 100%;
  position: relative;
  background: var(--bg-input);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-light);
  transition: var(--transition);
  box-shadow: var(--shadow-md);
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-md), 0 0 0 3px var(--accent-glow);
}

#user-input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  padding: 16px 56px 16px 22px;
  resize: none;
  max-height: 200px;
  outline: none;
  font-family: 'Inter', sans-serif;
  font-size: 0.925rem;
  line-height: 1.5;
}

#user-input::placeholder {
  color: var(--text-muted);
}

#send-btn {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 36px;
  height: 36px;
  background: var(--gradient-1);
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  font-size: 0.85rem;
}

#send-btn:disabled {
  opacity: 0.25;
  cursor: not-allowed;
  transform: none;
}

#send-btn:not(:disabled):hover {
  transform: scale(1.08);
  box-shadow: var(--shadow-glow);
}

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

.mobile-only-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.2rem;
  cursor: pointer;
  margin-right: 12px;
  transition: var(--transition);
}

.mobile-only-btn:hover {
  color: var(--accent);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.open {
  display: block;
  opacity: 1;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .mobile-only-btn {
    display: inline-block;
  }
  #sidebar { 
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    z-index: 1000;
  }
  #sidebar.open {
    transform: translateX(0);
  }
  
  .message-wrapper { padding: 16px; }
  .message-content { max-width: 100%; gap: 12px; }
  
  header { padding: 12px 16px; }
  #input-container { padding: 12px 16px 20px; }
  
  .welcome-title { font-size: 1.35rem; }
  .welcome-subtitle { font-size: 0.85rem; padding: 0 16px; }
  .welcome-logo { width: 48px; height: 48px; font-size: 1.2rem; }
}
