/* Global Overrides */
:root {
  --trex-bg: #F8F9FA;
  --trex-card-bg: #FFFFFF;
  --trex-text: #5e5873;
  --trex-text-muted: #b9b9c3;
  --trex-primary: #7367F0;
  /* Purple */
  --trex-success: #28C76F;
  /* Green */
  --trex-danger: #EA5455;
  /* Red */
  --trex-warning: #FF9F43;
  /* Orange */
  --trex-info: #00CFE8;
  /* Blue/Cyan */
  --trex-border-radius: 0.5rem;
  --trex-shadow: 0 4px 24px 0 rgba(34, 41, 47, 0.1);
  --bs-body-bg: var(--trex-bg);
  --bs-body-color: var(--trex-text);

  /* Login Page Defaults */
  --trex-login-left-bg: linear-gradient(135deg, #e0efff 0%, #f0f4f8 100%);
  --trex-login-right-bg: #FFFFFF;
  --trex-login-input-bg: #f8f9fa;
  --trex-login-text: #212529;

  /* Header & Overlay Defaults */
  --trex-block-bg: #FFFFFF;
  /* Used for headers, overlays */

  /* Status Row Backgrounds */
  --trex-bg-running: #f0fdf4;
  --trex-bg-stopped: #fceaea;
}

[data-bs-theme="dark"] {
  --trex-bg: #161d31;
  /* Dark background */
  --trex-card-bg: #283046;
  /* Dark card background */
  --trex-text: #d0d2d6;
  /* Light text */
  --trex-text-muted: #676d7d;
  --trex-shadow: 0 4px 24px 0 rgba(0, 0, 0, 0.24);

  --bs-body-bg: var(--trex-bg);
  --bs-body-color: var(--trex-text);

  /* Bootstrap Overrides for Dark Mode if needed */
  --bs-link-color: #7367F0;
  --bs-link-hover-color: #8278f2;

  /* Login Page Dark Mode */
  --trex-login-left-bg: linear-gradient(135deg, #161d31 0%, #283046 100%);
  --trex-login-right-bg: #161d31;
  --trex-login-input-bg: #283046;
  --trex-login-text: #d0d2d6;

  /* Header & Overlay Dark Mode */
  --trex-block-bg: #283046;

  /* Status Row Dark Mode */
  --trex-bg-running: rgba(40, 199, 111, 0.2);
  --trex-bg-stopped: rgba(234, 84, 85, 0.2);
}

/* Button Theming - Dark Mode Override for btn-light to avoid white blocks */
[data-bs-theme="dark"] .btn-light {
  background-color: #343d55;
  border-color: #343d55;
  color: #d0d2d6;
}

[data-bs-theme="dark"] .btn-light:hover {
  background-color: #3b4253;
  border-color: #3b4253;
}

[data-bs-theme="dark"] .btn-ghost-secondary {
  color: var(--trex-text);
}

[data-bs-theme="dark"] .btn-ghost-primary {
  color: var(--trex-text);
}

[data-bs-theme="dark"] .btn-ghost-primary:hover {
  background-color: rgba(115, 103, 240, 0.1);
  color: var(--trex-primary);
}

[data-bs-theme="dark"] .btn-ghost-secondary:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: #fff;
}

[data-bs-theme="dark"] .fill-text-primary {
  fill: #d0d2d6;
}

[data-bs-theme="dark"] .fill-text-secondary {
  fill: #b4b7bd;
}

/* Chart SVG Theme Support */
.fill-chart-bg {
  fill: rgba(40, 199, 111, 0.2);
}

.stroke-chart-line {
  stroke: #28C76F;
}

[data-bs-theme="dark"] .fill-chart-bg {
  fill: rgba(40, 199, 111, 0.15);
}

[data-bs-theme="dark"] .stroke-chart-line {
  stroke: #28C76F;
}

/* Keep vibrant in dark */

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--trex-bg);
}

a {
  text-decoration: none;
}

/* Theme Utilities */
.bg-surface-theme {
  background-color: var(--trex-block-bg) !important;
}

/* Overlay Theme Support */
.loading-overlay {
  background: transparent;
  border-radius: var(--trex-border-radius, 0.5rem);
  align-items: flex-start !important;
}

.loading-overlay .loading-spinner-pill {
  background: linear-gradient(135deg, #7367F0, #5A4FD4);
  border: none;
  border-radius: 50rem;
  padding: 14px 32px;
  box-shadow: 0 8px 32px rgba(115, 103, 240, 0.35), 0 2px 8px rgba(115, 103, 240, 0.15);
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 45vh;
  color: #fff;
}

.loading-overlay .loading-spinner-pill .spinner-border {
  color: #fff !important;
}

.loading-overlay .loading-spinner-pill span {
  color: #fff !important;
}

[data-bs-theme="dark"] .loading-overlay {
  background: transparent !important;
}

[data-bs-theme="dark"] .loading-overlay .loading-spinner-pill {
  background: linear-gradient(135deg, #7367F0, #5A4FD4);
  border: none;
  box-shadow: 0 8px 32px rgba(115, 103, 240, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Skeleton Loading Placeholders */
@keyframes skeleton-shimmer {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}

.skeleton-line {
  background: rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
}

.skeleton-circle {
  background: rgba(0, 0, 0, 0.08);
  border-radius: 50%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
}

[data-bs-theme="dark"] .skeleton-line {
  background: rgba(255, 255, 255, 0.08);
}

[data-bs-theme="dark"] .skeleton-circle {
  background: rgba(255, 255, 255, 0.08);
}

/* Sortable table headers */
.sortable-th:hover { background: rgba(0,0,0,0.03); }
[data-bs-theme="dark"] .sortable-th:hover { background: rgba(255,255,255,0.05); }

/* Production Dashboard — Responsive Filter Bar */
.pd-filter-bar {
  border-radius: 12px;
}

@media (min-width: 768px) {
  .pd-filter-bar {
    display: inline-block;
    border-radius: 50px;
  }
}

/* Mobile collapsible filters */
.pd-filters-mobile {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease;
  opacity: 0;
}

.pd-filters-mobile.pd-filters-open {
  max-height: 300px;
  opacity: 1;
}

/* Card Styling */
.card-trex {
  background-color: var(--trex-card-bg);
  border: none;
  border-radius: var(--trex-border-radius);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  /* Softer shadow initially */
  transition: all 0.3s ease-in-out;
  margin-bottom: 1.5rem;
}

.card-trex:hover {
  box-shadow: var(--trex-shadow);
  transform: translateY(-2px);
}

.card-trex .card-body {
  padding: 1.5rem;
}

/* Typography Utilities */
.text-primary-trex {
  color: var(--trex-primary) !important;
}

.text-success-trex {
  color: var(--trex-success) !important;
}

.text-danger-trex {
  color: var(--trex-danger) !important;
}

.text-muted-trex {
  color: var(--trex-text-muted) !important;
}

.text-navy-trex {
  color: #2c3e50 !important;
  /* Navy Blue */
}

[data-bs-theme="dark"] .text-navy-trex {
  color: #a6c5e8 !important;
  /* Light Steel Blue for Dark Mode */
}

.text-title-trex {
  background: linear-gradient(135deg, #2563eb, #3b82f6, #3dae2b) !important;
  -webkit-background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  background-clip: text !important;
}

[data-bs-theme="dark"] .text-title-trex {
  background: linear-gradient(135deg, #60a5fa, #93c5fd, #6ee7b7) !important;
  -webkit-background-clip: text !important;
  -webkit-text-fill-color: transparent !important;
  background-clip: text !important;
}

.fw-bolder {
  font-weight: 600 !important;
}

.fw-bold {
  font-weight: 500 !important;
}

/* Status Indicators */
.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
}

.status-dot.running {
  background-color: var(--trex-success);
  box-shadow: 0 0 6px var(--trex-success);
}

.status-dot.stopped {
  background-color: var(--trex-danger);
  opacity: 0.8;
}

.status-dot.idle {
  background-color: var(--trex-warning);
}

/* Custom Components */
.section-header-pill {
  width: 4px;
  height: 24px;
  background-color: var(--trex-primary);
  border-radius: 2px;
  display: inline-block;
  vertical-align: middle;
  margin-right: 0.5rem;
}

.btn-pill-light {
  background-color: #fceaea;
  /* Mock red light */
  color: var(--trex-danger);
  border-radius: 20px;
  font-size: 0.8rem;
  padding: 0.2rem 0.8rem;
}

.header-meta {
  font-size: 0.8rem;
  color: var(--trex-text-muted);
}

/* Progress Bars custom */
.progress-slim {
  height: 6px;
  border-radius: 3px;
  background-color: #f1f1f2;
}

[data-bs-theme="dark"] .progress-slim {
  background-color: #404656;
}

/* Select2 Dark Mode Support */
[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection {
  background-color: #343d55 !important;
  border-color: #343d55 !important;
  color: #d0d2d6 !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__rendered {
  color: #d0d2d6 !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__arrow b {
  border-color: #d0d2d6 transparent transparent transparent !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown {
  background-color: #283046 !important;
  border-color: #343d55 !important;
  color: #d0d2d6 !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-search__field {
  background-color: #343d55 !important;
  border-color: #343d55 !important;
  color: #d0d2d6 !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option {
  color: #d0d2d6 !important;
  background-color: #283046;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option--highlighted {
  background-color: #7367F0 !important;
  color: #FFFFFF !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-results__option[aria-selected="true"] {
  background-color: #343d55 !important;
  color: #FFFFFF !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__choice {
  background-color: rgba(115, 103, 240, 0.15) !important;
  border-color: rgba(115, 103, 240, 0.3) !important;
  color: #a6c5e8 !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__choice__remove {
  color: #a6c5e8 !important;
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection__choice__remove:hover {
  background-color: rgba(115, 103, 240, 0.25) !important;
  color: #FFFFFF !important;
}

/* FIX: Ensure Dropdown Menus (like Other Dashboards) are above the Loading Overlay */
.dropdown-menu {
  z-index: 2000 !important;
  /* Higher than loading overlay */
}

/* FIX: Active Dropdown items in Dark Mode should be readable */
[data-bs-theme="dark"] .dropdown-menu .dropdown-item.active {
  color: #ffffff !important;
  background-color: var(--trex-primary) !important;
}

/* SweetAlert2 Top-Center Position (below main navbar) */
.swal2-container.swal2-top {
  padding-top: 4.5rem !important;
  /* clears navbar height */
}

/* What-If Playground: Financial Model Documentation — wide modal, no vertical overflow (body scrolls) */
.swal2-popup.wi-fin-doc-swal-popup {
  width: min(920px, calc(100vw - 32px)) !important;
  max-width: calc(100vw - 32px) !important;
  max-height: min(88vh, calc(100dvh - 6.5rem)) !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  overflow: hidden !important;
  box-sizing: border-box !important;
}

.swal2-popup.wi-fin-doc-swal-popup .swal2-header {
  flex-shrink: 0;
}

.swal2-popup.wi-fin-doc-swal-popup .swal2-icon {
  flex-shrink: 0;
}

.swal2-popup.wi-fin-doc-swal-popup .swal2-title {
  flex-shrink: 0;
}

.swal2-popup.wi-fin-doc-swal-popup .swal2-html-container {
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  margin-top: 0.35em !important;
  padding-right: 0.4rem !important;
  -webkit-overflow-scrolling: touch;
}

.swal2-popup.wi-fin-doc-swal-popup .swal2-actions {
  flex-shrink: 0 !important;
  margin-top: 0.75em !important;
}

[data-bs-theme="dark"] .swal2-popup.wi-fin-doc-swal-popup .swal2-html-container {
  color: #b4b7bd !important;
}

/* SweetAlert2 Dark Mode Support */
[data-bs-theme="dark"] .swal2-popup {
  background-color: #283046 !important;
  color: #d0d2d6 !important;
}

[data-bs-theme="dark"] .swal2-title {
  color: #d0d2d6 !important;
}

[data-bs-theme="dark"] .swal2-html-container,
[data-bs-theme="dark"] .swal2-content {
  color: #b4b7bd !important;
}

[data-bs-theme="dark"] .swal2-input,
[data-bs-theme="dark"] .swal2-textarea,
[data-bs-theme="dark"] .swal2-select {
  background-color: #343d55 !important;
  border-color: #404656 !important;
  color: #d0d2d6 !important;
}

[data-bs-theme="dark"] .swal2-input::placeholder {
  color: #676d7d !important;
}

[data-bs-theme="dark"] .swal2-validation-message {
  background-color: #343d55 !important;
  color: #d0d2d6 !important;
}

[data-bs-theme="dark"] .swal2-close {
  color: #d0d2d6 !important;
}

[data-bs-theme="dark"] .swal2-close:hover {
  color: #fff !important;
}

[data-bs-theme="dark"] .swal2-input-label {
  color: #b4b7bd !important;
}

/* ============================
   Embedded Modals
   ============================ */

/* Full-screen mode: leave space on all 4 sides instead of edge-to-edge */
#embeddedModalView .modal-dialog.modal-fullscreen {
  margin: 1.5rem;
  width: calc(100% - 3rem);
  max-width: calc(100% - 3rem);
  height: calc(100% - 3rem);
  max-height: calc(100% - 3rem);
  border-radius: var(--trex-border-radius);
}

#embeddedModalView .modal-dialog.modal-fullscreen .modal-content {
  border-radius: var(--trex-border-radius);
}

/* Edit button hover in card dropdown menus */
.embedded-modal-edit-btn {
  opacity: 0.5;
  transition: opacity 0.2s, color 0.2s;
}

.embedded-modal-edit-btn:hover {
  opacity: 1;
  color: var(--trex-primary) !important;
}

/* Hamburger menu button — matches card action button sizing */
.embedded-modal-hamburger {
  padding: 0 !important;
  min-width: 0 !important;
  min-height: 0 !important;
  line-height: 1;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.embedded-modal-hamburger:hover {
  transform: scale(1.12);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Context params info bar in the view modal */
.embedded-modal-context-params {
  background-color: var(--trex-bg);
}

[data-bs-theme="dark"] .embedded-modal-context-params {
  background-color: var(--trex-card-bg);
}

[data-bs-theme="dark"] .embedded-modal-context-params .badge.bg-light {
  background-color: rgba(255, 255, 255, 0.08) !important;
  border-color: rgba(255, 255, 255, 0.15) !important;
}

/* What-If Playground — Modifications Summary Chevron */
.wi-mods-chevron {
  transition: transform 0.2s ease;
  display: inline-block;
  vertical-align: middle;
}
[aria-expanded="true"] .wi-mods-chevron {
  transform: rotate(90deg);
}

/* Customer branding logos — match trex header SVG height (28px) and aspect box */
.customer-brand-logo {
  height: 28px;
  width: calc(28px * 84.76 / 25.09);
  max-width: calc(28px * 84.76 / 25.09);
  object-fit: contain;
  vertical-align: middle;
}

[data-bs-theme="light"] .customer-brand-logo-dark {
  display: none !important;
}

[data-bs-theme="dark"] .customer-brand-logo-light {
  display: none !important;
}

/* What-If Playground — Overlays and Selectors */
.wi-overlay-translucent {
  background-color: rgba(255, 255, 255, 0.6) !important;
  backdrop-filter: blur(1px);
}

[data-bs-theme="dark"] .wi-overlay-translucent {
  background-color: rgba(40, 48, 70, 0.6) !important;
}

.wi-scope-selected {
  background-color: rgba(115, 103, 240, 0.12) !important;
  color: var(--trex-primary) !important;
  font-weight: 600;
}

[data-bs-theme="dark"] .wi-scope-selected {
  background-color: rgba(115, 103, 240, 0.25) !important;
  color: #a6c5e8 !important;
}

/* Custom primary brand outline button with perfect readability in dark mode */
.btn-outline-trex {
  color: var(--trex-primary);
  border-color: var(--trex-primary);
  background-color: transparent;
  transition: all 0.2s ease-in-out;
}

.btn-outline-trex:hover, .btn-outline-trex:focus, .btn-outline-trex:active {
  color: #fff !important;
  background-color: var(--trex-primary) !important;
  border-color: var(--trex-primary) !important;
}

[data-bs-theme="dark"] .btn-outline-trex {
  color: #9e95f5 !important;
  border-color: rgba(115, 103, 240, 0.6) !important;
}

[data-bs-theme="dark"] .btn-outline-trex:hover, [data-bs-theme="dark"] .btn-outline-trex:focus, [data-bs-theme="dark"] .btn-outline-trex:active {
  color: #fff !important;
  background-color: var(--trex-primary) !important;
  border-color: var(--trex-primary) !important;
}

/* ==========================================================================
   Global Header & Filter Panel Circular Buttons Hover Effects (Trex Green)
   ========================================================================== */
.bg-surface-theme .btn-icon.btn-light.rounded-circle,
.pd-filter-bar .btn-icon.btn-light.rounded-circle {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    border: 1px solid var(--bs-border-color, #dee2e6) !important;
}
.bg-surface-theme .btn-icon.btn-light.rounded-circle:hover:not(:disabled),
.pd-filter-bar .btn-icon.btn-light.rounded-circle:hover:not(:disabled) {
    transform: translateY(-1px) scale(1.08) !important;
    background-color: rgba(40, 199, 111, 0.08) !important;
    border-color: var(--trex-success, #28C76F) !important;
    color: var(--trex-success, #28C76F) !important;
    box-shadow: 0 4px 8px rgba(40, 199, 111, 0.12) !important;
}
.bg-surface-theme .btn-icon.btn-light.rounded-circle:hover:not(:disabled) i,
.pd-filter-bar .btn-icon.btn-light.rounded-circle:hover:not(:disabled) i {
    color: var(--trex-success, #28C76F) !important;
}

/* Dark Mode support */
[data-bs-theme="dark"] .bg-surface-theme .btn-icon.btn-light.rounded-circle,
[data-bs-theme="dark"] .pd-filter-bar .btn-icon.btn-light.rounded-circle {
    background-color: rgba(255, 255, 255, 0.05) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
    color: rgba(255, 255, 255, 0.75) !important;
}
[data-bs-theme="dark"] .bg-surface-theme .btn-icon.btn-light.rounded-circle:hover:not(:disabled),
[data-bs-theme="dark"] .pd-filter-bar .btn-icon.btn-light.rounded-circle:hover:not(:disabled) {
    background-color: rgba(40, 199, 111, 0.12) !important;
    border-color: var(--trex-success, #28C76F) !important;
    color: var(--trex-success, #28C76F) !important;
    box-shadow: 0 4px 10px rgba(40, 199, 111, 0.20) !important;
}
[data-bs-theme="dark"] .bg-surface-theme .btn-icon.btn-light.rounded-circle:hover:not(:disabled) i,
[data-bs-theme="dark"] .pd-filter-bar .btn-icon.btn-light.rounded-circle:hover:not(:disabled) i {
    color: var(--trex-success, #28C76F) !important;
}

/* Running/Cancel state (btn-danger) for any header/filter panel circular button */
.bg-surface-theme .btn-icon.btn-danger.rounded-circle,
.pd-filter-bar .btn-icon.btn-danger.rounded-circle {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
    background-color: rgba(220, 53, 69, 0.08) !important;
    border: 1px solid rgba(220, 53, 69, 0.2) !important;
    color: var(--trex-danger, #EA5455) !important;
}
.bg-surface-theme .btn-icon.btn-danger.rounded-circle:hover:not(:disabled),
.pd-filter-bar .btn-icon.btn-danger.rounded-circle:hover:not(:disabled) {
    transform: translateY(-1px) scale(1.08) !important;
    background-color: rgba(220, 53, 69, 0.15) !important;
    border-color: var(--trex-danger, #EA5455) !important;
    color: var(--trex-danger, #EA5455) !important;
    box-shadow: 0 4px 8px rgba(220, 53, 69, 0.12) !important;
}
.bg-surface-theme .btn-icon.btn-danger.rounded-circle i,
.bg-surface-theme .btn-icon.btn-danger.rounded-circle .spinner-border,
.pd-filter-bar .btn-icon.btn-danger.rounded-circle i,
.pd-filter-bar .btn-icon.btn-danger.rounded-circle .spinner-border {
    color: var(--trex-danger, #EA5455) !important;
}

/* Dark Mode for circular btn-danger */
[data-bs-theme="dark"] .bg-surface-theme .btn-icon.btn-danger.rounded-circle,
[data-bs-theme="dark"] .pd-filter-bar .btn-icon.btn-danger.rounded-circle {
    background-color: rgba(255, 255, 255, 0.05) !important;
    border-color: rgba(220, 53, 69, 0.3) !important;
    color: var(--trex-danger, #EA5455) !important;
}
[data-bs-theme="dark"] .bg-surface-theme .btn-icon.btn-danger.rounded-circle:hover:not(:disabled),
[data-bs-theme="dark"] .pd-filter-bar .btn-icon.btn-danger.rounded-circle:hover:not(:disabled) {
    background-color: rgba(220, 53, 69, 0.18) !important;
    border-color: var(--trex-danger, #EA5455) !important;
    color: var(--trex-danger, #EA5455) !important;
    box-shadow: 0 4px 10px rgba(220, 53, 69, 0.20) !important;
}
[data-bs-theme="dark"] .bg-surface-theme .btn-icon.btn-danger.rounded-circle:hover:not(:disabled) i,
[data-bs-theme="dark"] .pd-filter-bar .btn-icon.btn-danger.rounded-circle:hover:not(:disabled) i {
    color: var(--trex-danger, #EA5455) !important;
}