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

:root {
  --blue: #1a73e8;
  --blue-light: #e8f0fe;
  --green: #00AC47;
  --text-primary: #202124;
  --text-secondary: #5f6368;
  --border: #e0e0e0;
  --bg-sidebar: #f8f9fa;
  --bg-main: #fff;
  --bg-hover: #f1f3f4;
  --bubble-bot: #f1f3f4;
  --bubble-user: #d3e3fd;
  --radius: 20px;
  --font: 'Google Sans Text', 'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body { height: 100%; font-family: var(--font); color: var(--text-primary); background: var(--bg-main); }

body { display: flex; overflow: hidden; }

/* Sidebar */
.sidebar {
  width: 260px; min-width: 260px; background: var(--bg-sidebar);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  transition: transform 0.2s ease;
}
.sidebar-header {
  padding: 12px 16px; display: flex; align-items: center;
  border-bottom: 1px solid var(--border); height: 64px;
}
.sidebar-logo { display: flex; align-items: center; gap: 10px; font-family: 'Google Sans', sans-serif; font-size: 22px; font-weight: 500; color: var(--text-primary); }
.new-chat-btn {
  margin: 12px 16px; padding: 10px 20px; border-radius: 24px;
  border: 1px solid var(--border); background: var(--bg-main);
  font-family: var(--font); font-size: 14px; font-weight: 500;
  color: var(--text-primary); cursor: pointer; display: flex;
  align-items: center; gap: 10px; transition: box-shadow 0.15s;
}
.new-chat-btn:hover { box-shadow: 0 1px 3px rgba(0,0,0,0.15); }
.sidebar-section { padding: 8px 0; }
.sidebar-section-title { padding: 8px 24px; font-size: 11px; font-weight: 500; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.8px; }
.sidebar-item {
  display: flex; align-items: center; gap: 12px; padding: 8px 24px;
  font-size: 14px; cursor: pointer; border-radius: 0 24px 24px 0;
  margin-right: 12px; transition: background 0.1s;
}
.sidebar-item:hover { background: var(--bg-hover); }
.sidebar-item.active { background: var(--blue-light); color: var(--blue); font-weight: 500; }
.avatar-small { font-size: 20px; width: 28px; text-align: center; }

/* Main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* Header */
.chat-header {
  height: 64px; padding: 0 16px; display: flex; align-items: center;
  gap: 12px; border-bottom: 1px solid var(--border); background: var(--bg-main);
  flex-shrink: 0;
}
.menu-btn { display: none; background: none; border: none; cursor: pointer; padding: 8px; border-radius: 50%; }
.menu-btn:hover { background: var(--bg-hover); }
.avatar-header { font-size: 28px; }
.chat-header-info { display: flex; flex-direction: column; }
.chat-header-name { font-size: 16px; font-weight: 500; }
.chat-header-status { font-size: 12px; color: var(--green); }

/* Messages */
.messages {
  flex: 1; overflow-y: auto; padding: 16px 24px; display: flex;
  flex-direction: column; gap: 2px;
}
.welcome-msg {
  margin: auto; text-align: center; padding: 40px;
}
.welcome-icon { font-size: 64px; margin-bottom: 12px; }
.welcome-title { font-size: 22px; font-weight: 500; margin-bottom: 4px; }
.welcome-sub { font-size: 14px; color: var(--text-secondary); }

.msg-row { display: flex; align-items: flex-start; gap: 8px; max-width: 85%; padding: 4px 0; }
.msg-row.user { align-self: flex-end; flex-direction: row-reverse; }
.msg-row.bot { align-self: flex-start; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 20px;
  flex-shrink: 0; margin-top: 2px;
}
.msg-row.user .msg-avatar {
  background: var(--blue); color: white; font-size: 14px; font-weight: 500;
}

.msg-bubble {
  padding: 8px 14px; border-radius: var(--radius); font-size: 14px;
  line-height: 1.5; word-wrap: break-word; min-width: 20px;
}
.msg-row.bot .msg-bubble { background: var(--bubble-bot); border-top-left-radius: 4px; }
.msg-row.user .msg-bubble { background: var(--bubble-user); border-top-right-radius: 4px; }

/* Markdown inside bubbles */
.msg-bubble p { margin: 0 0 8px 0; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble pre {
  background: #1e1e1e; color: #d4d4d4; padding: 12px 16px;
  border-radius: 8px; overflow-x: auto; font-size: 13px;
  margin: 8px 0; font-family: 'Roboto Mono', 'Fira Code', monospace;
}
.msg-bubble code {
  background: rgba(0,0,0,0.06); padding: 1px 5px; border-radius: 4px;
  font-size: 13px; font-family: 'Roboto Mono', 'Fira Code', monospace;
}
.msg-bubble pre code { background: none; padding: 0; }
.msg-bubble ul, .msg-bubble ol { margin: 4px 0 4px 20px; }
.msg-bubble li { margin: 2px 0; }
.msg-bubble blockquote {
  border-left: 3px solid var(--border); padding-left: 12px;
  color: var(--text-secondary); margin: 8px 0;
}
.msg-bubble a { color: var(--blue); }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 { margin: 8px 0 4px; font-size: 15px; font-weight: 600; }
.msg-bubble table { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.msg-bubble th, .msg-bubble td { border: 1px solid var(--border); padding: 4px 10px; }
.msg-bubble th { background: var(--bg-hover); font-weight: 500; }

/* Typing indicator */
.typing-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--text-secondary); margin: 0 1px; animation: bounce 1.4s infinite ease-in-out; }
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); } 40% { transform: translateY(-6px); } }

/* Input */
.input-area { padding: 8px 24px 16px; background: var(--bg-main); }
.input-form { display: flex; }
.input-wrapper {
  flex: 1; display: flex; align-items: flex-end;
  border: 1px solid var(--border); border-radius: 24px;
  padding: 6px 6px 6px 18px; transition: border-color 0.2s;
  background: var(--bg-main);
}
.input-wrapper:focus-within { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }

#messageInput {
  flex: 1; border: none; outline: none; font-family: var(--font);
  font-size: 14px; resize: none; max-height: 160px; line-height: 1.4;
  padding: 6px 0; background: transparent;
}
.send-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: var(--blue); color: white; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.15s; flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.3; cursor: default; }
.send-btn:not(:disabled):hover { opacity: 0.85; }

/* Overlay for mobile */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 99;
}

/* Mobile */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .menu-btn { display: flex; }
  .messages { padding: 12px 12px; }
  .input-area { padding: 8px 12px 12px; }
  .msg-row { max-width: 92%; }
}

/* Scrollbar */
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 3px; }
.messages::-webkit-scrollbar-thumb:hover { background: #a0a0a0; }
