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

:root {
  --bg-primary: #08080d;
  --bg-secondary: #0e0e16;
  --bg-tertiary: #161625;
  --bg-card: #12121f;
  --text-primary: #e8e8f0;
  --text-secondary: #a0a0b8;
  --text-muted: #5a5a72;
  --accent-green: #00ff88;
  --accent-purple: #9945ff;
  --accent-blue: #14f195;
  --accent-pink: #ff6b9d;
  --accent-orange: #f7931a;
  --accent-cyan: #00d4ff;
  --border-color: #1e1e32;
  --sol-color: #9945ff;
  --eth-color: #627eea;
  --bnb-color: #f3ba2f;
  --base-color: #0052ff;
  --danger: #ff4757;
  --success: #2ed573;
  --warning: #ffa502;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --font-main: 'Inter', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Visibility helpers */
.mobile-only { display: none; }
.desktop-only { display: block; }

/* === App Layout === */
#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
}

/* === Sidebar Overlay === */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.3s ease;
}

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

/* === Sidebar === */
#sidebar {
  width: 310px;
  min-width: 310px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform 0.3s ease;
  z-index: 100;
}

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#sidebar-close {
  display: none;
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 22px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

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

.logo-icon {
  font-size: 24px;
  opacity: 0.9;
}

.logo-text {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--accent-green), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.3px;
}

/* Topic Navigation */
.topic-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
}

.topic-nav h3 {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: 12px 8px 6px;
  margin-bottom: 2px;
}

.topic-nav h3:first-child {
  padding-top: 4px;
}

.topic-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 12.5px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
}

.topic-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  transform: translateX(3px);
}

.topic-btn span {
  font-size: 14px;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
}

.chain-badges {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.chain-badge {
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.chain-badge.sol {
  background: rgba(153, 69, 255, 0.15);
  color: var(--sol-color);
  border: 1px solid rgba(153, 69, 255, 0.3);
}

.chain-badge.eth {
  background: rgba(98, 126, 234, 0.15);
  color: var(--eth-color);
  border: 1px solid rgba(98, 126, 234, 0.3);
}

.chain-badge.bnb {
  background: rgba(243, 186, 47, 0.15);
  color: var(--bnb-color);
  border: 1px solid rgba(243, 186, 47, 0.3);
}

.chain-badge.base {
  background: rgba(0, 82, 255, 0.15);
  color: var(--base-color);
  border: 1px solid rgba(0, 82, 255, 0.3);
}

.disclaimer {
  font-size: 10px;
  color: var(--text-muted);
  font-style: italic;
}

/* === Chat Area === */
#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

#sidebar-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.header-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-logo-icon {
  display: none;
  font-size: 20px;
}

.header-info h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 7px;
  height: 7px;
  background: var(--accent-green);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

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

.status-text {
  font-size: 12px;
  color: var(--text-muted);
}

/* === Mobile Quick Topics === */
#mobile-topics {
  display: none;
}

.mobile-topics-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  font-weight: 600;
  padding: 0 4px 8px;
}

.mobile-topics-scroll {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mobile-topic-pill {
  flex-shrink: 0;
  padding: 9px 14px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 500;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.mobile-topic-pill:active {
  background: var(--bg-tertiary);
  border-color: var(--accent-green);
  color: var(--text-primary);
  transform: scale(0.96);
}

/* === Messages === */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

.message {
  display: flex;
  gap: 12px;
  max-width: 85%;
  animation: fadeIn 0.3s ease;
}

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

.bot-message {
  align-self: flex-start;
}

.user-message {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
}

.user-message .message-avatar {
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-pink));
  font-size: 13px;
  color: white;
}

.message-bubble {
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  line-height: 1.65;
  font-size: 13.5px;
}

.bot-message .message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-top-left-radius: 4px;
}

.user-message .message-bubble {
  background: linear-gradient(135deg, #1a1a3e, #252545);
  color: white;
  border: 1px solid var(--border-color);
  border-top-right-radius: 4px;
}

.message-bubble h2 {
  font-size: 17px;
  margin-bottom: 10px;
  background: linear-gradient(135deg, var(--accent-green), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.message-bubble h3 {
  font-size: 14px;
  color: var(--accent-green);
  margin: 14px 0 6px;
  letter-spacing: -0.2px;
}

.message-bubble p {
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.bot-message .message-bubble p {
  color: var(--text-secondary);
}

.user-message .message-bubble p {
  color: rgba(255, 255, 255, 0.9);
}

.message-bubble ul, .message-bubble ol {
  margin: 8px 0;
  padding-left: 20px;
}

.message-bubble li {
  margin-bottom: 5px;
  color: var(--text-secondary);
}

.message-bubble strong {
  color: var(--text-primary);
  font-weight: 600;
}

.user-message .message-bubble strong {
  color: white;
}

.message-bubble code {
  background: rgba(153, 69, 255, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent-purple);
}

.message-bubble .warning-box {
  background: rgba(255, 71, 87, 0.08);
  border: 1px solid rgba(255, 71, 87, 0.25);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 10px 0;
  font-size: 12.5px;
}

.message-bubble .warning-box strong {
  color: var(--danger);
}

.message-bubble .tip-box {
  background: rgba(0, 255, 136, 0.06);
  border: 1px solid rgba(0, 255, 136, 0.2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 10px 0;
  font-size: 12.5px;
}

.message-bubble .tip-box strong {
  color: var(--accent-green);
}

.message-bubble .info-box {
  background: rgba(0, 212, 255, 0.06);
  border: 1px solid rgba(0, 212, 255, 0.2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin: 10px 0;
  font-size: 12.5px;
}

.message-bubble .info-box strong {
  color: var(--accent-cyan);
}

.message-bubble .chain-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  margin-right: 4px;
}

.chain-tag.sol { background: rgba(153,69,255,0.2); color: var(--sol-color); }
.chain-tag.eth { background: rgba(98,126,234,0.2); color: var(--eth-color); }
.chain-tag.bnb { background: rgba(243,186,47,0.2); color: var(--bnb-color); }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* === Input Area === */
#input-area {
  padding: 14px 24px 18px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--accent-green);
  box-shadow: 0 0 0 3px rgba(0, 255, 136, 0.08);
}

#user-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 16px;
  line-height: 1.5;
  resize: none;
  max-height: 120px;
  padding: 6px 4px;
}

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

#user-input:focus {
  outline: none;
}

#send-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: linear-gradient(135deg, var(--accent-green), #00cc6a);
  color: #000;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.15s;
}

#send-btn:hover {
  transform: scale(1.08);
}

#send-btn:active {
  transform: scale(0.95);
}

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
}

/* === Scrollbar === */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ================================================
   RESPONSIVE — MOBILE (768px and below)
   ================================================ */
@media (max-width: 768px) {
  /* Show/hide helpers */
  .mobile-only { display: block; }
  .desktop-only { display: none !important; }

  /* Sidebar */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    width: 300px;
    min-width: 300px;
    transform: translateX(-100%);
    box-shadow: 4px 0 30px rgba(0, 0, 0, 0.5);
    border-right: 1px solid rgba(0, 255, 136, 0.1);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #sidebar-close {
    display: flex;
  }

  /* Header — enhanced for mobile */
  #chat-header {
    padding: 12px 16px;
    background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
    border-bottom: 1px solid var(--border-color);
  }

  #sidebar-toggle {
    display: flex;
  }

  .header-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  .header-logo-icon {
    display: inline;
  }

  .header-info h1 {
    font-size: 17px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-green), var(--accent-cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
  }

  .status-text {
    font-size: 11px;
  }

  /* Mobile Quick Topic Pills */
  #mobile-topics {
    display: block;
    padding: 4px 0 8px;
  }

  .mobile-topics-scroll {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .mobile-topic-pill {
    padding: 8px 12px;
    font-size: 12.5px;
    border-radius: 18px;
  }

  /* Messages */
  #messages {
    padding: 16px 14px;
    gap: 16px;
  }

  .message {
    max-width: 100%;
    gap: 8px;
  }

  .message-avatar {
    width: 30px;
    height: 30px;
    font-size: 15px;
  }

  .message-bubble {
    padding: 12px 14px;
    font-size: 13.5px;
    line-height: 1.6;
    border-radius: var(--radius-md);
  }

  .message-bubble h2 {
    font-size: 16px;
    margin-bottom: 8px;
  }

  .message-bubble h3 {
    font-size: 13.5px;
    margin: 12px 0 5px;
  }

  .message-bubble ul, .message-bubble ol {
    padding-left: 16px;
  }

  .message-bubble li {
    margin-bottom: 4px;
    font-size: 13px;
  }

  .message-bubble .warning-box,
  .message-bubble .tip-box,
  .message-bubble .info-box {
    padding: 10px 12px;
    font-size: 12px;
  }

  /* Tables responsive */
  .message-bubble table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Input area */
  #input-area {
    padding: 10px 14px calc(10px + var(--safe-bottom));
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
  }

  .input-wrapper {
    padding: 6px 10px;
    border-radius: var(--radius-md);
  }

  #user-input {
    font-size: 16px; /* Prevents iOS zoom on focus */
    padding: 8px 4px;
  }

  #send-btn {
    width: 42px;
    height: 42px;
  }
}

/* ================================================
   RESPONSIVE — SMALL PHONES (480px and below)
   ================================================ */
@media (max-width: 480px) {
  #sidebar {
    width: 100%;
    min-width: 100%;
  }

  #chat-header {
    padding: 10px 12px;
  }

  #messages {
    padding: 12px 10px;
    gap: 14px;
  }

  .message-avatar {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }

  .message-bubble {
    padding: 10px 12px;
    font-size: 13px;
  }

  .mobile-topic-pill {
    padding: 7px 11px;
    font-size: 12px;
  }

  #input-area {
    padding: 8px 10px calc(8px + var(--safe-bottom));
  }
}
