/* ================================================================
   AI CHATBOT - STYLE.CSS
   Mobile-first, animated, dark/light theme
   ================================================================ */

/* ── Google Fonts Import ── */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Bengali:wght@300;400;500;600;700&family=Inter:wght@300;400;500;600;700&display=swap');

/* ── CSS Variables ── */
:root {
  --font-main: 'Oswald', 'Noto Sans Bengali', 'Inter', sans-serif;

  /* Colors - Dark Theme (default) */
  --bg-base:       #0d0f1a;
  --bg-surface:    #13162a;
  --bg-elevated:   #1a1f3a;
  --bg-card:       #1e2440;
  --bg-input:      #232848;

  --accent-1:      #6c63ff;
  --accent-2:      #a78bfa;
  --accent-3:      #38bdf8;
  --accent-glow:   rgba(108, 99, 255, 0.35);

  --user-bubble:   linear-gradient(135deg, #6c63ff, #a78bfa);
  --bot-bubble:    #1e2440;

  --text-primary:  #f0f2ff;
  --text-secondary:#a8b4d8;
  --text-muted:    #5a6490;

  --border-color:  rgba(108, 99, 255, 0.18);
  --border-light:  rgba(255,255,255,0.06);

  --shadow-sm:     0 2px 12px rgba(0,0,0,0.3);
  --shadow-md:     0 8px 32px rgba(0,0,0,0.4);
  --shadow-glow:   0 0 30px rgba(108, 99, 255, 0.25);

  --header-h:      60px;
  --footer-h:      auto;
  --sidebar-w:     300px;

  --radius-sm:     8px;
  --radius-md:     16px;
  --radius-lg:     24px;
  --radius-xl:     32px;

  --transition:    0.25s cubic-bezier(0.4, 0, 0.2, 1);

  /* Orb colors */
  --orb1-color:    rgba(108, 99, 255, 0.18);
  --orb2-color:    rgba(56, 189, 248, 0.12);
  --orb3-color:    rgba(167, 139, 250, 0.14);
}

/* ── Light Theme ── */
body.light-theme {
  --bg-base:       #f0f4ff;
  --bg-surface:    #ffffff;
  --bg-elevated:   #f8faff;
  --bg-card:       #ffffff;
  --bg-input:      #f0f4ff;

  --accent-1:      #5b52e8;
  --accent-2:      #7c6ff7;
  --accent-glow:   rgba(91, 82, 232, 0.2);

  --bot-bubble:    #ffffff;

  --text-primary:  #1a1f3a;
  --text-secondary:#4a5480;
  --text-muted:    #8892b0;

  --border-color:  rgba(91, 82, 232, 0.15);
  --border-light:  rgba(0,0,0,0.06);

  --shadow-sm:     0 2px 12px rgba(0,0,0,0.08);
  --shadow-md:     0 8px 32px rgba(0,0,0,0.12);
  --shadow-glow:   0 0 30px rgba(91, 82, 232, 0.15);

  --orb1-color:    rgba(108, 99, 255, 0.08);
  --orb2-color:    rgba(56, 189, 248, 0.06);
  --orb3-color:    rgba(167, 139, 250, 0.07);
}

/* ── Super Light Theme (Pure White) ── */
body.super-light-theme {
  --bg-base:       #ffffff;
  --bg-surface:    #f8f9fa;
  --bg-elevated:   #ffffff;
  --bg-card:       #ffffff;
  --bg-input:      #f1f3f4;

  --accent-1:      #1a73e8;
  --accent-2:      #185abc;
  --accent-glow:   rgba(26, 115, 232, 0.1);

  --bot-bubble:    #f1f3f4;
  --user-bubble:   linear-gradient(135deg, #1a73e8, #185abc);

  --text-primary:  #111111;
  --text-secondary:#3c4043;
  --text-muted:    #5f6368;

  --border-color:  #dadce0;
  --border-light:  #e8eaed;

  --shadow-sm:     0 1px 3px rgba(60,64,67,0.3);
  --shadow-md:     0 4px 12px rgba(60,64,67,0.15);
  --shadow-glow:   0 0 20px rgba(26, 115, 232, 0.1);

  --orb1-color:    rgba(26, 115, 232, 0.04);
  --orb2-color:    rgba(26, 115, 232, 0.03);
  --orb3-color:    rgba(26, 115, 232, 0.02);
}

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

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

body {
  font-family: var(--font-main);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  
  /* Firefox Scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--accent-1) var(--bg-surface);
  transition: background var(--transition), color var(--transition);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--accent-1); border-radius: 99px; }

/* ================================================================
   AMBIENT BACKGROUND
   ================================================================ */
.ambient-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  animation: orbFloat 10s ease-in-out infinite alternate;
}

.orb-1 {
  width: 500px; height: 500px;
  background: var(--orb1-color);
  top: -150px; left: -100px;
  animation-duration: 12s;
}

.orb-2 {
  width: 400px; height: 400px;
  background: var(--orb2-color);
  bottom: 0; right: -100px;
  animation-duration: 15s;
  animation-delay: -5s;
}

.orb-3 {
  width: 300px; height: 300px;
  background: var(--orb3-color);
  top: 40%; left: 40%;
  animation-duration: 9s;
  animation-delay: -3s;
}

@keyframes orbFloat {
  from { transform: translate(0, 0) scale(1); }
  to   { transform: translate(30px, 30px) scale(1.1); }
}

/* ================================================================
   APP SHELL
   ================================================================ */
.app-shell {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  margin: 0;
  background: var(--bg-surface);
  border: none;
  box-shadow: none;
  overflow: hidden;
}

/* ───── GLOBAL APP LOADER ───── */
.global-loader {
  position: fixed;
  inset: 0;
  background: var(--bg-base);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.global-loader.loaded {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transform: scale(1.05);
}

.loader-content {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.loader-ripple.large {
  width: 120px;
  height: 120px;
}

.loader-ripple.large div {
  border-width: 6px;
  border-color: var(--accent-1);
}

.loader-text.pulse {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  animation: pulseOpacity 2s infinite ease-in-out;
}

.loader-subtext {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 400;
}

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

@media (max-width: 600px) {
  .loader-ripple.large {
    width: 100px;
    height: 100px;
  }
}

@media (min-width: 500px) {
  .app-shell {
    border-radius: var(--radius-lg);
    top: 8px; bottom: 8px;
    left: 50%; right: auto;
    transform: translateX(-50%);
    height: calc(100vh - 16px);
  }
}

/* ================================================================
   HEADER
   ================================================================ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  height: var(--header-h);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-color);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  flex-shrink: 0;
  z-index: 10;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.header-right {
  justify-content: flex-end;
}

.header-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  max-width: 50%;
  text-align: center;
  pointer-events: none;
}

.header-chat-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: rgba(108, 99, 255, 0.08);
  padding: 4px 12px;
  border-radius: 99px;
  border: 1px solid rgba(108, 99, 255, 0.15);
  animation: fadeIn 0.5s ease;
  display: none; /* Hidden until content is available */
}

.header-chat-title:not(:empty) {
  display: block;
}

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

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

.bot-avatar-sm {
  position: relative;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 0 2px var(--bg-surface), 0 0 0 3px var(--accent-1);
}

.avatar-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--accent-1);
  animation: avatarPulse 2.5s ease-in-out infinite;
  opacity: 0;
}

@keyframes avatarPulse {
  0%   { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.5); opacity: 0; }
}

.bot-info {
  display: flex;
  flex-direction: column;
}

.bot-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--text-primary);
  letter-spacing: 0.01em;
}

.bot-status {
  font-size: 11px;
  color: #34d399;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}

.bot-status::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #34d399;
  animation: blink 1.5s ease-in-out infinite;
}

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

/* ── Icon Button ── */
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--border-color);
  color: var(--accent-1);
  transform: scale(1.08);
}

.icon-btn svg {
  width: 20px; height: 20px;
}

/* ================================================================
   SIDEBAR
   ================================================================ */
.sidebar-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.sidebar {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  max-width: 85%;
  z-index: 50;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transform: translateX(-105%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
}

.sidebar.open {
  transform: translateX(0);
  box-shadow: 4px 0 40px rgba(0,0,0,0.4);
}

/* ── History Panel (Drawer) ── */
.history-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.history-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.history-panel {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  max-width: 85%;
  z-index: 50;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.history-panel.open {
  transform: translateX(0);
  box-shadow: -4px 0 40px rgba(0,0,0,0.4);
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 40px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.history-item:hover {
  border-color: var(--accent-1);
  background: var(--bg-input);
  transform: translateX(4px);
}

.history-item.active {
  border-color: var(--accent-1);
  background: var(--accent-glow);
  box-shadow: 0 0 15px var(--accent-glow);
}

.history-item .item-icon {
  font-size: 18px;
  opacity: 0.7;
}

.history-item .item-content {
  flex: 1;
  min-width: 0;
}

.history-item .item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item .item-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.history-item .item-delete {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition);
  opacity: 0;
}

.history-item:hover .item-delete {
  opacity: 1;
}

.item-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.item-delete, .item-edit {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 6px;
  border-radius: 6px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.item-delete:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.item-edit:hover {
  background: rgba(108, 99, 255, 0.1);
  color: var(--accent-1);
}

.item-delete svg, .item-edit svg {
  width: 16px;
  height: 16px;
}

/* ── Custom Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.custom-modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -40%) scale(0.95);
  z-index: 101;
  width: 90%;
  max-width: 360px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 30px 20px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
}

.custom-modal.active {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.modal-content {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 100%;
}

.modal-body {
  overflow-y: auto;
  padding-right: 5px;
  flex: 1;
}

/* Custom scrollbar for modal */
.modal-body::-webkit-scrollbar {
  width: 4px;
}
.modal-body::-webkit-scrollbar-thumb {
  background: rgba(108, 99, 255, 0.3);
  border-radius: 4px;
}

.custom-modal.active {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, -50%) scale(1);
}

.modal-icon {
  font-size: 48px;
  margin-bottom: 20px;
}

.modal-content h3 {
  font-size: 18px;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.modal-content p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.modal-input {
  width: 100%;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1.5px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  margin: 15px 0;
  transition: all 0.3s ease;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

.modal-input:focus {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--accent-1);
  box-shadow: 0 0 0 4px rgba(108, 99, 255, 0.15);
}

select.modal-input option {
  background-color: var(--bg-elevated);
  color: var(--text-primary);
}

.modal-btn {
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  border: none;
}

.modal-btn.cancel {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}

.modal-btn.cancel:hover {
  background: var(--border-light);
}

.modal-btn.confirm {
  background: #ef4444;
  color: white;
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.modal-btn.confirm:hover {
  background: #dc2626;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

.modal-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none !important;
}

/* ── Loading Spinner ── */
.btn-loading-tag {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Session Loader Overlay ── */
.session-loader {
  position: absolute;
  inset: 0;
  background: var(--bg-base);
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  animation: fadeIn 0.3s ease;
}

.session-loader.active {
  display: flex;
}

.loader-ripple {
  display: inline-block;
  position: relative;
  width: 64px;
  height: 64px;
}
.loader-ripple div {
  position: absolute;
  border: 4px solid var(--accent-1);
  opacity: 1;
  border-radius: 50%;
  animation: ripple 1s cubic-bezier(0, 0.2, 0.8, 1) infinite;
}
.loader-ripple div:nth-child(2) {
  animation-delay: -0.5s;
}
@keyframes ripple {
  0% { top: 32px; left: 32px; width: 0; height: 0; opacity: 1; }
  100% { top: 0px; left: 0px; width: 64px; height: 64px; opacity: 0; }
}

.loader-text {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.5px;
}

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

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

.sidebar-logo {
  height: 42px !important;
  max-height: 42px !important;
  width: auto;
  max-width: 160px;
  object-fit: contain;
  flex-shrink: 0;
  transition: all 0.3s ease;
}

@media (max-width: 600px) {
  .sidebar-logo {
    height: 36px !important;
    max-height: 36px !important;
  }
}

.sidebar-header h2 {
  font-size: 17px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin: 0;
}

.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
}

.section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.section-label svg {
  width: 14px; height: 14px;
  stroke: var(--accent-1);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
}

.setting-text {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 500;
}

.theme-switch-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--accent-1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-switch-btn:hover {
  background: var(--accent-glow);
  transform: rotate(45deg);
  border-color: var(--accent-2);
}

.theme-switch-btn svg {
  width: 22px;
  height: 22px;
}

/* Model Select */
.model-select-wrapper {
  position: relative;
}

.model-select {
  width: 100%;
  padding: 10px 36px 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 13px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

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

.model-select optgroup {
  background: var(--bg-card);
  color: var(--accent-2);
  font-style: normal;
  font-size: 12px;
}

.model-select option {
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: 6px;
}

.select-arrow {
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--accent-1);
  pointer-events: none;
  font-size: 14px;
}

.current-model-badge {
  margin-top: 8px;
  padding: 6px 12px;
  background: var(--accent-glow);
  border: 1px solid var(--accent-1);
  border-radius: 99px;
  font-size: 12px;
  color: var(--accent-2);
  text-align: center;
  font-weight: 600;
  animation: badgePop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes badgePop {
  from { transform: scale(0.9); opacity: 0.5; }
  to   { transform: scale(1); opacity: 1; }
}

/* System Prompt Textarea */
.system-textarea {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 13px;
  padding: 10px 12px;
  resize: vertical;
  min-height: 80px;
  outline: none;
  transition: border-color var(--transition);
  line-height: 1.3;
}

.system-textarea:focus {
  border-color: var(--accent-1);
}

/* Range Slider */
.range-slider {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  background: var(--bg-card);
  border-radius: 99px;
  outline: none;
  margin: 8px 0 4px;
  transition: background var(--transition);
}

.range-slider::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-glow);
  transition: transform var(--transition);
}

.range-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
}

.sidebar-footer {
  padding: 16px;
  margin-top: auto;
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.8;
}

.api-setting-btn {
  width: 100%;
  padding: 10px 14px;
  background: var(--accent-1);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.api-setting-btn:hover {
  background: var(--accent-2);
}

/* ================================================================
CHAT MAIN
=============================================================== */
.chat-main {
  flex: 1;
  overflow-y: auto;
  scroll-behavior: smooth;
  position: relative;
  padding-bottom: 8px;
}

/* ── Welcome Screen ── */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 24px;
  min-height: 100%;
  animation: fadeInUp 0.5s ease both;
}

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

.welcome-avatar {
  position: relative;
  width: 100px; height: 100px;
  margin-bottom: 24px;
}

.welcome-rings {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
}

.ring {
  position: absolute;
  border-radius: 50%;
  border: 2px solid var(--accent-1);
  animation: ringPulse 2.5s ease-in-out infinite;
}

.ring-1 { width: 80px; height: 80px; opacity: 0.6; }
.ring-2 { width: 100px; height: 100px; opacity: 0.35; animation-delay: 0.5s; }
.ring-3 { width: 120px; height: 120px; opacity: 0.15; animation-delay: 1s; }

@keyframes ringPulse {
  0%   { transform: scale(0.95); opacity: inherit; }
  50%  { transform: scale(1.05); }
  100% { transform: scale(0.95); }
}

.welcome-icon {
  position: absolute;
  inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 44px;
  filter: drop-shadow(0 0 16px var(--accent-glow));
  animation: iconFloat 3s ease-in-out infinite;
}

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

.welcome-title {
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-3));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 10px;
}

.welcome-desc {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 28px;
  max-width: 280px;
}

.quick-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.quick-prompt-btn {
  padding: 8px 14px;
  border: 1px solid var(--border-color);
  border-radius: 99px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.quick-prompt-btn:hover {
  border-color: var(--accent-1);
  color: var(--accent-2);
  background: var(--accent-glow);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px var(--accent-glow);
}

/* ── Messages Container ── */
.messages-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 10px;
}

/* ── Message Bubble ── */
.message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: msgSlideIn 0.35s cubic-bezier(0.34, 1.2, 0.64, 1) both;
  max-width: 100%;
}

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

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

.message-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
  margin-bottom: 4px;
}

.message.bot .message-avatar {
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  box-shadow: 0 0 12px var(--accent-glow);
}

.message.user .message-avatar {
  background: linear-gradient(135deg, #f97316, #fb923c);
}

.message-bubble-wrap {
  max-width: 82%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0; /* Prevents flex blowout from wide tables */
}

.message.user .message-bubble-wrap {
  align-items: flex-end;
}

.message-bubble {
  padding: 11px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
  position: relative;
  min-width: 0; /* Prevents block blowout overflow */
  max-width: 100%;
}

/* ── INLINE MESSAGE EDITING ── */
.edit-message-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  min-width: 250px;
  background: var(--bg-card);
  border: 1px solid var(--accent-1);
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
  animation: badgePop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.edit-message-input {
  width: 100%;
  min-height: 60px;
  background: rgba(0,0,0,0.15);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 14px;
  padding: 10px;
  resize: none;
  outline: none;
  line-height: 1.4;
  transition: border-color var(--transition);
}

.edit-message-input:focus {
  border-color: var(--accent-1);
  box-shadow: inset 0 0 5px rgba(108, 99, 255, 0.2);
}

.edit-message-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Code Block Enhancements */
.message-bubble pre {
  position: relative;
  margin: 16px 0;
  border-radius: 12px;
  background: #0d1117 !important; /* GitHub dark style */
  border: 1px solid rgba(255,255,255,0.1);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.message-bubble pre:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.4);
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: #161b22;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  font-family: var(--font-main);
}

.code-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.window-controls {
  display: flex;
  gap: 6px;
}

.control-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  opacity: 0.8;
}

.dot-red { background: #ff5f56; }
.dot-yellow { background: #ffbd2e; }
.dot-green { background: #27c93f; }

.lang-badge {
  text-transform: uppercase;
  color: var(--accent-1);
  letter-spacing: 0.5px;
  padding: 2px 6px;
  background: rgba(108,99,255,0.1);
  border-radius: 4px;
}

.copy-code-btn {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: 6px;
}

.copy-code-btn span:first-child {
  font-size: 13px;
}

.copy-code-btn:hover {
  background: rgba(255,255,255,0.1);
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.2);
}

.copy-code-btn.copied {
  background: #059669; /* Sleek green */
  color: white;
  border-color: #059669;
}

.message-bubble code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 13px;
  display: block;
  overflow-x: auto;
  padding: 16px;
  line-height: 1.6;
  color: #e6edf3;
  -webkit-font-smoothing: antialiased;
}

/* Custom Scrollbar for Code Blocks */
.message-bubble code {
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.message-bubble code::-webkit-scrollbar {
  height: 6px;
}
.message-bubble code::-webkit-scrollbar-track {
  background: transparent;
}
.message-bubble code::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 10px;
}
.message-bubble code::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.2);
}

.message.user .message-bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 4px 20px rgba(108, 99, 255, 0.3);
}

.message.bot .message-bubble {
  background: var(--bot-bubble);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.message-time {
  font-size: 10px;
  color: var(--text-muted);
  padding: 0 4px;
}

/* ── Message Actions ── */
.message-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
  padding: 0 4px;
}

.message:hover .message-actions,
.message-actions.always-visible {
  opacity: 1;
}

.msg-action-btn {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-elevated);
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  font-size: 13px;
}

.msg-action-btn:hover {
  border-color: var(--accent-1);
  color: var(--accent-1);
  background: var(--accent-glow);
  transform: scale(1.1);
}

/* ── Markdown Content ── */
.message-bubble h1, .message-bubble h2, .message-bubble h3 {
  margin: 12px 0 6px;
  font-weight: 700;
  color: var(--accent-2);
}

.message-bubble h1 { font-size: 18px; }
.message-bubble h2 { font-size: 16px; }
.message-bubble h3 { font-size: 14px; }

.message-bubble p { margin: 6px 0; }

.message-bubble ul, .message-bubble ol {
  margin: 6px 0 6px 20px;
}

.message-bubble code {
  font-family: 'Consolas', 'Monaco', monospace;
  background: rgba(108, 99, 255, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--accent-2);
}

.message.user .message-bubble code {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

.message-bubble pre {
  margin: 10px 0;
  border-radius: var(--radius-sm);
  overflow: auto;
}

.message-bubble pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: 12px;
}

.message-bubble blockquote {
  border-left: 3px solid var(--accent-1);
  padding: 6px 12px;
  margin: 8px 0;
  opacity: 0.85;
  background: rgba(108,99,255,0.06);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.message-bubble a {
  color: var(--accent-3);
  text-decoration: underline;
}

.message-bubble table {
  display: block;
  width: 100%;
  overflow-x: auto;
  white-space: nowrap;
  border-collapse: collapse;
  font-size: 13px;
  margin: 8px 0;
  border-radius: var(--radius-sm);
  scrollbar-width: thin;
  scrollbar-color: var(--accent-1) var(--bg-base);
}

.message-bubble table::-webkit-scrollbar {
  height: 6px;
}
.message-bubble table::-webkit-scrollbar-track {
  background: var(--bg-base);
}
.message-bubble table::-webkit-scrollbar-thumb {
  background: var(--accent-1);
  border-radius: 10px;
}

.message-bubble th, .message-bubble td {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  text-align: left;
}

.message-bubble th {
  background: var(--accent-glow);
  color: var(--accent-2);
}

/* ── Typing Indicator ── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 14px;
}

.typing-indicator span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent-1);
  animation: typingBounce 1.2s ease-in-out infinite;
}

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

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

/* ── Error State ── */
.error-bubble {
  border-color: #f87171 !important;
  background: rgba(248, 113, 113, 0.08) !important;
}

.error-bubble::before {
  content: '⚠️ ';
}

.reconnect-google-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 8px 16px;
  border: none;
  border-radius: 20px;
  background: linear-gradient(135deg, #6c63ff, #a78bfa);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 2px 10px rgba(108, 99, 255, 0.3);
}

.reconnect-google-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(108, 99, 255, 0.45);
  filter: brightness(1.1);
}

.reconnect-google-btn:active {
  transform: translateY(0);
}

.reconnect-google-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

/* ================================================================
   IMAGE PREVIEW AREA
   ================================================================ */
.image-preview-container {
  display: flex !important;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 8px 10px;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  animation: fadeIn 0.3s ease;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.image-preview-container[style*="display: none"] {
  display: none !important;
}

/* Each individual image chip */
.preview-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 4px 8px 4px 6px;
  font-size: 12px;
  color: var(--text-primary);
  font-weight: 500;
  max-width: calc(100% - 8px);
  flex-shrink: 1;
  animation: fadeIn 0.2s ease;
}

.preview-chip .chip-icon {
  font-size: 14px;
  flex-shrink: 0;
}

.preview-chip .chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}

.preview-chip .chip-remove {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border: none;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  font-size: 10px;
  line-height: 1;
  padding: 0;
}

.preview-chip .chip-remove:hover {
  background: #ef4444;
  color: white;
}

@media (max-width: 480px) {
  .preview-chip .chip-name {
    max-width: 80px;
  }
}

/* ================================================================
   INPUT AREA
   ================================================================ */
.input-area {
  padding: 8px 10px 10px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

/* Regenerate Bar */
.regenerate-bar {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 6px 0 8px;
  animation: fadeIn 0.3s ease;
}

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

.regen-btn, .stop-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: 99px;
  border: none;
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition);
}

.regen-btn {
  background: var(--bg-card);
  border: 1px solid var(--accent-1);
  color: var(--accent-2);
}

.regen-btn:hover {
  background: var(--accent-glow);
  transform: translateY(-2px);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.regen-btn svg, .stop-btn svg {
  width: 15px; height: 15px;
}

.stop-btn {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid #f87171;
  color: #f87171;
}

.stop-btn:hover {
  background: rgba(248, 113, 113, 0.25);
  transform: translateY(-2px);
}

/* Voice Status Bar */
.voice-status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(108, 99, 255, 0.1);
  border: 1px solid var(--accent-1);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  animation: fadeIn 0.3s ease;
}

.voice-waves {
  display: flex;
  gap: 3px;
  align-items: center;
}

.voice-waves span {
  width: 3px;
  background: var(--accent-1);
  border-radius: 99px;
  animation: voiceWave 0.8s ease-in-out infinite alternate;
}

.voice-waves span:nth-child(1) { height: 8px;  animation-delay: 0s;    }
.voice-waves span:nth-child(2) { height: 16px; animation-delay: 0.1s;  }
.voice-waves span:nth-child(3) { height: 24px; animation-delay: 0.2s;  }
.voice-waves span:nth-child(4) { height: 16px; animation-delay: 0.3s;  }
.voice-waves span:nth-child(5) { height: 8px;  animation-delay: 0.4s;  }

@keyframes voiceWave {
  from { transform: scaleY(0.5); opacity: 0.6; }
  to   { transform: scaleY(1.3); opacity: 1; }
}

.voice-label {
  flex: 1;
  font-size: 13px;
  color: var(--accent-2);
  font-weight: 500;
}

/* Input Row */
.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  position: relative;
  transition: all 0.3s ease;
}

.input-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: flex-end;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 26px;
  transition: all 0.3s ease;
}

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

.chat-input {
  width: 100%;
  min-height: 48px;
  max-height: 160px;
  padding: 13px 16px;
  background: transparent;
  border: none;
  border-radius: 26px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14.5px;
  resize: none;
  outline: none;
  overflow-y: auto;
  line-height: 1.3;
  transition: padding 0.3s ease;
  appearance: none;
  -webkit-appearance: none;
}

/* Default (Empty) State */
.chat-input {
  padding-left: 90px;
  padding-right: 50px;
}

.attach-btn.outside {
  display: none;
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.attach-btn.inside {
  position: absolute;
  left: 6px;
  bottom: 6px;
  z-index: 5;
  color: var(--text-muted);
}

.input-actions-right {
  position: absolute;
  right: 6px;
  bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 5;
}

.mic-btn {
  color: var(--text-muted);
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #f59e0b; /* Premium Yellow */
  color: white;
  border: none;
  cursor: pointer;
  display: none; /* Hidden by default */
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.send-btn:hover {
  background: #d97706;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.4);
}

/* HAS TEXT STATE */
.input-row.has-text .attach-btn.outside {
  display: flex;
  opacity: 1;
  transform: scale(1);
}

.input-row.has-text .attach-btn.inside {
  display: none;
}

.input-row.has-text .chat-input {
  padding-left: 48px;
}

.input-row.has-text .mic-btn {
  display: none;
}

.input-row.has-text .send-btn {
  display: flex;
}

/* Voice recording state on mic button */
.mic-btn.recording {
  background: #f87171;
  color: white;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.4); }
  70% { box-shadow: 0 0 0 10px rgba(248, 113, 113, 0); }
  100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0); }
}

.attach-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  transition: all 0.3s ease;
}

.attach-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

/* Voice Button Recording Pulse */
.mic-btn.recording svg {
  animation: pulseIcon 1.2s ease-in-out infinite;
}

@keyframes pulseIcon {
  0% { transform: scale(1); }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* Character Count & Loading */
.send-btn.loading svg {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.char-count {
  position: absolute;
  top: -24px;
  right: 12px;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-surface);
  padding: 2px 8px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  display: none;
}

/* Attachment Popup Menu */
.attach-popup {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 8px;
  display: none;
  flex-direction: column;
  gap: 4px;
  min-width: 180px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 1000;
  animation: popupSlideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.attach-popup.active {
  display: flex;
}

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

.popup-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  color: var(--text-primary);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 14px;
  font-weight: 500;
}

.popup-item:hover {
  background: rgba(255, 255, 255, 0.05);
  transform: translateX(4px);
}

.popup-icon {
  font-size: 18px;
}

/* Modal Textarea */
.modal-textarea {
  width: 100%;
  min-height: 120px;
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
  margin-top: 12px;
  transition: border-color 0.3s ease;
}

.modal-textarea:focus {
  outline: none;
  border-color: var(--accent-1);
}

/* Tools Connection Styles */
.modal-input {
  width: 100%;
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  margin-bottom: 12px;
  transition: border-color 0.3s ease;
}

.modal-input:focus {
  outline: none;
  border-color: var(--accent-1);
}

.tools-form {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}

.full-width {
  width: 100%;
}

.tools-list-container h4 {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.tools-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 200px;
  overflow-y: auto;
  padding-right: 4px;
}

.tool-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  transition: all 0.2s ease;
}

.tool-item:hover {
  background: rgba(255, 255, 255, 0.05);
  transform: translateX(4px);
}

.tool-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tool-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.tool-guide-preview {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.tool-actions {
  display: flex;
  gap: 6px;
}

.tool-action-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tool-action-btn:hover {
  background: var(--accent-glow);
  color: var(--accent-1);
  border-color: var(--accent-1);
}

.tool-action-btn.delete:hover {
  background: rgba(255, 71, 87, 0.1);
  color: #ff4757;
  border-color: #ff4757;
}

/* ── Unified Toast ── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 24px;
  background: rgba(19, 22, 42, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  color: #fff;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  gap: 10px;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ================================================================
   API MANAGEMENT MODAL STYLES
   ================================================================ */
.modal-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s ease;
}
.modal-tab-btn:hover {
  color: var(--text-primary);
}
.modal-tab-btn.active {
  color: var(--accent-1);
  border-bottom: 2px solid var(--accent-1);
}

.api-key-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.api-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.api-provider-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--accent-2);
}
.api-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 12px;
  font-weight: 600;
  text-transform: uppercase;
}
.api-badge.active { background: rgba(76, 175, 80, 0.15); color: #4CAF50; border: 1px solid rgba(76,175,80,0.3); }
.api-badge.inactive { background: rgba(244, 67, 54, 0.15); color: #F44336; border: 1px solid rgba(244,67,54,0.3); }
.api-badge.limited { background: rgba(255, 152, 0, 0.15); color: #FF9800; border: 1px solid rgba(255,152,0,0.3); }

.api-models-list {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.3;
}
.api-key-hidden {
  font-family: monospace;
  background: rgba(0,0,0,0.2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: #ccc;
}
.api-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.api-actions button {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}
.api-actions button:hover {
  background: rgba(255,255,255,0.1);
}
.api-actions button.del-btn {
  color: #F44336;
  border-color: rgba(244,67,54,0.3);
}
.api-actions button.del-btn:hover {
  background: rgba(244,67,54,0.1);
}

.bot-msg-footer {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11px;
  font-style: italic;
  color: var(--text-muted);
  text-align: right;
  opacity: 0.8;
}

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

/* ================================================================
   MOBILE SPECIFIC OVERRIDES
   ================================================================ */
@media screen and (max-width: 768px) {
  .message-bubble-wrap {
      max-width: 100%;
      display: flex;
      flex-direction: column;
      gap: 4px;
      min-width: 0; /* Prevents wide tables expanding beyond screen wrap */
  }
  .message-bubble {
      padding: 9px 7px;
      border-radius: 18px;
      font-size: 14px;
      line-height: 1.4;
      word-break: break-word;
      position: relative;
      min-width: 0; /* Constrain max bounds */
      max-width: 100%;
  }
  .message-avatar {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 15px;
      flex-shrink: 0;
      margin-bottom: 4px;
  }
}

/* ── Jump to Bottom Button ── */
.jump-to-bottom-btn {
  position: fixed;
  bottom: 85px;
  right: 20px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(45, 43, 85, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--text-primary);
  border: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  z-index: 50;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0;
  transform: translateY(20px) scale(0.9);
  pointer-events: none;
}
.jump-to-bottom-btn:hover {
  background: var(--bg-hover);
  color: var(--accent-1);
  transform: translateY(-2px) scale(1);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.jump-to-bottom-btn.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
@media (max-width: 600px) {
  .jump-to-bottom-btn {
    bottom: 80px;
    right: 15px;
    width: 38px;
    height: 38px;
  }
}

/* ── Grouped API Key Styling ── */
.api-key-item.grouped {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 15px;
  margin-bottom: 20px;
  transition: all 0.3s ease;
}

.api-key-item.grouped:hover {
  border-color: var(--accent-2);
  background: rgba(108, 99, 255, 0.05);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.api-group-header {
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
}

.api-provider-name {
  font-size: 16px;
  color: var(--accent-2);
  margin: 0 0 4px 0;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.api-base-url {
  font-size: 11px;
  color: var(--text-muted);
  margin: 0;
  word-break: break-all;
  opacity: 0.8;
}

.api-key-badges-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.api-key-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s ease;
  position: relative;
}

.api-key-badge:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-1px);
}

.api-key-badge.status-active {
  border-left: 3px solid #00c853;
}

.api-key-badge.status-inactive {
  border-left: 3px solid #757575;
  opacity: 0.7;
}

.api-key-badge.status-limited {
  border-left: 3px solid #ff9100;
}

.active-check {
  font-size: 10px;
  color: #00c853;
}

.badge-del-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  padding: 2px;
  margin-left: 4px;
  cursor: pointer;
  opacity: 0.5;
  transition: 0.2s;
}

.badge-del-btn:hover {
  color: #ff5252;
  opacity: 1;
}

.api-models-preview {
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.2);
  padding: 8px;
  border-radius: 6px;
  margin-top: 10px;
  line-height: 1.4;
}

.api-group-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.add-btn-mini {
  background: rgba(108, 99, 255, 0.15);
  color: var(--accent-2);
  border: 1px solid var(--accent-2);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: 0.2s;
}

.add-btn-mini:hover {
  background: var(--accent-2);
  color: white;
}

/* ── API Setting Button in Sidebar ── */
.api-setting-btn {
  width: 100%;
  padding: 12px;
  background: rgba(108, 99, 255, 0.1);
  border: 1px solid rgba(108, 99, 255, 0.2);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.3s ease;
  margin-top: 5px;
}

.api-setting-btn:hover {
  background: rgba(108, 99, 255, 0.2);
  border-color: var(--accent-2);
  transform: translateY(-2px);
}

.api-setting-btn:active {
  transform: translateY(0);
}

/* ── Mobile Responsive Overrides for API Management ── */
@media (max-width: 600px) {
  .api-key-item.grouped {
    padding: 12px;
    margin-bottom: 15px;
  }
  
  .api-provider-name {
    font-size: 14px;
  }
  
  .api-key-badge {
    padding: 8px 12px; /* Larger tap target */
    font-size: 11px;
    flex: 1 1 calc(50% - 8px); /* Two badges per row on small phones */
    justify-content: center;
  }
  
  .api-models-preview {
    font-size: 11px;
    padding: 6px;
  }
  
  .add-btn-mini {
    width: 100%;
    text-align: center;
    padding: 8px;
    font-size: 12px;
  }
  
  .api-group-actions {
    justify-content: center;
  }
}

/* ================================================================
   NEW FEATURE STYLES
   ================================================================ */

.theme-selector {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
  width: 100%;
}

.theme-opt {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 16px;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-opt:hover {
  background: var(--bg-elevated);
}

.theme-opt.active {
  background: var(--accent-1);
  color: white;
  box-shadow: var(--shadow-sm);
}

.search-mode-btn {
  position: absolute;
  left: 48px;
  bottom: 6px;
  z-index: 5;
  color: var(--text-muted);
  width: 42px !important;
  height: 42px !important;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
}

.input-row.has-text .search-mode-btn {
  left: 8px;
}

.search-mode-btn:hover {
  color: var(--accent-3);
  background: rgba(56, 189, 248, 0.1) !important;
}

.search-mode-btn.active {
  color: #38bdf8 !important;
  background: rgba(56, 189, 248, 0.15) !important;
  filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.4));
}

.input-row.search-active {
  border: 2px solid #38bdf8 !important;
  box-shadow: 0 0 20px rgba(56, 189, 248, 0.15) !important;
}

.search-mode-indicator {
  position: absolute;
  top: -28px;
  left: 50%;
  transform: translateX(-50%);
  background: #38bdf8;
  color: #0d0f1a;
  font-size: 10px;
  font-weight: 800;
  padding: 2px 10px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3);
  pointer-events: none;
  z-index: 10;
}
