/**
 * ═══════════════════════════════════════════════════════════════════════════
 * 🎨 CHAT APPLICATION STYLES
 * ═══════════════════════════════════════════════════════════════════════════
 * 
 * Table of Contents:
 * ──────────────────
 * 1. Fonts & Imports
 * 2. Design Tokens (CSS Variables)
 * 3. Reset & Base
 * 4. Layout Structure
 * 5. Sidebar
 * 6. Topbar
 * 7. Form Elements (Select, Input)
 * 8. Quota Panel
 * 9. Chat Area
 * 10. Message Avatars
 * 11. Message Bubbles
 * 12. Prose & Typography
 * 13. Code Blocks
 * 14. Composer (Input Area)
 * 15. Buttons
 * 16. Modals
 * 17. Animations
 * 18. Utilities
 * 19. Responsive (Mobile)
 * 
 * ═══════════════════════════════════════════════════════════════════════════
 */

/* ═══════════════════════════════════════════════════════════════════════════
   1. FONTS & IMPORTS
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Fira+Code:wght@400;500;600&display=swap');

/* ═══════════════════════════════════════════════════════════════════════════
   2. DESIGN TOKENS
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  /* ─── Primary Colors ─── */
  --primary: #3b82f6;
  --primary-light: #60a5fa;
  --primary-dark: #2563eb;
  --primary-glow: rgba(59, 130, 246, 0.15);

  /* ─── Surfaces ─── */
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f1f3f6;

  /* ─── Text ─── */
  --text: #1c2030;
  --text-2: #5c6275;
  --text-3: #8b91a5;

  /* ─── Borders ─── */
  --border: #e2e5ee;
  --border-2: #cdd2de;

  /* ─── Component Backgrounds ─── */
  --sidebar-bg: #f9fafb;
  --topbar-bg: rgba(249, 250, 251, 0.90);
  --chat-bg: #f4f5f9;
  --bot-bubble: #ffffff;
  --user-bubble: rgba(88, 114, 228, 0.06);
  --code-bg: #1c2030;

  /* ─── Shadows ─── */
  --shadow-sm: 0 1px 3px rgba(28, 32, 48, 0.04);
  --shadow-md: 0 4px 14px rgba(28, 32, 48, 0.06);
  --shadow-lg: 0 10px 35px rgba(28, 32, 48, 0.08);

  /* ─── Radii ─── */
  --radius: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* ─── Transitions ─── */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: 0.2s var(--ease);
  --transition-normal: 0.3s var(--ease);

  /* ─── Misc ─── */
  --app-vh: 1vh;

  /* ─── Avatars ─── */
  --avatar-user: linear-gradient(135deg, #2563eb, #3b82f6);
  --avatar-bot: linear-gradient(135deg, #1d4ed8, #60a5fa);
}

/* ─── Dark Theme ─── */
html.dark {
  --primary: #60a5fa;
  --primary-light: #93c5fd;
  --primary-dark: #3b82f6;
  --primary-glow: rgba(96, 165, 250, 0.14);

  --surface: #0f1219;
  --surface-2: #161b28;
  --surface-3: #1e2436;

  --text: #e2e5ef;
  --text-2: #8b91a5;
  --text-3: #5c6275;

  --border: rgba(139, 156, 245, 0.10);
  --border-2: rgba(139, 156, 245, 0.16);

  --sidebar-bg: rgba(15, 18, 25, 0.97);
  --topbar-bg: rgba(15, 18, 25, 0.90);
  --chat-bg: #0f1219;
  --bot-bubble: rgba(22, 27, 40, 0.95);
  --user-bubble: rgba(139, 156, 245, 0.07);
  --code-bg: #0a0d14;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.30);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.40);
  --shadow-lg: 0 10px 35px rgba(0, 0, 0, 0.50);

  --avatar-user: linear-gradient(135deg, #3b82f6, #60a5fa);
  --avatar-bot: linear-gradient(135deg, #2563eb, #3b82f6);
}

/* ═══════════════════════════════════════════════════════════════════════════
   3. RESET & BASE
   ═══════════════════════════════════════════════════════════════════════════ */

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

html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans',
               Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
  font-size: 15px;
  line-height: 1.6;
  width: 100%;
  height: calc(var(--app-vh) * 100);
  min-height: calc(var(--app-vh) * 100);
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--chat-bg);
  color: var(--text);
  transition: background-color 0.35s ease, color 0.35s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html, body, main, #chat-container, #chat-box {
  overflow-x: hidden;
}

/* ═══════════════════════════════════════════════════════════════════════════
   4. LAYOUT STRUCTURE
   ═══════════════════════════════════════════════════════════════════════════ */

main {
  margin-top: 0;
  height: calc(var(--app-vh) * 100);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#chat-container {
  display: flex;
  flex: 1 1 auto;
  overflow: hidden;
  min-height: 0;
  min-width: 0;
}

#chat-container > aside,
#chat-container > div {
  height: 100%;
  min-height: 0;
}

#chat-container > div {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

#chat-container > div,
#chat-container > aside,
.msg-bubble {
  min-width: 0;
}

#chat-history,
.chat-container {
  overflow-x: hidden !important;
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* ═══════════════════════════════════════════════════════════════════════════
   5. SIDEBAR
   ═══════════════════════════════════════════════════════════════════════════ */

#sidebar {
  width: 300px;
  flex: 0 0 300px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}

.glass-sidebar {
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}

#sidebar-overlay.hidden {
  display: none !important;
  pointer-events: none !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   6. TOPBAR
   ═══════════════════════════════════════════════════════════════════════════ */

#topbar {
  background: var(--topbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════════════════════════
   7. FORM ELEMENTS
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Select / Dropdown ─── */
select {
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239095ab' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 22px !important;
}

select option {
  padding: 8px 12px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
}

html:not(.dark) select option {
  background: #ffffff !important;
  color: #1a1d2e !important;
}

html.dark select option {
  background: #1c2042 !important;
  color: #e4e6f0 !important;
}

html.dark select option:checked {
  background: #2a2f5a !important;
  color: #f0f1ff !important;
}

/* ─── Select Pill ─── */
.select-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  padding: 5px 10px 5px 12px;
  border-radius: 999px;
  transition: all var(--transition-fast);
}

.select-pill:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.select-pill select {
  background: transparent;
  border: none;
  outline: none;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}

/* ═══════════════════════════════════════════════════════════════════════════
   8. QUOTA PANEL
   ═══════════════════════════════════════════════════════════════════════════ */

#quota-panel {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

html.dark #quota-panel {
  background: var(--surface-2);
}

#quota-fill {
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 999px;
  transition: width 0.6s ease;
}

#quota-text {
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════════════════
   9. CHAT AREA
   ═══════════════════════════════════════════════════════════════════════════ */

#chat-box {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  background: var(--chat-bg);
  padding-bottom: 0;

  /* Scrollbar - Webkit */
  &::-webkit-scrollbar {
    width: 4px;
  }

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

  &::-webkit-scrollbar-thumb {
    background: rgba(140, 145, 170, 0.25);
    border-radius: 10px;
  }

  &::-webkit-scrollbar-thumb:hover {
    background: rgba(140, 145, 170, 0.4);
  }

  /* Scrollbar - Firefox */
  scrollbar-width: thin;
  scrollbar-color: rgba(140, 145, 170, 0.25) transparent;
}

/* ═══════════════════════════════════════════════════════════════════════════
   10. MESSAGE AVATARS
   ═══════════════════════════════════════════════════════════════════════════ */

.msg-avatar {
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.msg-avatar svg {
  display: block;
  stroke: white !important;
  fill: none;
}

.msg-avatar-user {
  background: var(--avatar-user);
  box-shadow: 0 4px 12px var(--primary-glow);
}

.msg-avatar-bot {
  background: var(--avatar-bot);
  box-shadow: 0 4px 12px rgba(108, 92, 231, 0.2);
}

/* ═══════════════════════════════════════════════════════════════════════════
   11. MESSAGE BUBBLES
   ═══════════════════════════════════════════════════════════════════════════ */

.msg-bubble {
  border-radius: var(--radius-xl);
  max-width: min(85%, 48rem);
  width: fit-content;
  min-width: 0 !important;
  height: auto !important;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
  hyphens: auto;
  transition: box-shadow var(--transition-fast);
}

.msg-bubble.msg-bot {
  background: var(--bot-bubble) !important;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  border-radius: var(--radius) var(--radius-xl) var(--radius-xl) var(--radius-xl);
}

.msg-bubble.msg-user {
  background: var(--user-bubble) !important;
  border: 1px solid rgba(91, 95, 199, 0.12);
}

html.dark .msg-bubble.msg-bot {
  background: var(--bot-bubble) !important;
  border-color: var(--border) !important;
  box-shadow: var(--shadow-md);
}

html.dark .msg-bubble.msg-user {
  background: var(--user-bubble) !important;
  border-color: rgba(139, 156, 245, 0.15) !important;
  border-radius: var(--radius-xl) var(--radius) var(--radius-xl) var(--radius-xl);
}

/* ─── Message Content ─── */
.msg-content {
  contain: layout style paint;
  will-change: contents;
}

.msg-content > * {
  animation: fadeInContent 0.15s ease-out;
}

[id^="msg-"],
.msg-bot,
.msg-content,
.message-bubble {
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  overflow-wrap: break-word !important;
  word-wrap: break-word !important;
  white-space: pre-wrap !important;
  word-break: normal !important;
  display: block !important;
}

/* ─── Direction ─── */
.msg-rtl {
  direction: rtl;
  text-align: right;
}

.msg-rtl .prose {
  direction: rtl;
  text-align: right;
}

.msg-ltr {
  direction: ltr;
  text-align: left;
}

.msg-ltr .prose {
  direction: ltr;
  text-align: left;
}

/* ═══════════════════════════════════════════════════════════════════════════
   12. PROSE & TYPOGRAPHY
   ═══════════════════════════════════════════════════════════════════════════ */

.prose {
  max-width: 100% !important;
  min-width: 0 !important;
  width: 100% !important;
  font-size: 15px !important;
  line-height: 1.7 !important;
  color: inherit !important;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
  hyphens: auto;
  overflow-x: auto !important;

  display: flex !important;
  flex-direction: column !important;
}

.prose,
.prose * {
  max-width: 100%;
}

.prose p {
  margin-bottom: 1.1rem !important;
}

.prose p,
.prose ul,
.prose ol {
  min-width: 0 !important;
  max-width: 100% !important;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
  margin-top: 0.75rem !important;
  margin-bottom: 0.75rem !important;
}

.prose strong {
  color: inherit !important;
  font-weight: 600;
}

/* ─── Links ─── */
.prose a {
  color: var(--primary);
  text-decoration: underline;
  text-decoration-color: var(--primary-glow);
  text-underline-offset: 2px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.prose a:hover {
  color: var(--primary-light);
}

/* ─── Media ─── */
.prose img,
.prose video,
.prose iframe,
.prose canvas,
.prose svg {
  max-width: 100% !important;
  height: auto !important;
  border-radius: var(--radius);
}

.prose img:not(.emoji) {
  max-width: 300px;
  max-height: 300px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.2s ease;
  object-fit: contain;
}

.prose img:not(.emoji):hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-md);
}

/* ─── Tables ─── */
.prose table {
  display: table;
  width: 100%;
  max-width: 100%;
  border-collapse: collapse;
  margin: 1.25em 0;
  font-size: 0.925em;
  line-height: 1.5;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
}

.prose thead {
  display: table-header-group;
  background: var(--surface-2, var(--surface-100));
}

.prose th {
  display: table-cell;
  padding: 10px 14px;
  font-weight: 600;
  text-align: left;
  color: var(--text);
  border-bottom: 2px solid var(--border);
  border-right: 1px solid var(--border);
  white-space: nowrap;
}

.prose th:last-child {
  border-right: none;
}

.prose td {
  display: table-cell;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: top;
}

.prose td:last-child {
  border-right: none;
}

.prose tbody tr:last-child td {
  border-bottom: none;
}

.prose tbody tr {
  transition: background-color 0.15s ease;
}

.prose tbody tr:hover {
  background-color: var(--surface-2, var(--surface-100));
}

/* زيادة التباين في الوضع الداكن */
html.dark .prose thead {
  background: rgba(255, 255, 255, 0.05);
}

html.dark .prose th {
  border-bottom-color: rgba(255, 255, 255, 0.1);
  border-right-color: rgba(255, 255, 255, 0.05);
}

html.dark .prose td {
  border-bottom-color: rgba(255, 255, 255, 0.08);
  border-right-color: rgba(255, 255, 255, 0.05);
}

html.dark .prose tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.04);
}

/* دعم الجداول الواسعة مع scroll */
.prose table {
  min-width: 100%;
}

/* ─── Inline Code ─── */
.prose :not(pre) > code {
  font-family: "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace !important;
  font-size: 0.85em !important;
  line-height: 1.6;
  unicode-bidi: plaintext;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--primary-dark);
}

html.dark .prose :not(pre) > code {
  background: rgba(139, 143, 245, 0.1);
  border-color: rgba(139, 143, 245, 0.2);
  color: var(--primary-light);
}

/* ─── KaTeX (Math) ─── */
.katex,
.katex-display {
  direction: ltr !important;
  text-align: left !important;
  unicode-bidi: isolate;
}

.katex-display {
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 5px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   13. CODE BLOCKS
   ═══════════════════════════════════════════════════════════════════════════ */

.prose pre,
.prose code,
.prose pre code {
  direction: ltr !important;
  text-align: left !important;
  unicode-bidi: plaintext;
}

.prose pre {
  overflow: auto !important;
  min-width: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  max-height: 50vh !important;
  overflow-x: auto !important;
  overflow-y: auto !important;
  white-space: pre;
  tab-size: 4;
  line-height: 1.6;
  font-size: 0.88em;
  border-radius: var(--radius-lg);
  padding: 2.5rem 18px 16px 18px !important;
  margin: 14px 0;
  border: 1px solid var(--border);
  background: var(--code-bg) !important;
  position: static !important;
  box-sizing: border-box !important;
  contain: layout style;
}

.prose pre code {
  display: block !important;
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  font-size: inherit !important;
  white-space: pre !important;
  min-width: 0 !important;
}

/* ─── Code Wrapper ─── */
.code-wrap {
  position: relative !important;
  min-width: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  margin-top: 1rem !important;
  margin-bottom: 1rem !important;
}

/* ─── Copy Button ─── */
/* ═══════════════════════════════════════════════════════════════════════════
   13. CODE BLOCKS
   ═══════════════════════════════════════════════════════════════════════════ */

.prose pre,
.prose code,
.prose pre code {
  direction: ltr !important;
  text-align: left !important;
  unicode-bidi: plaintext;
}

.prose pre {
  position: relative !important;
  overflow: auto !important;
  min-width: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  max-height: 50vh !important;
  white-space: pre;
  tab-size: 4;
  line-height: 1.6;
  font-size: 0.88em;
  border-radius: var(--radius-lg);
  padding: 16px 18px 16px 18px !important;
  margin: 14px 0;
  border: 1px solid var(--border);
  background: var(--code-bg) !important;
  box-sizing: border-box !important;
}

.prose pre code {
  display: block !important;
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  font-size: inherit !important;
  white-space: pre !important;
  min-width: 0 !important;
}

/* ─── Code Wrapper ─── */
.code-wrap {
  position: relative !important;
  min-width: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  margin-top: 1rem !important;
  margin-bottom: 1rem !important;
}

/* ─── Copy Button - ثابت دائماً ─── */
.prose pre > button:not(.copy-btn),
.prose pre > .copy-button {
  display: none !important;
}

.copy-btn {
  position: absolute !important;
  top: 18px !important;
  right: 18px !important;
  z-index: 100 !important;
  padding: 5px 14px !important;
  background: rgba(30, 41, 59, 0.95) !important;
  backdrop-filter: blur(4px);
  border: 1px solid rgba(148, 163, 184, 0.25) !important;
  border-radius: 6px !important;
  color: #a0a8b8 !important;
  font-size: 11px !important;
  font-weight: 500 !important;
  cursor: pointer !important;
  opacity: 0;                    /* ← أزل !important */
  visibility: visible !important;
  transition: background 0.2s, color 0.2s, border-color 0.2s, opacity 0.15s ease !important;
  pointer-events: auto !important;
}
.code-wrap .copy-btn {
  opacity: 0 !important;
}

.code-wrap:hover .copy-btn {
  opacity: 1 !important;
}

.code-wrap .copy-btn.copied {
  opacity: 1 !important;
}
.copy-btn:hover {
  background: rgba(51, 65, 85, 0.95) !important;
  color: #e2e8f0 !important;
  border-color: rgba(148, 163, 184, 0.4) !important;
}

.copy-btn.copied {
  background: rgba(34, 197, 94, 0.25) !important;
  color: #4ade80 !important;
  border-color: rgba(34, 197, 94, 0.5) !important;
}

/* ─── RTL/LTR - الزر دائماً يمين ─── */
.msg-rtl .copy-btn,
.msg-ltr .copy-btn {
  right: 18px !important;
  left: auto !important;
}
/* ═══════════════════════════════════════════════════════════════════════════
   14. COMPOSER (Input Area)
   ═══════════════════════════════════════════════════════════════════════════ */

#chat-box + div {
  flex: 0 0 auto;
  padding-top: 8px;
  padding-bottom: 8px;
}

#composer {
  flex-wrap: nowrap !important;
  gap: 0.5rem;
  padding: 6px 8px;
  border-radius: var(--radius-xl);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transition: all var(--transition-normal);
}

html.dark #composer {
  background: var(--surface-2);
  border-color: var(--border-2);
}

#composer:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow), var(--shadow-lg);
}

#composer textarea,
#user-in {
  min-height: 44px !important;
  max-height: 140px !important;
  overflow-y: auto !important;
  padding-top: 10px !important;
  padding-bottom: 10px !important;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: transparent;
  -webkit-text-size-adjust: 100%;
}

/* ═══════════════════════════════════════════════════════════════════════════
   15. BUTTONS
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Send Button ─── */
#send-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border-radius: 50%;
  background: var(--avatar-user);
  color: white;
  border: none;
  box-shadow: 0 3px 12px var(--primary-glow);
  transition: all 0.25s var(--ease);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}

#send-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 18px var(--primary-glow);
}

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

#send-btn.stop-btn {
  background: linear-gradient(135deg, #ef4444, #dc2626) !important;
  box-shadow: 0 3px 12px rgba(239, 68, 68, 0.25) !important;
  animation: gentle-pulse 1.5s ease-in-out infinite;
}

/* ─── Sidebar Buttons ─── */
#new-chat-btn {
  background: var(--avatar-user);
  box-shadow: 0 4px 16px var(--primary-glow);
  border: none;
  transition: all var(--transition-fast);
}

#new-chat-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--primary-glow);
}

#clear-history {
  background: rgba(239, 68, 68, 0.05);
  border: 1px solid rgba(239, 68, 68, 0.15);
  color: #ef4444;
  box-shadow: none;
  transition: all var(--transition-fast);
}

#clear-history:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.25);
}

html.dark #clear-history {
  background: rgba(239, 68, 68, 0.05);
  border-color: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

/* ─── Selection Action Button ─── */
.selection-action-btn {
  position: absolute;
  z-index: 50;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  box-shadow: 0 4px 14px var(--primary-glow);
  cursor: pointer;
}

.selection-action-btn.hidden {
  display: none;
}

/* ─── Retry Button ─── */
.retry-btn {
  display: inline-flex;
  align-items: center;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid rgba(91, 95, 199, 0.3);
  background: rgba(91, 95, 199, 0.08);
  color: var(--primary);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.retry-btn:hover {
  background: rgba(91, 95, 199, 0.15);
}

.retry-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ═══════════════════════════════════════════════════════════════════════════
   16. MODALS
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Project Settings Modal ─── */
#project-settings-modal > div {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

html.dark #project-settings-modal > div {
  background: var(--surface-2);
  border-color: var(--border-2);
}

/* ─── Confirm Modal ─── */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0);
  backdrop-filter: blur(0px);
  transition: background 0.25s ease, backdrop-filter 0.25s ease;
  padding: 16px;
}

.confirm-overlay.is-visible {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
}

.confirm-modal {
  background: var(--surface-1, #1a1f2e);
  border: 1px solid var(--border, rgba(96, 165, 250, 0.12));
  border-radius: 20px;
  padding: 32px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  transform: scale(0.9) translateY(10px);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.4), 0 0 40px rgba(59, 130, 246, 0.06);
}

.confirm-overlay.is-visible .confirm-modal {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.confirm-icon {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px auto;
}

.confirm-icon svg {
  width: 26px;
  height: 26px;
}

.confirm-icon--danger {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
}

.confirm-icon--warning {
  background: rgba(245, 158, 11, 0.12);
  color: #fbbf24;
}

.confirm-icon--info {
  background: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
}

.confirm-title {
  font-size: 17px;
  font-weight: 650;
  color: var(--text-1, #e2e5ef);
  margin: 0 0 8px 0;
  line-height: 1.3;
}

.confirm-message {
  font-size: 13.5px;
  color: var(--text-3, #8b91a5);
  margin: 0 0 26px 0;
  line-height: 1.6;
}

.confirm-actions {
  display: flex;
  gap: 10px;
}

.confirm-btn {
  flex: 1;
  padding: 10px 20px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
}

.confirm-btn--cancel {
  background: var(--surface-2, rgba(255, 255, 255, 0.06));
  color: var(--text-2, #bcc3d6);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
}

.confirm-btn--cancel:hover {
  background: var(--surface-3, rgba(255, 255, 255, 0.1));
}

.confirm-btn--danger {
  background: linear-gradient(135deg, #dc2626, #ef4444);
  color: #fff;
  box-shadow: 0 4px 14px rgba(220, 38, 38, 0.3);
}

.confirm-btn--danger:hover {
  background: linear-gradient(135deg, #b91c1c, #dc2626);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(220, 38, 38, 0.4);
}

.confirm-btn--warning {
  background: linear-gradient(135deg, #d97706, #f59e0b);
  color: #fff;
  box-shadow: 0 4px 14px rgba(217, 119, 6, 0.3);
}

.confirm-btn--warning:hover {
  background: linear-gradient(135deg, #b45309, #d97706);
  transform: translateY(-1px);
}

.confirm-btn--info {
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #fff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.3);
}

.confirm-btn--info:hover {
  background: linear-gradient(135deg, #1d4ed8, #2563eb);
  transform: translateY(-1px);
}

.confirm-btn:active {
  transform: translateY(0) scale(0.98);
}

/* ═══════════════════════════════════════════════════════════════════════════
   17. ANIMATIONS
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Keyframes ─── */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

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

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

@keyframes pulseGlow {
  0%, 100% {
    opacity: 0.4;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.3);
  }
}

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

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

@keyframes gentle-pulse {
  0%, 100% {
    box-shadow: 0 3px 12px rgba(239, 68, 68, 0.25);
  }
  50% {
    box-shadow: 0 3px 20px rgba(239, 68, 68, 0.4);
  }
}

/* ─── Animation Classes ─── */
.fade-in {
  animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.thinking-pulse {
  animation: pulse 2s ease-in-out infinite;
  color: var(--primary);
}

.spin-icon {
  animation: spin 0.8s linear infinite;
}

/* ─── Thinking Indicator ─── */
.thinking-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  animation: fadeInUp 0.3s ease-out;
}

.thinking-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary, #3b82f6);
  animation: pulseGlow 1.4s ease-in-out infinite;
}

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

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

.thinking-text {
  font-size: 13.5px;
  font-weight: 500;
  letter-spacing: 0.2px;
  background: linear-gradient(
    90deg,
    var(--text-3, #6b7280) 0%,
    var(--primary-light, #60a5fa) 40%,
    var(--text-3, #6b7280) 80%
  );
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: shimmer 2.5s linear infinite;
}

/* ─── Search Indicator ─── */
.search-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  margin: 0 auto 12px auto;
  max-width: fit-content;
  direction: ltr;
  animation: fadeIn 0.3s ease-out;
}

.search-indicator svg {
  flex-shrink: 0;
  color: var(--primary);
}

.search-tag {
  display: inline-block;
  padding: 2px 8px;
  margin: 0 3px;
  border-radius: 6px;
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid rgba(59, 130, 246, 0.2);
  font-size: 11.5px;
  color: var(--primary-light);
}

/* ═══════════════════════════════════════════════════════════════════════════
   18. UTILITIES
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── Scrollbar ─── */
.no-scrollbar {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.no-scrollbar::-webkit-scrollbar {
  display: none;
}

/* ─── Line Clamp ─── */
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ─── Safe Area ─── */
@supports (padding: max(0px)) {
  .safe-bottom {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   19. COLLAPSIBLE CODE (User Messages)
   ═══════════════════════════════════════════════════════════════════════════ */

.msg-user .snippet-container {
  position: relative;
  background-color: #f9f9f8;
  border: 1px solid #e5e5e0;
  border-radius: 12px;
  margin-top: 10px;
  margin-bottom: 10px;
  max-height: 150px;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

html.dark .msg-user .snippet-container {
  background-color: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.1);
}

.msg-user .snippet-container pre {
  background: transparent !important;
  border: none !important;
  margin: 0 !important;
  padding: 12px 12px 50px 12px !important;
  max-height: none !important;
}

.msg-user .snippet-fade {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: linear-gradient(to bottom, transparent, #f9f9f8 80%);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 12px;
  cursor: pointer;
}

html.dark .msg-user .snippet-fade {
  background: linear-gradient(to bottom, transparent, #1e2436 80%);
}

.msg-user .show-more-btn {
  background: #ffffff;
  border: 1px solid #e5e5e0;
  border-radius: 20px;
  padding: 6px 14px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  transition: all 0.2s;
  z-index: 2;
}

html.dark .msg-user .show-more-btn {
  background: #2a2f3e;
  border-color: #3b4256;
  color: #e2e8f0;
}

.msg-user .show-more-btn:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.msg-user .snippet-container.expanded {
  max-height: 5000px;
}

.msg-user .snippet-container.expanded .snippet-fade {
  background: transparent !important;
  height: 40px;
  cursor: default;
}

.msg-user .snippet-container .copy-btn {
  display: none !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   20. RESPONSIVE (Mobile)
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 767px) {
  #topbar {
    padding: 8px 12px !important;
    gap: 8px !important;
  }

  #current-project-name {
    font-size: 10px !important;
    line-height: 12px !important;
  }

  #current-chat-title {
    font-size: 13px !important;
    line-height: 16px !important;
    max-width: 40vw !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  #model-select,
  #thinking-level {
    font-size: 11px !important;
  }

  #topbar > div:last-child {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    max-width: 65vw;
  }

  #quota-panel {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 8px 12px;
  }

  #quota-panel > div {
    width: 100%;
  }

  #chat-box {
    padding-left: 12px;
    padding-right: 12px;
  }
}

@media (max-width: 640px) {
  #sidebar {
    width: 85vw;
    flex-basis: 85vw;
  }

  #quota-text {
    font-size: 11px;
    line-height: 1.25;
  }

  #composer textarea,
  #user-in {
    font-size: 15px;
    max-height: 120px !important;
    -webkit-text-size-adjust: 100%;
  }

  #attach-btn {
    padding: 10px;
  }

  #send-btn {
    border-radius: 14px;
  }

  .msg-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    border-radius: 10px;
  }

  .msg-avatar svg {
    width: 14px;
    height: 14px;
  }
}


/* ═══════════════════════════════════════════════════════════════════════════
   END OF STYLESHEET
   ═══════════════════════════════════════════════════════════════════════════ */