/* Theme System - Light and Dark Mode Variables */

/* ==========================================
   Light Theme (Default)
   ========================================== */
:root {
  /* Primary Accent — Antique Gold
     Change these to rebrand the entire app */
  --accent: #B8882F;
  --accent-hover: #A07828;
  --accent-subtle: rgba(184, 136, 47, 0.06);
  --accent-light: rgba(184, 136, 47, 0.12);
  --accent-shadow: rgba(184, 136, 47, 0.2);
  --accent-border: rgba(184, 136, 47, 0.25);
  --accent-shadow-hover: rgba(184, 136, 47, 0.3);
  /* Cream text/glyph colour for use on top of gold/accent fills (matches landing buttons) */
  --accent-text: #F7F4EE;

  /* Legacy aliases — referenced widely, kept for compatibility */
  --primary-blue: var(--accent);
  --primary-blue-hover: var(--accent-hover);
  --primary-blue-light: var(--accent-light);

  /* Background Colors — Warm Cream */
  --bg-primary: #FAF8F4;
  --bg-secondary: #ffffff;
  --bg-tertiary: #F5F2EC;
  --bg-elevated: #ffffff;
  --bg-hover: #EFEBE3;
  --bg-active: #E5E0D8;

  /* Text Colors */
  --text-primary: #2A2A2A;
  --text-secondary: #4A4540;
  --text-tertiary: #6B6560;
  --text-muted: #9C9590;
  --text-inverse: #ffffff;

  /* Border Colors — Warm */
  --border-color: #E5E0D8;
  --border-color-light: #F0EDE7;
  --border-color-strong: #D0C9C0;

  /* Status Colors — Warm family */
  --success-color: #5B9E6F;
  --success-bg: #E8F5EC;
  --success-text: #2D5E3A;
  --error-color: #C75B4A;
  --error-bg: #FAEAE7;
  --error-text: #8B3426;
  --warning-color: #D4943A;
  --warning-bg: #FDF3E3;
  --warning-text: #8B5E1A;
  --info-color: #5B8DB8;
  --info-bg: #E6F0F8;
  --info-text: #2D5A7B;

  /* Shadows */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-xl: 0 12px 40px rgba(0, 0, 0, 0.12);

  /* Sidebar */
  --sidebar-bg: linear-gradient(to bottom, #252d38, #192028);
  --sidebar-text: #CCCAC6;
  --sidebar-text-muted: #7A7570;
  --sidebar-hover-bg: rgba(255, 255, 255, 0.05);
  --sidebar-active-bg: rgba(255, 255, 255, 0.08);
  --sidebar-accent: var(--accent);
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --sidebar-hover-text: #F7F4EE;

  /* Cards */
  --card-bg: #ffffff;
  --card-bg-hover: #FAF8F4;
  --card-border: rgba(229, 224, 216, 0.8);

  /* Forms */
  --input-bg: #FAF8F4;
  --input-bg-focus: #ffffff;
  --input-border: #E5E0D8;
  --input-border-focus: var(--accent);
  --input-text: #4A4540;
  --input-placeholder: #9C9590;

  /* Tables */
  --table-header-bg: #F5F2EC;
  --table-row-even: rgba(245, 242, 236, 0.7);
  --table-row-hover: rgba(239, 235, 227, 0.9);

  /* Charts & Metrics */
  --metric-card-bg: var(--card-bg);
  --risk-card-bg: var(--card-bg);

  /* Chart line colors — match metric card text to graph lines */
  --chart-std: #0ea5e9;
  --chart-sharpe: #f59e0b;
  --chart-drawdown: #8b5cf6;
  --chart-price: #10b981;

  /* Chat Panel */
  --chat-bg: #F0EDE7;
  --chat-bg-secondary: #E8E4DD;
  --chat-bubble-assistant: #ffffff;
  --chat-bubble-border: rgba(0, 0, 0, 0.06);
  --chat-text: #4A4540;
  --chat-text-strong: #2A2A2A;
  --chat-text-muted: rgba(0, 0, 0, 0.4);
  --chat-input-bg: #ffffff;
  --chat-input-border: rgba(0, 0, 0, 0.12);
  --chat-placeholder: rgba(0, 0, 0, 0.3);
  --chat-code-bg: rgba(0, 0, 0, 0.06);
  --chat-scrollbar: rgba(0, 0, 0, 0.12);
  --chat-border: rgba(0, 0, 0, 0.08);

  /* Card Inset (metric cards inside tiles) */
  --card-bg-inset: rgba(0, 0, 0, 0.02);
  --card-border-subtle: rgba(0, 0, 0, 0.04);

  /* Misc */
  --overlay-bg: rgba(0, 0, 0, 0.5);
  --modal-overlay: rgba(0, 0, 0, 0.6);
  --loading-overlay: rgba(25, 32, 40, 0.4);
  --glass-overlay-bg: rgba(25, 32, 40, 0.46);
  --glass-surface-bg: rgba(255, 255, 255, 0.9);
  --glass-surface-bg-strong: rgba(255, 255, 255, 0.95);
  --glass-surface-border: rgba(229, 224, 216, 0.78);
  --glass-surface-shadow: 0 24px 70px rgba(15, 23, 42, 0.18);
  --glass-dropdown-bg: rgba(255, 255, 255, 0.92);
  --glass-dropdown-border: rgba(229, 224, 216, 0.82);
  --glass-dropdown-shadow: 0 18px 42px rgba(15, 23, 42, 0.16);
  --glass-surface-blur: 18px;
  --glass-dropdown-blur: 16px;
  --scrollbar-bg: #E5E0D8;
  --scrollbar-thumb: #9C9590;
  --code-bg: #F5F2EC;
}

/* ==========================================
   Dark Theme — "The Private Study"
   ========================================== */
[data-theme="dark"] {
  /* Primary Accent — Antique Gold (dark mode shades) */
  --accent: #C9973B;
  --accent-hover: #E2BE76;
  --accent-subtle: rgba(201, 151, 59, 0.08);
  --accent-light: rgba(201, 151, 59, 0.15);
  --accent-shadow: rgba(201, 151, 59, 0.2);
  --accent-border: rgba(201, 151, 59, 0.25);
  --accent-shadow-hover: rgba(201, 151, 59, 0.3);

  /* Legacy aliases */
  --primary-blue: var(--accent);
  --primary-blue-hover: var(--accent-hover);
  --primary-blue-light: var(--accent-light);

  /* Background Colors — Warm Ink */
  --bg-primary: #192028;
  --bg-secondary: #252d38;
  --bg-tertiary: #252d38;
  --bg-elevated: #3a4553;
  --bg-hover: #3a4553;
  --bg-active: #4d5a6a;

  /* Text Colors — Warm Cream */
  --text-primary: #F7F4EE;
  --text-secondary: #EDEAE4;
  --text-tertiary: #ABA6A0;
  --text-muted: #847F79;
  --text-inverse: #192028;

  /* Border Colors */
  --border-color: #3a4553;
  --border-color-light: #252d38;
  --border-color-strong: #4d5a6a;

  /* Status Colors — Warm family for dark mode */
  --success-color: #6DBF82;
  --success-bg: rgba(91, 158, 111, 0.15);
  --success-text: #8ED4A0;
  --error-color: #E07A6B;
  --error-bg: rgba(199, 91, 74, 0.15);
  --error-text: #F0A090;
  --warning-color: #E2BE76;
  --warning-bg: rgba(212, 148, 58, 0.15);
  --warning-text: #F0D090;
  --info-color: #7BADD0;
  --info-bg: rgba(91, 141, 184, 0.15);
  --info-text: #A0C8E8;

  /* Shadows */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 12px 40px rgba(0, 0, 0, 0.6);

  /* Sidebar */
  --sidebar-bg: linear-gradient(to bottom, #192028, #111820);
  --sidebar-text: #EDEAE4;
  --sidebar-text-muted: #9C9590;
  --sidebar-hover-bg: rgba(255, 255, 255, 0.06);
  --sidebar-active-bg: rgba(255, 255, 255, 0.10);
  --sidebar-accent: var(--accent);
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --sidebar-hover-text: #F7F4EE;

  /* Cards */
  --card-bg: #252d38;
  --card-bg-hover: #3a4553;
  --card-border: rgba(58, 69, 83, 0.8);

  /* Forms */
  --input-bg: #252d38;
  --input-bg-focus: #3a4553;
  --input-border: #3a4553;
  --input-border-focus: var(--accent);
  --input-text: #EDEAE4;
  --input-placeholder: #7A7570;

  /* Tables */
  --table-header-bg: #252d38;
  --table-row-even: rgba(37, 45, 56, 0.7);
  --table-row-hover: rgba(58, 69, 83, 0.9);

  /* Charts & Metrics */
  --metric-card-bg: var(--card-bg);
  --risk-card-bg: var(--card-bg);

  /* Chart line colors — match metric card text to graph lines */
  --chart-std: #0ea5e9;
  --chart-sharpe: #f59e0b;
  --chart-drawdown: #8b5cf6;
  --chart-price: #10b981;

  /* Chat Panel */
  --chat-bg: #1c2430;
  --chat-bg-secondary: #1a2230;
  --chat-bubble-assistant: #252d38;
  --chat-bubble-border: rgba(255, 255, 255, 0.06);
  --chat-text: #e0e0e0;
  --chat-text-strong: #ffffff;
  --chat-text-muted: rgba(255, 255, 255, 0.4);
  --chat-input-bg: #252d38;
  --chat-input-border: rgba(255, 255, 255, 0.1);
  --chat-placeholder: rgba(255, 255, 255, 0.3);
  --chat-code-bg: rgba(255, 255, 255, 0.1);
  --chat-scrollbar: rgba(255, 255, 255, 0.15);
  --chat-border: rgba(255, 255, 255, 0.08);

  /* Card Inset (metric cards inside tiles) */
  --card-bg-inset: rgba(255, 255, 255, 0.03);
  --card-border-subtle: rgba(255, 255, 255, 0.05);

  /* Misc */
  --overlay-bg: rgba(0, 0, 0, 0.7);
  --modal-overlay: rgba(0, 0, 0, 0.8);
  --loading-overlay: rgba(17, 24, 32, 0.7);
  --glass-overlay-bg: rgba(0, 0, 0, 0.62);
  --glass-surface-bg: rgba(37, 45, 56, 0.82);
  --glass-surface-bg-strong: rgba(37, 45, 56, 0.9);
  --glass-surface-border: rgba(255, 255, 255, 0.13);
  --glass-surface-shadow: 0 26px 70px rgba(0, 0, 0, 0.38);
  --glass-dropdown-bg: rgba(37, 45, 56, 0.9);
  --glass-dropdown-border: rgba(255, 255, 255, 0.12);
  --glass-dropdown-shadow: 0 18px 42px rgba(0, 0, 0, 0.26);
  --glass-surface-blur: 18px;
  --glass-dropdown-blur: 16px;
  --scrollbar-bg: #252d38;
  --scrollbar-thumb: #4d5a6a;
  --code-bg: #252d38;
}

/* ==========================================
   Theme Toggle Switch Styles
   ========================================== */
.theme-toggle-section {
  padding: 12px 10px;
  border-top: 1px solid var(--sidebar-border);
  margin-top: auto;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.theme-toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--sidebar-text);
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
}

.theme-toggle-label i {
  font-size: 0.85rem;
  color: var(--sidebar-accent);
  flex-shrink: 0;
}

.theme-toggle-label span {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The switch container */
.theme-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  min-width: 50px;
  max-width: 50px;
  height: 26px;
  flex-shrink: 0;
}

/* Hide the default checkbox */
.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

/* The slider */
.theme-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #4d5a6a;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 26px;
  overflow: hidden;
}

/* The knob */
.theme-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: #C9973B;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Dark mode slider */
input:checked + .theme-slider {
  background-color: #252d38;
}

input:checked + .theme-slider:before {
  transform: translateX(24px);
  background-color: #EDEAE4;
}

/* Focus state for accessibility */
.theme-switch input:focus + .theme-slider {
  box-shadow: 0 0 0 3px rgba(201, 151, 59, 0.3);
}

/* ==========================================
   Global Dark Mode Overrides
   ========================================== */

/* Scrollbar styles */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-bg);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

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

/* Selection colors */
::selection {
  background: var(--primary-blue-light);
  color: var(--text-primary);
}

/* Smooth transition for theme switch */
body,
.sidemenu,
.content,
.card,
.modal-content,
.form-group input,
.form-group select,
.form-group textarea,
table,
.tabcontent,
.grid-item,
.portfolio-stats-card,
.stat-item,
.metric-card,
.auth-form,
.alert,
#ticker-search-results,
.add-stock-panel {
  transition: background-color 0.3s ease,
              color 0.3s ease,
              border-color 0.3s ease,
              box-shadow 0.3s ease;
}

/* Dark mode specific overrides for external elements */
[data-theme="dark"] .bk-root,
[data-theme="dark"] .plotly {
  filter: brightness(0.95);
}

/* Ensure Bokeh/Plotly charts blend better in dark mode */
[data-theme="dark"] .bk-canvas-overlays,
[data-theme="dark"] .bk-root .bk-canvas {
  background: transparent !important;
}

/* Bokeh tooltip styling — adapts to current theme */
.bk-tooltip,
.bk-tooltip-content,
.bk-tooltip > div,
.bk-tooltip > div > div,
.bk-tooltip-row,
div.bk-tooltip,
div.bk-tooltip > div,
.bk .bk-tooltip,
.bk-root .bk-tooltip {
  background-color: var(--card-bg) !important;
  background: var(--card-bg) !important;
  border: none !important;
  border-color: transparent !important;
  border-width: 0 !important;
  border-radius: 6px !important;
  box-shadow: var(--shadow-md) !important;
  padding: 0 !important;
  margin: 0 !important;
  outline: none !important;
}

/* Target the tooltip arrow/pointer */
.bk-tooltip::before,
.bk-tooltip::after,
.bk-tooltip > div::before,
.bk-tooltip > div::after {
  display: none !important;
  border: none !important;
  background: transparent !important;
}

/* Ensure the inner tooltip content from HTML template shows properly */
.bk-tooltip-row-label,
.bk-tooltip-row-value {
  color: var(--text-primary) !important;
  background: transparent !important;
  border: none !important;
}

/* Override any table-based tooltip styling Bokeh might use */
.bk-tooltip table,
.bk-tooltip tr,
.bk-tooltip td {
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
}

/* Target inner tooltip div to ensure no extra borders */
.bk-tooltip > div:first-child {
  background: var(--card-bg) !important;
  border: none !important;
  border-radius: 6px !important;
}

/* Plotly tooltip/hover styling */
.plotly .hoverlayer .hovertext {
  fill: var(--card-bg) !important;
  stroke: var(--border-color) !important;
}

.plotly .hoverlayer .hovertext text {
  fill: var(--text-primary) !important;
}

.plotly .hoverlayer .hovertext path {
  fill: var(--card-bg) !important;
  stroke: var(--border-color) !important;
}
