:root {
  --font-size: 16px;

  /* Light mode colors (default) — bridged to DESIGN.md tokens in tokens.css */
  --primary-color: var(--ldg-primary-900, #003333);
  --secondary-color: #001453;

  /* Main theme colors - Light mode */
  --bs-primary: var(--ldg-primary-900, #003333) !important;
  --bs-link-color: var(--ldg-primary-900, #003333) !important;
  --bs-text-primary: var(--ldg-primary-900, #003333);

  /* Keep the rest of the primary family on-brand — without these, var-chained
     components (text-bg-primary, badge-light-primary, active pills, subtle
     surfaces) still resolve to the bundle's blue in light mode. */
  --bs-primary-rgb: 0, 51, 51;
  --bs-primary-inverse: #ffffff;
  --bs-primary-active: var(--ldg-primary-800, #063d27);
  --bs-primary-light: rgba(0, 51, 51, 0.08);
  --bs-primary-text-emphasis: #003333;
  --bs-primary-bg-subtle: rgba(0, 51, 51, 0.08);
  --bs-primary-border-subtle: rgba(13, 102, 64, 0.4);
  --bs-primary-clarity: rgba(0, 51, 51, 0.1);
  --bs-component-active-bg: var(--ldg-primary-900, #003333);
  --bs-component-active-color: #ffffff;

  /* Background colors - Light mode */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #f1f1f4;

  /* Text colors - Light mode */
  --text-primary: #212529;
  --text-secondary: #6c757d;
  --text-muted: #adb5bd;
  --text-inverse: #ffffff;

  /* Border colors - Light mode */
  --border-primary: #dbdfe9;
  --border-secondary: #dee2e6;

  /* Button colors - Light mode */
  --btn-primary-bg: var(--ldg-primary-900, #003333);
  --btn-primary-border: var(--ldg-primary-900, #003333);
  --btn-primary-text: var(--primary-color);

  /* Form colors - Light mode */
  --form-bg: #ffffff;
  --form-border: #dbdfe9;
  --form-focus-border: #ccffcc;
  --form-text: #212529;

  /* Status colors - Light mode */
  --success-color: #17c653;
  --error-color: #f8285a;
  --warning-color: #ffa500;

  /* Shadow colors - Light mode */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0px 1px 3px 0px rgba(16, 24, 40, 0.1);
  --shadow-lg: 0 0 20px #f1f1f4;

  --bs-app-sidebar-panel-width: 270px !important;
}

.btn.btn-light-primary {
  color: #ccffcc !important;
  border-color: var(--btn-primary-bg);
  background-color: var(--btn-primary-bg);
}

/* Keep icon glyphs and the dropdown caret on the label's mint: the bundle
   recolors them to --bs-primary (equals our #003333 surface in light mode)
   or --bs-primary-inverse on interaction (#003333 in dark mode) — invisible
   either way. These non-important bundle rules lose to this !important pin
   in every state. */
.btn.btn-light-primary .svg-icon,
.btn.btn-light-primary i,
.btn.btn-light-primary.dropdown-toggle::after {
  color: #ccffcc !important;
}

/* The bundle's interactive-state ruleset puts !important on
   background-color under selectors one class deeper than a bare :hover
   (e.g. .btn.btn-light-primary:hover:not(.btn-active) is 0,4,0), so a
   shorter override loses and --bs-primary paints the surface — mint in dark
   mode, behind our pinned mint label: invisible text on hover/active/focus.
   Mirror the bundle's exact state list so specificity ties and this
   later-loaded declaration wins. */
.btn-check:active + .btn.btn-light-primary,
.btn-check:checked + .btn.btn-light-primary,
.btn.btn-light-primary.active,
.btn.btn-light-primary.show,
.btn.btn-light-primary:active:not(.btn-active),
.btn.btn-light-primary:focus:not(.btn-active),
.btn.btn-light-primary:hover:not(.btn-active),
.show > .btn.btn-light-primary {
  border-color: var(--btn-primary-bg) !important;
  background-color: var(--btn-primary-bg) !important;
}

/* Dark mode colors — driven by Metronic's data-bs-theme attribute.
   Do NOT add a prefers-color-scheme block here: main.php resolves the OS
   preference into data-bs-theme, so a media-query layer would double-apply
   and desync. All dark vars must live in this block. */
[data-bs-theme="dark"] {
  --primary-color: var(--ldg-primary-100, #ccffcc);
  --secondary-color: #001453;

  /* Main theme colors - Dark mode */
  --bs-primary: var(--ldg-primary-100, #ccffcc) !important;
  --bs-link-color: var(--ldg-primary-100, #ccffcc) !important;
  --bs-text-primary: var(--ldg-primary-100, #ccffcc);

  /* Background colors - Dark mode */
  --bg-primary: #1a1d23;
  --bg-secondary: #252f4a;
  --bg-tertiary: #2f3349;

  /* Text colors - Dark mode */
  --text-primary: #f9f9f9;
  --text-secondary: #b5b5c3;
  --text-muted: #6c7293;
  --text-inverse: #1a1d23;

  /* Border colors - Dark mode */
  --border-primary: #3f4254;
  --border-secondary: #4b5675;

  /* Button colors - Dark mode */
  --btn-primary-bg: #003333;
  --btn-primary-border: #003333;
  --btn-primary-text: var(--primary-color);

  /* Form colors - Dark mode */
  --form-bg: #252f4a;
  --form-border: #3f4254;
  --form-focus-border: var(--ldg-action-primary, #2aaa66);
  --form-text: #f9f9f9;

  /* Status colors - Dark mode */
  --success-color: #17c653;
  --error-color: #f8285a;
  --warning-color: #ffa500;

  /* Shadow colors - Dark mode */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0px 1px 3px 0px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 0 20px rgba(0, 0, 0, 0.5);

  /* Sidebar menu section labels: bundle default (#636674) is only ~3.4:1 on
     the #0D0E12 sidebar — below WCAG AA for fs-7 uppercase text. */
  --bs-app-sidebar-light-menu-heading-color: #9a9cae;

  /* The --bs-primary inversion above recolors only the hex token; the rest of
     the primary family still resolves to bundle blue. Keep the rgb twin
     consistent with the mint hex so var-chained surfaces stay on-brand, and
     pin the background-context members to deep brand green so
     primary-as-surface components stay legible (light text on deep green). */
  --bs-primary-rgb: 204, 255, 204;
  --bs-primary-inverse: #003333;
  --bs-primary-active: var(--ldg-primary-700, #0a5033);
  --bs-primary-light: rgba(42, 170, 102, 0.15);
  --bs-primary-text-emphasis: #ccffcc;
  --bs-primary-bg-subtle: rgba(6, 61, 39, 0.45);
  --bs-primary-border-subtle: var(--ldg-primary-600, #0d6640);
  --bs-primary-clarity: rgba(42, 170, 102, 0.2);
  --bs-component-active-bg: var(--ldg-primary-800, #063d27);
  --bs-component-active-color: #f5f5f5;
}

[data-bs-theme="dark"] {
  @media (min-width: 992px) {
    [data-kt-app-layout="light-sidebar"]
      .app-header-menu
      .menu
      > .menu-item.here
      > .menu-link
      .menu-title {
      color: var(--ldg-primary-100, #ccffcc);
    }
  }

  [data-kt-app-layout="light-sidebar"]
    .app-sidebar
    .menu
    .menu-item
    .menu-sub
    .menu-item
    .menu-link.active
    .menu-title {
    color: var(--ldg-primary-100, #ccffcc);
  }

  /* Active pill/nav states keep baked bundle blue otherwise. */
  .nav-pills .nav-link.active,
  .nav-pills .show > .nav-link {
    background-color: var(--bs-component-active-bg);
    color: var(--bs-component-active-color);
  }
}

.btn-primary {
  background-color: var(--btn-primary-bg) !important;
  border-color: var(--btn-primary-border) !important;
  color: #ccffcc !important;
}

/* Same icon recolor trap as .btn-light-primary: --bs-primary-inverse is
   #003333 in dark mode — identical to the button surface — so bundle icon /
   caret rules paint invisible glyphs. Pin them to the label color. */
.btn.btn-primary .svg-icon,
.btn.btn-primary i,
.btn.btn-primary.dropdown-toggle::after {
  color: #ccffcc !important;
}

.btn-primary:hover {
  background-color: var(--btn-primary-bg) !important;
  border-color: var(--btn-primary-border) !important;
}

.brand-color {
  color: #003333 !important;
}

[data-bs-theme="dark"] {
  .brand-color {
    color: #ccffcc !important;
  }
}

.form-group {
  max-width: 24rem;
  /* Tailwind's max-w-sm */
  margin: 0 auto;
  width: 100%;
}

/* Shared input/textarea styles */
.form-input,
.form-textarea,
.form-select {
  display: block;
  width: 100%;
  padding: 0.5rem 1rem;
  font-size: 1rem;
  line-height: 1.5;
  border: 1px solid var(--form-border);
  border-radius: 0.75rem;
  /* rounded-xl */
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease-in-out;
  outline: none;
}

/* Focus state */
.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--bs-primary);
  outline: 2px solid var(--bs-primary);
  outline-offset: 2px;
  box-shadow: 0 0 0 0.25rem rgba(44, 160, 28, 0.25);
}

/* Global Select2 focus enhancement */
.select2-container--open .select2-selection,
.select2-container--focus .select2-selection {
  outline: 2px solid var(--bs-primary) !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 0.25rem rgba(44, 160, 28, 0.25) !important;
}

[data-bs-theme="dark"] {
  .select2-container--open .select2-selection,
  .select2-container--focus .select2-selection {
    box-shadow: 0 0 0 0.25rem rgba(204, 255, 204, 0.25) !important;
  }
}

/* .invoice-date-filters .input-group {
  align-items: stretch;
} */

.input-group {
  flex-wrap: nowrap !important;
}

.invoice-date-filters .flatpickr-input {
  padding: 0.5rem 1rem;
  border: 1px solid var(--form-border, #e4e6ef);
  border-radius: 0.75rem 0 0 0.75rem;
  background-color: var(--bs-body-bg);
  color: var(--bs-body-color);
  transition: all 0.15s ease-in-out;
}

.invoice-date-filters .flatpickr-input:focus {
  border-color: var(--form-focus-border, #a7d046);
  box-shadow: none;
}

/* .invoice-date-filters .input-group .btn {
  min-width: 48px;
  height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--form-border, #e4e6ef);
  border-left: 0;
  border-radius: 0 0.75rem 0.75rem 0;
  background-color: var(--bs-body-bg);
  color: var(--bs-body-color);
  transition: all 0.15s ease-in-out;
  box-shadow: none;
} */

/* .invoice-date-filters .input-group .btn:focus {
  border-color: var(--form-focus-border, #a7d046);
  box-shadow: none;
} */

[data-bs-theme="dark"] .invoice-date-filters .flatpickr-input {
  background-color: var(--form-bg, #1f2235);
  color: var(--form-text, #f5f8fa);
  border-color: var(--form-border, #2b2f4c);
}

/* [data-bs-theme="dark"] .invoice-date-filters .input-group .btn {
  background-color: var(--form-bg, #1f2235);
  color: var(--form-text, #f5f8fa);
  border-color: var(--form-border, #2b2f4c);
} */

.form-input-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.875rem;
  border-radius: 0.5rem;
}

.invoice-items-table .form-select-sm {
  min-height: 2.5rem;
  border-radius: 0.5rem;
}

.invoice-item-cell {
  padding-top: 1.25rem;
  padding-bottom: 1.25rem;
}

.invoice-item-field {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-secondary);
  border-radius: 0.75rem;
  padding: 0.5rem 0.75rem;
}

[data-bs-theme="dark"] .invoice-item-field {
  background-color: #1f2235;
  border-color: var(--border-secondary);
}

.invoice-item-field .form-input-sm {
  background: transparent;
  border: 1px dashed transparent;
  padding: 0.35rem 0.5rem;
}

.invoice-item-quick-add {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.65rem;
}

.invoice-item-quick-add i {
  color: var(--primary-color);
}

[data-bs-theme="dark"] .invoice-item-quick-add i {
  color: var(--form-focus-border);
}

[data-bs-theme="dark"] .form-input-sm {
  background-color: var(--form-bg);
  color: var(--form-text);
}

[data-bs-theme="dark"] {
  .form-input,
  .form-textarea,
  .form-select {
    display: block;
    width: 100%;
    padding: 0.5rem 1rem;
    font-size: 1rem;
    line-height: 1.5;
    border: 1px solid var(--form-border);
    border-radius: 0.75rem;
    /* rounded-xl */
    box-shadow: var(--shadow-sm);
    transition: all 0.15s ease-in-out;
    outline: none;
    background-color: #0D0E12;
    color: var(--form-text);
  }

  /* Focus state */
  .form-input:focus,
  .form-textarea:focus,
  .form-select:focus {
    border-color: var(--bs-primary);
    outline: 2px solid var(--bs-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 0.25rem rgba(204, 255, 204, 0.25);
  }
}

/* Validation messages */
.form-message {
  margin-top: 0.25rem;
  font-size: 0.875rem;
}

.form-message.success {
  color: var(--success-color);
}

.form-message.error {
  color: var(--error-color);
}

/* Error and success states */
.form-input.error,
.form-textarea.error {
  border-color: var(--error-color);
  box-shadow: 0 0 0 2px rgba(248, 40, 90, 0.5);
}

.form-input.success,
.form-textarea.success {
  border-color: var(--form-focus-border);
  box-shadow: 0 0 0 2px rgba(167, 208, 70, 0.5);
}

/* Textarea-specific */
.form-textarea {
  resize: vertical;
}

.nav-tabs {
  border-bottom: none;
  background-color: transparent;
}

.nav-tabs .nav-link {
  flex: 1;
  text-align: center;
  border: 1px solid transparent;
  border-radius: 0.5rem;
  transition: background-color 0.3s ease;
}

.nav-tabs .nav-link.active {
  box-shadow: var(--shadow-md);
  font-weight: 600;
}

.ellipsis {
  white-space: nowrap;
  /* Prevents line breaks */
  overflow: hidden;
  /* Hides overflow content */
  text-overflow: ellipsis;
  /* Adds the "..." */
}

[data-bs-theme="dark"] .nav-tabs .nav-link.active {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

.tab-content {
  margin-top: 1rem;
}

.spinner {
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* Documentation sidebar */
#docs_sidebar {
  transition: transform 0.3s ease;
}

@media (max-width: 767.98px) {
  #docs_sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 250px;
    background-color: var(--bg-primary);
    z-index: 1050;
    transform: translateX(-100%);
    padding: 1rem;
    overflow-y: auto;
  }

  #docs_sidebar.open {
    transform: translateX(0);
  }
}

@media (max-width: 767.98px) {
  table.table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  form.row {
    flex-direction: column;
  }
}

.question-handle {
  cursor: move;
}

/* Lead stage pipeline */
.lead-stages {
  display: flex;
  list-style: none;
  padding: 0;
  margin: 0;
}

.lead-stage {
  flex: 1 1 0;
  position: relative;
  text-align: center;
  padding: 0.5rem 1rem;
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
}

.lead-stage:not(:last-child)::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 100%;
  width: 100%;
  height: 2px;
  background-color: var(--border-primary);
  transform: translateY(-50%);
}

.lead-stage--completed {
  background-color: var(--form-focus-border);
  color: var(--text-inverse);
}

.lead-stage--completed:not(:last-child)::after {
  background-color: var(--form-focus-border);
}

.lead-stage--current {
  background-color: var(--secondary-color);
  color: var(--text-inverse);
}

.lead-stage--current:not(:last-child)::after {
  background-color: var(--secondary-color);
}

.lead-stage--lost {
  background-color: var(--error-color);
  color: var(--text-inverse);
}

.lead-stage--lost:not(:last-child)::after {
  background-color: var(--error-color);
}

/* Hide scrollbars */
.hide-scrollbar {
  -ms-overflow-style: none;
  /* IE and Edge */
  scrollbar-width: none;
  /* Firefox */
}

.hide-scrollbar::-webkit-scrollbar {
  display: none;
  /* Chrome, Safari, Opera */
}

.fv-plugins-bootstrap5:not(.fv-plugins-bootstrap5-form-inline)
  label
  ~ .fv-plugins-icon {
  top: 25px !important;
}

@media (min-width: 992px) {
  [data-kt-app-header-fixed="true"] .app-header {
    z-index: 104 !important;
  }
}

/* Highlight active parent links in sidebar */
.app-sidebar .menu-link.active {
  color: var(--bs-primary) !important;
  font-weight: 600;
}

/* Sidebar menu links: the bundle ships .menu-link{outline:0!important} and no
   background reset, and the group triggers/locked placeholders are real
   <button>s — so the UA ButtonFace background (light gray in dark mode) and
   border paint every trigger as a pale pill. Reset them and give keyboard
   users a visible focus ring that follows the theme (--bs-primary is mint in
   dark mode). */
.app-sidebar .menu button.menu-link {
  border: 0;
  background-color: transparent;
  appearance: none;
  -webkit-appearance: none;
}

.app-sidebar .menu .menu-link:focus-visible {
  outline: 2px solid var(--bs-primary) !important;
  outline-offset: -2px;
}

/* The bundle hardcodes .text-bg-primary{color:#000} which fails on the deep
   brand green in light mode and would have failed on mint in dark mode.
   Pair the rgb-derived background with the theme-aware inverse color. */
.text-bg-primary {
  color: var(--bs-primary-inverse) !important;
}

/* Responsive adjustments */
@media (max-width: 575.98px) {
  table.table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
}

/* Stepper content visibility (mirror Metronic behavior) */
.stepper [data-kt-stepper-element="content"] {
  display: none;
}

.stepper [data-kt-stepper-element="content"].current {
  display: block;
}

.app-toolbar,
#kt_app_toolbar {
  height: auto !important;
  min-height: 0 !important;
  padding-top: 0.35rem !important;
  padding-bottom: 0.35rem !important;
}

.app-toolbar .app-container,
#kt_app_toolbar_container {
  min-height: 0 !important;
  align-items: flex-start !important;
}

.app-toolbar .page-title,
.app-toolbar .page-heading,
.app-toolbar .breadcrumb {
  margin-bottom: 0 !important;
}

.app-toolbar .page-title {
  gap: 0.1rem !important;
}

.app-toolbar .page-heading {
  line-height: 1.2 !important;
}

.app-toolbar .breadcrumb {
  padding-top: 0 !important;
  margin-top: 0 !important;
  line-height: 1.1 !important;
}

.app-toolbar + .app-content {
  margin-top: 0 !important;
}

@media (min-width: 992px) {
  .app-content {
    padding-top: 0 !important;
  }
}

@media (max-width: 991.98px) {
  .app-content {
    padding-top: 0 !important;
  }
}

@media (min-width: 992px) {
  .app-container {
    padding-left: 20px !important;
    padding-right: 20px !important;
  }
}

@media (min-width: 992px) {
  [data-kt-app-header-fixed="true"][data-kt-app-sidebar-fixed="true"][data-kt-app-sidebar-push-header="true"]
    .app-header,
  [data-kt-app-header-fixed="true"][data-kt-app-sidebar-sticky="on"][data-kt-app-sidebar-push-header="true"]
    .app-header {
    left: calc(
      var(--bs-app-sidebar-width) + var(--bs-app-sidebar-gap-start, 0px) +
        var(--bs-app-sidebar-gap-end, 0px)
    );
  }
}
@media (min-width: 992px) {
  [data-kt-app-header-fixed="true"][data-kt-app-toolbar-fixed="true"]
    .app-header {
    box-shadow: none;
  }
}
@media (min-width: 992px) {
  [data-kt-app-header-fixed="true"] .app-header {
    z-index: 107 !important;
  }
  [data-kt-app-sidebar-fixed="true"] .app-sidebar,
  [data-kt-app-sidebar-sticky="on"] .app-sidebar {
    z-index: 108 !important;
  }
  .app-header .menu-sub-lg-dropdown {
    z-index: 109 !important;
  }
  #kt_app_sidebar_toggle {
    z-index: 110 !important;
  }
}
@media (min-width: 992px) {
  [data-kt-app-toolbar-fixed="true"] .app-header {
    background-color: var(--bs-app-header-minimize-bg-color);
  }
}
@media (min-width: 992px) {
  [data-kt-app-header-fixed="true"] .app-header {
    z-index: 110;
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
  }
  .w-lg-450px {
    width: 450px !important;
  }
  .w-lg-700px {
    width: 700px !important;
  }
  .w-lg-1200px {
    width: 1200px !important;
  }
  .w-lg-1400px {
    width: 1400px !important;
  }
  .app-header-menu .menu-item > .menu-sub-lg-dropdown {
    max-width: calc(100vw - 300px) !important;
  }
}

.header-menu-masonry {
  column-count: 1;
  column-gap: 0.5rem;
}

@media (min-width: 768px) {
  .header-menu-masonry {
    column-count: 2;
  }
}

@media (min-width: 992px) {
  .header-menu-masonry {
    column-count: var(--menu-cols, 3);
  }
}

.header-menu-section {
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: 1.25rem;
  display: inline-block;
  width: 100%;
}
