/* --- 🎨 ADVANCED DESIGN SYSTEM (UNCHANGED) --- */
:root {
  --font-family: "Manrope", Inter, system-ui, -apple-system, sans-serif;
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-pill: 999px;
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  /* Light Theme */
  --accent-light: #4f46e5;
  --bg-light: #faf9f7;
  --surface-light: #fffefc;
  --glass-light: rgba(255, 255, 255, 0.8);
  --text-primary-light: #141414;
  --text-secondary-light: #6b7280;
  --user-text-light: #141414;
  --border-light: #e5e7eb;
  --shadow-light: 0 8px 32px rgba(0, 0, 0, 0.08);
  --shadow-input-light: 0 -8px 24px rgba(0, 0, 0, 0.08);
  --bot-bubble-light: #f0f2f5;
  --user-bubble-light: #f0f4f9;
  /* Dark Theme */
  --accent-dark: #f97316;
  --bg-dark: #161514;
  --surface-dark: #1f1d1c;
  --sidebar-bg-dark: #191817;
  --glass-dark: rgba(22, 21, 20, 0.75);
  --text-primary-dark: #e8e6e3;
  --text-secondary-dark: #969390;
  --user-text-dark: #ffffff;
  --border-dark: #2c2a29;
  --shadow-dark: 0 8px 32px rgba(0, 0, 0, 0.6);
  --shadow-input-dark: 0 -8px 24px rgba(0, 0, 0, 0.6);
  --bot-bubble-dark: #262423;
  --user-bubble-dark: #3a3634;
}

[data-theme="light"] {
  --accent: var(--accent-light);
  --bg: var(--bg-light);
  --surface: var(--surface-light);
  --sidebar-bg: var(--bg-light);
  --glass: var(--glass-light);
  --text-primary: var(--text-primary-light);
  --text-secondary: var(--text-secondary-light);
  --user-text: var(--user-text-light);
  --border: var(--border-light);
  --shadow: var(--shadow-light);
  --shadow-input: var(--shadow-input-light);
  --bot-bubble: var(--bot-bubble-light);
  --user-bubble: var(--user-bubble-light);
}

[data-theme="light"] .ambient-glow {
  background: radial-gradient(circle at 50% 100%, rgba(249, 115, 22, 0.4) 0%, rgba(253, 186, 116, 0.2) 50%, transparent 70%) !important;
}
[data-theme="light"] .purple-blob {
  background: radial-gradient(ellipse at 50% 100%, rgba(234, 88, 12, 0.4) 0%, rgba(251, 146, 60, 0.2) 50%, transparent 70%) !important;
  mix-blend-mode: normal !important;
}

[data-theme="dark"] {
  --accent: var(--accent-dark);
  --bg: var(--bg-dark);
  --surface: var(--surface-dark);
  --sidebar-bg: var(--sidebar-bg-dark);
  --glass: var(--glass-dark);
  --text-primary: var(--text-primary-dark);
  --text-secondary: var(--text-secondary-dark);
  --user-text: var(--user-text-dark);
  --border: var(--border-dark);
  --shadow: var(--shadow-dark);
  --shadow-input: var(--shadow-input-dark);
  --bot-bubble: var(--bot-bubble-dark);
  --user-bubble: var(--user-bubble-dark);
}

/* --- 💅 BASE & RESET (UNCHANGED) --- */
* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

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

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  color: inherit;
}

::-webkit-scrollbar {
  width: 8px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
  border: 2px solid transparent;
  background-clip: content-box;
}

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

/* --- 🏗️ APP LAYOUT (UNCHANGED) --- */
#app {
  display: flex;
  height: 100%;
  padding: 1rem;
  gap: 1rem;
}

/* --- 🗺️ SIDEBAR (MODIFIED) --- */
#sidebar {
  width: 320px;
  background: var(--sidebar-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 300;
  /* ✅ [FIX] Increased z-index */
  padding: 1rem 1rem 0.5rem 1rem;
  transition: transform var(--transition-slow), background-color var(--transition-slow);
}


#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-shrink: 0;
  padding: 0 0.5rem;
  /* Match new user profile horizontal padding */
}

#sidebar-header h2 {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  color: var(--text-secondary);
}

#sidebar-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  transition: background-color var(--transition-fast);
}

.icon-btn:hover {
  background-color: var(--bg);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  color: var(--text-secondary);
}

.hamburger-btn {
  /* Inherits from .icon-btn */
}

.hamburger-icon {
  width: 20px;
  height: 12px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}

.hamburger-icon .line {
  display: block;
  width: 100%;
  height: 1.5px;
  background-color: var(--text-primary);
  border-radius: 2px;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform-origin: center;
}

@keyframes pulseLineTop {
  0%, 100% { width: 100%; }
  50% { width: 60%; }
}

@keyframes pulseLineBottom {
  0%, 100% { width: 60%; }
  50% { width: 100%; }
}

.hamburger-icon .line-top {
  transform: translateY(0);
  align-self: flex-start;
}

.hamburger-icon .line-bottom {
  transform: translateY(0);
  width: 60%;
  align-self: flex-start;
}

.hamburger-btn:not(.active) .hamburger-icon .line-top {
  animation: pulseLineTop 2.5s ease-in-out infinite;
}

.hamburger-btn:not(.active) .hamburger-icon .line-bottom {
  animation: pulseLineBottom 2.5s ease-in-out infinite;
}

.hamburger-btn:hover .hamburger-icon .line-top,
.hamburger-btn:hover .hamburger-icon .line-bottom {
  animation: none;
  width: 100%;
}

.hamburger-btn.active .hamburger-icon .line-top {
  transform: translateY(5px) rotate(45deg);
}

.hamburger-btn.active .hamburger-icon .line-bottom {
  transform: translateY(-5.5px) rotate(-45deg);
  width: 100%;
}

#live-mode-btn {
  width: 44px;
  height: 44px;
  aspect-ratio: 1 / 1;
  padding: 10px;
  border: none;
  background: transparent !important;
  border-radius: 50%;
  display: flex !important; /* Force visible */
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: none !important;
  animation: none !important;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

#live-mode-btn svg {
  width: 100%;
  height: 100%;
  stroke: #a0a0a0;
  filter: none !important;
}

#live-mode-btn:hover {
  background: rgba(255, 255, 255, 0.05) !important;
}

/* Hidden elements check */
#live-mode-btn.hidden {
  display: none !important;
}

#session-list {
  flex-grow: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0 0.5rem;
  /* Match horizontal padding */
  margin: 0 -0.5rem;
  /* Negative margin to extend scrollbar */
}

.session-item {
  padding: 1rem;
  border-radius: var(--radius-md);
  background-color: transparent;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all var(--transition-fast);
  position: relative;
}

.session-item:hover {
  background-color: var(--bg);
}

.session-item.active {
  background-color: var(--surface);
  border-color: var(--border);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Base Skeleton Loader for Chat History */
.skeleton {
  height: 65px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--border) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius-md);
  margin-bottom: 0.5rem;
  animation: skeletonLoading 1.5s infinite linear;
}

@keyframes skeletonLoading {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.session-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.skeleton {
  background-color: var(--bg);
  border-radius: var(--radius-md);
  height: 68px;
  opacity: 0.5;
  animation: pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  margin: 0 0.5rem;
  /* Match list padding */
}

@keyframes pulse {

  0%,
  100% {
    opacity: 0.5;
  }

  50% {
    opacity: 1;
  }
}

/* --- ✅ [NEW] 👤 USER PROFILE --- */
#user-profile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.5rem;
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
}

#user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background-color: var(--border);
  flex-shrink: 0;
}

#user-info {
  flex-grow: 1;
  min-width: 0;
  /* For text overflow */
}

#user-display-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#user-email {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#user-settings-btn.active {
  background-color: var(--bg);
}

#user-settings-popup {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  width: 280px;
  background-color: var(--bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  z-index: 301;
  /* ✅ [FIX] Increased to be > sidebar */
  padding: 0.5rem;
  opacity: 0;
  transform: translateY(10px);
  visibility: hidden;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  pointer-events: none;
}

#user-settings-popup.show {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
  pointer-events: auto;
}

.popup-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 0.5rem 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.popup-action-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  text-align: left;
  transition: background-color var(--transition-fast);
}

.popup-action-btn:hover {
  background-color: var(--surface);
}

.popup-action-btn svg {
  width: 20px;
  height: 20px;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.popup-action-btn span {
  color: var(--text-primary);
  transition: color var(--transition-fast);
}

.popup-action-btn.danger span {
  color: #ef4444;
}

.popup-action-btn.danger svg {
  color: #ef4444;
}

.popup-action-btn.danger:hover {
  background-color: #ef44441a;
}

#theme-icon-popup {
  display: flex;
  align-items: center;
  justify-content: center;
}

#theme-icon-popup svg {
  width: 20px;
  height: 20px;
}

#chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow);
  position: relative;
  transition: background-color var(--transition-slow);
  padding-bottom: 1rem;
  z-index: 1;
}

/* --- Ambient Effects Container --- */
.glow-container {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
  transition: opacity 1.2s cubic-bezier(0.4, 0, 0.2, 1), transform 1.2s cubic-bezier(0.4, 0, 0.2, 1);
  will-change: opacity, transform;
  opacity: 1;
}

#chat-container.is-chatting .glow-container {
  opacity: 0;
  transform: translateY(15%);
}

/* Base Blue Glow */
.ambient-glow {
  position: absolute;
  bottom: -10%; 
  left: -10%;
  width: 120%;
  height: 60%;
  background: radial-gradient(circle at 50% 100%, #8c2a00 0%, #4a1300 50%, transparent 70%);
  animation: flow-blue 10s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  border-radius: 50% 50% 20% 20% / 100% 100% 0% 0%;
  will-change: transform, border-radius;
}

@keyframes flow-blue {
  0% { transform: translateX(0) scale(1); border-radius: 50% 50% 20% 20% / 80% 80% 0% 0%; }
  33% { transform: translateX(-4%) scale(1.03); border-radius: 40% 60% 30% 20% / 90% 70% 10% 20%; }
  66% { transform: translateX(4%) scale(0.97); border-radius: 60% 40% 20% 30% / 70% 90% 20% 10%; }
  100% { transform: translateX(0) scale(1); border-radius: 50% 50% 20% 20% / 80% 80% 0% 0%; }
}

/* Purple/Red blobs */
.purple-blob {
  position: absolute;
  bottom: -10%;
  height: 38%;
  width: 70%;
  background: radial-gradient(ellipse at 50% 100%, rgba(245, 120, 0, 0.45) 0%, rgba(180, 50, 0, 0.2) 50%, transparent 70%);
  mix-blend-mode: screen;
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  will-change: transform;
}

.purple-blob.left {
  left: -15%;
  animation: blob-left 8s cubic-bezier(0.4, 0, 0.2, 1) infinite alternate;
}

.purple-blob.right {
  right: -15%;
  animation: blob-right 8.5s cubic-bezier(0.4, 0, 0.2, 1) infinite alternate;
}

@keyframes blob-left {
  0% { transform: translateX(0) scale(1); }
  50% { transform: translateX(30%) scale(1.1); }
  100% { transform: translateX(-5%) scale(0.95); }
}

@keyframes blob-right {
  0% { transform: translateX(0) scale(1); }
  50% { transform: translateX(-30%) scale(1.1); }
  100% { transform: translateX(5%) scale(0.95); }
}

/* Flashing Star Matrix Overlay */
.pattern-layer {
  position: absolute;
  bottom: 0;
  left: -10%;
  width: 120%;
  height: 42%;
  background-image: url("data:image/svg+xml,%3Csvg width='18' height='18' viewBox='0 0 18 18' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M9 2 C9 5.5, 12.5 9, 16 9 C12.5 9, 9 12.5, 9 16 C9 12.5, 5.5 9, 2 9 C5.5 9, 9 5.5, 9 2' fill='%23ff5eaf'/%3E%3C/svg%3E");
  background-size: 18px 18px;
  -webkit-mask-image: radial-gradient(ellipse at 50% 100%, rgba(0,0,0,1) 5%, rgba(0,0,0,0) 55%);
  mask-image: radial-gradient(ellipse at 50% 100%, rgba(0,0,0,1) 5%, rgba(0,0,0,0) 55%);
  mix-blend-mode: screen;
  animation: breathe-pattern 9s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  will-change: opacity, transform;
}

@keyframes breathe-pattern {
  0%   { opacity: 0.0; transform: scale(1) translateY(0); }
  15%  { opacity: 0.05; transform: scale(1) translateY(0); }
  50%  { opacity: 0.7; transform: scale(1.02) translateY(-1%); }
  85%  { opacity: 0.05; transform: scale(1) translateY(0); }
  100% { opacity: 0.0; transform: scale(1) translateY(0); }
}

/* Gemini Star AI message avatar */
.msg-ai .gemini-star {
  /* It might still be used for messages, but we can override it if needed. 
     Wait, the old gemini-star had animations. Let's keep it just in case they are used in AI messages. */
}

.logo-wrapper {
  position: relative;
  z-index: 10;
  width: 72px;
  height: 72px;
  opacity: 0; /* JS will animate this */
  transform-style: preserve-3d;
  will-change: transform;
  cursor: pointer;
  margin-bottom: 24px;
}

.logo-wrapper::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  box-shadow: 0 0 50px rgba(255, 255, 255, 0);
  z-index: -1;
  transition: box-shadow 2s cubic-bezier(0.22, 1, 0.36, 1);
}

.logo-wrapper.active::after {
  box-shadow: 0 0 60px rgba(255, 255, 255, 0.12);
}

[data-theme="light"] .logo-wrapper.active::after {
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.12);
}

.logo-wrapper svg {
  overflow: visible;
  filter: drop-shadow(0px 5px 10px rgba(0, 0, 0, 0.3));
}

.star-hole-tint {
  fill: transparent;
  transition: fill 0.3s ease;
}

[data-theme="light"] .star-hole-tint {
  fill: rgba(0, 0, 0, 0.65);
}

#shockwave {
  transform-origin: center center;
  opacity: 0;
}
@keyframes shockwave {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.05); }
  100% { transform: rotate(360deg) scale(1); }
}


/* Glassmorphism Header (MODIFIED) */
#chat-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1.5rem;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: none !important;
  box-shadow: none !important;
  transition: all var(--transition-slow);
}

#menu-btn {
  display: none;
}

#bot-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  background-color: var(--accent);
}

#chat-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  flex-grow: 1;
}

/* ✅ [REMOVED] #theme-toggle styles, as it's now .popup-action-btn */

/* --- 📨 MESSAGES AREA (UNCHANGED) --- */
#chat-messages {
  flex-grow: 1;
  min-height: 0;
  overflow-y: scroll;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
  padding: 5.5rem 1.5rem calc(var(--composer-height, 90px) + 2rem) 1.5rem;
}

#welcome-screen {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--text-secondary);
  animation: fade-up var(--transition-slow) ease-out;
  z-index: 2;
  position: relative;
}

.app-container.is-chatting #welcome-screen {
  display: none !important;
}

#welcome-screen h1 {
  margin: 1.5rem 0 2.5rem 0;
  color: var(--text-primary);
  font-family: "Inter", "SF Pro Display", -apple-system, system-ui, sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--text-primary) 30%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

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

.message-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-group.bot {
  max-width: 96%;
  align-self: flex-start;
}

.message-group.user {
  align-self: flex-end;
  align-items: flex-end;
  max-width: 85%;
}

.message {
  position: relative;
  line-height: 1.6;
  animation: slide-in 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

@keyframes slide-in {
  from {
    opacity: 0;
    transform: translateY(15px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

.message.user {
  background: var(--user-bubble, #2a2a2c) !important;
  color: var(--user-text, #ffffff);
  padding: 10px 16px !important;
  border-radius: 20px !important;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
  animation: popInUser 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  transform-origin: bottom right;
  word-wrap: break-word;
  width: fit-content;
  max-width: 100%;
}

.message.user .message-content {
  line-height: 1.5;
  font-size: 16px;
  font-weight: 500;
  white-space: pre-wrap;
}
.message.user .message-content p {
  margin: 0 !important;
  padding: 0;
  line-height: inherit;
}

.message.bot {
  background: transparent;
  padding: 8px 0;
  color: #e3e3e3;
}

.message-group.bot .message {
  border-radius: 0;
}

.message-content strong {
  font-weight: 700;
}

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

/* --- Premium Markdown Table Styles --- */
.message-content table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  margin: 1.25rem 0;
  border-radius: var(--radius-sm);
  box-shadow: 0 0 0 1px var(--border);
  background: var(--surface);
  white-space: nowrap; /* Prevents squished columns */
}

.message-content th,
.message-content td {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  line-height: 1.5;
}

.message-content td {
  white-space: normal; /* Allow cell text to wrap if it needs to, but the <th> forces good width */
  min-width: 120px;
}

.message-content th {
  background-color: color-mix(in srgb, var(--accent) 8%, transparent);
  font-weight: 700;
  color: var(--text-primary);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

.message-content tbody tr {
  transition: background-color var(--transition-fast);
}

.message-content tbody tr:nth-child(even) {
  background-color: color-mix(in srgb, var(--text-secondary) 5%, transparent);
}

.message-content tbody tr:hover {
  background-color: color-mix(in srgb, var(--accent) 6%, transparent);
}

.message-content tbody tr:last-child td {
  border-bottom: none;
}
/* ------------------------------------- */

.message-content pre {
  position: relative;
}

.message-content pre code.hljs {
  border-radius: var(--radius-md);
  padding: 1.25em;
  font-size: 0.9em;
}

.copy-code-btn,
.copy-message-btn {
  position: absolute;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  opacity: 0;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  cursor: pointer;
}

.copy-code-btn {
  top: 0.75rem;
  right: 0.75rem;
}

.copy-message-btn {
  bottom: 0.5rem;
  right: 0.75rem;
}

.message:hover .copy-message-btn,
.message-content pre:hover .copy-code-btn {
  opacity: 1;
}

.copy-message-btn:hover,
.copy-code-btn:hover {
  background: var(--bg);
}

.copy-message-btn:active,
.copy-code-btn:active {
  transform: scale(0.95);
}

.tts-btn {
  position: absolute;
  bottom: 0.5rem;
  right: 2.75rem;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition-fast), transform var(--transition-fast), background-color var(--transition-fast);
  cursor: pointer;
}

.message:hover .tts-btn,
.tts-btn.loading,
.tts-btn.playing,
.tts-btn.auto-playing {
  opacity: 1 !important;
  visibility: visible !important;
}

.tts-btn:hover {
  background: var(--bg);
}

.tts-btn:active {
  transform: scale(0.95);
}

.tts-btn svg {
  width: 16px;
  height: 16px;
}

.tts-btn .play-icon {
  display: block;
}

.tts-btn .pause-icon,
.tts-btn .tts-wave-bars {
  display: none;
}

.tts-btn.playing .play-icon,
.tts-btn.loading .play-icon,
.tts-btn.loading .pause-icon {
  display: none;
}

.tts-btn.playing .pause-icon {
  display: block;
}

/* Beautiful TTS Wave Animation */
.tts-btn.loading .tts-wave-bars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 16px;
}

.tts-btn.loading .tts-wave-bars span {
  display: inline-block;
  width: 3px;
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
  animation: tts-wave 1.2s ease-in-out infinite;
}

.tts-btn.loading .tts-wave-bars span:nth-child(1) {
  animation-delay: 0s;
}

.tts-btn.loading .tts-wave-bars span:nth-child(2) {
  animation-delay: 0.15s;
}

.tts-btn.loading .tts-wave-bars span:nth-child(3) {
  animation-delay: 0.3s;
}

.tts-btn.loading .tts-wave-bars span:nth-child(4) {
  animation-delay: 0.45s;
}

@keyframes tts-wave {

  0%,
  100% {
    height: 4px;
    opacity: 0.4;
  }

  50% {
    height: 14px;
    opacity: 1;
  }
}

/* Auto-playing TTS indicator */
.tts-btn.auto-playing {
  opacity: 1 !important;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border-color: var(--accent);
  animation: tts-auto-pulse 2s ease-in-out infinite;
}

.tts-btn.auto-playing .tts-wave-bars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 16px;
}

.tts-btn.auto-playing .tts-wave-bars span {
  display: inline-block;
  width: 3px;
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
  animation: tts-wave 1.2s ease-in-out infinite;
}

.tts-btn.auto-playing .tts-wave-bars span:nth-child(1) {
  animation-delay: 0s;
}

.tts-btn.auto-playing .tts-wave-bars span:nth-child(2) {
  animation-delay: 0.15s;
}

.tts-btn.auto-playing .tts-wave-bars span:nth-child(3) {
  animation-delay: 0.3s;
}

.tts-btn.auto-playing .tts-wave-bars span:nth-child(4) {
  animation-delay: 0.45s;
}

@keyframes tts-auto-pulse {

  0%,
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 40%, transparent);
  }

  50% {
    box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent) 0%, transparent);
  }
}

/* Global Audio Visualizer in Header */
#global-audio-visualizer {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 24px;
  margin-left: auto;
  padding-right: 12px;
  transition: opacity 0.3s ease;
}

#global-audio-visualizer.hidden {
  opacity: 0;
  pointer-events: none;
}

#global-audio-visualizer span {
  width: 3px;
  height: 8px;
  background: var(--accent);
  border-radius: 2px;
  opacity: 0.8;
  box-shadow: 0 0 8px var(--accent);
}

/* Generating state: slow breathing pulse */
#global-audio-visualizer.generating span {
  animation: visualizer-breathe 1.5s ease-in-out infinite;
}

/* Speaking state: active equalizer */
#global-audio-visualizer.speaking span {
  animation: visualizer-bounce 0.8s ease-in-out infinite;
}

#global-audio-visualizer span:nth-child(1) {
  animation-delay: 0.0s;
}

#global-audio-visualizer span:nth-child(2) {
  animation-delay: 0.1s;
}

#global-audio-visualizer span:nth-child(3) {
  animation-delay: 0.2s;
}

#global-audio-visualizer span:nth-child(4) {
  animation-delay: 0.3s;
}

#global-audio-visualizer span:nth-child(5) {
  animation-delay: 0.4s;
}

@keyframes visualizer-breathe {

  0%,
  100% {
    height: 6px;
    opacity: 0.4;
  }

  50% {
    height: 12px;
    opacity: 0.8;
  }
}

@keyframes visualizer-bounce {

  0%,
  100% {
    height: 6px;
  }

  50% {
    height: 20px;
  }
}

.download-btn {
  position: absolute;
  bottom: 0.5rem;
  right: 4.75rem;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition-fast), transform var(--transition-fast), background-color var(--transition-fast);
  cursor: pointer;
}

.message:hover .download-btn {
  opacity: 1;
}

.download-btn:hover {
  background: var(--bg);
}

.download-btn:active {
  transform: scale(0.95);
}

.download-btn svg {
  width: 16px;
  height: 16px;
}

.typing-indicator {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  background: transparent;
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  font-family: "Manrope", sans-serif;
  font-size: 15px;
  font-weight: 500;
}

.premium-loader {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background-color: var(--text-primary);
  animation: premium-pulse 1.2s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

@keyframes premium-pulse {
  0%, 100% { transform: scale(0.6); opacity: 0.3; }
  50% { transform: scale(1); opacity: 1; }
}

#scroll-to-bottom {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  width: 40px;
  height: 40px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
}

#scroll-to-bottom.visible {
  opacity: 1;
  visibility: visible;
  bottom: calc(var(--composer-height, 90px) + 1rem);
}

#scroll-to-bottom svg {
  width: 20px;
  height: 20px;
}

/* --- ⌨️ COMPOSER AREA (UNCHANGED) --- */
#composer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  flex-shrink: 0;
  z-index: 101;
  transition: padding var(--transition-slow);
  padding: 0 0 1.5rem 0;
}

#composer.file-attached {
  padding-top: 66px;
}

#status-row {
  font-size: 0.8rem;
  color: var(--text-secondary);
  min-height: 24px;
  padding: 0 1.5rem 0.5rem 1.5rem;
  text-align: center;
}

#api-status-row {
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
  padding: 0.4rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-pill);
  margin: 0 auto 0.75rem auto;
  max-width: calc(100% - 3rem);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

#api-status-row:not(.hidden) {
  opacity: 1;
  transform: translateY(0);
}

#input-wrapper {
  position: relative;
  display: flex;
  align-items: flex-end;
  flex-wrap: nowrap;
  gap: 0.75rem;
  background: #212121;
  border: none;
  border-radius: 50px;
  padding: 10px 20px 10px 20px;
  min-height: 80px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transition: all 0.3s;
  width: calc(100% - 3rem);
  max-width: 700px;
  margin: 0 auto;
  z-index: 105;
}

#input-wrapper:focus-within {
  background: #2a2a2a;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.left-actions, .right-actions {
  display: flex;
  align-items: center;
  height: 60px;
  flex-shrink: 0;
}

.right-actions {
  gap: 0.5rem;
}

/* Expanded state for input wrapper when multiline */
#input-wrapper.is-expanded {
  flex-wrap: wrap;
  border-radius: 38px;
  padding: 12px 20px 10px 20px;
  row-gap: 0;
}

#input-wrapper.is-expanded #message-input {
  order: 1;
  flex: 0 0 100%;
  margin-bottom: -6px;
  padding: 0;
}

#input-wrapper.is-expanded .left-actions {
  order: 2;
}

#input-wrapper.is-expanded .right-actions {
  order: 3;
  margin-left: auto;
}

#message-input {
  flex-grow: 1;
  border: none;
  padding: 18px 4px;
  resize: none;
  outline: none;
  font-size: 1rem;
  max-height: 160px;
  overflow-y: auto;
  background-color: transparent;
  color: #e8e6e3; /* Force light text against the dark textarea */
  line-height: 24px;
  min-height: 60px;
  box-sizing: border-box;
}

#message-input:focus {
  box-shadow: none;
}

#message-input::placeholder {
  color: #969390; /* Force light grey placeholder */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#send-btn {
  width: 44px;
  height: 44px;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: #31406d !important;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
  cursor: pointer;
  box-shadow: none !important;
}

#send-btn svg {
  width: 35px;
  height: 35px;
  stroke: #a8c7fa;
}

#send-btn:hover {
  background: #28345a !important;
}

#send-btn:active {
  transform: scale(0.95);
  transition-duration: 0.1s;
}

#send-btn:disabled {
  opacity: 1 !important;
  cursor: not-allowed;
  transform: scale(1);
}

#send-btn .mic-icon {
  display: block;
}

#send-btn .send-icon {
  display: none;
}

#send-btn .spinner {
  display: none;
}

#send-btn.loading .mic-icon,
#send-btn.loading .send-icon {
  display: none;
}

#send-btn.loading .spinner {
  display: block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

#send-btn.listening {
  /* keep this if needed */
}

#live-mode-btn .recording-indicator {
  display: none;
  width: 14px;
  height: 14px;
  background-color: #ef4444;
  border-radius: 4px;
  margin: auto;
  animation: pulse-record 1.5s infinite;
}

#live-mode-btn.recording-active svg {
  display: none !important;
}

#live-mode-btn.recording-active .recording-indicator {
  display: block;
}

@keyframes pulse-record {
  0% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { transform: scale(0.9); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

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

@keyframes pulse-mic {
  0% {
    box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.7);
  }

  70% {
    box-shadow: 0 0 0 10px rgba(229, 57, 53, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(229, 57, 53, 0);
  }
}

/* --- ⚙️ USER SETTINGS POPUP --- */
#user-settings-popup {
  position: absolute;
  bottom: 80px;
  left: 20px;
  width: 260px;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  opacity: 0;
  transform: translateY(10px);
  visibility: hidden;
  transition: all var(--transition-fast);
}

#user-settings-popup.active {
  opacity: 1;
  transform: translateY(0);
  visibility: visible;
}

.popup-section-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 0.5rem;
  padding: 0 0.5rem;
}

.popup-action-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.popup-action-btn:hover {
  background: var(--surface);
}

.popup-action-btn svg {
  width: 18px;
  height: 18px;
  color: var(--text-secondary);
}

.popup-action-btn.danger {
  color: #ef4444;
}

.popup-action-btn.danger svg {
  color: #ef4444;
}

.popup-divider {
  height: 1px;
  background: var(--border);
  margin: 0.5rem 0;
}

/* Voice Selection Section */
.popup-section {
  padding: 0.5rem;
}

.popup-select-wrapper {
  position: relative;
  width: 100%;
  margin-top: 0.25rem;
}

.popup-select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.9rem;
  appearance: none;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition-fast);
}

.popup-select:focus {
  border-color: var(--accent);
}

/* Custom arrow for select */
.popup-select-wrapper::after {
  content: '▼';
  font-size: 0.6rem;
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  pointer-events: none;
}

/* --- ACTIONS BUTTON & POPUP (UNCHANGED) --- */
#composer-actions-btn {
  flex-shrink: 0;
  position: relative;
  transition: transform var(--transition-slow);
}

#composer-actions-btn.active {
  transform: rotate(135deg);
  background-color: var(--bg);
}

#composer-actions-popup {
  position: absolute;
  bottom: calc(100% + 16px);
  left: 0;
  width: 280px;
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: 24px;
  box-shadow: var(--shadow-lg, 0 8px 32px rgba(0,0,0,0.15));
  border: 1px solid var(--border);
  z-index: 200;
  padding: 16px;
  opacity: 0;
  transform: translateY(10px) scale(0.95);
  visibility: hidden;
  transform-origin: bottom left;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

#composer-actions-popup.show {
  opacity: 1;
  transform: translateY(0) scale(1);
  visibility: visible;
  pointer-events: auto;
}

#personality-list-title {
  display: block;
}

.popup-section-title {
  display: block;
  padding: 4px 16px 8px 16px;
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

#personality-list {
  display: flex;
  flex-direction: row;
  gap: 0.5rem;
  padding: 0 16px 12px 16px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none; /* Firefox */
}
#personality-list::-webkit-scrollbar {
  display: none; /* Chrome/Safari */
}

.personality-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 8px 4px;
  border-radius: 12px;
  cursor: pointer;
  transition: background-color var(--transition-fast);
  width: 80px;
  flex-shrink: 0;
  text-align: center;
}

.personality-item .personality-avatar {
  width: 40px;
  height: 40px;
  margin: 0 auto;
}

.personality-item .personality-name {
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.personality-item .personality-description {
  display: none; /* Hide description in grid view to save space */
}



.personality-item:hover {
  background-color: var(--surface);
}

.personality-item.active {
  background-color: #12373b;
  color: #5eead4;
}

.personality-item.active .personality-name {
  color: #5eead4;
}

.personality-item.active .personality-description {
  color: rgba(94, 234, 212, 0.7);
}

.personality-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background-color: var(--border);
}

.personality-info {
  overflow: hidden;
}

.personality-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.personality-description {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.popup-divider {
  height: 1px;
  background-color: var(--border);
  margin: 0.75rem 0;
}

#file-upload-wrapper {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: calc(100% - 32px);
  margin: 0 16px 12px 16px;
  padding: 10px 12px;
  border-radius: 12px;
  transition: background-color var(--transition-fast);
  color: #fff;
  cursor: pointer;
}

#file-upload-wrapper:hover {
  background-color: rgba(255,255,255,0.05);
}

#file-upload-wrapper svg {
  width: 22px;
  height: 22px;
  color: var(--text-secondary);
}

#file-upload-wrapper span {
  font-weight: 600;
  color: var(--text-primary);
}

#file-upload {
  position: absolute;
  left: 0;
  top: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* --- 📱 RESPONSIVENESS & OVERLAY (UNCHANGED) --- */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 99;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-slow);
}

#overlay.show {
  opacity: 1;
  visibility: visible;
}

@media (max-width: 900px) {
  #app {
    padding: 0;
    gap: 0;
  }

  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-105%);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.2);
    width: 80%;
    max-width: 340px;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
  }

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

  #menu-btn {
    display: flex;
  }

  #chat-header {
    padding-left: 1rem;
    padding-right: 1rem;
    border-radius: 0;
  }

  #chat-container {
    border-radius: 0;
    padding-bottom: 0.5rem;
  }

  #composer {
    padding-bottom: 0.5rem;
  }

  #composer.file-attached {
    padding-top: 60px;
  }

  #input-wrapper {
    width: calc(100% - 1rem);
    margin: 0 auto;
  }

  #chat-messages {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  #file-preview-container {
    left: 0.5rem;
    right: 0.5rem;
  }
}

/* --- 💅 PRO AI TYPOGRAPHY (REPLACE EXISTING .message-content SECTION) --- */

.message-content {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  word-wrap: break-word;
  font-weight: 400;
}

.message-content p {
  margin-top: 0;
  margin-bottom: 1em;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content h1,
.message-content h2,
.message-content h3 {
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  line-height: 1.3;
}

.message-content h3 {
  font-size: 1.1rem;
}

.message-content ul,
.message-content ol {
  margin: 0.5em 0 1em 1.2em;
  padding-left: 0;
}

.message-content li {
  margin-bottom: 0.4em;
  padding-left: 0.2em;
}

.message-content li::marker {
  color: var(--text-secondary);
  font-weight: 500;
}

.message-content pre {
  background: #1e1e1e !important;
  color: #e0e0e0;
  border-radius: 12px;
  padding: 1.2rem;
  margin: 1.5rem 0;
  overflow-x: auto;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.9em;
  line-height: 1.6;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.message-content pre code {
  background: transparent !important;
  padding: 0;
  border-radius: 0;
  color: inherit;
}

.message-content :not(pre)>code {
  background-color: var(--bg-secondary, rgba(125, 125, 125, 0.1));
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 0.2em 0.5em;
  border-radius: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85em;
  font-weight: 600;
}

.message-content blockquote {
  border-left: 4px solid var(--accent);
  background: linear-gradient(to right, var(--surface), transparent);
  margin: 1.5em 0;
  padding: 0.5em 0 0.5em 1.5em;
  color: var(--text-secondary);
  font-style: italic;
}

.message-content a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}

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

.message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5em 0;
  font-size: 0.95rem;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.message-content th,
.message-content td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.message-content th {
  background-color: var(--surface);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.message-content .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.5em 0;
}

.message-content .katex {
  font-size: 1.05em;
  color: var(--text-primary);
}

[data-theme="dark"] .message-content .katex {
  color: var(--text-primary-dark);
}

.message-content .katex .mathnormal {
  font-family: "Manrope", KaTeX_Main, serif !important;
}

.message-content mjx-container {
  display: block !important;
  max-width: 100% !important;
  white-space: normal !important;
  overflow: hidden !important;
}

.message-content mjx-container>svg {
  max-width: 100% !important;
  height: auto !important;
}

.message-content mjx-container[display="block"] {
  text-align: left !important;
  margin: 0.5em 0;
}

.message-content img,
.message-image-attachment {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  background-color: var(--surface);
}

.message-images-container {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  max-width: 480px;
}

.message-images-container a {
  display: block;
  overflow: hidden;
  border-radius: var(--radius-md);
  background-color: var(--surface);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
}

.message-images-container .message-image-attachment {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 1px solid var(--border);
  transition: transform var(--transition-fast);
}

.message-images-container a:hover .message-image-attachment {
  transform: scale(1.05);
}

.images-count-1 {
  grid-template-columns: 1fr;
  max-width: 320px;
}

.images-count-2 {
  grid-template-columns: 1fr 1fr;
}

.images-count-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.images-count-4 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.images-count-5 {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(2, 1fr);
}

.images-count-5 a:nth-child(1) {
  grid-area: 1 / 1 / 2 / 4;
}

.images-count-5 a:nth-child(2) {
  grid-area: 1 / 4 / 2 / 7;
}

.images-count-5 a:nth-child(3) {
  grid-area: 2 / 1 / 3 / 3;
}

.images-count-5 a:nth-child(4) {
  grid-area: 2 / 3 / 3 / 5;
}

.images-count-5 a:nth-child(5) {
  grid-area: 2 / 5 / 3 / 7;
}

.message-images-container a {
  aspect-ratio: 1 / 1;
}

.images-count-1 a {
  aspect-ratio: 4 / 3;
}

#file-preview-container {
  position: absolute;
  bottom: 100%;
  left: 1.5rem;
  right: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

#file-preview-container::-webkit-scrollbar {
  display: none;
}

.file-preview-item {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 0.3rem 0.3rem 0.3rem 0.6rem;
  font-size: 0.9rem;
  flex-shrink: 0;
  animation: slide-in 0.3s ease-out;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  max-width: 200px;
  transition: border-color var(--transition-fast);
}

.file-preview-item.completed {
  border-color: #10b981;
}

.file-preview-item.error {
  border-color: #ef4444;
}

.file-preview-thumbnail {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 50%;
  flex-shrink: 0;
}

.file-preview-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--surface);
  border-radius: 50%;
  flex-shrink: 0;
}

.file-preview-icon svg {
  width: 16px;
  height: 16px;
  color: var(--text-secondary);
}

.file-preview-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.remove-file-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background-color: var(--border);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
  transition: all var(--transition-fast);
  margin-left: 0.25rem;
  flex-shrink: 0;
  z-index: 5;
}

.remove-file-btn:hover {
  background-color: #ef4444;
  color: white;
  transform: scale(1.1) rotate(90deg);
}

.file-preview-item.uploading .remove-file-btn {
  display: none;
}

.file-preview-overlay {
  position: absolute;
  inset: 0;
  background-color: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  transition: opacity var(--transition-fast);
}

[data-theme="dark"] .file-preview-overlay {
  background-color: rgba(20, 20, 20, 0.7);
}

.file-preview-overlay .spinner {
  width: 20px;
  height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.file-preview-overlay svg {
  width: 24px;
  height: 24px;
}

.file-preview-item.completed .file-preview-overlay svg {
  color: #10b981;
}

.file-preview-item.error .file-preview-overlay svg {
  color: #ef4444;
}


/* --- File Upload Progress and Status Enhancements --- */

.file-preview-item {
  position: relative;
  /* Needed for absolute positioning */
  /* padding-bottom: 8px; /* Make space for the progress bar - REMOVED, use margin on name */
  overflow: hidden;
  /* Prevent progress bar overflowing rounded corners */
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

/* Ensure content stays aligned vertically */
.file-preview-item>*:not(.file-progress-bar):not(.file-preview-overlay) {
  z-index: 1;
  /* Keep content above progress bar bg */
}


/* Style for active processing states */
.file-preview-item.status-parsing,
.file-preview-item.status-processing_rag {
  /* Optional: Subtle background/border change */
  /* background-color: color-mix(in srgb, var(--bg) 90%, var(--accent)); */
  border-color: var(--accent);
}

/* Progress bar container */
.file-progress-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  /* Use right instead of width for responsiveness */
  height: 5px;
  /* Slightly thicker bar */
  background-color: color-mix(in srgb, var(--border) 50%, transparent);
  /* More subtle background */
  border-radius: 0 0 var(--radius-pill) var(--radius-pill);
  /* Match parent rounding */
  overflow: hidden;
  z-index: 0;
  /* Behind content, above background */
  opacity: 0;
  /* Hidden by default */
  transition: opacity var(--transition-fast);
}

.file-preview-item.status-parsing .file-progress-bar,
.file-preview-item.status-processing_rag .file-progress-bar {
  opacity: 1;
  /* Show during processing */
}


/* Progress bar fill */
.file-progress-bar .file-progress-fill {
  height: 100%;
  width: 0%;
  /* Initial width */
  background-color: var(--accent);
  /* Progress color */
  border-radius: inherit;
  /* Inherit rounding */
  transition: width 0.2s linear;
  /* Linear transition for smoother progress update */
}

/* Adjustments for overlay positioning */
.file-preview-overlay {
  z-index: 2;
  /* Ensure overlay is above content but below remove button */
  border-radius: var(--radius-pill);
  /* Match parent rounding */
}

.file-preview-overlay svg {
  /* Ensure icons in overlay are visible */
  z-index: 3;
}

/* Ensure remove button is above overlay */
.remove-file-btn {
  z-index: 5;
}

/* Prevent interaction with overlay during processing */
.file-preview-item.status-parsing .file-preview-overlay,
.file-preview-item.status-processing_rag .file-preview-overlay {
  pointer-events: none;
}

/* Style for completed state overlay icon */
.file-preview-item.status-completed .file-preview-overlay svg,
.file-preview-item.status-completed_rag .file-preview-overlay svg {
  color: #10b981;
}

/* Style for error state overlay icon */
.file-preview-item.status-error .file-preview-overlay svg {
  color: #ef4444;
}

.file-preview-item.status-error {
  border-color: #ef4444;
  /* Keep border red on error */
}


/* Style for cancelled state overlay icon */
.file-preview-item.status-cancelled .file-preview-overlay svg {
  color: var(--text-secondary);
  /* Use secondary text color for cancelled */
}

.file-preview-item.status-cancelled {
  opacity: 0.7;
  /* Optional: fade cancelled items */
}

/* Ensure name doesn't overlap remove button when long */
.file-preview-name {
  margin-right: 5px;
  /* Add some space before remove button */
  /* Text overflow handled by parent */
}

/* Adjust spinner color in overlay */
.file-preview-overlay .spinner {
  border-top-color: var(--accent);
}



.prompt-suggestions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1rem;
  width: 100%;
  max-width: 550px;
}

.prompt-suggestion-btn {
  padding: 0.6rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background-color: var(--surface);
  transition: all var(--transition-fast);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.04), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
}

.prompt-suggestion-btn:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  background-color: var(--bg);
  box-shadow: var(--shadow);
}

.prompt-suggestion-btn .prompt-title {
  font-weight: 600;
}



.hidden {
  display: none !important;
}

.image-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: var(--bg);
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem 1rem;
  margin: 0.5rem 0;
  max-width: 350px;
  aspect-ratio: 1 / 1;
  transition: all var(--transition-fast);
}

.image-placeholder .spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 1rem;
}

.image-placeholder p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
  margin: 0;
  line-height: 1.5;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(20, 20, 20, 0.6);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity var(--transition-fast), backdrop-filter var(--transition-fast);
  padding: 1rem;
}

.modal-overlay:not(.hidden) {
  opacity: 1;
}

.modal-content {
  position: relative;
  background-color: var(--bg);
  padding: 1.5rem 2rem;
  border-radius: var(--radius-md);
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow);
  text-align: center;
  transform: scale(0.95);
  transition: transform var(--transition-fast);
}

.modal-overlay:not(.hidden) .modal-content {
  transform: scale(1);
}

.modal-close-btn {
  position: absolute;
  top: 10px;
  right: 15px;
  font-size: 2rem;
  font-weight: 300;
  line-height: 1;
  color: var(--text-secondary);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: color var(--transition-fast);
}

.modal-close-btn:hover {
  color: var(--text-primary);
}

.modal-content h3 {
  margin-top: 0;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
  font-size: 1.25rem;
}

.modal-content p {
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  line-height: 1.6;
  font-size: 0.9rem;
}

.modal-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.btn {
  padding: 8px 8px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  transition: all var(--transition-fast);
  background-color: var(--accent);
  color: white;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.btn.ghost {
  background-color: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.btn.ghost:hover {
  background-color: var(--surface);
  border-color: var(--accent);
}

.modal-content .spinner {
  width: 20px;
  height: 20px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  display: inline-block;
  vertical-align: middle;
  margin-right: 0.5rem;
}

.modal-content.preview {
  max-width: 370px;
  width: 100%;
  aspect-ratio: 8 / 11;
  padding: 0;
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background-color: var(--surface);
  transform: scale(0.95) translateY(10px);
}

.modal-overlay:not(.hidden) .modal-content.preview {
  transform: scale(1) translateY(0);
}

.modal-content.preview #preview-video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 80%;
  object-fit: cover;
  z-index: 1;
}

.modal-content.preview .preview-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: linear-gradient(180deg, rgba(20, 20, 20, 0) 0%, rgba(20, 20, 20, 0.2) 50%, rgba(20, 20, 20, 0.9) 100%);
}

.modal-content.preview .preview-content {
  position: relative;
  z-index: 3;
  width: 100%;
  height: 100%;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

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

.modal-content.preview .preview-header h3 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.modal-content.preview .preview-header span {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.6rem;
  background-color: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: var(--radius-pill);
  color: #f0f0f0;
}

.modal-content.preview .preview-header span svg {
  color: #10b981;
  animation: pulse-live 2s infinite;
}

@keyframes pulse-live {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.4;
  }
}

.modal-content.preview .preview-footer {
  text-align: left;
}

.modal-content.preview .preview-footer p {
  font-size: 0.95rem;
  line-height: 1.6;
  margin-bottom: 1rem;
  color: #e5e7eb;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}

.modal-content.preview .modal-actions {
  gap: 0.75rem;
}

.modal-content.preview .btn {
  flex-grow: 1;
  text-align: center;
  justify-content: center;
  padding: 0.8rem 1rem;
  font-size: 0.9rem;
}

.modal-content.preview #confirm-personality-switch-btn {
  background-color: #ec4899;
  border: none;
}

.modal-content.preview #confirm-personality-switch-btn:hover {
  background-color: #db2777;
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(236, 72, 153, 0.3);
}

.modal-content.preview .btn.ghost {
  background-color: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
}

.modal-content.preview .btn.ghost:hover {
  background-color: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.3);
}

.modal-content.preview .modal-close-btn {
  z-index: 4;
  color: #fff;
  opacity: 0.7;
  top: 1rem;
  right: 1rem;
  transition: all var(--transition-fast);
}

.modal-content.preview .modal-close-btn:hover {
  opacity: 1;
  transform: scale(1.1) rotate(90deg);
}

#tour-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  transition: opacity var(--transition-slow), clip-path var(--transition-slow);
}

.tour-spotlight {
  position: absolute;
  border-radius: var(--radius-md);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6);
  transition: all var(--transition-slow);
  pointer-events: none;
}

.tour-tooltip {
  position: absolute;
  background-color: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  max-width: 320px;
  z-index: 9999;
  transition: all var(--transition-slow);
  border: 1px solid var(--border);
}

.tour-content h4 {
  margin: 0 0 0.5rem 0;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.tour-content p {
  margin: 0 0 1.25rem 0;
  line-height: 1.6;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.tour-navigation {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#tour-step-counter {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.tour-buttons {
  display: flex;
  gap: 0.5rem;
}

.tour-buttons .btn {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}

.announcement-popup-content {
  padding: 0;
  max-width: 420px;
  overflow: hidden;
  text-align: left;
}

.announcement-media {
  width: 100%;
  aspect-ratio: 16 / 9;
  background-color: var(--bg);
}

.announcement-media img,
.announcement-media video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.announcement-text-content {
  padding: 1.5rem 2rem;
}

#announcement-popup h3 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

#announcement-popup p {
  font-size: 1rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.announcement-actions {
  padding: 0 2rem 1.5rem 2rem;
  display: flex;
}

.announcement-actions .btn {
  width: 100%;
  justify-content: center;
}

.announcement-details-content {
  max-width: 650px;
  text-align: left;
}

#announcement-details-content {
  max-height: 70vh;
  overflow-y: auto;
  padding-right: 1rem;
}

#export-loading-modal {
  z-index: 1001;
}

.export-loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  background-color: var(--surface);
  padding: 2.5rem 3rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  max-width: 320px;
  width: 100%;
}

#export-loader-svg {
  width: 80px;
  height: 80px;
  transform-origin: center;
  animation: spin 2s linear infinite;
}

#export-loader-svg circle {
  fill: none;
  stroke-width: 6;
  stroke-linecap: round;
  transform-origin: center;
}

#export-loader-svg .track {
  stroke: var(--border);
}

#export-loader-svg .progress {
  stroke: var(--accent);
  stroke-dasharray: 200;
  stroke-dashoffset: 200;
  animation: progress-animation 1.5s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

#export-loading-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
}

@keyframes progress-animation {
  0% {
    stroke-dashoffset: 200;
  }

  50% {
    stroke-dashoffset: 50;
    transform: rotate(180deg);
  }

  100% {
    stroke-dashoffset: 200;
    transform: rotate(360deg);
  }
}

.message-content .download-link {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--bg);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-pill);
  font-weight: 600;
  text-decoration: none;
  transition: all var(--transition-fast);
  margin-top: 0.75rem;
}

.message-content .download-link:hover {
  background-color: var(--surface);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.message-content .download-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* --- ✅ [NEW] NON-BLOCKING TOAST NOTIFICATION STYLES --- */
#toast-container {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: flex-end;
}

.toast-notification {
  display: flex;
  align-items: center;
  gap: 1rem;
  background-color: var(--surface);
  color: var(--text-primary);
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 380px;
  pointer-events: auto;
}

.toast-notification.entering {
  animation: slide-in-from-right 0.5s cubic-bezier(0.21, 1.02, 0.73, 1) forwards;
}

.toast-notification.exiting {
  animation: slide-out-to-right 0.5s cubic-bezier(0.25, 0, 0.5, 1) forwards;
}

.toast-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toast-message {
  flex-grow: 1;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.5;
}

.toast-close-btn {
  color: var(--text-secondary);
  font-size: 1.5rem;
  line-height: 1;
  opacity: 0.7;
  transition: all var(--transition-fast);
}

.toast-close-btn:hover {
  opacity: 1;
  transform: scale(1.1);
}

.toast-loader-svg {
  width: 24px;
  height: 24px;
  animation: spin 1.5s linear infinite;
}

.toast-loader-svg .path {
  stroke: #e53935;
  /* Red color as requested */
  stroke-linecap: round;
  animation: dash 1.5s ease-in-out infinite;
}

@keyframes slide-in-from-right {
  from {
    opacity: 0;
    transform: translateX(100%);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slide-out-to-right {
  from {
    opacity: 1;
    transform: translateX(0);
  }

  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

@keyframes dash {
  0% {
    stroke-dasharray: 1, 150;
    stroke-dashoffset: 0;
  }

  50% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -35;
  }

  100% {
    stroke-dasharray: 90, 150;
    stroke-dashoffset: -124;
  }
}

/* --- ✅ [NEW] PDF DOWNLOAD LINK STATUS STYLES --- */
.message-content .download-link-pdf {
  min-width: 150px;
  /* Prevent layout shift during text changes */
  justify-content: center;
  cursor: pointer;
}

.message-content .download-link-pdf svg {
  transition: all var(--transition-fast);
}

.message-content .download-link-pdf[data-status="processing"] {
  color: var(--text-secondary);
  background-color: var(--surface);
  border-color: var(--border);
  cursor: wait;
  pointer-events: none;
  /* Prevent multiple clicks */
}

.message-content .download-link-pdf[data-status="completed"] {
  border-color: #10b981;
  color: #10b981;
}

.message-content .download-link-pdf[data-status="completed"]:hover {
  background-color: #10b9811a;
  color: #059669;
}

.message-content .download-link-pdf[data-status="completed"] svg {
  color: #10b981;
}

.message-content .download-link-pdf[data-status="failed"] {
  border-color: #ef4444;
  color: #ef4444;
}

.message-content .download-link-pdf[data-status="failed"]:hover {
  background-color: #ef44441a;
  color: #dc2626;
}

.message-content .download-link-pdf[data-status="failed"] svg {
  color: #ef4444;
}

.link-loader-svg {
  width: 18px;
  height: 18px;
  animation: spin 1.5s linear infinite;
}

.link-loader-svg .path {
  stroke: var(--accent);
  stroke-linecap: round;
  fill: none;
  stroke-width: 5;
  animation: dash 1.5s ease-in-out infinite;
}

/* --- Basic Styling for User Message Attachments --- */
.message-attachments-user {
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  /* border-bottom: 1px solid rgba(255, 255, 255, 0.2); Optional separator */
}

.attachment-item-user {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85em;
  opacity: 0.9;
  margin-bottom: 0.2rem;
}

.attachment-item-user svg {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
}

.message-content hr {
  /* Separator between attachments and text */
  border: none;
  height: 1px;
  background-color: var(--border);
  /* Use theme border color */
  opacity: 0.3;
  margin: 0.6rem 0;
}

/* Adjustments for dark theme user message */
[data-theme="dark"] .message.user .message-attachments-user {
  /* border-bottom-color: rgba(255, 255, 255, 0.1); */
  color: #e0e0e0;
  /* Slightly lighter text for dark background */
}

[data-theme="dark"] .message.user .message-content hr {
  background-color: rgba(255, 255, 255, 0.2);
}


/* Adjustments for light theme user message */
[data-theme="light"] .message.user .message-attachments-user {
  /* border-bottom-color: rgba(0, 0, 0, 0.1); */
  color: #333;
  /* Darker text for light background */
}

[data-theme="light"] .message.user .message-content hr {
  background-color: rgba(0, 0, 0, 0.1);
}

/* --- 🖼️ Fix Massive Images --- */
.message-content img,
.message-image-attachment {
  max-width: 100%;
  max-height: 350px;
  /* Restrict height so it doesn't fill the screen */
  width: auto;
  height: auto;
  border-radius: 12px;
  object-fit: contain;
  display: block;
  margin: 0.5rem 0;
  background-color: rgba(0, 0, 0, 0.03);
  border: 1px solid var(--border);
}

/* --- 📧 Modern Email Draft Card --- */
.email-draft-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-top: 1rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 500px;
  /* Prevent it from getting too wide */
}

/* Header with Icon */
.email-draft-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  font-size: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
}

/* Field Container */
.email-draft-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* Labels */
.email-draft-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Inputs & Textarea */
.email-draft-input,
.email-draft-textarea {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.email-draft-input:focus,
.email-draft-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.email-draft-textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.5;
}

/* Buttons Footer */
.email-draft-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding-top: 0.5rem;
}

.email-draft-actions .btn {
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.email-draft-actions .btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.email-draft-actions .btn.ghost:hover {
  background: var(--bg);
  color: var(--text-primary);
  border-color: var(--text-primary);
}

.send-email-btn {
  background: var(--accent);
  color: white;
  border: none;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.send-email-btn:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

/* --- 🖥️ RESPONSIVE & LARGE SCREEN OVERHAUL --- */

/* 1. Global Image Constraints (Fixes "Massive Images") */
.message-content img,
.message-image-attachment {
  max-width: 100%;
  max-height: 350px;
  /* Cap height so you don't scroll forever */
  width: auto;
  height: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  object-fit: contain;
  /* Ensure whole image is visible */
  background-color: rgba(0, 0, 0, 0.03);
  margin-top: 8px;
  display: block;
}

/* 2. Tablet & Desktop Layout (Min-Width: 600px) 
   This fixes the "Too Long" text and the "Side Badge" issue */
@media (min-width: 600px) {

  /* Center the Chat Column */
  #chat-messages {
    max-width: 720px;
    /* Limit reading width for comfort */
    width: 100%;
    margin: 0 auto;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }

  /* Fix the Input Area Layout */
  #composer {
    display: flex;
    flex-direction: column;
    /* ✅ Force Vertical Stacking (Status on top of Input) */
    align-items: center;
    /* Center them horizontally */
    width: 100%;
  }

  /* Constrain Input Width to match Chat */
  #input-wrapper {
    width: calc(100% - 3rem);
    max-width: 700px;
    margin: 0 auto;
  }

  /* Constrain & Center Status Badge */
  #status-row,
  #api-status-row {
    width: 100%;
    max-width: 700px;
    text-align: center;
    margin-bottom: 0.5rem;
  }

  /* Better Bubble Widths (Prevents ultra-wide bubbles) */
  .message-group {
    max-width: 85%;
  }

  .message-group.bot {
    max-width: 85%;
  }

  .email-draft-card {
    max-width: 550px;
    margin: 0;
    /* Align with content */
  }
}

/* 3. Desktop Specific Polish (Min-Width: 1025px) */
@media (min-width: 1025px) {
  #chat-messages {
    max-width: 760px;
    /* Tighter reading width for big screens */
  }

  #input-wrapper {
    max-width: 760px;
  }

  #status-row,
  #api-status-row {
    max-width: 760px;
  }

  /* Limit user bubble width to keep it neat */
  .message-group.user {
    max-width: 60%;
  }

  /* Let bot text length out completely like in Gemini */
  .message-group.bot {
    max-width: 100%;
  }
}

/* 4. Mobile & Tablet Compact Mode (Max-Width: 1024px)
   This fixes the "Too High" bubbles on smaller screens */
@media (max-width: 1024px) {

  /* Reduce Sidebar Width */
  :root {
    --sidebar-width: 240px;
  }

  /* Tighter Bubble Padding */
  .message {
    padding: 0.5rem 0.5rem;
    /* Slimmer look */
    border-radius: 12px;
  }

  .message.user {
    padding: 14px 20px !important;
    border-radius: 28px !important;
  }

  .message-content {
    font-size: 0.95rem;
    line-height: 1.5;
  }

  /* Compact Input */
  #message-input {
    padding: 0.4rem 0.5rem;
    min-height: 24px;
  }
}
/* --- EXACT MOBILE MOCKUP CSS INTEGRATION --- */
:root {
    --bg-color: #000000;
    --input-bg: #1c1c1e;
    --audio-btn-bg: #1e3163;
    --audio-btn-hover: #263e7c;
    --audio-icon: #a8c7fa;
    --icon-color: #c4c4c4;
}

/* Animations and Global effects */
.glow-container {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: 0;
    pointer-events: none;
    transition: opacity 1.2s cubic-bezier(0.4, 0, 0.2, 1), transform 1.2s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: opacity, transform;
}
.app-container.is-chatting .glow-container {
    opacity: 0;
    transform: translateY(15%);
}
.ambient-glow {
    position: absolute;
    bottom: -10%;
    left: -10%;
    width: 120%;
    height: 60%;
    background: radial-gradient(circle at 50% 100%, rgba(255, 140, 50, 0.55) 0%, rgba(255, 140, 50, 0.2) 50%, transparent 75%);
    animation: flow-blue 10s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    border-radius: 50% 50% 20% 20% / 100% 100% 0% 0%;
    will-change: transform, border-radius;
}
@keyframes flow-blue {
    0% { transform: translateX(0) scale(1); border-radius: 50% 50% 20% 20% / 80% 80% 0% 0%; }
    33% { transform: translateX(-4%) scale(1.03); border-radius: 40% 60% 30% 20% / 90% 70% 10% 20%; }
    66% { transform: translateX(4%) scale(0.97); border-radius: 60% 40% 20% 30% / 70% 90% 20% 10%; }
    100% { transform: translateX(0) scale(1); border-radius: 50% 50% 20% 20% / 80% 80% 0% 0%; }
}
.purple-blob {
    position: absolute;
    bottom: -10%;
    height: 38%;
    width: 70%;
    background: radial-gradient(ellipse at 50% 100%, rgba(200, 45, 115, 0.45) 0%, rgba(130, 25, 75, 0.2) 50%, transparent 70%);
    mix-blend-mode: screen;
    border-radius: 50% 50% 0 0 / 100% 100% 0 0;
    will-change: transform;
}
.purple-blob.left {
    left: -15%;
    animation: blob-left 8s cubic-bezier(0.4, 0, 0.2, 1) infinite alternate;
}
.purple-blob.right {
    right: -15%;
    animation: blob-right 8.5s cubic-bezier(0.4, 0, 0.2, 1) infinite alternate;
}
@keyframes blob-left {
    0% { transform: translateX(0) scale(1); }
    50% { transform: translateX(30%) scale(1.1); }
    100% { transform: translateX(-5%) scale(0.95); }
}
@keyframes blob-right {
    0% { transform: translateX(0) scale(1); }
    50% { transform: translateX(-30%) scale(1.1); }
    100% { transform: translateX(5%) scale(0.95); }
}
.pattern-layer {
    position: absolute;
    bottom: 0;
    left: -10%;
    width: 120%;
    height: 42%;
    background-image: url("data:image/svg+xml,%3Csvg width='18' height='18' viewBox='0 0 18 18' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M9 2 C9 5.5, 12.5 9, 16 9 C12.5 9, 9 12.5, 9 16 C9 12.5, 5.5 9, 2 9 C5.5 9, 9 5.5, 9 2' fill='%23ff5eaf'/%3E%3C/svg%3E");
    background-size: 18px 18px;
    -webkit-mask-image: radial-gradient(ellipse at 50% 100%, rgba(0, 0, 0, 1) 5%, rgba(0, 0, 0, 0) 55%);
    mask-image: radial-gradient(ellipse at 50% 100%, rgba(0, 0, 0, 1) 5%, rgba(0, 0, 0, 0) 55%);
    mix-blend-mode: screen;
    animation: breathe-pattern 9s cubic-bezier(0.4, 0, 0.2, 1) infinite;
    will-change: opacity, transform;
}
@keyframes breathe-pattern {
    0% { opacity: 0.0; transform: scale(1) translateY(0); }
    15% { opacity: 0.05; transform: scale(1) translateY(0); }
    50% { opacity: 0.7; transform: scale(1.02) translateY(-1%); }
    85% { opacity: 0.05; transform: scale(1) translateY(0); }
    100% { opacity: 0.0; transform: scale(1) translateY(0); }
}

.gemini-star {
    width: 52px;
    height: 52px;
    background: conic-gradient(from 200deg at 50% 50%, #ea4335 0deg, #fbbc04 90deg, #34a853 180deg, #4285f4 270deg, #ea4335 360deg);
    -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Cpath d='M24 0 C24 14, 14 24, 0 24 C14 24, 24 34, 24 48 C24 34, 34 24, 48 24 C34 24, 24 14, 24 0 Z' fill='black'/%3E%3C/svg%3E") no-repeat center;
    mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 48 48'%3E%3Cpath d='M24 0 C24 14, 14 24, 0 24 C14 24, 24 34, 24 48 C24 34, 34 24, 48 24 C34 24, 24 14, 24 0 Z' fill='black'/%3E%3C/svg%3E") no-repeat center;
    -webkit-mask-size: contain;
    mask-size: contain;
    margin-bottom: 20px;
}
.msg-ai .gemini-star {
    width: 24px;
    height: 24px;
    margin-bottom: 0;
    flex-shrink: 0;
    margin-top: 2px;
}
.ai-thinking {
    display: flex;
    gap: 6px;
    align-items: center;
    height: 24px;
    padding: 0 8px;
}
.ai-thinking span {
    width: 6px;
    height: 6px;
    background-color: #a8c7fa;
    border-radius: 50%;
    animation: pulse-dot 1.4s infinite ease-in-out both;
}
.ai-thinking span:nth-child(1) { animation-delay: -0.32s; }
.ai-thinking span:nth-child(2) { animation-delay: -0.16s; }
@keyframes pulse-dot {
    0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}
@keyframes popInUser {
    0% { opacity: 0; transform: scale(0.9) translateY(10px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes fadeUpIn {
    0% { opacity: 0; transform: translateY(15px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* MOBILE EXCLUSIVE LAYOUT */
@media (max-width: 768px) {
    #chat-container {
        width: 100%;
        max-width: 100%;
        height: 100vh; /* Fallback for older browsers */
        height: 100dvh; /* Fixes bottom cut-off on mobile browsers (Chrome/Safari) */
        display: flex;
        flex-direction: column;
        position: relative;
        background-color: var(--bg, #000000);
        margin: 0;
        border-radius: 0;
        box-shadow: none;
    }

    /* Override standard chat header to match mockup */
    #chat-header {
        display: flex;
        align-items: center;
        padding: 12px 20px; /* Reduced from 24px */
        position: absolute;
        top: 0; left: 0; right: 0;
        z-index: 10;
        background: transparent !important;
        border-bottom: none !important;
        box-shadow: none !important;
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
    }

    /* The Gemini-style blur + fade effect */
    #chat-header::before {
        content: '';
        position: absolute;
        top: 0; left: 0; right: 0;
        height: 80px; /* Extends below the buttons */
        background: linear-gradient(to bottom, var(--bg) 30%, transparent 100%);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        -webkit-mask-image: linear-gradient(to bottom, black 40%, transparent 100%);
        mask-image: linear-gradient(to bottom, black 40%, transparent 100%);
        z-index: -1;
        pointer-events: none;
    }

    #chat-header .icon-btn {
        background: none;
        border: none;
        cursor: pointer;
        padding: 4px;
        display: flex;
        align-items: center;
        justify-content: center;
        outline: none;
        transition: opacity 0.2s;
        width: auto;
        height: auto;
        color: var(--text-primary);
    }
    #chat-header .icon-btn:active {
        opacity: 0.6;
    }

    .header-title {
        display: flex;
        align-items: center;
        font-size: 16px;
        font-weight: 400;
        color: var(--text-primary, #ffffff);
        cursor: pointer;
        letter-spacing: 0.3px;
        margin-left: 28px;
    }
    .header-title span.dot {
        color: #4285f4;
        font-size: 8px;
        position: relative;
        top: -6px;
        margin-left: 2px;
    }
    .settings-btn {
        margin-left: auto;
    }
    #chat-header img#bot-avatar { display: none; }

    /* Idle content */
    .idle-content {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        margin-top: -8vh;
        position: absolute;
        width: 100%;
        height: 100%;
        z-index: 2;
        transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1), transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
        pointer-events: none;
    }
    .app-container.is-chatting .idle-content {
        opacity: 0;
        transform: scale(0.95) translateY(-20px);
    }
    .idle-content h1 {
        font-size: 28px;
        font-weight: 300;
        color: var(--text-primary, #ececec);
        margin: 0;
        letter-spacing: 0.2px;
        text-align: center;
        font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    }

    /* Chat Area */
    .chat-area {
        position: absolute;
        top: 0; /* Changed from 76px so it scrolls under the header */
        left: 0;
        right: 0;
        bottom: 104px;
        padding: 60px 20px 0 20px; /* Replaces top offset, allowing under-scroll */
        overflow-y: auto;
        display: flex;
        flex-direction: column;
        gap: 28px;
        opacity: 0;
        pointer-events: none;
        z-index: 5;
        transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1) 0.2s;
        scroll-behavior: smooth;
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
    .chat-area::-webkit-scrollbar { display: none; }
    .app-container.is-chatting .chat-area {
        opacity: 1;
        pointer-events: all;
    }

    /* Message bubbles */
    .message-group.user .message-content {
        padding: 0;
        background: transparent;
        border-radius: 0;
        font-size: 16px;
        font-weight: 500;
        line-height: 1.5;
        font-family: 'Outfit', -apple-system, sans-serif;
    }
    .msg-user {
        align-self: flex-end;
        background: var(--user-bubble, #2a2a2c);
        color: var(--user-text, #ffffff);
        padding: 10px 16px;
        border-radius: 20px;
        max-width: 85%;
        font-size: 15px;
        font-weight: 500;
        line-height: 1.4;
        animation: popInUser 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
        transform-origin: bottom right;
        word-wrap: break-word;
        font-family: 'Outfit', -apple-system, sans-serif;
    }
    .message-group:not(.user) .message-content, .msg-ai {
        align-self: flex-start;
        max-width: 100%;
        font-size: 16px;
        font-weight: 300;
        line-height: 1.6;
        color: var(--text-primary, #e3e3e3);
        display: flex;
        flex-direction: column;
        gap: 16px;
        animation: fadeUpIn 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
        background: transparent;
        font-family: 'Outfit', -apple-system, sans-serif;
    }
    /* Hide old bot avatars in mobile view since we have gemini star */
    .message-group:not(.user) .bot-msg-avatar { display: none; }
    
    /* Footer & Input */
    #composer {
        padding: 0 16px 24px 16px;
        width: 100%;
        position: absolute;
        bottom: 0;
        z-index: 10;
        background: transparent;
        border-top: none;
        box-shadow: none;
        backdrop-filter: none;
    }

    .input-container {
        display: flex;
        align-items: flex-end;
        flex-wrap: nowrap;
        background: var(--input-bg);
        border-radius: 50px;
        padding: 10px 20px 10px 20px;
        min-height: 80px;
        width: 100%;
        transition: background 0.3s;
        border: none;
    }
    .input-container:focus-within {
        background: #2a2a2c;
    }
    .input-container.is-expanded {
        flex-wrap: wrap;
        border-radius: 35px;
    }

    .left-actions { order: 1; height: 60px; display: flex; align-items: center; position: static; }
    .right-actions { order: 3; height: 60px; display: flex; align-items: center; gap: 8px; position: static; right: auto; bottom: auto; }

    #composer-actions-btn { height: 40px; width: 40px; aspect-ratio: 1 / 1; padding: 4px; border: none; background: transparent; }
    #composer-actions-btn svg { width: 100%; height: 100%; stroke: #c4c4c4; stroke-width: 1px; }
    
    .right-actions { order: 3; height: 60px; display: flex; align-items: center; gap: 12px; position: static; right: auto; bottom: auto; padding-right: 4px; }

    #live-mode-btn { 
        height: 44px !important; width: 44px !important; aspect-ratio: 1 / 1; 
        padding: 10px; border: none; 
        background: transparent !important;
        border-radius: 50%;
        display: flex; align-items: center; justify-content: center;
        cursor: pointer;
        box-shadow: none !important;
        animation: none !important;
    }
    #live-mode-btn svg { width: 100%; height: 100%; stroke: #a0a0a0; filter: none !important; }

    #send-btn {
        background: #31406d !important;
        border: none;
        border-radius: 50%;
        height: 44px !important;
        width: 44px !important;
        aspect-ratio: 1 / 1;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        transition: background 0.2s;
        box-shadow: none !important;
    }
    #send-btn:hover { background: #28345a !important; }
    #send-btn:disabled { opacity: 1 !important; }
    #send-btn svg { width: 35px; height: 35px; stroke: #a8c7fa; }
    #send-btn .mic-icon svg, #send-btn .send-icon svg { display: block; }

    textarea#message-input {
        order: 2;
        flex: 1 1 auto;
        min-width: 0;
        background: transparent;
        border: none;
        color: #ffffff;
        font-size: 15px;
        margin: 0 12px;
        font-family: 'Outfit', sans-serif;
        resize: none;
        line-height: 24px;
        height: 60px;
        max-height: 160px;
        overflow-y: auto;
        padding: 18px 0;
        box-sizing: border-box;
        transition: height 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
    }
    textarea#message-input:focus { outline: none; }
    textarea#message-input::placeholder { color: var(--text-dim); font-weight: 400; letter-spacing: 0.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    textarea#message-input::-webkit-scrollbar { display: none; }

    .input-container.is-expanded textarea#message-input {
        order: 1;
        flex: 0 0 100%;
        margin: 0;
    }
    .input-container.is-expanded .left-actions { order: 2; }
    .input-container.is-expanded .right-actions { order: 3; margin-left: auto; }
}

/* Custom Model Dropdown */
#custom-model-dropdown {
    position: absolute;
    top: 64px;
    left: 20px;
    transform: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 12px 0;
    width: 320px;
    box-shadow: var(--shadow-lg, 0 10px 40px rgba(0,0,0,0.15));
    z-index: 100;
}
#custom-model-dropdown .model-option {
    display: flex;
    align-items: flex-start;
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.2s;
}
#custom-model-dropdown .model-option:hover {
    background: var(--bg);
}
#custom-model-dropdown .model-option .check-icon {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
}
#custom-model-dropdown .model-option .check-icon svg {
    width: 16px;
    height: 16px;
    color: var(--text-primary);
}
#custom-model-dropdown .model-info {
    display: flex;
    flex-direction: column;
}
#custom-model-dropdown .model-name {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}
#custom-model-dropdown .badge {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}
#custom-model-dropdown .model-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}
#custom-model-dropdown .dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 12px 20px;
}
#custom-model-dropdown .dropdown-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 20px 4px 52px;
    font-size: 14px;
    color: var(--text-secondary);
}
#custom-model-dropdown .dropdown-section-header svg {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
}
#custom-model-dropdown .model-option.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}
#custom-model-dropdown .badge-images {
    background: rgba(59, 130, 246, 0.12);
    border-color: rgba(59, 130, 246, 0.25);
    color: #60a5fa;
}
#custom-model-dropdown .badge-new {
    background: rgba(34, 197, 94, 0.12);
    border-color: rgba(34, 197, 94, 0.25);
    color: #4ade80;
}
#custom-model-dropdown .badge-disabled {
    background: rgba(161, 161, 170, 0.12);
    border-color: rgba(161, 161, 170, 0.25);
    color: #a1a1aa;
}

/* Send Button Active Mode (Right Arrow, Bright Blue) */
#send-btn.send-mode-active {
    background: #1a73e8 !important;
}
#send-btn.send-mode-active:hover {
    background: #155cb0 !important;
}

/* --- BEAUTIFUL CUSTOM SELECTS --- */
.chaka-custom-select-wrapper {
  position: relative;
  width: 100%;
  font-family: "Manrope", sans-serif;
  user-select: none;
  margin-top: 4px;
}

.chaka-custom-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
  border-radius: 12px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

[data-theme="light"] .chaka-custom-select-trigger {
  background: rgba(0, 0, 0, 0.03);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.chaka-custom-select-trigger:hover {
  background: rgba(249, 115, 22, 0.08);
  border-color: rgba(249, 115, 22, 0.3);
}

.chaka-custom-select-trigger .arrow {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chaka-custom-select-wrapper.open .chaka-custom-select-trigger .arrow {
  transform: rotate(180deg);
  color: var(--accent);
}

.chaka-custom-select-wrapper.open .chaka-custom-select-trigger {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.15);
}

.chaka-custom-select-options {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--glass, rgba(30, 30, 30, 0.95));
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px) scale(0.98);
  transform-origin: top;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  z-index: 1000;
  max-height: 250px;
  overflow-y: auto;
  padding: 8px;
}

[data-theme="light"] .chaka-custom-select-options {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.chaka-custom-select-wrapper.open .chaka-custom-select-options {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.chaka-custom-option {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.chaka-custom-option:last-child {
  margin-bottom: 0;
}

.chaka-custom-option:hover {
  background: rgba(249, 115, 22, 0.1);
  color: var(--accent);
}

.chaka-custom-option.selected {
  background: rgba(249, 115, 22, 0.15);
  color: var(--accent);
  font-weight: 600;
}

[data-theme="light"] .chaka-custom-option.selected {
  background: rgba(249, 115, 22, 0.1);
  color: var(--accent);
}

.chaka-custom-option.selected::before {
  content: "✓";
  display: inline-block;
  margin-right: 8px;
  font-size: 0.9rem;
}

/* --- DESKTOP IDLE STATE (ChatGPT + Gemini hybrid) --- */
@media (min-width: 769px) {
  .app-container:not(.is-chatting) {
    justify-content: center;
    align-items: center;
    background-color: #0b0f19; /* Deep space black */
  }
  
  .app-container:not(.is-chatting) #chat-messages {
    display: none;
  }

  .app-container:not(.is-chatting) #chaka-logo-anim {
    display: none; /* Hide the big sphere logo for cleaner look */
  }

  .app-container:not(.is-chatting) #welcome-screen {
    flex-grow: 0;
    margin-top: -10vh;
    margin-bottom: 2.5rem;
    padding: 0;
  }

  .app-container:not(.is-chatting) #welcome-greeting {
    font-family: "Inter", "SF Pro Display", -apple-system, system-ui, sans-serif;
    font-size: 2.1rem;
    font-weight: 700;
    color: var(--text-primary);
    background: linear-gradient(135deg, var(--text-primary) 40%, var(--text-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -1px;
    margin: 0;
  }

  .app-container:not(.is-chatting) #composer {
    position: relative;
    width: 100%;
    max-width: 768px;
    margin: 0 auto;
    bottom: auto;
    padding: 0;
    left: auto;
    right: auto;
    z-index: 101;
  }

  .app-container:not(.is-chatting) .input-container {
    /* Glowing ethereal aura surrounding the actual textarea */
    box-shadow: 0 0 30px 0px rgba(255, 255, 255, 0.08), 
                0 0 60px 0px rgba(249, 115, 22, 0.12),
                inset 0 0 0 1px rgba(255, 255, 255, 0.12);
  }

  /* Refined Gemini-style Liquid Fluid Glow */
  .app-container:not(.is-chatting) .input-container {
    max-width: 800px;
    margin: 0 auto;
  }

  .app-container:not(.is-chatting) #composer-actions-popup,
  .app-container:not(.is-chatting) .edu-tools-popup {
    bottom: auto;
    top: calc(100% + 16px);
    transform-origin: top left;
    transform: translateY(-10px) scale(0.95);
  }

  .app-container:not(.is-chatting) #composer-actions-popup.show,
  .app-container:not(.is-chatting) .edu-tools-popup.show {
    transform: translateY(0) scale(1);
  }

  /* Refined Gemini-style Liquid Fluid Glow */
  .app-container:not(.is-chatting) .glow-container {
    opacity: 1;
    z-index: 0;
  }
  
  /* --- WELCOME SCREEN ANIMATIONS --- */
  .app-container:not(.is-chatting) .pattern-layer {
    display: none; /* Remove the cutoff dots! */
  }

  .app-container:not(.is-chatting) .purple-blob {
    display: block !important; /* Bring blobs back for liquid effect */
  }

  .app-container:not(.is-chatting) .ambient-glow {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80vw;
    height: 80vh;
    bottom: auto;
    background: radial-gradient(ellipse at center, rgba(230, 81, 0, 0.20) 0%, transparent 60%);
    border-radius: 50% !important;
    filter: blur(100px);
    animation: liquid-1 20s ease-in-out infinite;
  }

  .app-container:not(.is-chatting) .purple-blob.left {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70vw;
    height: 70vh;
    bottom: auto;
    background: radial-gradient(ellipse at center, rgba(255, 143, 0, 0.15) 0%, transparent 60%);
    border-radius: 50% !important;
    filter: blur(90px);
    animation: liquid-2 24s ease-in-out infinite;
    mix-blend-mode: screen;
  }

  .app-container:not(.is-chatting) .purple-blob.right {
    top: 50%;
    right: auto;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60vw;
    height: 60vh;
    bottom: auto;
    background: radial-gradient(ellipse at center, rgba(191, 54, 12, 0.18) 0%, transparent 60%);
    border-radius: 50% !important;
    filter: blur(80px);
    animation: liquid-3 18s ease-in-out infinite;
    mix-blend-mode: screen;
  }
}

@keyframes liquid-1 {
  0% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  33% { transform: translate(-45%, -55%) scale(1.05) rotate(5deg); }
  66% { transform: translate(-55%, -45%) scale(0.95) rotate(-5deg); }
  100% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
}

@keyframes liquid-2 {
  0% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
  33% { transform: translate(-55%, -45%) scale(1.1) rotate(-5deg); }
  66% { transform: translate(-45%, -55%) scale(0.9) rotate(5deg); }
  100% { transform: translate(-50%, -50%) scale(1) rotate(0deg); }
}

@keyframes liquid-3 {
  0% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -55%) scale(1.08); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* --- TRULY FLUSH DESKTOP LAYOUT (ChatGPT Style) --- */
@media (min-width: 901px) {
  #app {
    padding: 0;
    gap: 0;
  }
  
  #sidebar {
    border-radius: 0;
    box-shadow: none;
    border-right: 1px solid var(--border);
    background: var(--sidebar-bg); /* Deep black for sidebar */
    margin: 0;
  }

  #chat-container {
    border-radius: 0;
    box-shadow: none;
    margin: 0;
    background: var(--surface); /* Lighter background for main area */
  }

  .app-container:not(.is-chatting) #chat-header {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border-bottom: none;
    box-shadow: none;
  }
}


/* View Transition for Theme Toggle */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
::view-transition-old(root) {
  z-index: 1;
}
::view-transition-new(root) {
  z-index: 9999;
}
[data-theme="dark"]::view-transition-old(root) {
  z-index: 9999;
}
[data-theme="dark"]::view-transition-new(root) {
  z-index: 1;
}

/* Theme Segmented Control */
.theme-segmented-control {
  display: flex;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 4px;
  gap: 4px;
  margin-bottom: 8px;
}
[data-theme="light"] .theme-segmented-control {
  background: rgba(0, 0, 0, 0.05);
}
.theme-segment {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 6px 0;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}
.theme-segment:hover {
  color: var(--text-primary);
}
.theme-segment.active {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Improve View Transition Animation */
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
::view-transition-old(root) {
  animation: none;
  mix-blend-mode: normal;
}

[data-theme="dark"]::view-transition-old(root) {
  z-index: 1;
}
[data-theme="dark"]::view-transition-new(root) {
  z-index: 9999;
  filter: drop-shadow(0 0 60px rgba(0, 0, 0, 1));
}
[data-theme="light"]::view-transition-old(root) {
  z-index: 1;
}
[data-theme="light"]::view-transition-new(root) {
  z-index: 9999;
  filter: drop-shadow(0 0 60px rgba(255, 255, 255, 1));
}

/* ===================== THEME APPLE WAVE ===================== */
.theme-aurora-dialog {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  overflow: hidden;
  pointer-events: none;
  max-width: none;
  max-height: none;
  z-index: 999999;
}
.theme-aurora-dialog::backdrop {
  background: transparent;
  pointer-events: none;
}

.theme-aurora-wrap {
  position: absolute;
  inset: 0;
  filter: blur(40px) saturate(1.4);
  /* Removed mix-blend-mode: screen so it shows on white backgrounds too */
  pointer-events: none;
  overflow: hidden;
}

.theme-aurora {
  position: absolute;
  width: 200vmax;
  height: 200vmax;
  transform: translate3d(-50%, -50%, 0) scale(0.02);
  will-change: transform;
  border-radius: 50%;
  opacity: 0;
  background: conic-gradient(from 90deg at 50% 50%,
          rgba(255, 255, 255, 0.05),
          rgba(255, 255, 255, 0.7),
          rgba(220, 235, 255, 0.4),
          rgba(255, 255, 255, 0.1),
          rgba(255, 255, 255, 0.8),
          rgba(255, 255, 255, 0.05));
  animation: theme-aurora-sweep 1.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.theme-aurora--secondary {
  background: conic-gradient(from 270deg at 50% 50%,
          rgba(220, 235, 255, 0.3),
          rgba(255, 255, 255, 0.6),
          rgba(255, 255, 255, 0.05),
          rgba(255, 255, 255, 0.8),
          rgba(220, 235, 255, 0.2),
          rgba(220, 235, 255, 0.3));
  animation: theme-aurora-sweep-2 1.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-delay: 0.12s;
}

@keyframes theme-aurora-sweep {
  0% { transform: translate3d(-50%, -50%, 0) scale(0.02); opacity: 0; }
  12% { opacity: 0.95; }
  55% { transform: translate3d(-50%, -50%, 0) scale(0.6); opacity: 0.85; }
  100% { transform: translate3d(-50%, -50%, 0) scale(1.5); opacity: 0; }
}

@keyframes theme-aurora-sweep-2 {
  0% { transform: translate3d(-50%, -50%, 0) scale(0.02) rotate(0deg); opacity: 0; }
  15% { opacity: 0.8; }
  60% { transform: translate3d(-50%, -50%, 0) scale(0.7) rotate(15deg); opacity: 0.6; }
  100% { transform: translate3d(-50%, -50%, 0) scale(1.6) rotate(25deg); opacity: 0; }
}

.theme-ring {
  position: absolute;
  width: 30px;
  height: 30px;
  border: 2px solid rgba(255, 255, 255, 0.0);
  border-radius: 50%;
  transform: translate3d(-50%, -50%, 0) scale(0);
  will-change: transform;
  pointer-events: none;
  animation: theme-ring-pop 1.2s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

@keyframes theme-ring-pop {
  0% { transform: translate3d(-50%, -50%, 0) scale(0); border-color: rgba(255, 255, 255, 0.0); opacity: 1; }
  10% { border-color: rgba(255, 255, 255, 0.55); }
  100% { transform: translate3d(-50%, -50%, 0) scale(60); border-color: rgba(255, 255, 255, 0); opacity: 0; }
}

/* ===================== MESSAGE WAVE (TEXTAREA) ===================== */
.message-aurora-wrap {
  position: absolute;
  inset: 0;
  filter: blur(40px) saturate(1.4);
  pointer-events: none;
  overflow: hidden;
}

.message-aurora {
  position: absolute;
  width: 200vmax;
  height: 200vmax;
  transform: translate3d(-50%, -50%, 0) scale(0.02);
  will-change: transform;
  border-radius: 50%;
  opacity: 0;
  background: conic-gradient(from 90deg at 50% 50%,
          rgba(42, 26, 20, 0.4),
          rgba(255, 154, 90, 0.6),
          rgba(255, 197, 147, 0.5),
          rgba(130, 178, 184, 0.4),
          rgba(255, 154, 90, 0.5),
          rgba(42, 26, 20, 0.4));
  animation: message-aurora-sweep 1.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.message-aurora--secondary {
  background: conic-gradient(from 270deg at 50% 50%,
          rgba(130, 178, 184, 0.3),
          rgba(255, 197, 147, 0.5),
          rgba(42, 26, 20, 0.3),
          rgba(255, 154, 90, 0.6),
          rgba(130, 178, 184, 0.2),
          rgba(130, 178, 184, 0.3));
  animation: message-aurora-sweep-2 1.8s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  animation-delay: 0.12s;
}

@keyframes message-aurora-sweep {
  0% { transform: translate3d(-50%, -50%, 0) scale(0.02); opacity: 0; }
  12% { opacity: 0.6; }
  55% { transform: translate3d(-50%, -50%, 0) scale(0.6); opacity: 0.5; }
  100% { transform: translate3d(-50%, -50%, 0) scale(1.5); opacity: 0; }
}

@keyframes message-aurora-sweep-2 {
  0% { transform: translate3d(-50%, -50%, 0) scale(0.02) rotate(0deg); opacity: 0; }
  15% { opacity: 0.5; }
  60% { transform: translate3d(-50%, -50%, 0) scale(0.7) rotate(15deg); opacity: 0.4; }
  100% { transform: translate3d(-50%, -50%, 0) scale(1.6) rotate(25deg); opacity: 0; }
}

.message-ring {
  position: absolute;
  width: 30px;
  height: 30px;
  border: 2px solid rgba(255, 197, 147, 0.0);
  border-radius: 50%;
  transform: translate3d(-50%, -50%, 0) scale(0);
  will-change: transform;
  pointer-events: none;
  animation: message-ring-pop 1.2s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

@keyframes message-ring-pop {
  0% { transform: translate3d(-50%, -50%, 0) scale(0); border-color: rgba(255, 197, 147, 0.0); opacity: 1; }
  10% { border-color: rgba(255, 197, 147, 0.35); }
  100% { transform: translate3d(-50%, -50%, 0) scale(60); border-color: rgba(255, 197, 147, 0); opacity: 0; }
}
