/* ============================================
   RESPONSIVE PWA STYLES
   Stock Broker Analysis Dashboard

   MOBILE-FIRST APPROACH
   ============================================ */

/* ============================================
   MOBILE STYLES (Default - for phones)
   ============================================ */

/* Navigation - Hamburger style */
.navbar {
  padding: 0.25rem 0.5rem !important;
}

.navbar-brand {
  font-size: 0.9rem !important;
  padding: 0 !important;
}

/* Hide text nav links on mobile, show as dropdown */
@media screen and (max-width: 991px) {
  .navbar-nav {
    flex-direction: column !important;
    background: #16213e;
    padding: 0.5rem;
    border-radius: 8px;
    margin-top: 0.5rem;
  }

  .nav-link {
    padding: 0.5rem 1rem !important;
    font-size: 0.85rem !important;
  }

  .navbar-toggler {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    border-color: rgba(255,255,255,0.3);
  }
}

/* Stock Selector */
@media screen and (max-width: 767px) {
  /* Container */
  .container-fluid {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }

  /* Emiten selector row */
  .row {
    margin-left: -4px !important;
    margin-right: -4px !important;
  }

  .row > [class*='col'] {
    padding-left: 4px !important;
    padding-right: 4px !important;
  }

  /* Select dropdown */
  .Select, .Select-control {
    font-size: 14px !important;
  }

  .Select-menu-outer {
    font-size: 14px !important;
  }

  /* ============================================
     CARDS - Full width, compact
     ============================================ */
  .card {
    margin-bottom: 8px !important;
    border-radius: 6px !important;
  }

  .card-header {
    padding: 0.4rem 0.6rem !important;
  }

  .card-header h5,
  .card-header .h5 {
    font-size: 0.85rem !important;
    margin: 0 !important;
  }

  .card-body {
    padding: 0.5rem !important;
  }

  /* ============================================
     SUMMARY CARDS ROW (Price, Phase, etc)
     ============================================ */
  /* Make summary cards 2 columns (50%) on mobile */
  .row > [class*='col-md-3'],
  .row > [class*='col-lg-3'],
  .row > [class*='col-xl-3'] {
    flex: 0 0 50% !important;
    max-width: 50% !important;
    padding: 2px !important;
  }

  /* Inner cards in summary */
  .card .card {
    margin-bottom: 3px !important;
    height: 100% !important;
  }

  .card .card .card-body {
    padding: 0.3rem !important;
  }

  /* Card titles - smaller font, no word break */
  .card .card h6,
  .card .card .h6 {
    font-size: 0.5rem !important;
    margin-bottom: 0.1rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  /* Card values */
  .card .card h4,
  .card .card .h4 {
    font-size: 0.7rem !important;
    margin-bottom: 0 !important;
    white-space: nowrap !important;
  }

  /* Card description text - very small */
  .card .card p,
  .card .card small {
    font-size: 0.45rem !important;
    line-height: 1.1 !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }

  /* ============================================
     TYPOGRAPHY
     ============================================ */
  h1, .h1 { font-size: 1.3rem !important; }
  h2, .h2 { font-size: 1.15rem !important; }
  h3, .h3 { font-size: 1rem !important; }
  h4, .h4 { font-size: 0.9rem !important; }
  h5, .h5 { font-size: 0.8rem !important; }
  h6, .h6 { font-size: 0.7rem !important; }

  p, .small, small {
    font-size: 0.75rem !important;
  }

  .text-muted {
    font-size: 0.7rem !important;
  }

  /* ============================================
     BADGES
     ============================================ */
  .badge {
    font-size: 0.6rem !important;
    padding: 0.2rem 0.4rem !important;
    white-space: nowrap;
  }

  /* ============================================
     BUTTONS
     ============================================ */
  .btn {
    font-size: 0.75rem !important;
    padding: 0.25rem 0.5rem !important;
  }

  .btn-sm {
    font-size: 0.65rem !important;
    padding: 0.15rem 0.35rem !important;
  }

  /* ============================================
     CHARTS - Plotly
     ============================================ */
  .js-plotly-plot {
    width: 100% !important;
  }

  .js-plotly-plot .plotly .main-svg {
    width: 100% !important;
  }

  /* Smaller modebar */
  .modebar {
    transform: scale(0.7) !important;
    transform-origin: top right !important;
  }

  .modebar-btn {
    font-size: 12px !important;
  }

  /* ============================================
     TABLES
     ============================================ */
  .table-responsive {
    font-size: 0.65rem !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .table {
    font-size: 0.65rem !important;
  }

  .table th,
  .table td {
    padding: 0.25rem 0.35rem !important;
    white-space: nowrap;
    vertical-align: middle !important;
  }

  .table thead th {
    font-size: 0.6rem !important;
    font-weight: 600 !important;
  }

  /* ============================================
     TABS
     ============================================ */
  .nav-tabs {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    border-bottom: none !important;
  }

  .nav-tabs::-webkit-scrollbar {
    display: none;
  }

  .nav-tabs .nav-link {
    font-size: 0.7rem !important;
    padding: 0.4rem 0.6rem !important;
    white-space: nowrap;
    border-radius: 4px 4px 0 0 !important;
  }

  /* ============================================
     BUY SIGNAL TRACKER
     ============================================ */
  /* Stack columns vertically */
  .buy-signal-tracker .col-md-4,
  .buy-signal-tracker .col-4 {
    flex: 0 0 100% !important;
    max-width: 100% !important;
    margin-bottom: 0.3rem;
  }

  /* ============================================
     PHASE ANALYSIS
     ============================================ */
  .phase-analysis .col-6,
  .phase-analysis .col-md-6 {
    flex: 0 0 100% !important;
    max-width: 100% !important;
  }

  /* ============================================
     ACCUMULATION CRITERIA
     ============================================ */
  .accumulation-criteria .col-md-2,
  .accumulation-criteria .col-2 {
    flex: 0 0 50% !important;
    max-width: 50% !important;
    padding: 2px !important;
  }

  /* ============================================
     ANALYSIS PAGE - Keep component cards normal
     ============================================ */
  /* Analysis component cards (A, B, C, D, E) - stay as columns */

  /* Only the "Cara Membaca" and "Scoring Reference" sections need fix */
  /* These are identified by having 3 columns of text that overlap */

  /* ============================================
     CHARTS - Keep original, just responsive width
     ============================================ */
  .js-plotly-plot {
    width: 100% !important;
  }

  /* ============================================
     DATA TABLES - Horizontal scroll
     ============================================ */
  .dash-table-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    max-width: 100% !important;
  }

  .dash-spreadsheet-container {
    overflow-x: auto !important;
  }

  .dash-table-container .dash-spreadsheet {
    font-size: 0.7rem !important;
    min-width: 500px !important;
  }

  .dash-table-container td,
  .dash-table-container th {
    padding: 0.25rem 0.4rem !important;
    white-space: nowrap !important;
  }

  /* ============================================
     TEXT CONTENT - Proper wrapping
     ============================================ */
  .card-body ul {
    padding-left: 1rem !important;
    margin-bottom: 0.5rem !important;
  }

  .card-body ul li {
    font-size: 0.7rem !important;
    margin-bottom: 0.2rem !important;
    white-space: normal !important;
  }

  .card-body small,
  .card-body .small,
  .card-body .text-muted {
    font-size: 0.65rem !important;
    white-space: normal !important;
    word-break: break-word !important;
  }

  /* ============================================
     PROGRESS BARS
     ============================================ */
  .progress {
    height: 0.6rem !important;
    font-size: 0.55rem !important;
  }

  .progress-bar {
    font-size: 0.5rem !important;
    line-height: 0.6rem !important;
  }

  /* ============================================
     ALERTS
     ============================================ */
  .alert {
    padding: 0.4rem 0.6rem !important;
    font-size: 0.75rem !important;
    margin-bottom: 0.5rem !important;
  }

  /* ============================================
     SPACING OVERRIDES
     ============================================ */
  .mb-4 { margin-bottom: 0.75rem !important; }
  .mb-3 { margin-bottom: 0.5rem !important; }
  .mb-2 { margin-bottom: 0.35rem !important; }
  .mt-4 { margin-top: 0.75rem !important; }
  .mt-3 { margin-top: 0.5rem !important; }
  .py-4 { padding-top: 0.75rem !important; padding-bottom: 0.75rem !important; }
  .py-3 { padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; }
  .px-4 { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }
  .px-3 { padding-left: 0.5rem !important; padding-right: 0.5rem !important; }

  /* ============================================
     SPECIFIC FIXES
     ============================================ */
  /* Refresh button & time */
  .refresh-section {
    font-size: 0.7rem !important;
  }

  /* Force text wrap for long content */
  .text-wrap-mobile {
    white-space: normal !important;
    word-break: break-word;
  }

  /* Hide non-essential on mobile */
  .d-none-mobile {
    display: none !important;
  }
}

/* ============================================
   TABLET STYLES (768px - 1024px)
   ============================================ */
@media screen and (min-width: 768px) and (max-width: 1024px) {
  .container-fluid {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  .card-body > .row > .col-md-3 {
    flex: 0 0 25% !important;
    max-width: 25% !important;
  }

  .card-header h5 {
    font-size: 0.95rem !important;
  }

  .table {
    font-size: 0.8rem !important;
  }
}

/* ============================================
   DESKTOP STYLES (> 1024px) - NO CHANGES
   ============================================ */
@media screen and (min-width: 1025px) {
  /* Desktop: Keep original styles */
}

/* ============================================
   PWA STANDALONE MODE
   ============================================ */
@media all and (display-mode: standalone) {
  body {
    -webkit-user-select: none;
    user-select: none;
  }

  /* Extra padding for notch/status bar */
  .navbar {
    padding-top: env(safe-area-inset-top) !important;
  }
}

/* ============================================
   TOUCH DEVICE ENHANCEMENTS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets */
  .btn, .nav-link, .dropdown-item {
    min-height: 40px;
  }

  /* Remove hover effects */
  .btn:hover, .card:hover, .nav-link:hover {
    transform: none !important;
  }

  /* Better tap feedback */
  button, a, select, input {
    -webkit-tap-highlight-color: rgba(23, 162, 184, 0.2);
  }
}

/* ============================================
   SAFE AREA (iPhone X+, Android notch)
   ============================================ */
@supports (padding: max(0px)) {
  .container-fluid {
    padding-left: max(8px, env(safe-area-inset-left)) !important;
    padding-right: max(8px, env(safe-area-inset-right)) !important;
  }

  body {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* ============================================
   LANDSCAPE PHONE
   ============================================ */
@media screen and (max-height: 500px) and (orientation: landscape) {
  .card {
    margin-bottom: 4px !important;
  }

  .card-body {
    padding: 0.35rem !important;
  }

  .navbar {
    padding: 0.15rem 0.5rem !important;
  }
}

/* ============================================
   DARK SCROLLBAR
   ============================================ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #1a1a2e;
}

::-webkit-scrollbar-thumb {
  background: #0f3460;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #17a2b8;
}

/* ============================================
   LOADING STATE
   ============================================ */
._dash-loading {
  background: #1a1a2e !important;
}

._dash-loading-callback {
  background: rgba(26, 26, 46, 0.8) !important;
}

/* ============================================
   STOCK DROPDOWN - Mobile Friendly
   ============================================ */
.stock-dropdown {
  min-width: 100px !important;
}

.stock-dropdown .Select-control {
  background-color: #16213e !important;
  border-color: #0f3460 !important;
  min-height: 36px !important;
}

.stock-dropdown .Select-value-label,
.stock-dropdown .Select-placeholder {
  color: #fff !important;
  line-height: 34px !important;
}

.stock-dropdown .Select-input input {
  color: #fff !important;
}

.stock-dropdown .Select-menu-outer {
  background-color: #16213e !important;
  border-color: #0f3460 !important;
  z-index: 9999 !important;
}

.stock-dropdown .Select-option {
  background-color: #16213e !important;
  color: #fff !important;
  padding: 10px 12px !important;
}

.stock-dropdown .Select-option:hover,
.stock-dropdown .Select-option.is-focused {
  background-color: #0f3460 !important;
}

.stock-dropdown .Select-option.is-selected {
  background-color: #17a2b8 !important;
}

/* Make dropdown touch-friendly */
@media (hover: none) and (pointer: coarse) {
  .stock-dropdown .Select-option {
    padding: 14px 12px !important;
    min-height: 44px !important;
  }

  .stock-dropdown .Select-control {
    min-height: 40px !important;
  }
}

/* ============================================
   NAVBAR MOBILE FIXES
   ============================================ */
@media screen and (max-width: 991px) {
  .navbar {
    padding: 0.3rem 0.5rem !important;
  }

  .navbar-brand {
    font-size: 0.9rem !important;
    margin-right: 0.5rem !important;
  }

  .navbar-toggler {
    padding: 0.2rem 0.4rem !important;
    font-size: 0.9rem !important;
    border: 1px solid rgba(255,255,255,0.3) !important;
  }

  .navbar-toggler-icon {
    width: 1.2em !important;
    height: 1.2em !important;
  }

  .navbar-collapse {
    background: #16213e;
    padding: 0.5rem;
    border-radius: 8px;
    margin-top: 0.5rem;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
  }

  .navbar-nav {
    flex-direction: column !important;
  }

  .navbar-nav .nav-link {
    padding: 0.6rem 1rem !important;
    border-bottom: 1px solid rgba(255,255,255,0.1);
  }

  .navbar-nav .nav-link:last-child {
    border-bottom: none;
  }

  /* Stock dropdown in navbar */
  .stock-dropdown {
    width: 90px !important;
    min-width: 90px !important;
  }

  .stock-dropdown .Select-control {
    min-height: 32px !important;
  }

  .stock-dropdown .Select-value-label {
    font-size: 0.85rem !important;
  }
}

/* ============================================
   LIGHT MODE THEME - Stockbit Style
   Clean, high contrast, professional
   ============================================ */
body.light-mode,
body.light-mode #main-container {
  background-color: #f7f7f7 !important;
  color: #333333 !important;
}

/* Navbar - Clean white */
body.light-mode .navbar,
body.light-mode .navbar-dark {
  background-color: #ffffff !important;
  border-bottom: 1px solid #e5e5e5 !important;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05) !important;
}

body.light-mode .navbar-brand {
  color: #333333 !important;
  font-weight: 600 !important;
}

body.light-mode .nav-link {
  color: #555555 !important;
}

body.light-mode .nav-link:hover,
body.light-mode .nav-link.active {
  color: #000000 !important;
}

/* Container */
body.light-mode .container-fluid {
  background-color: #f7f7f7 !important;
}

/* Cards - Blend with page, text contrasts */
body.light-mode .card {
  background-color: #f7f7f7 !important;
  color: #1a1a1a !important;
  border: none !important;
  border-radius: 8px !important;
  box-shadow: none !important;
}

body.light-mode .card-header {
  background-color: #f7f7f7 !important;
  color: #1a1a1a !important;
  border-bottom: 1px solid #e0e0e0 !important;
  font-weight: 600 !important;
}

body.light-mode .card-body {
  background-color: #f7f7f7 !important;
  color: #1a1a1a !important;
}

/* Tables - Clean and readable */
body.light-mode .table,
body.light-mode .table-dark,
body.light-mode .dash-table-container {
  background-color: #f7f7f7 !important;
  color: #1a1a1a !important;
}

body.light-mode .table th,
body.light-mode table th {
  background-color: #eeeeee !important;
  color: #1a1a1a !important;
  font-weight: 600 !important;
  border-bottom: 2px solid #d0d0d0 !important;
  text-transform: uppercase !important;
  font-size: 0.75rem !important;
  letter-spacing: 0.5px !important;
}

body.light-mode table td {
  background-color: #f7f7f7 !important;
  border-bottom: 1px solid #e0e0e0 !important;
}

body.light-mode .table td,
body.light-mode .table-dark td {
  background-color: #f7f7f7 !important;
  color: #1a1a1a !important;
  border-bottom: 1px solid #e0e0e0 !important;
}

body.light-mode .table-dark th {
  background-color: #eeeeee !important;
  color: #1a1a1a !important;
}

body.light-mode .table tbody tr:hover,
body.light-mode .table-hover tbody tr:hover,
body.light-mode .table-dark tbody tr:hover,
body.light-mode .table.table-dark.table-hover tbody tr:hover {
  background-color: #ffe5cc !important;
  color: #333333 !important;
}

body.light-mode .table tbody tr:hover td,
body.light-mode .table-hover tbody tr:hover td,
body.light-mode .table-dark tbody tr:hover td,
body.light-mode .table.table-sm.table-dark.table-hover tbody tr:hover td {
  background-color: #ffe5cc !important;
  color: #333333 !important;
}

/* Force override Bootstrap table-dark in light mode */
body.light-mode table.table-dark,
body.light-mode .table.table-dark {
  --bs-table-bg: #f7f7f7 !important;
  --bs-table-striped-bg: #eeeeee !important;
  --bs-table-hover-bg: #ffe5cc !important;
  background-color: #f7f7f7 !important;
}

body.light-mode table.table-dark tbody tr,
body.light-mode .table.table-dark tbody tr {
  background-color: #f7f7f7 !important;
}

body.light-mode table.table-dark tbody tr:hover,
body.light-mode .table.table-dark tbody tr:hover {
  background-color: #ffe5cc !important;
}

body.light-mode table.table-dark tbody tr:hover td,
body.light-mode .table.table-dark tbody tr:hover td,
body.light-mode table.table-dark tbody tr:hover th,
body.light-mode .table.table-dark tbody tr:hover th {
  background-color: #ffe5cc !important;
  color: #333333 !important;
}

/* Dark mode table hover - lighter gray */
.table-dark tbody tr:hover,
.table.table-dark tbody tr:hover,
.table-hover tbody tr:hover {
  background-color: #4a4a4a !important;
}

.table-dark tbody tr:hover td,
.table.table-dark tbody tr:hover td {
  background-color: #4a4a4a !important;
}

/* Text colors - High contrast */
body.light-mode .text-muted {
  color: #888888 !important;
}

body.light-mode .text-white {
  color: #333333 !important;
}

body.light-mode .text-info {
  color: #0066cc !important;
}

body.light-mode h1, body.light-mode h2, body.light-mode h3,
body.light-mode h4, body.light-mode h5, body.light-mode h6,
body.light-mode .h1, body.light-mode .h2, body.light-mode .h3,
body.light-mode .h4, body.light-mode .h5, body.light-mode .h6 {
  color: #222222 !important;
}

body.light-mode p, body.light-mode span, body.light-mode div,
body.light-mode label, body.light-mode small {
  color: #333333 !important;
}

/* Override inline white color styles */
body.light-mode [style*="color: white"],
body.light-mode [style*="color:#fff"],
body.light-mode [style*="color: #fff"],
body.light-mode [style*="color:#ffffff"],
body.light-mode [style*="color: #ffffff"] {
  color: #333333 !important;
}

/* Keep colored text visible */
body.light-mode .text-success,
body.light-mode span.text-success,
body.light-mode .metric-box .text-success,
body.light-mode .metric-box span.text-success,
body.light-mode .info-box .text-success {
  color: #198754 !important;
}

body.light-mode .text-danger,
body.light-mode span.text-danger,
body.light-mode .metric-box .text-danger,
body.light-mode .metric-box span.text-danger,
body.light-mode .info-box .text-danger {
  color: #dc3545 !important;
}

body.light-mode .text-warning { color: #cc8800 !important; }
body.light-mode .text-primary { color: #0066cc !important; }

/* Alerts - Subtle backgrounds */
body.light-mode .alert {
  border-radius: 6px !important;
}

body.light-mode .alert-info {
  background-color: #e8f4fd !important;
  color: #0c5460 !important;
  border: 1px solid #bee5eb !important;
}

body.light-mode .alert-warning {
  background-color: #fff8e6 !important;
  color: #856404 !important;
  border: 1px solid #ffeeba !important;
}

body.light-mode .alert-success {
  background-color: #e8f5e9 !important;
  color: #155724 !important;
  border: 1px solid #c3e6cb !important;
}

body.light-mode .alert-danger {
  background-color: #fdecea !important;
  color: #721c24 !important;
  border: 1px solid #f5c6cb !important;
}

/* Badges */
body.light-mode .badge-success,
body.light-mode .bg-success,
body.light-mode .badge.bg-success {
  background-color: #198754 !important;
  color: #ffffff !important;
}
body.light-mode .badge-danger,
body.light-mode .bg-danger,
body.light-mode .badge.bg-danger {
  background-color: #dc3545 !important;
  color: #ffffff !important;
}
body.light-mode .badge-warning,
body.light-mode .bg-warning,
body.light-mode .badge.bg-warning {
  background-color: #ffc107 !important;
  color: #333333 !important;
}
body.light-mode .badge-info,
body.light-mode .bg-info,
body.light-mode .badge.bg-info {
  background-color: #17a2b8 !important;
  color: #ffffff !important;
}

/* Buttons */
body.light-mode .btn-primary {
  background-color: #0066cc !important;
  border-color: #0066cc !important;
}

body.light-mode .btn-info {
  background-color: #17a2b8 !important;
  border-color: #17a2b8 !important;
  color: #fff !important;
}

body.light-mode .btn-outline-info {
  color: #17a2b8 !important;
  border-color: #17a2b8 !important;
}

/* Forms & Inputs */
body.light-mode input,
body.light-mode select,
body.light-mode textarea,
body.light-mode .form-control {
  background-color: #ffffff !important;
  color: #333333 !important;
  border: 1px solid #dddddd !important;
  border-radius: 4px !important;
}

body.light-mode input:focus,
body.light-mode .form-control:focus {
  border-color: #0066cc !important;
  box-shadow: 0 0 0 2px rgba(0,102,204,0.1) !important;
}

/* Dropdown - Clean style */
body.light-mode .Select-control,
body.light-mode .stock-dropdown .Select-control {
  background-color: #ffffff !important;
  border: 1px solid #dddddd !important;
  border-radius: 4px !important;
}

body.light-mode .Select-value-label,
body.light-mode .stock-dropdown .Select-value-label,
body.light-mode .Select-placeholder {
  color: #333333 !important;
}

body.light-mode .Select-menu-outer,
body.light-mode .stock-dropdown .Select-menu-outer {
  background-color: #ffffff !important;
  border: 1px solid #dddddd !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1) !important;
}

body.light-mode .Select-option {
  background-color: #ffffff !important;
  color: #333333 !important;
}

body.light-mode .Select-option:hover,
body.light-mode .Select-option.is-focused {
  background-color: #f5f5f5 !important;
}

body.light-mode .Select-option.is-selected {
  background-color: #e6f0ff !important;
  color: #0066cc !important;
}

/* Progress bars */
body.light-mode .progress {
  background-color: #e9ecef !important;
  border-radius: 4px !important;
}

/* Scrollbar - Subtle */
body.light-mode ::-webkit-scrollbar {
  width: 8px !important;
  height: 8px !important;
}

body.light-mode ::-webkit-scrollbar-track {
  background: #f1f1f1 !important;
}

body.light-mode ::-webkit-scrollbar-thumb {
  background: #cccccc !important;
  border-radius: 4px !important;
}

body.light-mode ::-webkit-scrollbar-thumb:hover {
  background: #999999 !important;
}

/* Plotly charts - Keep dark template intact in light mode */
/* Charts will have dark background even in light mode for visibility */

/* Dash DataTable */
body.light-mode .dash-spreadsheet-container {
  background: #f7f7f7 !important;
}

/* Dark mode (default) DataTable */
.dash-header {
  color: white;  /* Default dark mode text */
}

.dash-cell {
  color: white;  /* Default dark mode text */
}

body.light-mode .dash-header {
  background-color: #eeeeee !important;
  color: #1a1a1a !important;
}

body.light-mode .dash-cell {
  background-color: #f7f7f7 !important;
  color: #1a1a1a !important;
  border-color: #e0e0e0 !important;
}

/* ============================================
   METRIC BOX & INFO BOX - Theme Responsive
   ============================================ */
/* Dark mode (default) */
.metric-box {
  background-color: #383838;
  color: #ffffff;
}

.info-box {
  background-color: #2a2a2a;
  color: #ffffff;
}

/* Light mode */
body.light-mode .metric-box,
body.light-mode div.metric-box,
body.light-mode .card .metric-box,
body.light-mode .card-body .metric-box {
  background-color: #e8e8e8 !important;
  color: #1a1a1a !important;
  border: 1px solid #d0d0d0 !important;
}

body.light-mode .info-box,
body.light-mode div.info-box,
body.light-mode .card .info-box,
body.light-mode .card-body .info-box {
  background-color: #eeeeee !important;
  color: #1a1a1a !important;
  border: 1px solid #d0d0d0 !important;
}

body.light-mode .metric-box .text-muted,
body.light-mode .info-box .text-muted {
  color: #555555 !important;
}

body.light-mode .metric-box h4,
body.light-mode .metric-box h5,
body.light-mode .metric-box .h4,
body.light-mode .metric-box .h5,
body.light-mode .metric-box span:not(.text-success):not(.text-danger):not(.text-warning):not(.text-info):not(.broker-foreign):not(.broker-bumn):not(.broker-local):not(.broker-badge):not(.broker-badge-foreign):not(.broker-badge-bumn):not(.broker-badge-local),
body.light-mode .info-box span:not(.text-success):not(.text-danger):not(.text-warning):not(.text-info):not(.phase-accumulation):not(.phase-markup):not(.phase-distribution):not(.phase-markdown) {
  color: #1a1a1a !important;
}

/* ============================================
   ALERT BOXES - Theme Responsive
   ============================================ */
/* Dark mode (default) */
.alert-box-success {
  background-color: #2d3a2d;
  color: #ffffff;
}

.alert-box-danger {
  background-color: #3a2d2d;
  color: #ffffff;
}

.alert-box-warning {
  background-color: #3a3a2d;
  color: #ffffff;
}

/* Light mode */
body.light-mode .alert-box-success {
  background-color: #d4edda !important;
  color: #155724 !important;
  border: 1px solid #c3e6cb !important;
}

body.light-mode .alert-box-danger {
  background-color: #f8d7da !important;
  color: #721c24 !important;
  border: 1px solid #f5c6cb !important;
}

body.light-mode .alert-box-warning {
  background-color: #fff3cd !important;
  color: #856404 !important;
  border: 1px solid #ffeeba !important;
}

body.light-mode .alert-box-success .text-success {
  color: #155724 !important;
}
body.light-mode .alert-box-danger .text-danger {
  color: #721c24 !important;
}
body.light-mode .alert-box-warning .text-warning {
  color: #856404 !important;
}

/* ============================================
   OVERRIDE BOOTSTRAP DARK CARDS IN LIGHT MODE
   ============================================ */
body.light-mode .card.bg-dark,
body.light-mode .card[class*="border-dark"],
body.light-mode .card.text-white {
  background-color: #f7f7f7 !important;
  color: #1a1a1a !important;
  border-color: #e0e0e0 !important;
}

body.light-mode .bg-dark,
body.light-mode [style*="background-color: rgb(45"],
body.light-mode [style*="background-color: rgb(48"],
body.light-mode [style*="backgroundColor"]:not(.alert-box-success):not(.alert-box-danger):not(.alert-box-warning) {
  background-color: #e8e8e8 !important;
}

body.light-mode .card.bg-dark .text-white,
body.light-mode .card.bg-dark .text-muted {
  color: #555555 !important;
}

/* Override dbc.Alert color="dark" */
body.light-mode .alert-dark {
  background-color: #e8e8e8 !important;
  color: #1a1a1a !important;
  border-color: #d0d0d0 !important;
}

/* ============================================
   FORCE LIGHT BACKGROUNDS FOR ALL DARK ELEMENTS
   ============================================ */
body.light-mode .rounded.p-2,
body.light-mode .rounded.p-2.mb-2,
body.light-mode div.rounded.p-2,
body.light-mode div.mb-2.p-2.rounded {
  background-color: #e8e8e8 !important;
  color: #1a1a1a !important;
}

body.light-mode .border.rounded.p-2 {
  background-color: #e8e8e8 !important;
  color: #1a1a1a !important;
  border-color: #d0d0d0 !important;
}

/* Target all divs with dark inline backgrounds */
body.light-mode div[style*="background"] {
  background-color: #e8e8e8 !important;
}

/* Badge percentage styling */
body.light-mode .badge.bg-secondary,
body.light-mode .badge[style*="background"] {
  background-color: #ff9800 !important;
  color: #000000 !important;
  font-weight: 700 !important;
}

/* ============================================
   DATATABLE LIGHT MODE - OVERRIDE INLINE STYLES
   ============================================ */
body.light-mode .dash-spreadsheet-container,
body.light-mode .dash-spreadsheet,
body.light-mode .dash-table-container {
  background-color: #f7f7f7 !important;
}

body.light-mode .dash-spreadsheet td,
body.light-mode .dash-spreadsheet th,
body.light-mode td.dash-cell,
body.light-mode th.dash-header,
body.light-mode .dash-cell,
body.light-mode .dash-header,
body.light-mode .dash-cell div,
body.light-mode .dash-header div,
body.light-mode .cell-value,
body.light-mode .cell-table,
body.light-mode .cell-markdown {
  background-color: #f7f7f7 !important;
  color: #1a1a1a !important;
  border-color: #e0e0e0 !important;
}

body.light-mode .dash-spreadsheet tr:nth-child(odd) td,
body.light-mode .dash-spreadsheet tr:nth-child(odd) .dash-cell {
  background-color: #eeeeee !important;
}

body.light-mode .dash-spreadsheet th.dash-header,
body.light-mode th.dash-header {
  background-color: #e0e0e0 !important;
  font-weight: 600 !important;
}

/* Fix filter inputs in DataTable */
body.light-mode .dash-spreadsheet input,
body.light-mode .dash-filter {
  background-color: #ffffff !important;
  color: #333333 !important;
  border: 1px solid #cccccc !important;
}

/* Keep conditional formatting colors visible */
body.light-mode td[style*="background-color: rgb(40, 167, 69)"],
body.light-mode td[style*="background-color: #28a745"] {
  background-color: #28a745 !important;
  color: #ffffff !important;
}

body.light-mode td[style*="background-color: rgb(220, 53, 69)"],
body.light-mode td[style*="background-color: #dc3545"] {
  background-color: #dc3545 !important;
  color: #ffffff !important;
}

body.light-mode td[style*="background-color: rgb(111, 66, 193)"],
body.light-mode td[style*="background-color: #6f42c1"] {
  background-color: #6f42c1 !important;
  color: #ffffff !important;
}

/* Keep broker text colors visible in light mode (without background) */
body.light-mode td[style*="color: rgb(220, 53, 69)"],
body.light-mode td[style*="color: #dc3545"],
body.light-mode .dash-cell[style*="color: rgb(220, 53, 69)"],
body.light-mode .dash-cell[style*="color: #dc3545"] {
  color: #dc3545 !important;
}

body.light-mode td[style*="color: rgb(40, 167, 69)"],
body.light-mode td[style*="color: #28a745"],
body.light-mode .dash-cell[style*="color: rgb(40, 167, 69)"],
body.light-mode .dash-cell[style*="color: #28a745"] {
  color: #28a745 !important;
}

body.light-mode td[style*="color: rgb(111, 66, 193)"],
body.light-mode td[style*="color: #6f42c1"],
body.light-mode .dash-cell[style*="color: rgb(111, 66, 193)"],
body.light-mode .dash-cell[style*="color: #6f42c1"] {
  color: #6f42c1 !important;
}

/* ============================================
   ADDITIONAL LIGHT MODE OVERRIDES
   ============================================ */
body.light-mode .text-center.py-2[style*="background"],
body.light-mode div[style*="backgroundColor"][style*="borderRadius"] {
  background-color: #e8e8e8 !important;
  color: #1a1a1a !important;
}

/* ============================================
   PHASE ANALYSIS COLORS - High Priority
   ============================================ */
.phase-accumulation,
body.light-mode .phase-accumulation,
body.light-mode .phase-accumulation * {
  color: #17a2b8 !important;
}

.phase-markup,
body.light-mode .phase-markup,
body.light-mode .phase-markup * {
  color: #28a745 !important;
}

.phase-distribution,
body.light-mode .phase-distribution,
body.light-mode .phase-distribution * {
  color: #ffc107 !important;
}

.phase-markdown,
body.light-mode .phase-markdown,
body.light-mode .phase-markdown * {
  color: #dc3545 !important;
}

.phase-unknown,
body.light-mode .phase-unknown,
body.light-mode .phase-unknown * {
  color: #6c757d !important;
}

/* ============================================
   UPLOAD AREA - Theme Responsive
   ============================================ */
.upload-area {
  background-color: #2a2a2a;
  border-color: #555555 !important;
}

body.light-mode .upload-area {
  background-color: #f0f0f0 !important;
  border-color: #cccccc !important;
  color: #333333 !important;
}

/* ============================================
   BROKER TYPE COLORS - High Priority
   Must override body.light-mode span rule
   ============================================ */
.broker-foreign,
span.broker-foreign,
body.light-mode .broker-foreign,
body.light-mode span.broker-foreign,
body.light-mode td .broker-foreign,
body.light-mode td span.broker-foreign,
body.light-mode .table .broker-foreign,
body.light-mode .table span.broker-foreign {
  color: #dc3545 !important;
  font-weight: bold !important;
  font-size: 13px;  /* Desktop size */
}

.broker-bumn,
span.broker-bumn,
body.light-mode .broker-bumn,
body.light-mode span.broker-bumn,
body.light-mode td .broker-bumn,
body.light-mode td span.broker-bumn,
body.light-mode .table .broker-bumn,
body.light-mode .table span.broker-bumn {
  color: #28a745 !important;
  font-weight: bold !important;
  font-size: 13px;  /* Desktop size */
}

.broker-local,
span.broker-local,
body.light-mode .broker-local,
body.light-mode span.broker-local,
body.light-mode td .broker-local,
body.light-mode td span.broker-local,
body.light-mode .table .broker-local,
body.light-mode .table span.broker-local {
  color: #6f42c1 !important;
  font-weight: bold !important;
  font-size: 13px;  /* Desktop size */
}

/* Broker Badge - white text on colored background */
.broker-badge,
span.broker-badge,
body.light-mode .broker-badge,
body.light-mode span.broker-badge {
  color: #ffffff !important;
  font-weight: 700 !important;
  font-size: 12px !important;
  padding: 3px 8px !important;
  border-radius: 4px !important;
  display: inline-block !important;
}

/* Large broker badge for cards */
.broker-badge-lg,
span.broker-badge-lg,
body.light-mode .broker-badge-lg,
body.light-mode span.broker-badge-lg {
  color: #ffffff !important;
  font-weight: 700 !important;
  font-size: 1.75rem !important;
  padding: 10px 24px !important;
  border-radius: 6px !important;
  display: inline-block !important;
}

.broker-badge-foreign {
  background-color: #dc3545 !important;
}

.broker-badge-bumn {
  background-color: #28a745 !important;
}

.broker-badge-local {
  background-color: #6f42c1 !important;
}

/* Mobile/PWA - keep smaller font */
@media screen and (max-width: 767px) {
  .broker-foreign,
  .broker-bumn,
  .broker-local {
    font-size: 11px !important;
  }
  .broker-badge {
    font-size: 10px !important;
    padding: 2px 6px !important;
  }
}

/* ============================================
   TABLE HEADER & CELL CLASSES
   ============================================ */
/* Dark mode (default) */
.table-header {
  background-color: #404040 !important;
  color: white !important;
  padding: 6px 8px !important;
  font-size: 11px !important;
  font-weight: bold !important;
  border-bottom: 1px solid #555 !important;
}

.table-cell {
  background-color: #303030 !important;
  color: white;  /* No !important - allow inline style override */
  padding: 5px 8px !important;
  font-size: 11px !important;
  border-bottom: 1px solid #444 !important;
}

/* Light mode */
body.light-mode .table-header {
  background-color: #e8e8e8 !important;
  color: #1a1a1a !important;
  border-bottom: 2px solid #d0d0d0 !important;
}

body.light-mode .table-cell {
  background-color: #f7f7f7 !important;
  color: #333333;  /* No !important - allow inline style override */
  border-bottom: 1px solid #e0e0e0 !important;
}

/* ============================================
   COMPREHENSIVE LIGHT MODE TEXT FIX
   Ensure all text is visible on light background
   ============================================ */

/* Force all elements to have dark text in light mode */
body.light-mode * {
  --text-color: #333333;
}

/* Fix Bootstrap text-white class */
body.light-mode .text-white,
body.light-mode .text-light {
  color: #333333 !important;
}

/* Fix any remaining white text from inline styles or other sources */
body.light-mode .card *,
body.light-mode .container-fluid *,
body.light-mode .row * {
  color: inherit;
}

/* Ensure text is visible in all common containers */
body.light-mode .card-body > *,
body.light-mode .card-header > *,
body.light-mode .metric-box > *,
body.light-mode .info-box > *,
body.light-mode .alert > * {
  color: inherit;
}

/* Make sure numbers and values are dark */
body.light-mode .display-4,
body.light-mode .display-5,
body.light-mode .display-6,
body.light-mode .lead,
body.light-mode strong,
body.light-mode b {
  color: #1a1a1a !important;
}

/* Fix potential Plotly/Chart text issues */
body.light-mode .gtitle,
body.light-mode .xtitle,
body.light-mode .ytitle {
  fill: #333333 !important;
}

/* Navbar brand and links in light mode */
body.light-mode .navbar *:not(.badge) {
  color: #333333;
}

body.light-mode .navbar .nav-link {
  color: #555555 !important;
}

body.light-mode .navbar .nav-link:hover,
body.light-mode .navbar .nav-link.active {
  color: #000000 !important;
}

/* Fix dropdown text in navbar */
body.light-mode .navbar .dropdown-menu {
  background-color: #ffffff !important;
}

body.light-mode .navbar .dropdown-item {
  color: #333333 !important;
}

body.light-mode .navbar .dropdown-item:hover {
  background-color: #f5f5f5 !important;
}

/* ============================================
   NAVBAR MENU BUTTONS - Orange with White Text
   ============================================ */
.navbar .btn-warning {
  background-color: #ff9800 !important;
  border-color: #ff9800 !important;
  color: #ffffff !important;
  font-weight: bold !important;
}

.navbar .btn-warning:hover {
  background-color: #e68900 !important;
  border-color: #e68900 !important;
  color: #ffffff !important;
}

/* Light mode navbar buttons */
body.light-mode .navbar .btn-warning {
  background-color: #ff9800 !important;
  border-color: #ff9800 !important;
  color: #ffffff !important;
}

body.light-mode .navbar .btn-warning:hover {
  background-color: #e68900 !important;
  border-color: #e68900 !important;
}
