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

/* CSS Variables for Modern Theme */
:root {
  /* Modern Color Palette */
  --primary-bg: #0a0b0f;              /* Deep dark background */
  --secondary-bg: #111219;            /* Slightly lighter dark */
  --card-bg: rgba(17, 18, 25, 0.8);   /* Semi-transparent cards */
  --accent-primary: #6366f1;          /* Indigo primary */
  --accent-secondary: #8b5cf6;        /* Purple secondary */
  --accent-tertiary: #06b6d4;         /* Cyan accent */
  --accent-quaternary: #f59e0b;       /* Amber accent */
  --text-primary: #f8fafc;            /* Light text */
  --text-secondary: #cbd5e1;          /* Muted text */
  --text-muted: #64748b;              /* Very muted text */
  --white: #ffffff;
  --success: #10b981;
  --error: #ef4444;

  /* Gradients */
  --gradient-primary: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  --gradient-secondary: linear-gradient(135deg, var(--accent-tertiary), var(--accent-quaternary));
  --gradient-hero: linear-gradient(135deg, #667eea 0%, #764ba2 100%);

  /* Typography */
  --font-primary: system-ui, -apple-system, BlinkMacSystemFont,
                  "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --font-weight-light: 400;
  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 600;
  --font-weight-extrabold: 600;

  /* Font Sizes */
  --font-xs: clamp(0.75rem, 0.72rem + 0.15vw, 0.8rem);
  --font-sm: clamp(0.85rem, 0.82rem + 0.18vw, 0.9rem);
  --font-base: clamp(0.95rem, 0.92rem + 0.2vw, 1rem);
  --font-lg: clamp(1.05rem, 1rem + 0.25vw, 1.15rem);
  --font-xl: clamp(1.2rem, 1.15rem + 0.35vw, 1.3rem);
  --font-2xl: clamp(1.35rem, 1.3rem + 0.45vw, 1.55rem);
  --font-3xl: clamp(1.6rem, 1.55rem + 0.6vw, 1.85rem);

  /* Spacing */
  --space-xs: 0.5rem;
  --space-sm: 1rem;
  --space-md: 1.5rem;
  --space-lg: 2rem;
  --space-xl: 3rem;

  /* Shadows & Effects */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 50px rgba(99, 102, 241, 0.3);

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Animations */
  --transition-fast: 0.15s ease;
  --transition-base: 0.3s ease;
  --transition-slow: 0.6s ease;

  /* Chat bubble theme */
  --bubble-in: var(--secondary-bg);
  --bubble-out: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
  --bubble-out-border: rgba(139, 92, 246, 0.55);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: var(--font-primary);
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
}

body.ui-loading {
  overflow: hidden !important;
}

body.ui-loading .history-sidebar,
body.ui-loading .container,
body.ui-loading .chatbot,
body.ui-loading #sidebar-toggle {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

.app-shell-loader {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: #ffffff;
  overflow: hidden;
}

body.ui-loading .app-shell-loader {
  display: flex;
}

.app-shell-loader__brand {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  animation: loaderBrandEnter 0.6s ease both;
}

.app-shell-loader__logo {
  position: relative;
  width: 92px;
  height: 92px;
  border-radius: 0;
  object-fit: cover;
  flex-shrink: 0;
  animation: loaderLogoFloat 2.2s ease-in-out infinite;
}

.app-shell-loader__title {
  position: relative;
  display: inline-flex;
  align-items: center;
  color: #111111;
  font-size: 36px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.app-shell-loader__title span {
  display: inline-block;
  opacity: 0;
  transform: translateY(10px);
  animation: loaderLetterReveal 0.45s ease forwards;
}

.app-shell-loader__title span:nth-child(1) { animation-delay: 0.08s; }
.app-shell-loader__title span:nth-child(2) { animation-delay: 0.16s; }
.app-shell-loader__title span:nth-child(3) { animation-delay: 0.24s; }
.app-shell-loader__title span:nth-child(4) { animation-delay: 0.32s; }
.app-shell-loader__title span:nth-child(5) { animation-delay: 0.4s; }
.app-shell-loader__title span + span {
  margin-left: 0.02em;
}

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

@keyframes loaderLogoFloat {
  0%, 100% {
    transform: translateY(0) scale(1);
  }
  50% {
    transform: translateY(-6px) scale(1.02);
  }
}

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

@media (max-width: 640px) {
  .app-shell-loader {
    padding: 16px;
  }

  .app-shell-loader__brand {
    gap: 12px;
  }

  .app-shell-loader__logo {
    width: 74px;
    height: 74px;
  }

  .app-shell-loader__title {
    font-size: 29px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-shell-loader__brand,
  .app-shell-loader__logo,
  .app-shell-loader__title span {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}

.container {
  height: 100vh;
  width: 100vw;
  background: var(--primary-bg);
  background-size: cover;
  animation: color 12s ease-in-out infinite;
  position: relative;
}

/* ================= THEME TOGGLE BUTTON (FIXED POSITION) ================= */
#mode-toggle {
  position: fixed !important;
  top: 16px !important;
  right: 16px !important;
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--font-xl);
  color: var(--text-primary);
  padding: 8px;
  z-index: 1000;
  transition: all var(--transition-fast);
  border-radius: 50%;
  
  backdrop-filter: blur(10px);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#mode-toggle:hover {
  background: rgba(0, 0, 0, 0.5);
  transform: scale(1.05);
}

/* Light mode theme toggle */
body.light-mode #mode-toggle {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.3);
}

/* ================= MAIN LAYOUT ================= */
/* Welcome screen: hide EVERYTHING except welcome and theme toggle */
body:not(.chat-started) .history-sidebar,
body:not(.chat-started) .chatbot,
body:not(.chat-started) #sidebar-toggle {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Chatbot container */
.chatbot {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  background: var(--secondary-bg);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.7);
  transition: all var(--transition-base);
  z-index: 10;
  max-width: 100%;
}

.chat-container {
  display: none;
}

.chat-home {
  width: min(720px, calc(100% - 32px));
  margin: 0 auto;
  padding: 44px 24px 10px;
  text-align: center;
}

.chat-home-title {
  margin-top: 18px;
  color: var(--text-primary);
  font-size: clamp(2rem, 1.7rem + 1vw, 3rem);
  line-height: 1.08;
  letter-spacing: -0.03em;
}

.chat-home-subtitle {
  margin-top: 14px;
  width: min(100%, 520px);
  margin-left: auto;
  margin-right: auto;
  padding: 0;
  color: rgba(248, 250, 252, 0.72);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.6;
  letter-spacing: 0.02em;
  text-wrap: balance;
}

.chat-home-actions {
  width: min(100%, 760px);
  margin: 24px auto 0;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chat-home-action-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
  animation: fadeUp 0.34s ease both;
}

.chat-home-action-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(99, 102, 241, 0.28);
  background: rgba(255, 255, 255, 0.08);
}

.chat-home-action-btn--primary {
  background: rgba(99, 102, 241, 0.16);
  border-color: rgba(99, 102, 241, 0.24);
}

.chat-home-prompts {
  width: min(100%, 760px);
  margin: 28px auto 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  animation: fadeUp 0.42s ease both;
}

body.prompt-options-open .chat-home-prompts {
  display: none;
}

.chat-home-prompt {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.04);
  padding: 18px 18px 16px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
  animation: fadeUp 0.36s ease both;
}

.chat-home-prompt:nth-child(1) { animation-delay: 0.02s; }
.chat-home-prompt:nth-child(2) { animation-delay: 0.06s; }
.chat-home-prompt:nth-child(3) { animation-delay: 0.1s; }
.chat-home-prompt:nth-child(4) { animation-delay: 0.14s; }

.chat-home-prompt:hover {
  transform: translateY(-2px);
  border-color: rgba(99, 102, 241, 0.34);
  background: rgba(255, 255, 255, 0.07);
}

.chat-home-prompt.active {
  border-color: rgba(99, 102, 241, 0.34);
  background: rgba(255, 255, 255, 0.08);
}

.chat-home-prompt__title {
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
}

.chat-home-prompt__copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}

.chat-home-prompt__icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  line-height: 1;
  text-align: center;
  font-size: 20px;
  font-variation-settings:
    "FILL" 0,
    "wght" 500,
    "GRAD" 0,
    "opsz" 24;
  color: var(--text-primary);
}

.chat-home-prompt[data-group="summarize"] .chat-home-prompt__icon {
  color: #2563eb;
}

.chat-home-prompt[data-group="code"] .chat-home-prompt__icon {
  color: #ea580c;
}

.chat-home-prompt[data-group="brainstorm"] .chat-home-prompt__icon {
  color: #c026d3;
}

.chat-home-prompt[data-group="plan"] .chat-home-prompt__icon {
  color: #0f9f6e;
}

.chat-home-prompt__desc {
  color: rgba(248, 250, 252, 0.72);
  font-size: 13px;
  line-height: 1.55;
}

.chat-home-options {
  width: min(100%, 760px);
  margin: 14px auto 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  animation: fadeUp 0.28s ease both;
}

.chat-home-option {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-primary);
  padding: 12px 14px;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  line-height: 1.45;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
  animation: fadeUp 0.28s ease both;
}

.chat-home-option:nth-child(1) { animation-delay: 0.02s; }
.chat-home-option:nth-child(2) { animation-delay: 0.05s; }
.chat-home-option:nth-child(3) { animation-delay: 0.08s; }
.chat-home-option:nth-child(4) { animation-delay: 0.11s; }

.chat-home-option:hover {
  transform: translateY(-2px);
  border-color: rgba(99, 102, 241, 0.28);
  background: rgba(255, 255, 255, 0.06);
}

.chat-home-option__icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
  line-height: 1;
  font-variation-settings:
    "FILL" 0,
    "wght" 500,
    "GRAD" 0,
    "opsz" 24;
  color: var(--text-primary);
}

.chat-home-option__text {
  min-width: 0;
}

.chat-home-option[data-group="summarize"] .chat-home-option__icon {
  color: #2563eb;
}

.chat-home-option[data-group="code"] .chat-home-option__icon {
  color: #ea580c;
}

.chat-home-option[data-group="brainstorm"] .chat-home-option__icon {
  color: #c026d3;
}

.chat-home-option[data-group="plan"] .chat-home-option__icon {
  color: #0f9f6e;
}

body.light-mode .chat-home-prompt {
  border-color: rgba(15, 23, 42, 0.08);
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

body.light-mode .chat-home-action-btn {
  border-color: rgba(15, 23, 42, 0.08);
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.05);
}

body.light-mode .chat-home-action-btn:hover {
  border-color: rgba(99, 102, 241, 0.24);
  background: #fbfbff;
}

body.light-mode .chat-home-action-btn--primary {
  background: #f5f7ff;
}

body.light-mode .chat-home-prompt:hover {
  border-color: rgba(99, 102, 241, 0.24);
  background: #fbfbff;
}

body.light-mode .chat-home-prompt.active {
  border-color: rgba(99, 102, 241, 0.24);
  background: #f8faff;
}

body.light-mode .chat-home-prompt__desc {
  color: rgba(15, 23, 42, 0.64);
}

body.light-mode .chat-home-option {
  border-color: rgba(15, 23, 42, 0.08);
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.05);
}

body.light-mode .chat-home-option:hover {
  border-color: rgba(99, 102, 241, 0.24);
  background: #fbfbff;
}

body.chat-started .chatbot {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
  display: flex !important;
}

/* Desktop layout adjustments */
@media (min-width: 481px) {
  body.chat-started .chatbot {
    width: calc(100% - 280px);
    left: 280px;
    right: auto;
  }
  
  /* Fix for 768px range - reduce gap */
  @media (min-width: 481px) and (max-width: 768px) {
    body.chat-started .chatbot {
      width: calc(100% - 230px);
      left: 230px;
    }
    
    .history-sidebar {
      width: 230px;
    }
  }
}

.chatbot header {
  background: transparent;
  color: var(--text-primary);
  padding: var(--space-md);
  text-align: center;
  position: relative;
  flex-shrink: 0;
  padding-top: 16px !important;
}

.chatbot header h2 {
  font-size: var(--font-2xl);
  font-weight: var(--font-weight-bold);
}

.chatbot header .close-btn {
  display: none !important; /* Hide the close button */
}

/* ================= CHATBOX ================= */
.chatbox {
  flex-grow: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  background-color: var(--secondary-bg);
}

.chatbox .chat {
  display: flex;
  list-style: none;
  margin: var(--space-sm) 0;
  animation: messageSlideIn 0.22s ease both;
}

.chatbox .outgoing {
  justify-content: flex-end;
  position: relative;
  width: 100%;
}

.chatbox .outgoing p {
  background: var(--bubble-out);
  border: 1px solid var(--bubble-out-border);
  color: #ffffff;
  padding: var(--space-sm);
  border-radius: var(--radius-xl) var(--radius-xl) var(--radius-sm) var(--radius-xl);
  margin-left: auto;
  max-width: 80%;
}

.chatbox .outgoing .outgoing-message {
  display: inline-block;
  min-width: 0;
  width: fit-content;
  max-width: min(80%, 680px);
  margin-right: 0;
  line-height: 1.55;
  text-align: left;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chatbox .outgoing.outgoing-media .user-media-card {
  background: var(--bubble-out);
  border: 1px solid var(--bubble-out-border);
  color: #ffffff;
  padding: var(--space-sm);
  border-radius: var(--radius-xl) var(--radius-xl) var(--radius-sm) var(--radius-xl);
  margin-left: auto;
  max-width: min(340px, 80%);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chatbox .outgoing.outgoing-media .user-media-preview {
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  border-radius: 12px;
  display: block;
}

.chatbox .outgoing.outgoing-media .user-media-file {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  padding: 8px 10px;
  font-weight: 600;
  word-break: break-word;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chatbox .outgoing.outgoing-media .user-media-meta {
  font-size: 12px;
  opacity: 0.9;
  word-break: break-word;
}

.chatbox .outgoing.outgoing-media .user-media-prompt {
  margin: 0;
  max-width: 100%;
  background: rgba(255, 255, 255, 0.14);
  border: 0;
  border-radius: 12px;
  color: #ffffff;
  padding: 8px 10px;
  white-space: pre-wrap;
  word-break: break-word;
}

.chatbox .outgoing.outgoing-media .user-media-open-link {
  display: block;
}

.chatbox .outgoing.outgoing-media .user-media-file-actions {
  display: flex;
  gap: 8px;
}

.chatbox .outgoing.outgoing-media .user-media-open-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  text-decoration: none;
  color: #fff;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.24);
}

.chatbox .outgoing.outgoing-media .user-media-open-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

.chatbox .incoming p {
  background: var(--bubble-in);
  border: none;
  color: var(--text-primary);
  padding: var(--space-sm);
  border-radius: var(--radius-xl) var(--radius-xl) var(--radius-xl) var(--radius-sm);
  max-width: 80%;
}

.chatbox .incoming .bot-message-container p {
  flex: 1;
  min-width: 100%;
  word-break: break-word;
  white-space: pre-wrap;
}

.bot-message-container {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  min-width: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  border: none;
  position: relative;
}

.chat.incoming {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  position: relative;
  padding-bottom: var(--space-lg);
}

.chatbox .incoming {
  justify-content: flex-start;
}

/* ================= CHAT INPUT ================= */
.chat-input {
  padding: var(--space-sm) var(--space-lg);
  background: var(--card-bg);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.selected-media-preview {
  width: 100%;
}

.selected-media-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  max-width: min(380px, 100%);
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  border: none;
}

.selected-media-thumb {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  display: block;
}

.selected-media-doc {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  font-size: 22px;
}

.selected-media-text {
  min-width: 0;
}

.selected-media-name {
  color: var(--text-primary);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.selected-media-name-link {
  color: var(--text-primary);
  font-size: 13px;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.selected-media-name-link:hover {
  text-decoration: underline;
}

.selected-media-thumb-link,
.selected-media-doc-link {
  text-decoration: none;
}

.selected-media-kind {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: capitalize;
}

.selected-media-remove {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 8px;
  padding: 2px;
}

.selected-media-remove:hover {
  background: rgba(255, 255, 255, 0.12);
}

.chat-input textarea {
  width: 100%;
  padding: var(--space-sm);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font-size: var(--font-base);
  resize: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: border-color var(--transition-fast);
}

.chat-input textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
}

.chat-input span {
  font-size: var(--font-xl);
  color: var(--accent-primary);
  cursor: pointer;
  visibility: hidden;
}

.chat-input textarea:valid ~ span {
  visibility: visible;
}

@keyframes revealText {
  0% { opacity: 0; }
  25% { opacity: 1; }
  50% { opacity: 1; }
  75% { opacity: 1; }
  100% { opacity: 1; }
}

/* ================= SIDEBAR (COMPLETELY FIXED) ================= */
/* Welcome screen: absolutely hidden */
body:not(.chat-started) .history-sidebar {
  display: none !important;
  transform: translateX(-100%) !important;
  opacity: 0 !important;
  visibility: hidden !important;
}
/* Chat started: sidebar logic */
.history-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100vh;
  background-color: var(--secondary-bg);
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  z-index: 9;
  overflow: hidden;
  scrollbar-width: thin;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
  /* START HIDDEN ON ALL SCREENS */
  transform: translateX(-100%);
  opacity: 0;
  visibility: hidden;
}

/* Desktop: sidebar visible when chat started */
@media (min-width: 481px) {
  body.chat-started .history-sidebar {
    display: flex !important;
    transform: translateX(0) !important;
    opacity: 1 !important;
    visibility: visible !important;
  }
}

/* Mobile: sidebar hidden initially, shown when active */
@media (max-width: 480px) {
  body.chat-started .history-sidebar {
    display: flex !important;
    transform: translateX(-100%) !important;
    opacity: 1 !important;
    visibility: visible !important;
    position: fixed !important;
    z-index: 1001 !important;
    width: min(320px, 88%) !important;
  }
  
  body.chat-started .history-sidebar.active {
    transform: translateX(0) !important;
    opacity: 1 !important;
    visibility: visible !important;
  }
}

/* Fix for 768px range - reduce sidebar width */
@media (min-width: 481px) and (max-width: 768px) {
  .history-sidebar {
    width: 230px !important;
  }
  
  body.chat-started .chatbot {
    width: calc(100% - 230px) !important;
    left: 230px !important;
  }
}

.history-sidebar::-webkit-scrollbar {
  width: 1px;
}

.history-sidebar::-webkit-scrollbar-thumb {
  background-color: var(--secondary-bg);
  border-radius: 1px;
}

.history-sidebar::-webkit-scrollbar-track {
  background: var(--secondary-bg);
}

.history-sidebar h3 {
  font-size: var(--font-lg);
  font-weight: var(--font-weight-semibold);
  padding-bottom: var(--space-sm);
  color: var(--text-primary);
  padding: var(--space-md) var(--space-md) var(--space-sm);
  margin: 0;
}

.history-list {
  list-style: none;
  padding: 0 var(--space-md);
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  position: relative;
  z-index: 1;
  padding-bottom: var(--space-md);
}

.history-list li {
  padding: 10px 12px;
  background-color: var(--card-bg);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-xs);
  font-size: var(--font-sm);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  height: 56px;
  min-height: 56px;
  max-height: 56px;
  box-sizing: border-box;
  position: relative;
  z-index: 1;
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: all var(--transition-fast);
  overflow: hidden;
}

.history-title {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  max-width: 100%;
  overflow: hidden;
  height: 100%;
}

.history-title__text {
  display: -webkit-box;
  max-width: 100%;
  white-space: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.history-list .history-list-spacer {
  height: 96px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent !important;
  opacity: 0;
  pointer-events: none;
}

.history-list li:hover {
  background-color: rgba(99, 102, 241, 0.2);
  transform: translateY(-2px);
}

.history-list li.menu-open {
  z-index: 40;
  transform: none !important;
  overflow: visible;
}

.delete-icon {
  cursor: pointer;
  margin-left: var(--space-sm);
  color: var(--text-secondary);
  transition: color var(--transition-fast);
}

.delete-icon:hover {
  color: var(--error);
}

.history-actions-btn {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

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

.history-item-actions-menu {
  position: absolute;
  right: 8px;
  top: calc(100% + 6px);
  min-width: 132px;
  background: rgba(20, 20, 24, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 6px;
  display: none;
  z-index: 30;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.25);
  pointer-events: auto;
}

.history-item-actions-menu.open {
  display: block;
}

.history-item-actions-menu.open-up {
  top: auto;
  bottom: calc(100% + 6px);
}

.history-menu-item {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
}

.history-menu-item .material-symbols-outlined {
  font-size: 18px;
}

.history-menu-item:hover {
  background: rgba(255, 255, 255, 0.08);
}

.history-menu-item.delete-item:hover {
  color: #ef4444;
}

.history-item.renaming {
  transform: none !important;
}

.history-title-input {
  width: 100%;
  border: 1px solid rgba(99, 102, 241, 0.45);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
  color: var(--text-primary);
  padding: 4px 8px;
  font-size: 13px;
  outline: none;
}

body.light-mode .history-title-input {
  background: #fff;
  border: 1px solid rgba(99, 102, 241, 0.35);
}

/* ================= SIDEBAR TOGGLE BUTTON ================= */
/* Hidden on welcome screen */
body:not(.chat-started) #sidebar-toggle {
  display: none !important;
}

/* Hidden on desktop */
@media (min-width: 481px) {
  #sidebar-toggle {
    display: none !important;
  }
}

/* Visible on mobile when chat started */
@media (max-width: 480px) {
  body.chat-started #sidebar-toggle {
    display: flex !important;
    position: fixed !important;
    top: 16px !important;
    left: 16px !important;
    font-size: var(--font-xl) !important;
    background: none !important;
    border: none !important;
    color: var(--text-primary) !important;
    cursor: pointer !important;
    z-index: 1002 !important;
    padding: 8px !important;
    border-radius: 50% !important;
   
    backdrop-filter: blur(10px) !important;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
  }
  
  /* Adjust close button position to match */
  .chatbot header .close-btn {
    top: 16px !important;
    right: 16px !important;
  }
  
  /* Adjust chatbot header padding for mobile */
  .chatbot header {
    padding-top: 24px !important;
    padding-bottom: 16px !important;
  }
}

/* ================= CLOSE SIDEBAR BUTTON ================= */


@media (max-width: 480px) {
  .close-sidebar-btn {
    
    background: none !important;
    border: none !important;
    font-size: var(--font-xl) !important;
    color: var(--text-primary) !important;
    position: absolute !important;
    top: var(--space-sm) !important;
    right: var(--space-sm) !important;
    z-index: 100 !important;
    cursor: pointer !important;
    padding: 8px !important;
  }
}

/* ================= DELETE ALL BUTTON ================= */
.delete-all-btn {
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  background: none;
  border: none;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-base);
  cursor: pointer;
  width: 100%;
  text-align: left;
  transition: color var(--transition-fast);
  margin-top: var(--space-md);
  border-radius: var(--radius-md);
  margin: 6px var(--space-md) var(--space-md);
  width: calc(100% - 2 * var(--space-md));
}

.delete-all-btn:hover {
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--error);
}

.delete-all-btn .material-icons {
  margin-right: var(--space-xs);
}

/* ================= START CHAT BUTTON ================= */
.start-chat-btn {
  background: var(--gradient-primary);
  color: var(--white);
  font-size: var(--font-base);
  padding: var(--space-sm) var(--space-lg);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  margin-top: var(--space-lg);
  transition: all var(--transition-base);
  font-weight: var(--font-weight-medium);
  box-shadow: var(--shadow-md);
}

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

/* ================= RESPONSIVE ADJUSTMENTS ================= */
@media (max-width: 769spx) {
  .history-sidebar {
    width: 200px;
  }

  body.chat-started .chatbot {
    width: calc(100% - 200px);
  }

  .chatbot header h2 {
    font-size: var(--font-lg);
  }

  .chatbox .chat p {
    font-size: var(--font-sm);
  }

  .chat-input textarea {
    font-size: var(--font-sm);
  }
}

@media (max-width: 575px) {
  .history-sidebar {
    width: 180px;
  }

  body.chat-started .chatbot {
    width: calc(100% - 180px);
  }

  .chatbox .chat p {
    font-size: var(--font-xs);
  }

  .chat-input textarea {
    font-size: var(--font-xs);
  }
}

/* ================= MOBILE VIEW FIXES ================= */
@media (max-width: 480px) {
  .chatbot {
    width: 100% !important;
    left: 0 !important;
  }

  .chatbox .outgoing p {
    margin-left: auto;
    margin-right: 8px;
    max-width: 85%;
  }

  .chatbox .outgoing .outgoing-message {
    max-width: min(85%, 100%);
  }

  .chatbox .incoming,
  .chat-incoming {
    display: flex;
    justify-content: flex-start;
    margin-left: 0 !important;
    padding-left: 0 !important;
  }

  .chatbox .incoming p,
  .chat-incoming p {
    margin-left: 0 !important;
    max-width: 85%;
    border-radius: var(--radius-xl) var(--radius-xl) var(--radius-xl) var(--radius-sm);
  }

  .chat-input {
    padding: 10px;
    width: 100%;
    gap: 8px;
  }

  .chat-input textarea {
    width: 100%;
  }
}

/* ================= LIGHT MODE STYLES ================= */
body.light-mode {
  --primary-bg: #f8fafc;
  --secondary-bg: #ffffff;
  --card-bg: rgba(255, 255, 255, 0.8);
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --bubble-out-border: rgba(99, 102, 241, 0.45);
}

/* App backgrounds */
body.light-mode .container {
  background-color: var(--primary-bg);
}

body.light-mode .chatbot {
  background-color: var(--secondary-bg);
  border-left: 1px solid rgba(0,0,0,0.08);
}

body.light-mode .chatbox {
  background-color: var(--secondary-bg);
}

/* Header */
body.light-mode .chatbot header {
  background-color: var(--secondary-bg);
  color: var(--text-primary);
  border-bottom: 1px solid rgba(0,0,0,0.08);
}

body.light-mode .chatbot header .close-btn {
  color: var(--text-primary);
}

/* Chat input */
body.light-mode .chat-input {
  background-color: var(--secondary-bg);
  border-top: 1px solid rgba(0,0,0,0.08);
}

body.light-mode .chat-input textarea {
  background: rgba(0,0,0,0.04);
  color: var(--text-primary);
  border: 1px solid rgba(0,0,0,0.1);
}

/* Chat bubbles */
body.light-mode .chatbox .incoming p {
  background: rgba(0,0,0,0.04);
  color: var(--text-primary);
}

body.light-mode .chatbox .outgoing p {
  background: var(--bubble-out);
  color: #ffffff;
  border: 1px solid var(--bubble-out-border);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.22);
}

/* Sidebar */
body.light-mode .history-sidebar {
  background-color: var(--secondary-bg);
  border-right: 1px solid rgba(0,0,0,0.08);
}

body.light-mode .history-sidebar h3 {
  color: var(--text-primary);
}

body.light-mode .history-list li {
  background: #ffffff;
  color: var(--text-primary);
  border: 1px solid rgba(0,0,0,0.1);
}

body.light-mode .history-actions-btn:hover {
  background: rgba(0, 0, 0, 0.06);
}

body.light-mode .history-item-actions-menu {
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.15);
}

body.light-mode .history-menu-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

body.light-mode .history-list li:hover {
  background-color: rgba(0,0,0,0.04);
}

body.light-mode .delete-icon {
  color: var(--text-secondary);
}

body.light-mode .delete-all-btn {
  color: var(--text-primary);
}

/* Sidebar toggle button in light mode */
body.light-mode #sidebar-toggle {
  color: var(--text-primary) !important;
  background: rgba(255, 255, 255, 0.3) !important;
}

/* ================= MICROPHONE ================= */
#mic-btn {
  font-size: var(--font-xl);
  color: var(--accent-primary);
  cursor: pointer;
  user-select: none;
  transition: color var(--transition-fast);
}

#mic-btn.listening {
  color: var(--error);
  animation: pulse 1s infinite;
}

#mic-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.speech-status {
  display: none;
}

.speech-status.listening {
  color: var(--error);
  animation: pulse 1s infinite;
}

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

/* ================= CHAT INPUT LAYOUT ================= */
.chat-input {
  display: flex;
  align-items: center;
  padding: var(--space-sm);
  background-color: transparent;
  gap: var(--space-xs);
}

.chat-input textarea {
  flex: 1;
  height: 60px;
  resize: none;
  padding: var(--space-sm);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font-size: var(--font-base);
}

.chat-input button,
.chat-input label {
  cursor: pointer;
  background: none;
  border: none;
  font-size: var(--font-xl);
  padding: 4px;
  color: var(--accent-primary);
  transition: all var(--transition-fast);
}

.chat-input button:hover,
.chat-input label:hover {
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
}

/* GPT-like composer override (scoped, minimal risk) */
.chatbot .chat-input {
  position: sticky;
  bottom: 0;
  width: min(860px, calc(100% - 20px));
  margin: 8px auto 28px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 28px;
  background: rgba(22, 24, 31, 0.92);
  backdrop-filter: blur(6px);
  gap: 8px;
  align-items: center;
}

/* Keep the same composer geometry in light mode (only colors may differ) */
body.light-mode .chatbot .chat-input {
  position: sticky;
  bottom: 0;
  width: min(860px, calc(100% - 20px));
  margin: 8px auto 28px;
  padding: 8px 10px;
  border-radius: 28px;
  gap: 8px;
  border-top: none !important;
  border: 1px solid rgba(0, 0, 0, 0.12) !important;
  background: #ffffff !important;
  backdrop-filter: blur(6px) !important;
}

body.light-mode .chatbot .chat-input textarea {
  background: transparent !important;
  border: none !important;
  color: #0f172a !important;
}

body.light-mode .chatbot .chat-input button,
body.light-mode .chatbot .chat-input label {
  background: rgba(0, 0, 0, 0.06) !important;
}

.chatbot .chat-input textarea {
  min-height: 44px;
  max-height: 160px;
  height: 44px;
  border: none;
  border-radius: 12px;
  background: transparent;
  padding: 10px 12px;
  line-height: 1.4;
  overflow-y: auto;
}

.chatbot .chat-input textarea:focus {
  outline: none;
}

.chatbot .chat-input button,
.chatbot .chat-input label {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  align-self: center;
  transform: translateY(-1px);
}

.chatbot .chat-input .upload-icon {
  position: relative;
  flex: 0 0 auto;
  font-size: 0;
  line-height: 1;
  color: var(--accent-primary);
  padding: 0;
  text-align: center;
  transform: none !important;
}

.chatbot .chat-input .upload-icon::before {
  content: "+";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -53%);
  font-size: 24px;
  font-weight: 500;
  line-height: 1;
  color: var(--accent-primary);
  pointer-events: none;
}

.chatbot .chat-input .upload-icon::after {
  content: "Upload files";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%) translateY(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
  font-size: 11px;
  color: #fff;
  background: rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 4px 7px;
  white-space: nowrap;
}

.chatbot .chat-input .upload-icon:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.chatbot .chat-input #image-mode-btn.active {
  background: linear-gradient(135deg, #12b981, #0ea5a7);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
}

.chatbot .chat-input button:disabled,
.chatbot .chat-input label[for="image-upload"][aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

@media (max-width: 640px) {
  .chatbot .chat-input {
    width: calc(100% - 22px);
    margin: 6px auto 22px;
    padding: 7px 8px;
    border-radius: 22px;
    gap: 6px;
  }

  body.light-mode .chatbot .chat-input {
    width: calc(100% - 22px);
    margin: 6px auto 22px;
    padding: 7px 8px;
    border-radius: 22px;
    gap: 6px;
  }

  .chatbot .chat-input textarea {
    min-height: 40px;
    height: 40px;
    max-height: 120px;
    padding: 8px 10px;
    font-size: 14px;
  }

  .chatbot .chat-input button,
  .chatbot .chat-input label {
    width: 32px;
    height: 32px;
    font-size: 20px;
    transform: translateY(-1px);
  }
}

.chat-footer-note {
  width: min(860px, calc(100% - 20px));
  margin: -16px auto 10px;
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.9;
}

@media (max-width: 640px) {
  .chat-footer-note {
    width: calc(100% - 22px);
    margin: -12px auto 8px;
    font-size: 11px;
  }
}

/* App view/mobile: keep composer centered with side gaps in dark mode too */
body.app-view .chatbot .chat-input {
  width: min(860px, calc(100% - 22px));
  margin-left: auto;
  margin-right: auto;
}

body.fresh-chat-home .chatbot {
  justify-content: flex-start;
}

body.fresh-chat-home .chatbot header {
  padding-top: 26px !important;
}

body.fresh-chat-home .chat-container {
  display: block;
  padding-top: 56px;
}

body.fresh-chat-home .chatbox,
body.fresh-chat-home .document-context-banner {
  display: none !important;
}

body.fresh-chat-home .chat-input {
  position: static;
  margin: 18px auto 10px;
}

body.fresh-chat-home .chat-footer-note {
  margin-top: 2px;
  margin-bottom: 18px;
}

body.light-mode .chat-home-subtitle {
  color: rgba(15, 23, 42, 0.64);
}

@media (max-width: 640px) {
  .chat-home {
    width: calc(100% - 24px);
    padding: 18px 6px 4px;
  }

  .chat-home-title {
    font-size: clamp(1.7rem, 1.45rem + 1.4vw, 2.2rem);
  }

  .chat-home-subtitle {
    font-size: 13px;
    line-height: 1.55;
    letter-spacing: 0.015em;
  }

  .chat-home-prompts {
    margin-top: 20px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .chat-home-actions {
    margin-top: 18px;
    gap: 8px;
  }

  .chat-home-action-btn {
    width: 100%;
    justify-content: center;
    padding: 10px 14px;
  }

  .chat-home-prompt {
    border-radius: 16px;
    min-height: 58px;
    align-items: center;
    gap: 10px;
    padding: 10px 11px;
  }

  .chat-home-prompt__desc {
    display: none;
  }

  .chat-home-prompt__copy {
    gap: 0;
  }

  .chat-home-prompt__title {
    font-size: 13px;
    line-height: 1.25;
  }

  .chat-home-prompt__icon {
    width: 18px;
    height: 18px;
    font-size: 18px;
  }

  .chat-home-options {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 10px;
  }

  .chat-home-option {
    border-radius: 14px;
    padding: 10px 11px;
    font-size: 12px;
    line-height: 1.35;
  }

  body.fresh-chat-home .chat-input {
    margin-top: 14px;
  }

  body.fresh-chat-home .chat-footer-note {
    margin-bottom: 12px;
  }
}

@media (min-width: 481px) {
body.fresh-chat-home .history-sidebar {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transform: translateX(-100%) !important;
}
}

@media (min-width: 481px) {
  body.fresh-chat-home .chatbot {
    width: 100% !important;
    left: 0 !important;
    right: 0 !important;
  }

  body.fresh-chat-home .chat-title {
    transform: none !important;
  }
}

@media (max-width: 480px) {
  body.fresh-chat-home .chatbot {
    justify-content: flex-start;
  }

  body.fresh-chat-home .chatbot header {
    position: sticky !important;
    top: 0 !important;
    z-index: 999 !important;
    height: 74px !important;
    padding-top: 14px !important;
    padding-bottom: 8px !important;
    display: block !important;
  }

  body.fresh-chat-home .chatbot header #sidebar-toggle {
    position: absolute !important;
    left: 12px !important;
    top: 12px !important;
    bottom: auto !important;
  }

  body.fresh-chat-home .chatbot header h2 {
    position: absolute !important;
    left: 50% !important;
    top: 18px !important;
    transform: translateX(-50%) !important;
    margin: 0 !important;
    width: auto !important;
    max-width: calc(100% - 120px) !important;
  }

  body.fresh-chat-home .chat-container {
    margin-top: auto;
    padding-top: 0;
    padding-bottom: 8px;
  }

  body.fresh-chat-home .chat-home {
    padding-top: 0;
    padding-bottom: 0;
    transform: translateY(-56px);
  }

  body.fresh-chat-home .chat-input {
    margin-top: 10px;
    margin-bottom: 8px;
  }

  body.fresh-chat-home .chat-footer-note {
    margin-bottom: 14px;
  }
}

body.app-view.fresh-chat-home .chatbot {
  justify-content: flex-start;
}

body.app-view.fresh-chat-home .chatbot header h2 {
  top: 18px !important;
}

body.app-view.fresh-chat-home .chat-container {
  margin-top: auto;
  padding-top: 0;
  padding-bottom: 8px;
}

body.app-view.fresh-chat-home .chat-home {
  padding-top: 0;
  padding-bottom: 0;
  transform: translateY(-56px);
}

body.app-view.fresh-chat-home .chat-input {
  margin-top: 10px;
  margin-bottom: 8px;
}

@media (min-width: 481px) {
  body.fresh-chat-home .chatbot header {
    position: sticky;
    top: 0;
    z-index: 20;
  }

  body.fresh-chat-home .chat-container {
    padding-top: min(18vh, 160px);
  }

  body.fresh-chat-home .chat-input {
    margin-top: 24px;
  }

  body.fresh-chat-home .chat-footer-note {
    margin-bottom: 22px;
  }
}

/* ================= MESSAGE ACTIONS ================= */
.chat.incoming .bot-message-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  max-width: 80%;
}

.chat.incoming .bot-message-container p {
  padding-bottom: 0;
}

.chat.incoming .msg-actions {
  position: static;
  display: flex;
  justify-content: flex-start;
  align-self: flex-start;
  gap: 10px;
  align-items: center;
  margin-top: 2px;
  padding-left: 2px;
}

.chat.incoming .msg-actions .copy-btn,
.chat.incoming .msg-actions .speak-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-size: 18px;
  color: #ffffff;
  opacity: 1;
}

.chat.incoming .msg-actions .copy-btn:hover,
.chat.incoming .msg-actions .speak-btn:hover {
  opacity: 0.85;
}

/* Light mode message actions */
body.light-mode .chat.incoming .msg-actions .copy-btn,
body.light-mode .chat.incoming .msg-actions .speak-btn {
  color: var(--text-primary) !important;
}

/* ================= CODE BLOCKS ================= */
.code-block {
  position: relative;
  background-color: #2d2d2d;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  margin: 10px 0;
  overflow: hidden;
  max-width: 100%;
}

.code-block pre[class*="language-"] {
  background: #2d2d2d;
  margin: 0;
  padding: 36px 14px 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.code-block code {
  background: transparent !important;
  white-space: pre;
}

.code-block .code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
  background: rgba(32, 32, 32, 0.5);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
}

.code-block .code-copy-btn:hover {
  background: rgba(0,0,0,0.7);
}

.bot-message-content {
  color: white;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  line-height: 1.65;
  font-size: 15px;
  overflow-x: hidden;
}

.bot-message-content > *:first-child {
  margin-top: 0;
}

.bot-message-content > *:last-child {
  margin-bottom: 0;
}

.bot-message-content p {
  margin: 0 0 12px;
}

.bot-message-content h1,
.bot-message-content h2,
.bot-message-content h3,
.bot-message-content h4,
.bot-message-content h5,
.bot-message-content h6 {
  margin: 14px 0 10px;
  line-height: 1.25;
  letter-spacing: 0.01em;
}

.bot-message-content h1 { font-size: 1.45rem; }
.bot-message-content h2 { font-size: 1.28rem; }
.bot-message-content h3 { font-size: 1.15rem; }

.bot-message-content ul,
.bot-message-content ol {
  margin: 0 0 12px 18px;
  padding: 0 0 0 4px;
}

.bot-message-content li {
  margin: 6px 0;
}

.bot-message-content blockquote {
  margin: 12px 0;
  padding: 8px 12px;
  border-left: 3px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
}

.bot-message-content a {
  color: #7dd3fc;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.bot-message-content .inline-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.92em;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  padding: 1px 6px;
}

.bot-message-content .code-block {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin: 10px 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.bot-message-content .code-block pre {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  margin: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 44px 12px 12px;
}

.bot-message-content .code-block code {
  display: block;
  width: max-content;
  min-width: 100%;
  white-space: pre;
}

.bot-message-content .code-block .code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
}

body.light-mode .bot-message-content
{
  color: #000;
}

body.light-mode .bot-message-content blockquote {
  border-left: 3px solid rgba(15, 23, 42, 0.2);
  background: rgba(15, 23, 42, 0.05);
}

body.light-mode .bot-message-content a {
  color: #1d4ed8;
}

body.light-mode .bot-message-content .inline-code {
  background: rgba(15, 23, 42, 0.08);
}

.generated-image-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, 90vw);
}

.generated-image-link {
  display: block;
}

.generated-image-preview {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(148, 163, 184, 0.1);
}

.generated-image-caption {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.generated-image-open {
  width: fit-content;
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  color: #0ea5a7;
}

@media (max-width: 480px) {
  .chatbox { 
    padding-left: 30px; 
    padding-right: 10px; 
  }
  .bot-message-content .code-block pre { 
    padding: 44px 10px 10px; 
  }
}

/* ================= HISTORY HEADER ================= */
.history-actions {
  display: block;
  flex-shrink: 0;
  padding: 0;
  margin: 0;
}

.delete-all-btn {
  flex-shrink: 0;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--space-xs);
  background: none;
  border: none;
  color: var(--text-primary);
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: var(--font-base);
  margin: var(--space-md) var(--space-md) 6px;
  width: calc(100% - 2 * var(--space-md));
  text-align: left;
  transition: color var(--transition-fast);
}

.new-chat-btn .material-symbols-outlined {
  font-size: 20px;
}

body.light-mode .new-chat-btn {
  background: none;
  color: var(--text-primary);
}

.new-chat-btn:hover {
  background-color: rgba(99, 102, 241, 0.12);
  color: var(--accent-primary);
}

.sidebar-footer {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  padding: 12px;
  background:
    linear-gradient(
      180deg,
      rgba(17, 18, 25, 0) 0%,
      rgba(17, 18, 25, 0.92) 22%,
      rgba(17, 18, 25, 1) 100%
    );
  z-index: 80;
  pointer-events: auto;
  flex-shrink: 0;
}

.sidebar-settings-btn {
  width: 100%;
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

.sidebar-settings-btn:hover {
  background: rgba(99, 102, 241, 0.12);
  border-color: rgba(129, 140, 248, 0.28);
  transform: translateY(-1px);
}

.sidebar-settings-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-settings-copy strong {
  font-size: 14px;
  font-weight: 600;
}

.sidebar-settings-copy small {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.35;
}

body.light-mode .sidebar-footer {
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  background:
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0) 0%,
      rgba(255, 255, 255, 0.92) 22%,
      rgba(255, 255, 255, 1) 100%
    );
}

body.light-mode .sidebar-settings-btn {
  border-color: rgba(15, 23, 42, 0.08);
  background: rgba(15, 23, 42, 0.03);
}

/* ================= TYPING INDICATOR ================= */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
}

.typing-indicator__title {
  color: var(--text-primary);
  font-weight: 500;
}

.thinking-inline {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
}

.thinking-inline__text {
  color: var(--text-primary);
  font-weight: 500;
}

.thinking-inline__dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  transform: translateY(1px);
}

.thinking-inline__dots span {
  width: 4px;
  height: 4px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.9);
  animation: thinkingDotWave 1.15s ease-in-out infinite;
}

.thinking-inline__dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking-inline__dots span:nth-child(3) {
  animation-delay: 0.3s;
}

body.light-mode .typing-indicator,
body.light-mode .thinking-inline {
  color: rgba(15, 23, 42, 0.62);
}

body.light-mode .typing-indicator__title,
body.light-mode .thinking-inline__text {
  color: rgba(15, 23, 42, 0.86);
}

@keyframes thinkingPulse {
  0%, 100% { opacity: 0.35; transform: scale(0.75); }
  50% { opacity: 1; transform: scale(1); }
}

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

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

@keyframes thinkingPing {
  0% { box-shadow: 0 0 0 0 rgba(157, 193, 255, 0.45); }
  70% { box-shadow: 0 0 0 14px rgba(157, 193, 255, 0); }
  100% { box-shadow: 0 0 0 0 rgba(157, 193, 255, 0); }
}

@keyframes thinkingDotWave {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* ================= DOTS ANIMATION ================= */
.dots::after {
  content: '';
  display: inline-block;
  width: 1em;
  animation: dots 1s steps(3, end) infinite;
}

@keyframes dots {
  0% { content: ''; }
  33% { content: '.'; }
  66% { content: '..'; }
  100% { content: '...'; }
}

/* ================= RESPONSIVE WELCOME TEXT ================= */
@media (max-width: 780px) {
  .welcomes {
    font-size: var(--font-2xl);
  }
}

@media (max-width: 480px) {
  .welcomes {
    font-size: var(--font-xl);
  }
}

/* ================= CLEANUP ================= */
.chatbot-toggler {
  display: none !important;
}

@media (max-width: 480px) {
  /* Keep close button aligned if shown anywhere */
  .chatbot header .close-btn {
    right: 16px !important;
    top: 16px !important;
    left: auto !important;
  }
}

/* ================= CLOSE SIDEBAR BUTTON ================= */
.close-sidebar-btn {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  cursor: pointer !important;
  pointer-events: auto !important;
  z-index: 1000 !important;
  color: var(--text-primary) !important;
  font-size: var(--font-xl) !important;
  background: none !important;
  border: none !important;
  padding: 8px !important;
  margin: 0 !important;
  position: absolute !important;
  top: 12px !important;
  right: 12px !important;
}

/* Show on BOTH desktop and mobile when sidebar is active */
body.chat-started .history-sidebar .close-sidebar-btn {
  display: block !important;
}

/* On mobile, make sure it's positioned correctly */
@media (max-width: 480px) {
  .close-sidebar-btn {
    position: absolute !important;
    top: 12px !important;
    right: 12px !important;
    z-index: 1001 !important;
  }
}

/* Make sure close button is visible */
#close-sidebar {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  pointer-events: auto !important;
  cursor: pointer !important;
  position: absolute !important;
  top: 12px !important;
  right: 12px !important;
  z-index: 1000 !important;
}

/* Make button more touch-friendly for WebView */
#close-sidebar {
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(0,0,0,0.1);
  min-width: 44px;
  min-height: 44px; /* Apple recommends 44x44px for touch targets */
}

/* ================= ERROR MESSAGE STYLING ================= */
.chatbox .error {
  display: flex;
  justify-content: flex-start;
  margin: var(--space-sm) 0;
  list-style: none;
}

.chatbox .error p {
  background: var(--secondary-bg);
  color: #ffffff !important; /* White text */
  padding: var(--space-sm);
  border-radius: var(--radius-xl) var(--radius-xl) var(--radius-xl) var(--radius-sm);
  max-width: 80%;
  font-size: var(--font-base);
  border: none;
  box-shadow: none;
  margin: 0;
}

/* Ensure text is white */
.chatbox .error p,
.chatbox .error {
  color: #ffffff !important;
}

/* Light mode error styling */
body.light-mode .chatbox .error p {
  background: rgba(0, 0, 0, 0.04);
  color: #333333 !important; /* Dark text for light mode */
  border: none;
}

/* Make sure no-chats message is also styled */
.chatbox .no-chats,
.history-list .no-chats,
.history-list .error {
  color: #ffffff !important;
  background: transparent;
  border: none;
  text-align: center;
  padding: var(--space-md);
  font-style: italic;
  opacity: 0.7;
}

body.light-mode .chatbox .no-chats,
body.light-mode .history-list .no-chats,
body.light-mode .history-list .error {
  color: #333333 !important;
}

/* ================= MOBILE INCOMING CHAT LAYOUT ONLY ================= */
@media (max-width: 480px) {
  /* Chatbox container */
  .chatbox {
    padding: 12px 12px 80px !important;
  }
  
  /* INCOMING messages only (bot): left-aligned with full width */
  .chat.incoming {
    justify-content: flex-start !important;
    margin-left: 8px !important;
    margin-right: 8px !important;
    width: calc(100% - 16px) !important;
  }
  
  .chatbox .incoming p,
  .chat.incoming p {
    max-width: 100% !important;
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    border-radius: 18px 18px 18px 4px !important;
    padding: 12px 14px !important;
    background: var(--bubble-in) !important;
    border: none !important;
    box-shadow: none !important;
  }
  
  /* Bot message container */
  .chat.incoming .bot-message-container {
    max-width: 100% !important;
    width: 100% !important;
  }
  
  /* Bot message content */
  .bot-message-content {
    width: 100% !important;
  }
  
  /* OUTGOING messages stay AS BEFORE (unchanged) */
  .chat.outgoing {
    /* Keep original outgoing styles - don't change */
    justify-content: flex-end !important;
  }
   
  /* Code blocks on mobile */
  .bot-message-content .code-block {
    width: 100% !important;
    max-width: 100% !important;
    margin: 8px 0 !important;
    border-radius: 12px !important;
    overflow: hidden !important;
  }
  
  .bot-message-content .code-block pre {
    padding: 40px 10px 10px !important;
    font-size: 13px !important;
  }
  
  /* Message actions on mobile */
  .chat.incoming .msg-actions {
    position: static !important;
    justify-content: flex-start !important;
    align-self: flex-start !important;
    margin-top: 4px !important;
    padding-left: 2px !important;
  }
  
  /* Typing indicator spacing */
  .typing-indicator {
    min-width: 0 !important;
    max-width: 100% !important;
    gap: 8px !important;
    display: inline-flex !important;
  }

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

  .thinking-inline__text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  
  /* Light mode adjustments for incoming only */
  body.light-mode .chatbox .incoming p,
  body.light-mode .chat.incoming p {
    background: rgba(0, 0, 0, 0.04) !important;
  }
}

/* ✅ Light mode + Mobile: outgoing bubble should be subtle card like ChatGPT */
@media (max-width: 480px) {
  body.light-mode .chatbox .outgoing p {
    background: var(--bubble-out) !important;
    color: #ffffff !important;
    border: 1px solid var(--bubble-out-border) !important;
    border-radius: 14px !important;

    box-shadow:
      0 2px 8px rgba(99, 102, 241, 0.2),
      0 10px 22px rgba(99, 102, 241, 0.24) !important;

    backdrop-filter: blur(4px);
  }
}
/* ================= MOBILE HEADER FINAL (NO ERRORS) ================= */
@media (max-width: 480px) {
  /* Match mobile positioning with app-view layout */
  body.chat-started .chatbot header {
    position: sticky !important;
    top: 0 !important;
    z-index: 999 !important;
    height: 72px !important;
    padding-top: 18px !important;
    padding-bottom: 8px !important;
    display: block !important;
  }

  body.chat-started .chatbot header #sidebar-toggle {
    position: absolute !important;
    left: 12px !important;
    bottom: 8px !important;
    top: auto !important;
  }

  body.chat-started .chatbot header h2 {
    position: absolute !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    top: 6px !important;
    bottom: auto !important;
    margin: 0 !important;
    width: auto !important;
    max-width: calc(100% - 132px) !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 0 !important;
    text-align: center !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  body.chat-started .chatbot header #mode-toggle {
    position: absolute !important;
    right: 12px !important;
    bottom: 8px !important;
    top: auto !important;
  }

  body.chat-started .chatbot header #auth-btn {
    position: absolute !important;
    right: 58px !important;
    bottom: 8px !important;
    top: auto !important;
  }

  body.chat-started .chatbot header #close-chatbot {
    display: none !important;
  }
}

/* Desktop: hide sidebar close button */
@media (min-width: 481px) {
  .history-sidebar .close-sidebar-btn,
  #close-sidebar {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }
}

/* App-view should keep mobile-style header layout even above 480px */
@media (min-width: 481px) {
  body.app-view .chatbot header {
    position: sticky !important;
    top: 0 !important;
    z-index: 999 !important;
    height: 72px !important;
    padding-top: 18px !important;
    padding-bottom: 8px !important;
    display: block !important;
  }

  body.app-view .chatbot header #sidebar-toggle {
    position: absolute !important;
    left: 12px !important;
    bottom: 8px !important;
    top: auto !important;
  }

  body.app-view .chatbot header h2 {
    position: absolute !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    top: 6px !important;
    bottom: auto !important;
    margin: 0 !important;
    width: auto !important;
    max-width: calc(100% - 132px) !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 0 !important;
    text-align: center !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  body.app-view .chatbot header .chat-title-logo {
    width: 60px !important;
    height: 60px !important;
    background: transparent !important;
  }

  body.app-view .chatbot header #mode-toggle {
    position: absolute !important;
    right: 12px !important;
    bottom: 8px !important;
    top: auto !important;
  }

  body.app-view .chatbot header #auth-btn {
    position: absolute !important;
    right: 58px !important;
    bottom: 8px !important;
    top: auto !important;
  }

  body.app-view .chatbot header #close-chatbot {
    display: none !important;
  }
}

/* Mobile: hide download buttons */
@media (max-width: 480px) {
  #download-app-btn,
  #apk-download-header,
  .apk-download-btn {
    display: none !important;
  }
}
/* ================= MOBILE: HISTORY HEADER DOWN (SAFE TOP) ================= */
@media (max-width: 480px) {
  :root { --safe-top: 18px; } /* same value you use for chatbot header */

  /* Sidebar itself stays full height but content starts lower */
  body.chat-started .history-sidebar {
    padding-top: calc(12px + var(--safe-top)) !important;
    background: var(--secondary-bg) !important;
  }

  /* If your history header is sticky, keep it aligned */
  .history-header {
    position: sticky !important;
    top: 0 !important;
    background: var(--secondary-bg) !important;
    z-index: 10 !important;
    border-bottom: none !important; /* removes any thin line */
    box-shadow: none !important;
  }
}

/* ================= HEADER APK DOWNLOAD BUTTON ================= */

/* ================= HEADER GRID ================= */
.chat-header{
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 56px;
  padding: 0 12px;
}

/* Left / Right groups */
.header-left,
.header-right{
  display: flex;
  align-items: center;
  gap: 8px;
}

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

/* FORCE Genie dead-center */
.chat-title{
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 0px;
  text-align: center;
  justify-self: center;
  pointer-events: none;
}

@media (min-width: 769px) {
  .chat-title {
    transform: translateX(-140px);
  }
}

@media (min-width: 481px) and (max-width: 768px) {
  .chat-title {
    transform: translateX(-115px);
  }
}

.chat-title-logo{
  width: 60px;
  height: 60px;
  object-fit: contain;
  flex: 0 0 auto;
  mix-blend-mode: screen;
  background: transparent !important;
}

body.light-mode .chat-title-logo{
  mix-blend-mode: normal !important;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.55))
          drop-shadow(0 0 2px rgba(0, 0, 0, 0.35));
}

.chat-title-text{
  line-height: 1;
  margin-left: 0;
}

/* ================= APK BUTTON ================= */
.apk-download-btn{
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;

  border-radius: 999px;
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;

  color: var(--text-primary);
  background: var(--secondary-bg);
  border: 1px solid rgba(100, 100, 104, 0.35);
}

.apk-download-btn .material-symbols-outlined{
  font-size: 16px;
}

.auth-header-btn{
  display: inline-flex;
  align-items: center;
  gap: 0;
  height: 34px;
  width: 34px;
  padding: 0;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--secondary-bg);
  border: 1px solid rgba(100, 100, 104, 0.35);
  cursor: pointer;
  justify-content: center;
  overflow: hidden;
  transition: width .2s ease, padding .2s ease, border-color .2s ease, background .2s ease;
}

.auth-header-btn .material-symbols-outlined{
  font-size: 18px;
  flex: 0 0 auto;
}

.auth-header-btn .auth-text{
  opacity: 0;
  max-width: 0;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity .18s ease, max-width .2s ease, margin-left .2s ease;
}

@media (min-width: 481px){
  .auth-header-btn:hover{
    width: 108px;
    padding: 0 12px;
    justify-content: flex-start;
    border-color: rgba(255, 255, 255, 0.35);
  }

  .auth-header-btn:hover .auth-text{
    opacity: 1;
    max-width: 72px;
    margin-left: 6px;
  }
}

/* Hide inside APK */
body.in-app .apk-download-btn{
  display: none !important;
}

/* ================= MOBILE (≤480) ================= */
@media (max-width: 480px){

  /* Move download NEXT TO menu (swap position) */
  .header-left{
    gap: 6px;
  }

  .header-right{
    gap: 6px;
  }

  /* ICON ONLY */
  .apk-download-btn{
    padding: 0;
    width: 34px;
    justify-content: center;
  }

  .auth-header-btn{
    padding: 0;
    width: 34px;
    height: 34px;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.9);
    color: #fff;
    background: transparent;
  }

  .apk-download-btn .apk-text{
    display: none;
  }

  .auth-header-btn .auth-text{
    display: none;
  }
}
/* ================= DESKTOP FIX (Download at LEFT END) ================= */
@media (min-width: 481px){

  /* Place download button at far left of the header */
  .apk-download-btn{
    justify-self: start;
    grid-column: 1;            /* left column */
    grid-row: 1;
    margin-left: 0;
    margin-right: 12px;
  }

  /* Keep right actions still on right */
  .header-right{
    grid-column: 3;            /* right column */
    justify-self: end;
  }

  /* Keep title centered */
  .chat-title{
    grid-column: 2;
    justify-self: center;
  }
}
.header-right{
  display: contents; /* allows children to act like grid items */
}

/* ================= APP VIEW (WebView): PUSH HEADER DOWN ================= */
body.app-view .chatbot header{
  position: sticky !important;
  top: 0 !important;
  z-index: 999 !important;
  height: 72px !important;
  padding-top: 18px !important;
  padding-bottom: 8px !important;
  display: block !important;
}

body.app-view .chatbot header #sidebar-toggle{
  position: absolute !important;
  left: 12px !important;
  bottom: 8px !important;
  top: auto !important;
}

body.app-view .chatbot header h2{
  position: absolute !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  top: 6px !important;
  bottom: auto !important;
  margin: 0 !important;
  width: auto !important;
  max-width: calc(100% - 132px) !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 0 !important;
  text-align: center !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

body.app-view .chatbot header .chat-title-logo{
  width: 60px !important;
  height: 60px !important;
  background: transparent !important;
}

body.app-view .chatbot header #mode-toggle{
  position: absolute !important;
  right: 12px !important;
  bottom: 8px !important;
  top: auto !important;
}

body.app-view .chatbot header #auth-btn{
  position: absolute !important;
  right: 58px !important;
  bottom: 8px !important;
  top: auto !important;
}

body.app-view .chatbot header #close-chatbot{
  display: none !important;
}
body.app-view #download-app-btn,
body.app-view .apk-download-btn{
  display: none !important;
}

body.app-view .auth-header-btn{
  display: inline-flex !important;
}
/* APP VIEW + MOBILE: header height same, but items bottom-aligned */
@media (max-width: 480px){
  body.app-view .chatbot header{
    position: sticky !important;
    top: 0 !important;
    z-index: 999 !important;

    height: 72px !important;          /* fixed header height (same) */
    padding-top: 18px !important;     /* safe space */
    padding-bottom: 8px !important;

    display: block !important;        /* we will position items manually */
  }

  /* Menu (sidebar toggle) bottom-left */
  body.app-view .chatbot header #sidebar-toggle{
    position: absolute !important;
    left: 12px !important;
    bottom: 8px !important;           /* ⬅ bottom near */
    top: auto !important;
  }

  /* Title bottom-center */
  body.app-view .chatbot header h2{
    position: absolute !important;
    left: 50% !important;
    transform: translateX(-50%) !important;

    top: 6px !important;
    bottom: auto !important;

    margin: 0 !important;
    width: auto !important;
    max-width: calc(100% - 132px) !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 0 !important;
    text-align: center !important;

    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  /* Mode toggle bottom-right */
  body.app-view .chatbot header #mode-toggle{
    position: absolute !important;
    right: 12px !important;
    bottom: 8px !important;
    top: auto !important;
  }

  body.app-view .chatbot header #auth-btn{
    position: absolute !important;
    right: 58px !important;
    bottom: 8px !important;
    top: auto !important;
  }

  /* If close btn exists, keep it hidden or place it too */
  body.app-view .chatbot header #close-chatbot{
    display: none !important;
  }
}

/* Final lock: mode toggle must stay at far-right on mobile + app-view */
@media (max-width: 480px) {
  .chat-title-logo{
    width: 60px;
    height: 60px;
    background: transparent !important;
  }

  body.chat-started .chatbot header #mode-toggle,
  body.app-view .chatbot header #mode-toggle {
    position: absolute !important;
    right: 12px !important;
    left: auto !important;
    top: auto !important;
    bottom: 8px !important;
  }

  body.chat-started .chatbot header #auth-btn,
  body.app-view .chatbot header #auth-btn {
    right: 58px !important;
    left: auto !important;
  }
}


.code-block pre,
.code-block code{
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
}

.code-block pre{
  overflow-x: auto;
  max-width: 100%;
}
.code-block pre{ overflow-x:auto; max-width:100%; }
.code-block pre, .code-block code{
  white-space:pre;
  word-break:normal;
  overflow-wrap:normal;
}

/* ================= APP VIEW + LIGHT MODE: MATCH DARK BORDERS/RADIUS ================= */
body.app-view.light-mode .chatbot {
  border-left: none !important;
}

body.app-view.light-mode .chatbot header {
  border-bottom: none !important;
}

body.app-view.light-mode .chat-input {
  border-top: none !important;
}

body.app-view.light-mode .history-sidebar {
  border-right: none !important;
}

body.app-view.light-mode .chat-input textarea {
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  border-radius: var(--radius-md) !important;
  background: rgba(255, 255, 255, 0.05) !important;
}

body.app-view.light-mode .history-list li {
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  border-radius: var(--radius-md) !important;
}

body.app-view.light-mode .chatbox .outgoing p {
  background: var(--bubble-out) !important;
  border: 1px solid var(--bubble-out-border) !important;
  color: #ffffff !important;
  padding: var(--space-sm) !important;
  border-radius: var(--radius-xl) var(--radius-xl) var(--radius-sm) var(--radius-xl) !important;
  margin-left: auto !important;
  max-width: 80% !important;
}

body.app-view.light-mode .chatbox .outgoing .outgoing-message {
  max-width: min(80%, 680px) !important;
  white-space: pre-wrap !important;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
}

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

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

@media (prefers-reduced-motion: reduce) {
  .chat-home-prompts,
  .chat-home-prompt,
  .chat-home-options,
  .chat-home-option,
  .chatbox .chat {
    animation: none !important;
    transition-duration: 0.01ms !important;
  }
}


/* ================= DESKTOP NORMAL MODE: AUTH LEFT OF MODE TOGGLE ================= */
@media (min-width: 481px) {
body:not(.app-view) .chatbot header #auth-btn {
    position: fixed !important;
    top: 20px !important;
    right: 64px !important;
    left: auto !important;
    z-index: 1001 !important;
  }
}

/* Auth Button Styles */
#auth-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: none;
  border-radius: 30px;
  background-color:  transparent !important;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s ease;
  white-space: nowrap;
  max-width: 200px;
}

#auth-btn.logged-in {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  padding: 6px 16px 6px 12px;
}

#auth-btn.logged-in:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(99, 102, 241, 0.3);
}

#auth-btn .auth-text {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100px;
}

#auth-btn .material-symbols-outlined {
  font-size: 20px;
}

/* Mobile responsive */
@media (max-width: 768px) {
  #auth-btn .auth-text {
    display: none;
  }
  
  #auth-btn {
    padding: 8px;
    border-radius: 50%;
    aspect-ratio: 1;
  }
  
  #auth-btn .material-symbols-outlined {
    margin: 0;
  }
}

/* Keep sidebar auth button consistent on mobile/app-view */
@media (max-width: 768px) {
  .history-sidebar #auth-btn {
    width: 100% !important;
    aspect-ratio: auto !important;
    height: 44px !important;
    min-height: 44px !important;
    border-radius: 14px !important;
    padding: 0 14px !important;
    gap: 10px !important;
    justify-content: flex-start !important;
  }

  .history-sidebar #auth-btn .auth-text {
    display: inline !important;
    max-width: none !important;
  }
}
/* Frontend memory + document context UI */
.document-context-banner {
  display: none !important;
}

.document-context-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.document-context-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.document-context-copy strong,
.document-context-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-context-copy span {
  color: var(--text-secondary);
  font-size: var(--font-sm);
}

.document-context-clear {
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
}

.memory-modal[hidden] {
  display: none;
}

.memory-modal {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

body.settings-open {
  overflow: hidden;
}

.memory-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 10, 18, 0.72);
  backdrop-filter: blur(8px);
}

.memory-modal-card {
  position: relative;
  width: min(560px, calc(100vw - 32px));
  min-height: 336px;
  max-height: min(82vh, 760px);
  overflow: hidden;
  margin: 0;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(17, 18, 25, 0.96);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
}

.settings-overview-grid {
  padding: 24px 24px 30px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  justify-content: center;
  gap: 14px;
}

.settings-stat-card,
.settings-theme-btn,
.settings-auth-btn {
  width: 100%;
  min-height: 84px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  text-align: left;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-primary);
  box-shadow: none;
  justify-self: center;
}

.settings-theme-btn {
  cursor: pointer;
}

.settings-auth-btn {
  cursor: pointer;
}

.memory-modal-card .settings-overview-grid > #auth-btn.settings-auth-btn {
  position: static !important;
  inset: auto !important;
  left: auto !important;
  right: auto !important;
  top: auto !important;
  z-index: auto !important;
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
  min-height: 84px !important;
  height: auto !important;
  aspect-ratio: auto !important;
  display: flex !important;
  align-items: flex-start !important;
  justify-content: flex-start !important;
  gap: 12px !important;
  padding: 16px !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
  border-radius: 18px !important;
  background: rgba(255, 255, 255, 0.04) !important;
  color: var(--text-primary) !important;
  box-shadow: none !important;
  transform: none !important;
  white-space: normal !important;
  text-align: left !important;
}

.settings-theme-btn .material-symbols-outlined,
.settings-stat-card .material-symbols-outlined,
.settings-auth-btn .material-symbols-outlined {
  font-size: 22px;
  color: var(--text-primary);
  flex-shrink: 0;
  margin-top: 1px;
}

.settings-theme-copy,
.settings-auth-btn .auth-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.settings-stat-card strong,
.settings-theme-copy strong,
.settings-auth-btn .auth-text {
  display: block;
  font-size: 14px;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.settings-stat-card p,
.settings-theme-copy small,
.settings-auth-btn .auth-subtext {
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.45;
}

.memory-modal-card .settings-overview-grid > #auth-btn.settings-auth-btn .auth-text {
  display: block !important;
  max-width: none !important;
}

.memory-modal-card .settings-overview-grid > #auth-btn.settings-auth-btn .auth-copy {
  display: flex !important;
  flex: 1 1 auto !important;
  flex-direction: column !important;
  min-width: 0 !important;
}

.settings-auth-btn .auth-subtext {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  display: -webkit-box;
  line-clamp: 2;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.settings-section {
  padding: 18px 20px 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.settings-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.settings-section-head h4 {
  font-size: 14px;
  color: var(--text-primary);
}

.settings-section-note {
  color: var(--text-secondary);
  font-size: 12px;
  max-width: 260px;
  text-align: right;
  line-height: 1.45;
}

.memory-modal-header,
.memory-modal-actions {
  padding: 22px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.memory-modal-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.memory-modal-header h3 {
  font-size: var(--font-xl);
  color: var(--text-primary);
}

.memory-modal-header p {
  color: var(--text-secondary);
  font-size: var(--font-sm);
  margin-top: 4px;
}

.memory-close-btn,
.memory-clear-btn {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border-radius: 12px;
  cursor: pointer;
}

.memory-close-btn {
  width: 40px;
  height: 40px;
}

.memory-clear-btn {
  padding: 10px 14px;
}

.memory-list {
  padding: 0 0 20px;
  overflow-y: auto;
  display: grid;
  gap: 10px;
}

.memory-item,
.memory-empty {
  border-radius: 16px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
}

.memory-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.memory-item strong {
  display: block;
  font-size: var(--font-sm);
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.memory-item p,
.memory-empty {
  color: var(--text-primary);
}

.memory-delete-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(239, 68, 68, 0.08);
  color: #fda4af;
  cursor: pointer;
  flex-shrink: 0;
}

.memory-empty {
  color: var(--text-secondary);
  text-align: center;
}

body.light-mode .header-utility-btn,
body.light-mode .document-context-clear,
body.light-mode .memory-close-btn,
body.light-mode .memory-clear-btn,
body.light-mode .memory-item,
body.light-mode .memory-empty {
  border-color: rgba(15, 23, 42, 0.08);
}

body.light-mode .document-context-banner {
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.18);
}

body.light-mode .memory-modal-card {
  background: rgba(255, 255, 255, 0.98);
}

body.light-mode .settings-stat-card,
body.light-mode .settings-theme-btn,
body.light-mode .settings-auth-btn {
  border-color: rgba(15, 23, 42, 0.08);
  background: rgba(15, 23, 42, 0.03);
}

body.light-mode .settings-auth-btn .material-symbols-outlined,
body.light-mode .settings-auth-btn .auth-copy,
body.light-mode .settings-auth-btn .auth-text,
body.light-mode .memory-modal-header h3,
body.light-mode .settings-section-head h4,
body.light-mode .settings-stat-card .material-symbols-outlined,
body.light-mode .settings-stat-card strong,
body.light-mode .settings-theme-btn .material-symbols-outlined,
body.light-mode .settings-theme-copy strong {
  color: var(--text-primary);
}

@media (max-width: 640px) {
  .memory-modal {
    align-items: flex-end;
    justify-content: center;
    padding: 12px;
  }

  .memory-modal-card {
    width: min(100%, 520px);
    margin-top: auto;
    max-height: min(88vh, 760px);
    min-height: 0;
    border-bottom-left-radius: 22px;
    border-bottom-right-radius: 22px;
  }

  .settings-overview-grid {
    padding: 18px 16px 22px;
    grid-template-columns: 1fr;
  }

  .memory-modal-card .settings-overview-grid > #auth-btn.settings-auth-btn,
  .settings-auth-btn,
  .settings-theme-btn,
  .settings-stat-card {
    min-height: 68px;
    padding: 13px 14px;
    border-radius: 16px;
    width: 100% !important;
    max-width: none !important;
    aspect-ratio: auto !important;
  }

  .settings-auth-btn .auth-subtext {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
    display: block;
    line-clamp: unset;
    -webkit-line-clamp: unset;
    -webkit-box-orient: unset;
  }

  .settings-section-head {
    flex-direction: column;
  }

  .settings-section-note {
    max-width: none;
    text-align: left;
  }

  .settings-auth-btn,
  .settings-theme-btn,
  .settings-stat-card {
    gap: 10px;
  }

  .settings-auth-btn .material-symbols-outlined,
  .settings-theme-btn .material-symbols-outlined,
  .settings-stat-card .material-symbols-outlined {
    font-size: 20px;
  }

  .sidebar-footer {
    left: 10px;
    right: 10px;
    bottom: 10px;
  }
}

body.app-view .memory-modal {
  align-items: flex-end;
  justify-content: center;
  padding: 14px;
}

body.app-view .memory-modal-card {
  width: min(100%, 520px);
  margin-top: auto;
  min-height: 0;
}

body.app-view .memory-modal-card .settings-overview-grid > #auth-btn.settings-auth-btn,
body.app-view .settings-auth-btn,
body.app-view .settings-theme-btn,
body.app-view .settings-stat-card {
  min-height: 70px;
  width: 100% !important;
  max-width: none !important;
  aspect-ratio: auto !important;
}

/* ================= HEADER OVERLAP SAFETY ================= */
@media (max-width: 820px) {
  .chat-header {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) auto !important;
    align-items: center !important;
    gap: 8px !important;
    height: auto !important;
    min-height: 64px !important;
    padding: 10px 12px !important;
  }

  .header-left,
  .header-right {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    min-width: 0 !important;
  }

  .header-right {
    display: flex !important;
    justify-content: flex-end !important;
    justify-self: end !important;
  }

  .chat-title {
    position: static !important;
    left: auto !important;
    top: auto !important;
    bottom: auto !important;
    transform: none !important;
    width: 100% !important;
    max-width: min(100%, 220px) !important;
    margin: 0 auto !important;
    justify-self: center !important;
    justify-content: center !important;
    overflow: hidden !important;
    white-space: nowrap !important;
    text-overflow: ellipsis !important;
  }

  .chat-title-logo {
    width: 44px !important;
    height: 44px !important;
    flex-shrink: 0 !important;
  }

  .chat-title-text {
    min-width: 0 !important;
    margin-left: -6px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    font-size: 1rem !important;
  }

  .apk-download-btn {
    width: 34px !important;
    height: 34px !important;
    padding: 0 !important;
    justify-content: center !important;
  }

  .apk-download-btn .apk-text {
    display: none !important;
  }
}

body.app-view .chat-header {
  display: grid !important;
  grid-template-columns: auto minmax(0, 1fr) auto !important;
  align-items: center !important;
  gap: 8px !important;
  height: auto !important;
  min-height: 64px !important;
  padding: 10px 12px !important;
}

body.app-view .header-left,
body.app-view .header-right {
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  min-width: 0 !important;
}

body.app-view .header-right {
  justify-content: flex-end !important;
  justify-self: end !important;
}

body.app-view .chat-title {
  position: static !important;
  left: auto !important;
  top: auto !important;
  bottom: auto !important;
  transform: none !important;
  width: 100% !important;
  max-width: min(100%, 220px) !important;
  margin: 0 auto !important;
  justify-self: center !important;
  justify-content: center !important;
  overflow: hidden !important;
  white-space: nowrap !important;
  text-overflow: ellipsis !important;
}

body.app-view .chat-title-logo {
  width: 44px !important;
  height: 44px !important;
  flex-shrink: 0 !important;
}

body.app-view .chat-title-text {
  min-width: 0 !important;
  margin-left: -6px !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  font-size: 1rem !important;
}

/* ================= APP VIEW HEADER + SIDEBAR CLEANUP ================= */
body.app-view .chat-title-logo {
  display: none !important;
}

body.app-view .chat-title {
  max-width: min(100%, 180px) !important;
}

body.app-view .chat-title-text {
  margin-left: 0 !important;
}

body.app-view .history-actions {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 10px !important;
  padding: 14px 14px 8px !important;
}

body.app-view .new-chat-btn {
  margin: 0 !important;
  width: auto !important;
  min-width: 0 !important;
  flex: 1 1 auto !important;
}

body.app-view .close-sidebar-btn,
body.app-view #close-sidebar {
  position: static !important;
  top: auto !important;
  right: auto !important;
  margin: 0 !important;
  flex: 0 0 auto !important;
}

body.app-view .delete-all-btn {
  margin-top: 0 !important;
}

@media (max-width: 480px) {
  body.app-view .history-sidebar {
    padding-top: 8px !important;
  }

  body.app-view .history-actions {
    padding: 12px 12px 8px !important;
    gap: 8px !important;
  }

  body.app-view .new-chat-btn {
    padding: 10px 12px !important;
  }
}

/* Final header lock for app-view + mobile: keep everything on one row */
@media (max-width: 820px) {
  .chatbot header.chat-header,
  body.app-view .chatbot header.chat-header {
    position: relative !important;
    display: flex !important;
    align-items: center !important;
    min-height: 56px !important;
    height: 56px !important;
    padding: 0 12px !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
  }

  .chatbot header.chat-header .header-left,
  .chatbot header.chat-header .header-right,
  body.app-view .chatbot header.chat-header .header-left,
  body.app-view .chatbot header.chat-header .header-right {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    min-height: 44px !important;
    width: 44px !important;
    flex: 0 0 44px !important;
    z-index: 1 !important;
  }

  .chatbot header.chat-header .header-left,
  body.app-view .chatbot header.chat-header .header-left {
    justify-content: flex-start !important;
  }

  .chatbot header.chat-header .header-right,
  body.app-view .chatbot header.chat-header .header-right {
    justify-content: flex-end !important;
    justify-self: end !important;
  }

  .chatbot header.chat-header .chat-title,
  body.app-view .chatbot header.chat-header .chat-title {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: absolute !important;
    left: 50% !important;
    top: 50% !important;
    width: calc(100% - 112px) !important;
    max-width: calc(100% - 112px) !important;
    min-width: 0 !important;
    height: 44px !important;
    margin: 0 !important;
    line-height: 1 !important;
    text-align: center !important;
    overflow: hidden !important;
    transform: translate(-50%, calc(-50% + 2px)) !important;
    pointer-events: none !important;
  }

  .chatbot header.chat-header .chat-title-text,
  body.app-view .chatbot header.chat-header .chat-title-text {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 18px !important;
    font-weight: 700 !important;
    line-height: 1.1 !important;
    text-align: center !important;
    transform: translateY(1px) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  .chatbot header.chat-header #sidebar-toggle,
  .chatbot header.chat-header #close-chatbot,
  .chatbot header.chat-header .apk-download-btn,
  body.app-view .chatbot header.chat-header #sidebar-toggle,
  body.app-view .chatbot header.chat-header #close-chatbot,
  body.app-view .chatbot header.chat-header .apk-download-btn {
    position: static !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
    transform: none !important;
    align-self: center !important;
  }
}

/* App-only safe area: keep phone status bar separate from the app header */
body.app-view {
  --app-safe-top: max(24px, env(safe-area-inset-top, 0px));
}

body.app-view::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--app-safe-top);
  background: #000000;
  z-index: 1005;
  pointer-events: none;
}

body.app-view .history-sidebar,
body.app-view .chatbot {
  box-sizing: border-box;
  padding-top: var(--app-safe-top) !important;
}

body.app-view .chatbot header.chat-header,
body.app-view .history-actions {
  min-height: 56px !important;
}

@media (max-width: 480px) {
  body.app-view {
    --app-safe-top: max(28px, env(safe-area-inset-top, 0px));
  }
}
