/* 
==========================================================================
   STYLES.CSS INDEX
==========================================================================

   1. THEME VARIABLES
      - :root (Default Dark)
      - .light
      - many more

   2. BASE & RESETS
      - Global box-sizing
      - Body/HTML setup

   3. APP LAYOUT
      - .app-layout (Flex container)
      Level 1:
      - .app-sidebar
      - .app-content
      Level 2:
      - .paned-layout
      - .sub-sidebar
      - .sub-sidebar-header
      - .sub-sidebar-menu
      - .sub-nav-item
      - .sub-content

   4. SIDEBAR & NAVIGATION
      - .sidebar-item
      - .sidebar-icon
      - .sidebar-logo

   5.1 CHAT TREE
      - FOLDERS (.folder-row, .folder-children)
      - TREE VIEW & INDENTATION (The --depth logic)
      - CONTEXT MENU (.ctx-menu)

   5.2 CHAT INTERFACE
      - .chat-container
      - .chat-header (Title editing)
      - .chat-messages-container
      - .message-row / .message bubbles
      - .chat-input-area

   6. MARKDOWN & CONTENT STYLING
      - Syntax highlighting adjustments
      - Lists, code blocks, links inside chat

   7. UI COMPONENTS
      - Buttons (.btn)
      - Forms (.form-input, .checkbox)
      - Modals (dialog)
      - Toasts (#toast-container)
      - Cards (.card)

   8. PAGE SPECIFIC STYLES
      - Auth Pages (Login/Signup)
      - User Profile
      - Split View (Prompts / API Keys)
      - Settings

   9. UTILITIES
      - Scrollbars
      - Animations

========================================================================== 
*/

/* 
==========================================================================
   1. THEME VARIABLES
========================================================================== 
*/

:root {
  /* --- Core Colors (Default Dark Mode) --- */
  --color-bg: #212121; /* ChatGPT-like dark grey */
  --color-bg-alt: #171717; /* Sidebar / Inputs */
  --color-bg-color: #3b82f6; /* Selected items (Deep Blue) */

  --color-text: #ececec;
  --color-text-muted: #9ca3af;

  --color-border: #424242;

  --color-primary: #ffffff; /* Buttons/Accents */
  --color-primary-fg: #171717; /* Text on primary buttons */

  --color-accent: #60a5fa; /* Links/Highlights */
  --color-accent-rgb: 96, 165, 250;

  --color-msg-user: rgba(37, 99, 235, 0.25);
  --bg-code-block: #0d1117;
  --text-code-block: #c9d1d9;

  --color-danger: #ef4444;
  --color-danger-rgb: 239, 68, 68;
  --color-success: #10b981;

  /* --- UI Feedback --- */
  --color-msg-success-text: #155724;
  --color-msg-success-bg: #d4edda;
  --color-msg-success-border: #c3e6cb;

  --color-msg-error-text: #721c24;
  --color-msg-error-bg: #f8d7da;
  --color-msg-error-border: #f5c6cb;

  /* --- Fonts --- */
  --font-body:
    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-sans: var(--font-body);
  --font-size-base: 15px;

  /* --- Spacing & Dimensions --- */
  --space-xxs: 2px;
  --space-xs: 0.25rem; /* 4px */
  --space-sm: 0.5rem; /* 8px */
  --space-md: 1rem; /* 16px */
  --space-lg: 1.5rem; /* 24px */
  --space-xl: 2rem; /* 32px */
  --space-xxl: 3rem; /* 48px */
  --space-xxxl: 4rem; /* 64px */

  --sidebar-width: 64px;
  --sub-sidebar-width: 240px;
  --sidebar-item-height: 48px;
  --sidebar-icon-size: 24px;

  --radius: 0.5rem;
  --radius-sm: 0.375rem;

  --chat-width: 75%;
  --chat-max-width: 800px;

  /* --- Code --- */
  --code-white-space: pre; /* 'pre' = scroll, 'pre-wrap' = wrap */
}

/* --- Light Mode Theme --- */
body.light {
  --color-bg: #ffffff;
  --color-bg-alt: #f9fafb;
  --color-bg-color: #60a5fa;

  --color-text: #111827; /* Almost black */
  --color-text-muted: #6b7280;

  --color-border: #e5e7eb;

  --color-primary: #000000; /* Minimalist black primary */
  --color-primary-fg: #ffffff;

  --color-accent: #2563eb;
  --color-accent-rgb: 37, 99, 235;

  --color-msg-user: rgba(37, 99, 235, 0.15);
  --bg-code-block: #f6f8fa;
  --text-code-block: #24292e;
}

/* --- Tokyo Night --- */
body.theme-tokyo-night {
  --color-bg: #1a1b26;
  --color-bg-alt: #16161e;
  --color-bg-color: #2e3c64; /* Selection bg */

  --color-text: #c0caf5;
  --color-text-muted: #565f89;
  --color-border: #414868;

  --color-primary: #7aa2f7; /* Tokyo Blue */
  --color-primary-fg: #15161e;

  --color-accent: #bb9af7; /* Tokyo Purple */
  --color-accent-rgb: 187, 154, 247;

  --color-msg-user: #7aa2f740;
  --bg-code-block: #16161e;
  --text-code-block: #c0caf5;
}

/* --- Catppuccin Mocha (Darker) --- */
body.theme-catppuccin-mocha {
  --color-bg: #1e1e2e;
  --color-bg-alt: #181825;
  --color-bg-color: #45475a;

  --color-text: #cdd6f4;
  --color-text-muted: #6c7086;
  --color-border: #313244;

  --color-primary: #cba6f7; /* Mauve */
  --color-primary-fg: #1e1e2e;

  --color-accent: #89b4fa; /* Blue */
  --color-accent-rgb: 137, 180, 250;

  --color-msg-user: #cba6f740;
  --bg-code-block: #11111b;
  --text-code-block: #cdd6f4;
}

/* --- Catppuccin Frappé (Softer) --- */
body.theme-catppuccin-frappe {
  --color-bg: #303446;
  --color-bg-alt: #292c3c;
  --color-bg-color: #51576d;

  --color-text: #c6d0f5;
  --color-text-muted: #737994;
  --color-border: #414559;

  --color-primary: #ca9ee6; /* Lilac */
  --color-primary-fg: #303446;

  --color-accent: #8caaee; /* Blue */
  --color-accent-rgb: 140, 170, 238;

  --color-msg-user: #ca9ee640;
  --bg-code-block: #232634;
  --text-code-block: #c6d0f5;
}

/* --- Nord (Arctic) --- */
body.theme-nord {
  --color-bg: #2e3440;
  --color-bg-alt: #242933;
  --color-bg-color: #434c5e;

  --color-text: #d8dee9;
  --color-text-muted: #6d7b96; /* Nord3/4 mix */
  --color-border: #4c566a;

  --color-primary: #88c0d0; /* Frost Blue */
  --color-primary-fg: #2e3440;

  --color-accent: #81a1c1;
  --color-accent-rgb: 129, 161, 193;

  --color-msg-user: #88c0d040;
  --bg-code-block: #3b4252;
  --text-code-block: #e5e9f0;
}

/* --- Monokai Pro --- */
body.theme-monokai {
  --color-bg: #2d2a2e;
  --color-bg-alt: #221f22;
  --color-bg-color: #403e41;

  --color-text: #fcfcfa;
  --color-text-muted: #939293;
  --color-border: #5b595c;

  --color-primary: #ffd866; /* Yellow */
  --color-primary-fg: #2d2a2e;

  --color-accent: #ff6188; /* Red/Pink */
  --color-accent-rgb: 255, 97, 136;

  --color-msg-user: #ff618833;
  --bg-code-block: #221f22;
  --text-code-block: #fcfcfa;
}

/* --- Green Forest (Earthy/Terminal) --- */
body.theme-green-forest {
  --color-bg: #0f1712; /* Very dark forest */
  --color-bg-alt: #090e0b;
  --color-bg-color: #1b2e21;

  --color-text: #e2e8e4;
  --color-text-muted: #6e8a78;
  --color-border: #233829;

  --color-primary: #4ade80; /* Bright Green */
  --color-primary-fg: #051a0d;

  --color-accent: #22c55e;
  --color-accent-rgb: 34, 197, 94;

  --color-msg-user: #22c55e33;
  --bg-code-block: #051a0d;
  --text-code-block: #4ade80;
}

/* --- Desert (Gruvbox Inspired Warm) --- */
body.theme-desert {
  --color-bg: #282828;
  --color-bg-alt: #1d2021;
  --color-bg-color: #504945;

  --color-text: #ebdbb2;
  --color-text-muted: #a89984;
  --color-border: #3c3836;

  --color-primary: #d79921; /* Gold/Yellow */
  --color-primary-fg: #282828;

  --color-accent: #d65d0e; /* Orange */
  --color-accent-rgb: 214, 93, 14;

  --color-msg-user: #d7992133;
  --bg-code-block: #1d2021;
  --text-code-block: #ebdbb2;
}

/* --- Mediterranean (Light Theme Variant) --- */
body.theme-mediterranean {
  --color-bg: #fdfbf7; /* Off-white warm */
  --color-bg-alt: #f1f5f9;
  --color-bg-color: #cfe2f3;

  --color-text: #0f172a; /* Navy text */
  --color-text-muted: #475569;
  --color-border: #cbd5e1;

  --color-primary: #0ea5e9; /* Sky Blue */
  --color-primary-fg: #ffffff;

  --color-accent: #0284c7; /* Deep Blue */
  --color-accent-rgb: 2, 132, 199;

  --color-msg-user: #0ea5e926;
  --bg-code-block: #f0f9ff;
  --text-code-block: #0c4a6e;
}

/* 
==========================================================================
   2. BASE & RESETS
========================================================================== 
*/

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

html,
body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden; /* Prevent body scroll, handle internally */
}

body {
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--font-size-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;

  transition:
    background-color 0.3s ease,
    color 0.3s ease;
}

a {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

/* 
==========================================================================
   3. APP LAYOUT
========================================================================== 
*/

.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  background-color: var(--color-bg);
  position: relative;
}

/* --- Level 1: App Rail (Main Sidebar) --- */
.app-sidebar {
  width: var(--sidebar-width);
  background-color: var(--color-bg-alt); /* Darker background */
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  align-items: center;
  padding: var(--space-sm) 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.app-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  position: relative;
  background-color: var(--color-bg);
  margin-left: var(--sidebar-width);
}

/* --- Level 2: Generic Paned Layout --- */

/* The Container filling .app-content */
.paned-layout {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden; /* Prevent body scroll */
}

/* Level 2 Sidebar */
.sub-sidebar {
  width: var(--sub-sidebar-width);
  min-width: 200px;
  background-color: var(--color-bg); /* Matches main bg, or slight contrast */
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sub-sidebar-header {
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 var(--space-lg);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.sub-sidebar-header h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);
}

.sub-sidebar-menu {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

/* Level 2 Links */
.sub-nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  transition: all 0.2s;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
  text-align: left;
}
.sub-nav-item:hover {
  background-color: var(--color-bg-alt);
  color: var(--color-text);
  border-color: var(--color-border);
}
.sub-nav-item.active {
  background-color: var(--color-bg-alt);
  color: var(--color-text);
  border-color: var(--color-border);
}
.sub-nav-item.active i {
  color: var(--color-accent);
}

/* Level 2 Content Area */
.sub-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto; /* Scroll ONLY here */
  position: relative;
  background-color: var(--color-bg);
  padding: 0; /* Let children handle padding */
}

.sub-content-header {
  height: 60px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between; /* Standard: Title left, Actions right */
  padding: 0 var(--space-lg);
  border-bottom: 1px solid var(--color-border);
}

/* Level 2 Content: Scrollable area */
.sub-content-content {
  flex: 1;
  overflow-y: auto; /* Scroll ONLY here */
  display: flex;
  flex-direction: column; /* Stacks settings, textareas, etc */
  position: relative;
  /* No padding by default, let the child specific classes handle it */
}

/* Responsive: Collapse Sub-sidebar on mobile */
@media (max-width: 768px) {
  .paned-layout {
    flex-direction: column;
  }
  .sub-sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }
  .sub-sidebar-menu {
    flex-direction: row; /* Horizontal scroll on mobile */
    overflow-x: auto;
    padding: var(--space-sm);
  }
  .sub-nav-item {
    white-space: nowrap;
  }
}

/* 
==========================================================================
   4. SIDEBAR & NAVIGATION
========================================================================== 
*/

.sidebar-container {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  width: 100%;
  padding: var(--space-sm) var(--space-xs);
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
}

.sidebar-bottom-section {
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-sm);
  margin-top: var(--space-sm);
}

/* --- Standard Sidebar Items --- */
.sidebar-item,
.sidebar-logo {
  display: flex;
  justify-content: center;
  align-items: center;
  width: var(--sidebar-item-height);
  height: var(--sidebar-item-height);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  transition: all 0.2s;
  position: relative;
  cursor: pointer;
}
.sidebar-logo {
  margin-bottom: var(--space-sm);
}

/* --- Active & Hover State Indicator --- */

/* Define the BASE state for the indicator on ALL items. */
/* It's hidden by default and ready to be animated. */
.sidebar-item::before,
.sidebar-logo::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  background-color: var(--color-accent);
  border-radius: 2px;

  /* Start hidden and short */
  height: 0;
  opacity: 0;

  /* Animate changes to height and opacity */
  transition:
    height 0.2s ease,
    opacity 0.2s ease;
}

/* Define the HOVER state. */
.sidebar-item:hover::before,
.sidebar-logo:hover::before {
  height: calc(var(--sidebar-item-height) * 0.5);
  opacity: 0.7;
}

/* Define the ACTIVE state. */
.sidebar-item.active::before {
  height: calc(var(--sidebar-item-height) * 0.75);
  opacity: 1;
}

.sidebar-item.active .sidebar-icon {
  color: var(--color-accent);
}

/* --- Icon Styling --- */
.sidebar-icon {
  width: var(--sidebar-icon-size);
  height: var(--sidebar-icon-size);
  font-size: 1.25rem; /* Make icons larger to fill space */
  color: var(--color-text-muted);
  transition: color 0.2s;
}
img.sidebar-icon {
  object-fit: contain;
}
.sidebar-item:hover:not(.active) .sidebar-icon {
  color: rgba(var(--color-accent-rgb), 0.9);
}

/* Logout Specific */
.sidebar-item.btn-logout:hover .sidebar-icon {
  color: var(--color-danger);
}
.sidebar-item.btn-logout:hover::before {
  background-color: var(--color-danger);
}

/* 
==========================================================================
   5.1 CHAT TREE
========================================================================== 
*/

/* --- Chat Tree Item Base Styling (for Folders & Chats) --- */
.folder-row,
.tree-item {
  display: flex;
  align-items: center;
  width: 100%;
  height: 40px;
  padding-right: var(--space-xs);
  padding-top: 0;
  padding-bottom: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  transition:
    background-color 0.2s,
    color 0.2s;
  user-select: none;
  position: relative; /* For indentation lines if ever needed */
}

.tree-text {
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Indentation Logic --- */
.folder-row,
.tree-item,
.empty-folder-msg {
  --depth: 0; /* JS sets this dynamically */
  --base-padding: var(--space-sm);
  --indent-step: var(--space-md); /* More pronounced indent */
  /* Padding Calculation */
  padding-left: calc(
    var(--base-padding) + (var(--depth) * var(--indent-step))
  ) !important;
}

/* --- Hover & Active States --- */
.folder-row:hover,
.tree-item:hover {
  color: var(--color-text);
}

.tree-item.active {
  color: var(--color-text);
}

.tree-item.active:hover {
  filter: brightness(1.1);
}

/* --- Icons within the Tree --- */
.folder-icon,
.nav-icon {
  width: 20px;
  min-width: 20px;
  margin-right: var(--space-sm);
  text-align: center;
  font-size: 1rem;
  color: var(--color-text-muted);
  transition: color 0.2s;
}

/* Brighten icons on hover/active */
.folder-row:hover .folder-icon,
.tree-item:hover .nav-icon {
  color: var(--color-text);
}
.tree-item.active .nav-icon {
  color: #ffffff;
}

/* --- Folder Specifics --- */
.folders-section {
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-xs);
  padding-bottom: var(--space-xs);
}

.folders-section-header {
  height: 40px;
  font-weight: 600;
  color: var(--color-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-xs);
  cursor: pointer;
}
.folders-section-header:hover {
  color: var(--color-text);
}

.folder-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.folder-arrow {
  width: 20px;
  text-align: center;
  color: var(--color-text-muted);
  transition: transform 0.2s ease-in-out;
}

.folders-section-header.open .folder-arrow {
  transform: rotate(90deg);
}

.folder-children {
  display: none; /* JS toggles this to block */
  padding: 0;
  margin: 0;
}
.folder-children.visible {
  display: block;
}

/* --- Item Content & Actions --- */

/* View Mode (Default State) */
.folder-view-mode,
.chat-view-mode {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  gap: var(--space-sm);
}

.folder-info,
.chat-link {
  flex: 1; /* Allow content to fill available space */
  display: flex;
  align-items: center;
  height: 100%;
  min-width: 0; /* Critical fix for flexbox text truncation */
  gap: var(--space-sm);
}

.folder-name,
.chat-title.nav-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Actions (Appear on Hover) */
.folder-actions,
.chat-actions {
  display: flex;
  align-items: center;
  gap: var(--space-xxs);
  opacity: 0; /* Hide by default */
  transition: opacity 0.2s ease-in-out;
}

/* CORRECTED: This now targets .tree-item instead of .history-item */
.folder-row:hover .folder-actions,
.tree-item:hover .chat-actions {
  opacity: 1; /* Show on hover */
}

.btn-folder-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  cursor: pointer;
  transition:
    background-color 0.2s,
    color 0.2s;
}

.btn-folder-action:hover {
  color: var(--color-text);
}

/* --- Inline Editing Mode --- */
.folder-edit-mode,
.chat-edit-mode {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  width: 100%;
}

.folder-rename-input,
.chat-rename-input {
  background: transparent;
  border: 1px solid var(--color-accent);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  padding: var(--space-xxs) var(--space-sm);
  font-size: 0.9rem;
  font-family: inherit;
  width: 100%;
  outline: none;
  height: 30px; /* Fit inside the 40px row */
}

/* --- Empty State --- */
.empty-folder-msg {
  height: 30px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  font-style: italic;
  opacity: 0.8;
  cursor: default;
  display: flex;
  align-items: center;
}
.empty-folder-msg:hover {
  background-color: transparent;
}

/* --- Context Menu (Right-click menu) --- */
.ctx-menu {
  position: fixed;
  z-index: 9999;
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: var(--space-sm) 0;
  min-width: 160px;
  display: flex;
  flex-direction: column;
}
.ctx-item {
  display: flex;
  align-items: center;
  padding: var(--space-sm) var(--space-md);
  gap: var(--space-md);
  font-size: 0.9rem;
  color: var(--color-text);
  cursor: pointer;
  background: none;
  border: none;
  text-align: left;
  width: 100%;
}
.ctx-item:hover {
  background-color: var(--color-bg-alt);
}
.ctx-item i {
  height: 16px;
  width: 16px;
  text-align: center;
  color: var(--color-text-muted);
}
.ctx-item.danger:hover {
  color: var(--color-danger);
}
.ctx-item.danger:hover i {
  color: var(--color-danger);
}

/* 
==========================================================================
   5.2 CHAT INTERFACE
========================================================================== 
*/

.chat-container {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* Ensure the header and messages respect the pane width */
.chat-container > .chat-header,
.chat-container > .chat-messages-container,
.chat-container > .chat-input-area {
  width: 100%;
  max-width: var(--chat-max-width); /* Reasonable reading width */
  margin: 0 auto; /* Center in the right pane */
  padding-left: var(--space-md);
  padding-right: var(--space-md);
}
/* Header needs extra width for absolute/sticky context if needed */
.chat-container > .chat-header {
  width: calc(var(--chat-width) + 5%);
}

/* --- Header --- */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) 0;
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: var(--color-bg);
}

.chat-header .chat-title {
  justify-self: start;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);

  /* Truncation */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  padding-right: var(--space-md);
}

.title-display-mode {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}
.btn-icon.fade-in-hover {
  opacity: 0;
  transition: opacity 0.2s;
  color: var(--color-text-muted);
}
.chat-title:hover .btn-icon.fade-in-hover {
  opacity: 1;
}

.title-edit-mode {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  width: 100%;
}
.title-input-field {
  background: transparent;
  border: 1px solid var(--color-accent);
  color: var(--color-text);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  outline: none;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  width: 100%;
  max-width: 250px;
}

.token-count {
  display: inline-flex;
  align-items: center;
  margin-left: var(--space-lg);
  margin-right: auto;
  gap: var(--space-sm);
  font-size: 0.75rem;
  font-weight: 500;
  font-family: "SF Mono", "Menlo", monospace; /* Tabular numbers */
  color: var(--text-muted);
  user-select: none;
}

/* --- Messages --- */
.chat-messages-container {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  overflow-y: auto;
  gap: var(--space-sm);
  padding: var(--space-lg) 0;
  scroll-behavior: smooth;
}

.message-row {
  display: flex;
  flex-direction: column;
  width: 100%;
  margin-bottom: var(--space-sm);
  animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  line-height: 1.6;
  font-size: 0.9em;
  background-color: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  transition:
    background-color 0.2s,
    border-color 0.2s;
}
.message:hover {
  border-color: var(--color-border);
}

/* User vs AI Message Colors */
.message-user .message {
  background-color: var(--color-msg-user);
  color: var(--color-text);
}
.message-ai .message {
  background-color: transparent;
  color: var(--color-text);
}

/* Message Footer Layout */
.message-footer {
  display: flex;
  justify-content: space-between; /* Pushes Actions left, Tokens right */
  align-items: center;
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-xs);
  min-height: 20px; /* Prevent collapse */
}

/* Actions Area */
.message-actions {
  opacity: 0; /* Hidden by default until hover */
  transition: opacity 0.2s;
  display: flex;
  gap: var(--space-xs);
}

/* Show actions on hover */
.message-row:hover .message-actions {
  opacity: 1;
}

/* Mobile: Always show actions (no hover) */
@media (max-width: 768px) {
  .message-actions {
    opacity: 0.5;
  }
}

/* The Action Button (...) */
.btn-msg-action {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--space-xxs) var(--space-xs);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}

.btn-msg-action:hover {
  background: var(--color-bg-alt);
  color: var(--);
}

/* Token Statistics Footer */
.message-meta {
  font-size: 0.7rem;
  padding-top: var(--space-xs);
  justify-content: flex-end;
  opacity: 0.6;
  font-family: monospace; /* Makes numbers look tabular */
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  user-select: none; /* Optional: prevents copying the stats when selecting text */
}

/* Individual Items */
.meta-item {
  display: inline-flex;
  align-items: center;
  font-variant-numeric: tabular-nums; /* Keeps numbers monospaced width */
}

/* Input Tokens */
.meta-in {
  /* Optional: Icon or specific color */
}

/* Output Tokens */
.meta-out {
  /* Optional */
}

/* Cache Tokens - The "Snappy" Highlight */
.meta-cache {
  color: var(--color-success, #10a37f); /* OpenAI Green or your success color */
}

/* Highlight Cache hits in green to show savings */
.stat-cache {
  color: var(--color-success);
  font-weight: 600;
}

/* --- Message Editing Styles --- */

.edit-msg-wrapper {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.edit-msg-textarea {
  width: 100%;
  font-family: inherit;
  font-size: inherit;
  line-height: 1.5;
  color: inherit;

  /* Make it blend in */
  background: transparent;
  border: 1px dashed var(--color-border); /* Subtle dashed border to indicate edit mode */
  border-radius: var(--radius-sm);
  outline: none;
  padding: var(--space-xs);
  resize: none; /* We handle height via JS */
  overflow-y: hidden; /* Hide scrollbar */

  /* Ensure whitespace is preserved like markdown source */
  white-space: pre-wrap;
}

/* Focus state */
.edit-msg-textarea:focus {
  border-color: var(--color-border);
}

/* Button Row */
.edit-actions-row {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}

.btn-edit-action {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity 0.2s;
}

.btn-edit-save {
  background-color: var(--color-primary); /* Your main brand color */
  color: var(--color-bg);
}

.btn-edit-cancel {
  background-color: var(--color-bg-alt);
  color: var(--color-text);
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--color-text);
  padding: var(--space-xl);
}
.empty-icon {
  font-size: 3rem;
  margin-bottom: var(--space-md);
  color: var(--color-border);
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
  margin-top: var(--space-xl);
  max-width: 600px;
  width: 100%;
}
.suggestion-card {
  text-align: left;
  background-color: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-md);
  cursor: pointer;
  transition: background-color 0.2s;
}
.suggestion-card:hover {
  background-color: var(--color-bg-alt);
}

/* --- Input Area --- */
.chat-input-area {
  flex-shrink: 0;
  background-color: var(--color-bg);
  padding-bottom: var(--space-md);
  margin: var(--space-sm) auto;
}

.input-wrapper {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: var(--space-sm);
  background-color: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}
.input-wrapper:focus-within {
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.05);
}

.chat-editor {
  grid-column: 1;
  width: 100%;
  max-height: 200px; /* Max height before scrolling */
  min-height: 24px; /* Height of one line */

  /* Font settings must match your highlighting font */
  /* font-family: "Fira Code", "Roboto Mono", monospace; */
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);

  caret-color: var(--color-text);

  overflow-y: auto; /* Scroll when too tall */
  outline: none; /* Remove blue browser border */
  white-space: pre-wrap; /* Preserve spaces and line breaks */
  word-break: break-word;
}

/* Fake Placeholder Logic (Divs don't have placeholder="" attribute) */
.chat-editor:empty::before {
  content: "Write your message...";
  color: var(--color-text-muted);
  pointer-events: none;
  font-style: italic;
  opacity: 0.7;
}

/* Syntax Highlighting Styles inside the Input */
.chat-editor code,
.chat-editor span {
  font-family: inherit;
  background: transparent !important; /* No background colors on code blocks while typing */
}

/* RICH MARKDOWN STYLING FOR INPUT */

/* 1. Headers (e.g. # Title) */
.chat-editor .hljs-section {
  font-weight: 700;
  color: var(--color-accent); /* Make headers stand out */
  /* Note: Changing font-size in an input can sometimes cause cursor jumps, 
       but small adjustments like this are usually safe in CodeJar */
  font-size: 1.1em;
}

/* 2. Bold (e.g. **text**) */
.chat-editor .hljs-strong {
  font-weight: 700;
  color: var(--color-text); /* Ensure it stays readable */
}

/* 3. Italics (e.g. *text*) */
.chat-editor .hljs-emphasis {
  font-style: italic;
}

/* 4. Blockquotes (e.g. > text) */
.chat-editor .hljs-quote {
  color: var(--color-text-muted);
  font-style: italic;
}

/* 5. Code Blocks (e.g. `text`) */
.chat-editor .hljs-code,
.chat-editor .hljs-comment {
  color: #a5d6ff; /* Soft Blue for code */
  font-family:
    "Fira Code", monospace; /* Ensure distinct font if main is sans */
}

/* 6. Links (e.g. [title](url)) */
.chat-editor .hljs-link,
.chat-editor .hljs-string {
  color: var(--color-text-muted);
  text-decoration: underline;
}

/* 7. Lists (e.g. - item) */
.chat-editor .hljs-bullet {
  color: var(--color-accent);
  font-weight: bold;
}

/* --- Send Button Group --- */

.send-btn-group {
  grid-column: 2;
  height: 32px;
  display: flex;
  align-items: center;
  background-color: var(--color-primary);
  border-radius: var(--radius-sm); /* Pill shape */
  padding: var(--space-xxs);
  gap: 1px; /* Gap for divider look */
  transition: opacity 0.2s;
}

/* Send Button */
.btn-send {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background-color: transparent;
  color: var(--color-primary-fg);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-send:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

/* Chevron Option Button */
.send-opts-wrapper {
  position: relative; /* Anchor for menu */
  height: 100%;
  display: flex;
  align-items: center;
}

.btn-send-opts {
  width: 18px;
  height: 32px;
  border-top-right-radius: var(--radius-sm);
  border-bottom-right-radius: var(--radius-sm);
  background-color: transparent;
  color: var(--color-primary-fg);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 1px solid rgba(255, 255, 255, 0.2);
}
.btn-send-opts:hover {
  background-color: rgba(0, 0, 0, 0.1);
}

/* Disabled state for the whole group */
.send-btn-group:has(.btn-send:disabled) {
  background-color: var(--color-border);
  opacity: 0.6;
}

/* --- Pop-up Menu --- */
.send-menu {
  position: absolute;
  bottom: 120%; /* Pop UP, not down */
  right: 0;
  width: 160px;
  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  padding: var(--space-xs);
  z-index: 50;
  animation: fadeIn 0.1s ease-out;
}

.menu-label {
  padding: var(--space-sm) 12px;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-weight: 600;
  text-transform: uppercase;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-xs);
}

.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) 12px;
  background: transparent;
  border: none;
  color: var(--color-text);
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
  border-radius: var(--radius-sm);
}

.menu-item:hover {
  background-color: var(--color-bg-alt);
  border-bottom: 1px solid var(--color-accent);
}

.check-icon {
  width: 14px;
  color: var(--color-success);
  visibility: hidden; /* Hidden by default */
}

/* Helper to show checkmark */
.check-icon.selected {
  visibility: visible;
}

/* --- Input Footer & Selectors --- */

.input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-xs) 0 var(--space-xs);
  font-size: 0.75rem;
  color: var(--color-text-muted);
  gap: var(--space-md);
}

.footer-controls {
  display: flex;
  align-items: center;
}

.footer-disclaimer {
  text-align: right;
  opacity: 0.8;
}

/* --- Model Context Menu --- */

.model-menu-container {
  position: relative; /* Anchor for the absolute menu */
}

/* The Trigger Button */
.model-trigger-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
  max-width: 250px;
}
.model-trigger-btn:hover {
  background-color: var(--color-bg-alt);
  color: var(--color-text);
}

/* The Icon inside trigger */
.provider-icon-xs {
  width: 18px;
  height: 18px;
  object-fit: contain;
  border-radius: 2px;
}

.select-chevron-static {
  font-size: 0.7rem;
  margin-left: 4px;
  opacity: 0.7;
}

/* The Pop-Up Menu */
.model-ctx-menu {
  position: absolute;
  bottom: 120%; /* Pop UP */
  left: 0;
  width: 220px;
  max-height: 300px; /* Scrollable if too many models */
  overflow-y: auto;

  background-color: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);

  display: flex;
  flex-direction: column;
  padding: 4px;
  z-index: 60;
  animation: fadeIn 0.1s ease-out;
}

/* Menu Items */
.model-menu-header {
  padding: 8px 12px 4px 12px;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-xxs);
  margin-top: var(--space-xs);
}
.model-menu-header:first-child {
  margin-top: 0;
}

.model-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) 12px;
  background: transparent;
  border: none;
  color: var(--color-text);
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm);
  width: 100%;
}
.model-menu-item:hover {
  background-color: var(--color-bg-alt);
  border-bottom: 1px solid var(--color-accent);
}
.model-menu-item.selected {
  background-color: var(--color-bg-color); /* Blue background */
  color: white;
}

/* Context Popup Specifics */
.context-popup {
  min-width: 220px;
  padding: 12px;
  cursor: default;
  bottom: 100%;
  margin-bottom: var(--space-xs);
}

.ctx-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
}

.btn-text-xs {
  background: none;
  border: 1px solid transparent;
  font-size: 0.7rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: var(--space-xxs) 6px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.btn-text-xs:hover {
  background: var(--color-bg-alt);
  color: var(--text-primary);
}

.btn-text-xs.active {
  background: var(--color-primary);
  color: var(--color-bg);
  font-weight: 600;
}

/* Slider Styling */
.ctx-slider-row {
  margin-bottom: var(--space-xs);
  display: flex;
  align-items: center;
}

.ctx-range {
  width: 100%;
  accent-color: var(--color-primary);
  cursor: pointer;
}

/* Number Input Row */
.ctx-input-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-sm);
}

.ctx-num-input {
  width: 60px;
  padding: var(--space-xs);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  text-align: center;
  font-family: monospace;
  background: var(--color-bg);
  color: var(--color-text);
}

.ctx-num-input:focus {
  outline: 2px solid var(--color-accent);
  border-color: transparent;
}

/* --- Format Context Menu --- */
.format-menu-container .menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-sm) 12px;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text);
}

.format-menu-container .menu-item:hover {
  background-color: var(--color-bg-hover);
}

/* --- File Upload --- */
.upload-container {
  position: relative;
}

.upload-toast {
  position: absolute;
  bottom: 120%; /* Sits above the button */
  left: 50%;
  transform: translateX(-50%) translateY(10px); /* Start slightly down */

  background-color: var(--color-msg-success-bg);
  color: var(--color-msg-success-text);
  border: 1px solid var(--color-msg-success-border);
  border-radius: var(--radius-sm);
  padding: var(--space-xs) var(--space-sm);
  font-size: 0.8rem;
  white-space: nowrap;
  pointer-events: none; /* Let clicks pass through */

  /* Animation State: Hidden */
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28); /* Bouncy transition */
}

/* Active State: Visible */
.upload-toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

/* --- Shared / Read-Only Chat Styles --- */

/* Ensure the input area can hold the absolute overlay */
/* We use !important to ensure it overrides any default positioning behavior if necessary, 
   though usually just adding the class in HTML is enough. */
.chat-input-area.shared-mode {
  position: relative !important;
}

/* The invisible shield that blocks clicks */
.shared-overlay {
  position: absolute;
  inset: 0; /* Cover top, right, bottom, left */
  z-index: 100; /* Sit on top of everything */

  /* Visuals */
  background: rgba(255, 255, 255, 0.05); /* Extremely subtle tint */
  backdrop-filter: blur(1.5px); /* Tiny blur to indicate "inactive" depth */

  /* Layout for the badge */
  display: flex;
  align-items: center;
  justify-content: center;

  /* Cursor */
  cursor: default;
}

/* The "Read Only" Badge Button */
.shared-badge-btn {
  background-color: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  color: var(--color-text-main);
  padding: var(--space-sm) var(--space-md);
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);

  display: flex;
  align-items: center;
  gap: var(--space-sm);

  transition:
    transform 0.2s,
    box-shadow 0.2s;
  pointer-events: auto; /* Enable clicking THIS button */
}

.shared-badge-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
  border-color: var(--color-accent);
}

.shared-badge-btn i {
  color: var(--color-accent);
}

/* 
==========================================================================
   6. MARKDOWN & CONTENT STYLING
========================================================================== 
*/

.message > *:first-child {
  margin-top: 0;
}
.message > *:last-child {
  margin-bottom: 0;
}
.message p {
  margin-bottom: 0.75rem;
}
.message ul,
.message ol {
  margin: 0.5rem 0 1rem 1.5rem;
  padding: 0;
}
.message li {
  margin-bottom: 0.25rem;
}

/* Code Blocks */
.message pre {
  background-color: var(--bg-code-block);
  color: var(--text-code-block);
  border-radius: 6px;
  padding: var(--space-md);
  margin: 0.8rem 0;
  overflow-x: auto;
  font-size: 0.9em;
  white-space: var(--code-white-space, pre);
}
.message pre code {
  white-space: inherit;
}
.message pre code.hljs {
  background: transparent !important;
  padding: 0 !important;
  color: inherit; /* Let the pre color or individual syntax spans handle color */
}

/* Inline Code */
.message :not(pre) > code {
  background-color: rgba(125, 125, 125, 0.15);
  padding: 0.2em 0.4em;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9em;
  color: var(--color-accent);
}
.light .message :not(pre) > code {
  background-color: rgba(0, 0, 0, 0.1);
}

.message a {
  color: inherit;
  text-decoration: underline;
}
.message h1,
.message h2,
.message h3 {
  font-weight: 600;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  color: var(--color-text);
}

/* 
==========================================================================
   7. UI COMPONENTS
========================================================================== 
*/

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 500;
  font-size: 1rem;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s;
}
.btn:hover {
  border-color: var(--color-border);
}
.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background-color: var(--color-primary);
  color: var(--color-primary-fg);
  border: 1px solid var(--color-border);
  font-weight: 600;
}
.btn-primary:hover {
  filter: brightness(1.1);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.btn-secondary {
  background-color: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text);
}
.btn-secondary:hover {
  background-color: var(--color-bg-alt);
}

.btn-danger {
  background-color: var(--color-msg-error-bg);
  color: var(--color-msg-error-text);
  border: 1px solid var(--color-msg-error-border);
}
.btn-danger:hover {
  box-shadow: 0 4px 12px var(--color-msg-error-text);
}

.btn-icon {
  background-color: transparent;
  border: none;
  color: var(--color-text);
  cursor: pointer;
  padding: var(--space-sm);
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  transition: color 0.2s;
}
.btn-icon:hover {
  color: var(--color-accent);
}
.btn-icon-danger:hover {
  color: var(--color-msg-error-text);
}
.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  gap: 6px;
}

/* --- Forms --- */
.form-group {
  margin-bottom: var(--space-md);
}
.form-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: var(--space-xs);
  color: var(--color-text);
}
.form-input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background-color: transparent;
  color: var(--color-text);
  font-family: inherit;
  font-size: 1rem;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}
.form-input:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}
.form-subtext {
  width: 100%;
  text-align: right;
  margin-top: calc(-1 * var(--space-sm));
  margin-bottom: var(--space-md);
  font-size: 0.75rem;
}

/* Custom Select Input */
.form-select {
  /* Inherit base input styles to match .form-input */
  width: 100%;
  padding: 0.75rem;
  padding-right: 2.5rem; /* Extra space on the right for the arrow */
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background-color: transparent;
  color: var(--color-text);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.5;
  cursor: pointer;

  /* Smooth transitions */
  transition:
    border-color 0.2s,
    box-shadow 0.2s;

  /* Remove default browser arrow */
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;

  /* Add custom SVG arrow (Neutral Gray color #6b7280 to work on Light/Dark) */
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
}

/* Match the focus state of .form-input */
.form-select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* Styling the Group Labels */
.form-select optgroup {
  /* Ensure the background matches the theme, not the OS default white */
  background-color: var(--color-bg);

  /* Use muted text color to differentiate groups from clickable options */
  color: var(--color-text-muted);

  /* Style the font to look like a header */
  font-weight: 600;
  font-style: normal;
  font-family: var(--font-sans);
}

/* Ensure dropdown options have the correct background color */
/* This prevents options from being transparent/unreadable depending on OS */
.form-select option {
  background-color: var(--color-bg);
  color: var(--color-text);
  padding: 0.5rem;
}

.form-range {
  width: 100%;
  height: 6px;
  background: var(--color-border);
  border-radius: 5px;
  outline: none;
  -webkit-appearance: none;
}
.form-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-accent);
  cursor: pointer;
  border: 2px solid var(--color-bg);
}

.checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  user-select: none;
  font-size: 0.9rem;
  color: var(--color-text);
}
.checkbox-wrapper input[type="checkbox"] {
  accent-color: var(--color-accent);
  width: 16px;
  height: 16px;
}

/* --- Cards --- */
.card {
  background-color: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: var(--space-md);
  overflow: hidden;
}
.card-header {
  padding: var(--space-md) var(--space-lg);
  background-color: var(--color-bg);
  margin: 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 1.25rem;
}
.card-content {
  padding: var(--space-md) var(--space-lg);
}

/* --- Modals --- */
dialog.modal {
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background-color: var(--color-bg);
  color: var(--color-text);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  max-width: 500px;
  width: 90%;
}
dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}
.modal-box {
  padding: var(--space-xl);
}
.modal-box h3 {
  margin-top: 0;
  font-size: 1.25rem;
  font-weight: 600;
}
.modal-box p {
  color: var(--color-text-muted);
  font-size: 0.9rem;
  margin-bottom: var(--space-lg);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
  margin-top: var(--space-lg);
}
.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
}
.btn-ghost:hover {
  color: var(--color-text);
  background-color: var(--color-border);
}

/* --- Toasts --- */
#toast-container {
  position: absolute;
  top: var(--space-md);
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  width: 90%;
  max-width: 400px;
}
.c-message {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  animation: slideDown 0.3s ease-out forwards;
}
.c-message--success {
  background-color: var(--color-msg-success-bg);
  color: var(--color-msg-success-text);
}
.c-message--error {
  background-color: var(--color-msg-error-bg);
  color: var(--color-msg-error-text);
}

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

/* 
==========================================================================
   8. PAGE SPECIFIC STYLES
========================================================================== 
*/

/* --- Auth (Login / Signup) --- */
.auth-form-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  padding: var(--space-md);
}
.auth-form-content {
  width: 100%;
  max-width: 400px;
}
.auth-heading {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: var(--space-sm);
}
.auth-subheading {
  text-align: center;
  margin: var(--space-sm) 0;
  color: var(--color-text);
  font-weight: 600;
  line-height: 1;
}
.auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--color-text-muted);
  margin: var(--space-lg) 0;
  font-size: 0.85rem;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--color-border);
}
.auth-divider span {
  padding: 0 var(--space-sm);
}
.auth-footer {
  display: block;
  text-align: center;
  color: var(--color-text);
  margin-top: var(--space-sm);
}
.auth-form-error {
  color: var(--color-msg-error-text);
  background-color: var(--color-msg-error-bg);
  border: 1px solid var(--color-msg-error-border);
  border-radius: var(--radius);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-md);
  text-align: center;
  font-size: 0.9em;
}
.btn-auth {
  width: 100%;
  background-color: var(--color-primary);
  font-weight: 600;
  color: var(--color-primary-fg);
}
.btn-google {
  background-color: transparent;
  font-weight: 500;
  margin-bottom: var(--space-sm);
  border: 1px solid var(--color-border);
  color: var(--color-text);
}

/* --- User Profile --- */

.user-profile-container {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  margin: 0;
  padding: var(--space-xl);
  box-sizing: border-box;
  display: block;
}
/* Center the content elements inside */
.user-profile-container > h1,
.user-profile-container > p,
.user-profile-container > .card,
.user-profile-container > .info-message {
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}
/* Ensure the last card has breathing room at the bottom */
.user-profile-container > .card:last-child {
  margin-bottom: 50px;
}

.user-info-row,
.user-info-row-form {
  padding: var(--space-md) 0;
  border-bottom: 1px solid var(--color-border);
}
.user-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.user-info-label {
  font-size: 0.9rem;
  color: var(--color-text);
  opacity: 0.7;
}
.user-info-value {
  font-size: 1.1rem;
  font-weight: 600;
}

.info-message {
  padding: var(--space-sm) var(--space-md);
  margin: 0 var(--space-lg);
  border-radius: var(--radius-sm);
  font-size: 0.9em;
  line-height: 1.5;
  text-align: left;
  background-color: color-mix(in srgb, var(--color-accent) 10%, transparent);
  color: var(--color-text);
  border-left: 4px solid var(--color-accent);
}

.google-managed-message {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-top: var(--space-md);
}

.google-managed-message img {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

/* Prompts Specific */
#prompt-editor-container {
  flex: 1; /* Grow to fill parent */
  height: 100%; /* Force height for block display compatibility */
  overflow: hidden; /* Prevent double scrollbars */
  display: flex; /* Use flexbox to manage the form */
  flex-direction: column;
}
.prompt-title {
  height: 100%;
  border: none;
  background: transparent;
  color: var(--color-text);
  font-size: 1.25rem;
  font-weight: 700;
  outline: none;
  width: 100%;
}
.prompt-editor-content {
  flex: 1;
  display: flex;
  padding: 0 var(--space-lg) var(--space-lg) var(--space-lg);
}
.prompt-input-content {
  flex: 1;
  width: 100%;
  resize: none;
  padding: var(--space-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-text);
  font-family: monospace;
  font-size: 1rem;
  line-height: 1.6;
  outline: none;
}
.prompt-editor-form {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.prompt-editor-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-left: auto;
}
.prompt-editor-settings {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: var(--space-sm) var(--space-sm) var(--space-xs) var(--space-sm);
  margin-top: var(--space-sm);
}
.prompt-badge {
  margin-left: var(--space-sm);
}

/* API Keys Specific */
.provider-header-title {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.provider-logo-box {
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background-color: var(--color-bg-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  border: 1px solid var(--color-border);
}

.provider-form-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.provider-form-container .provider-form-header {
  flex-shrink: 0;
}

.provider-form-content {
  flex-shrink: 0;
  padding: var(--space-lg);
  padding-bottom: 0;
}

.provider-form-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-left: auto;
}

.provider-icon {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.btn-text-action {
  font-size: 0.8rem;
  color: var(--color-accent);
  text-decoration: none;
  background-color: transparent;
  border: none;
  cursor: pointer;
}

/* Models Section */
.models-section {
  overflow-y: auto;
  min-height: 0;
  padding: var(--space-lg);
  padding-top: 0;
}

.model-section-title {
  position: sticky;
  top: 0;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  z-index: 5;
  padding-bottom: var(--space-xs);
  margin-top: 0;
  margin-bottom: var(--space-xs);
}

.models-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}

.model-card {
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  transition:
    transform 0.2s,
    border-color 0.2s;
  height: 100%; /* Ensure uniform height in grid */
}
.model-card:hover {
  border-color: var(--color-accent);
  transform: translateY(-2px);
}

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

.model-name {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--color-text);
}

.modality-icons {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.model-modality-icon {
  color: var(--color-text-muted);
  opacity: 0.3;
  font-size: 1em;
  transition:
    opacity 0.2s,
    color 0.2s;
}
.model-modality-icon.active {
  color: var(--color-text);
  opacity: 1;
}

/* Badges */
.badge {
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-success {
  background-color: rgba(16, 185, 129, 0.15);
  color: var(--color-success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

/* ID Code styling */
.model-id-code {
  font-family: monospace;
  font-size: 0.8rem;
  background: rgba(125, 125, 125, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  width: fit-content;
  color: var(--color-text-muted);
}

.model-desc {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin: var(--space-xxs) 0;
  flex-grow: 1; /* Ensures footer aligns at bottom */
}

/* Model Details List (Grid Layout) */
.model-details-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-border);
  font-size: 0.85rem;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.detail-label {
  color: var(--color-text-muted);
}

.detail-value {
  color: var(--color-text);
  font-weight: 500;
  text-align: right;
}

/* --- Settings --- */
.settings-menu-header {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-muted);
  padding: var(--space-md) var(--space-sm) var(--space-xs);
  text-transform: uppercase;
}

/* Constraint for the settings area */
.settings-container {
  max-width: 700px;
  margin: 0 auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

/* Informational box at the top */
.settings-info-box {
  background-color: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-md) var(--space-lg);
}
.settings-info-box h3 {
  font-size: 1rem;
  margin-top: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--color-accent);
}
.settings-info-box p {
  font-size: 0.9rem;
  color: var(--color-text);
  line-height: 1.6;
}
.settings-info-box ul {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.settings-info-box li {
  font-size: 0.85rem;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.settings-info-box li i {
  color: var(--color-accent);
  margin-top: 3px;
  width: 14px;
}

/* Refined Sync Status */
.sync-status.active {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: var(--space-sm) var(--space-md);
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid var(--color-success);
  border-radius: var(--radius-sm);
  color: var(--color-success);
  font-size: 0.85rem;
  font-weight: 500;
}

/* Controlled Action Buttons (Smaller) */
.settings-action-buttons {
  display: flex;
  justify-content: center;
  gap: var(--space-md);
  margin-top: var(--space-md);
  flex-wrap: wrap;
}
.settings-action-buttons .btn-sm {
  padding: 6px 14px;
  font-size: 0.8rem;
  flex: 0 1 auto; /* Don't grow to fill width */
}

/* Storage Bar */
.storage-actions-row {
  margin-top: 20px;
  padding-top: 15px;
  border-top: 1px solid var(--color-border);

  display: flex;
  gap: 10px; /* Space between buttons */
  flex-wrap: wrap; /* Allow wrapping on very small mobile screens */
}

/* Make buttons expand evenly */
.storage-actions-row .btn {
  flex: 1; /* All 3 buttons take equal width */
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-sm); /* Space between icon and text */
  white-space: nowrap;
}
/* Ensure icons align nicely */
.storage-actions-row i {
  font-size: 1rem;
}

.storage-bar-bg {
  width: 100%;
  height: var(--space-md);
  /* background-color: var(--color-bg-alt); */

  background: linear-gradient(
    to right,
    rgba(var(--color-accent-rgb), 0.1),
    transparent
  );
  border: 1px solid var(--color-border);
  border-radius: 14px;
  overflow: hidden;
  margin: var(--space-sm) 0;
}
.storage-bar-fill {
  height: 100%;
  border: 1px solid var(--color-border);
  background-color: var(--color-accent);
  width: 0%; /* JS will update this */
  transition: width 0.5s ease-out;
}
.storage-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--color-text);
  font-weight: 500;
}
.storage-quota {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.premium-upsell-box {
  margin-top: var(--space-md);
  border: 1px solid var(--color-border);
  padding: 12px;
  background: linear-gradient(
    to right,
    rgba(var(--color-accent-rgb), 0.1),
    transparent
  );
  border-left: 3px solid var(--color-accent);
  border-radius: var(--radius-sm);
}
.premium-upsell-box .upsell-title {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: var(--space-xs);
  display: flex;
  align-items: center;
  gap: 8px;
}
.premium-upsell-box .upsell-description {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-md);
}
.premium-upsell-box .upsell-features {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--space-md) 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.premium-upsell-box .upsell-features li {
  font-size: 0.85rem;
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
}
.premium-upsell-box .upsell-features li i {
  color: var(--color-accent);
  margin-top: 3px;
  width: 14px;
}

/* Top-level stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.stat-item {
  background-color: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-bottom: var(--space-xs);
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-text);
  font-family: monospace;
}

/* Sub-header for the provider list */
.sub-header {
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: var(--space-lg);
  margin-bottom: var(--space-sm);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--color-border);
}

/* Provider breakdown list */
.provider-stats-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.provider-stat-item {
  display: grid;
  grid-template-columns: 150px 1fr;
  align-items: center;
  gap: var(--space-lg);
}

.provider-info .provider-name {
  font-weight: 500;
  color: var(--color-text);
  display: block;
  text-transform: capitalize;
}

.provider-info .provider-counts {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

.provider-breakdown {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.provider-percentage-bar {
  display: grid;
  grid-template-columns: 80px 1fr;
  align-items: center;
  gap: var(--space-sm);
}

.provider-percentage-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  text-align: right;
}

.provider-progress-bg {
  width: 100%;
  height: 8px;
  background-color: var(--color-bg-alt);
  border-radius: 4px;
  overflow: hidden;
}

.provider-progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease-out;
}

.provider-progress-fill.chats {
  background-color: var(--color-accent);
}

.provider-progress-fill.tokens {
  background-color: var(--color-success);
}

/* Responsive adjustment for mobile */
@media (max-width: 600px) {
  .provider-stat-item {
    grid-template-columns: 1fr; /* Stack vertically */
    gap: var(--space-sm);
  }
  .provider-percentage-bar {
    grid-template-columns: 60px 1fr;
  }
}

/* Appearance */
.appearance-toolbar-wrapper {
  background-color: transparent;
  padding: var(--space-md) var(--space-lg);
}

.appearance-toolbar {
  display: grid;
  /* Desktop: 4 columns. Mobile: 1 column. */
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-lg);
  align-items: start;
}

.toolbar-item {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.toolbar-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--color-text-muted);
  letter-spacing: 0.5px;
}

.toolbar-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toolbar-value {
  font-size: 0.75rem;
  color: var(--color-text);
  font-family: monospace;
}

/* Make inputs slightly more compact for the toolbar context */
.toolbar-input {
  padding: 0.4rem 2rem 0.4rem 0.6rem; /* Smaller padding */
  font-size: 0.9rem;
}

.range-wrapper {
  height: 35px; /* Match height of select inputs for alignment */
  display: flex;
  align-items: center;
}

/* Checkbox specific alignment */
.checkbox-item {
  justify-content: flex-end; /* Push to bottom to align with inputs */
  height: 100%;
}

.toolbar-checkbox {
  height: 35px; /* Match input height */
  display: flex;
  align-items: center;
  background-color: var(--color-bg); /* Contrast against toolbar bg */
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0 var(--space-sm);
  font-size: 0.85rem;
  width: 100%;
}

@media (max-width: 768px) {
  .mobile-hidden {
    display: none;
  }
}

/* --- Live Preview Area --- */

.appearance-preview-area {
  background-color: var(--color-bg); /* Uses the theme background */
  padding: var(--space-lg);
  flex-grow: 1;
  overflow-y: auto;
  min-height: 400px;
}

.preview-container {
  /* This creates a visual "page" for the preview if the screen is wide */
  max-width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.preview-label {
  display: flex;
  align-items: center;
  justify-content: left;
  gap: var(--space-sm);
  padding-top: var(--space-md);
  font-weight: 600;
  color: var(--color-text);
  user-select: none; /* Prevent selecting it */
}

/* 
==========================================================================
   9. UTILITIES
========================================================================== 
*/

/* Scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background-color: var(--color-border);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background-color: var(--color-text-muted);
}
