/* ==========================================================================
   moco_leads Modul-Styles
   ========================================================================== */

/* Layout & Sidebar */
#sidebar {
  min-width: 300px;
  max-width: 400px;
}

/* Tabellen-Spaltenbreiten */
.lead-col-status-marker {
  width: 6px;
  min-width: 6px;
  max-width: 6px;
  padding: 0 !important;
}

thead th.lead-col-status-marker {
  background-color: transparent !important;
  border-bottom: 1px solid #e9ecef;
}

.lead-col-pot {
  width: 70px;
  min-width: 65px;
}

.lead-col-title {
  min-width: 320px;
  max-width: 400px;
  overflow-wrap: break-word;
  word-break: normal;
}

/* Titel / Lead immer zweizeilig hoch */
.lead-title-box {
  min-height: 2.7em;
  display: flex;
  align-items: center;
  line-height: 1.35;
}

.lead-title-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.35;
}

.lead-col-probability {
  min-width: 160px;
}

.lead-col-amount {
  min-width: 140px;
}

.lead-col-monthly-amount {
  min-width: 140px;
}

.lead-col-period {
  min-width: 145px;
  text-align: left !important;
}

.lead-col-months {
  min-width: 80px;
  text-align: center;
}

.lead-col-action {
  min-width: 130px;
}

.lead-col-owner {
  white-space: nowrap;
  text-align: right;
}

/* Progress Bar für Wahrscheinlichkeiten */
.lead-progress {
  height: 6px;
  min-width: 50px;
}

/* Badges für Wahrscheinlichkeiten */
.prob-badge {
  min-width: 48px;
  text-align: center;
}

.sidebar-cat-badge {
  min-width: 42px;
  text-align: center;
}

/* Info-Icon hinter dem Lead-Titel */
.lead-info-icon {
  cursor: help;
  /* font-size: 0.9rem; */
  /* vertical-align: middle; */
}

/* Breiterer Tooltip für Info-Texte */
.lead-info-tooltip .tooltip-inner {
  max-width: 480px;
  text-align: left;
  white-space: pre-wrap;
}

/* ==========================================================================
   Wahrscheinlichkeits-Farben (Individuell anpassbar)
   Hier können Hintergrundfarben und Schriftfarben für jede Stufe
   nach Belieben definiert werden.
   ========================================================================== */

/* Stufe: Fast sicher / Höchste (>= 90%) */
.prob-highest,
.prob-p95,
.prob-p90 {
  background-color: #0f5132 !important; /* Dunkelgrün */
  color: #ffffff !important;
}

/* Stufe: Sehr hoch (75% - 89%) */
.prob-very-high {
  background-color: #198754 !important; /* Grün */
  color: #ffffff !important;
}

/* Stufe: Hoch (50% - 74%) */
.prob-high {
  background-color: #0dcaf0 !important; /* Cyan / Hellblau */
  color: #000000 !important;
}

/* Stufe: Mittel (25% - 49%) */
.prob-medium {
  background-color: #ffc107 !important; /* Gelb / Orange */
  color: #000000 !important;
}

/* Stufe: Niedrig (< 25%) */
.prob-low {
  background-color: #6c757d !important; /* Grau */
  color: #ffffff !important;
}

/* 
 * Optionale Definitionen für exakte Prozentwerte (falls gewünscht anpassbar):
 */
.prob-p80 {
  background-color: #198754 !important;
  color: #ffffff !important;
}
.prob-p60 {
  background-color: #0dcaf0 !important;
  color: #000000 !important;
}
.prob-p40 {
  background-color: #ffc107 !important;
  color: #000000 !important;
}
.prob-p20 {
  background-color: #fd7e14 !important;
  color: #ffffff !important;
}
.prob-p7 {
  background-color: #dc3545 !important;
  color: #ffffff !important;
}
.prob-p2 {
  background-color: #6c757d !important;
  color: #ffffff !important;
}
.prob-p1 {
  background-color: #adb5bd !important;
  color: #000000 !important;
}

/* ==========================================================================
   Lead-Status Farben (Marker & Sidebar)
   ========================================================================== */
:root {
  --lead-status-potential-color: #0dcaf0; /* Cyan / Potenzial */
  --lead-status-pending-color: #0d6efd; /* Blau / In Bearbeitung */
  --lead-status-won-color: #198754; /* Grün / Gewonnen */
  --lead-status-lost-color: #dc3545; /* Rot / Verloren */
  --lead-status-dropped-color: #6c757d; /* Grau / Verworfen */
}

.lead-status-potential {
  background-color: var(--lead-status-potential-color) !important;
}
.lead-status-pending,
.lead-status-open {
  background-color: var(--lead-status-pending-color) !important;
}
.lead-status-won {
  background-color: var(--lead-status-won-color) !important;
}
.lead-status-lost {
  background-color: var(--lead-status-lost-color) !important;
}
.lead-status-dropped {
  background-color: var(--lead-status-dropped-color) !important;
}

/* Sidebar Status-Marker */
.status-sidebar-marker {
  display: inline-block;
  width: 6px;
  height: 16px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ==========================================================================
   Finanz-Balken: Totalbetrag & Monatsanteil über die Zellen Betrag bis Monate
   ========================================================================== */

:root {
  --lead-bar-total-bg: rgba(
    222,
    226,
    230,
    0.35
  ); /* Ursprünglicher heller, dezenter Ton */
  --lead-bar-border-color: #90979d; /* Dunkelgrauer Rahmen belassen */
  --navbar-height: 58px; /* Fallback für Topbar-Höhe */
}

/* Einheitlich weiße Zeilen (keine grauen Streifen) */
#moco_leads_table thead tr.lead-header-main th {
  border-bottom: 1px solid #b8bec5 !important;
}

#moco_leads_table thead tr.lead-timeline-header-row th,
#moco_leads_table thead th.lead-timeline-header-cell {
  border-bottom: none !important;
  border-bottom-width: 0 !important;
}

#moco_leads_table tbody tr {
  background-color: #ffffff;
}

#moco_leads_table tbody tr > td {
  background-color: #ffffff;
  border-bottom: 1px solid #b8bec5;
}

#moco_leads_table tbody tr > td:last-child {
  border-right: 1px solid #b8bec5;
}

/* Zellen bleiben transparent für den Balken (Balken kann bei Beträgen > 100% in Folgespalten nach rechts ragen) */
#moco_leads_table tbody tr.lead-row > td:not(.lead-col-status-marker) {
  position: relative;
  background-color: transparent !important;
}

/* Zeilen-Hintergründe für gewonnene und verlorene Leads (hellgrün / hellrot mit Transparenz) */
#moco_leads_table tbody tr.lead-row-won:not(:hover) {
  background-color: rgba(25, 135, 84, 0.4) !important;
}
#moco_leads_table tbody tr.lead-row-won > td {
  border-bottom-color: rgba(25, 135, 84, 0.45);
}

#moco_leads_table tbody tr.lead-row-lost:not(:hover),
#moco_leads_table tbody tr.lead-row-dropped:not(:hover) {
  background-color: rgba(220, 53, 69, 0.4) !important;
}
#moco_leads_table tbody tr.lead-row-lost > td,
#moco_leads_table tbody tr.lead-row-dropped > td {
  border-bottom-color: rgba(220, 53, 69, 0.45);
}

/* Bei gewonnenen Leads: Monatsbalken (Umsatz / Monat) in Status-Grün */
#moco_leads_table tbody tr.lead-row-won .lead-financial-bar-monthly {
  background-color: rgba(25, 135, 84, 0.45) !important;
  border: 2px solid var(--lead-status-won-color) !important;
}

/* Bei gewonnenen und verlorenen Leads: Datum nächste Aktion neutral belassen (keine rote Hervorhebung) */
#moco_leads_table tbody tr.lead-row-won .lead-action-overdue,
#moco_leads_table tbody tr.lead-row-lost .lead-action-overdue,
#moco_leads_table tbody tr.lead-row-dropped .lead-action-overdue {
  background-color: transparent !important;
  color: inherit !important;
  font-weight: normal !important;
  padding: 0 !important;
}

.lead-row {
  position: relative;
}

.lead-title-box,
.lead-cell-content,
.lead-col-action > *,
.lead-col-owner > * {
  position: relative;
  z-index: 2;
}

/* ==========================================================================
   Dunkler Mouse-Over mit Farb-Invertierung (ohne verzögernde Transitions)
   ========================================================================== */
#moco_leads_table tbody tr:hover {
  background-color: #46484b !important; /* Sehr dunkles Anthrazit */
}

#moco_leads_table tbody tr:hover > td {
  background-color: #46484b !important;
  color: #ffffff !important;
}

#moco_leads_table tbody tr.lead-row:hover > td:not(.lead-col-status-marker) {
  background-color: transparent !important;
}

/* Status-Marker (Spalte 1) behält IMMER seine originale Status-Farbe (normal und bei Hover) */
#moco_leads_table tbody td.lead-col-status-marker.lead-status-potential {
  background-color: var(--lead-status-potential-color) !important;
}
#moco_leads_table tbody td.lead-col-status-marker.lead-status-pending,
#moco_leads_table tbody td.lead-col-status-marker.lead-status-open {
  background-color: var(--lead-status-pending-color) !important;
}
#moco_leads_table tbody td.lead-col-status-marker.lead-status-won {
  background-color: var(--lead-status-won-color) !important;
}
#moco_leads_table tbody td.lead-col-status-marker.lead-status-lost {
  background-color: var(--lead-status-lost-color) !important;
}
#moco_leads_table tbody td.lead-col-status-marker.lead-status-dropped {
  background-color: var(--lead-status-dropped-color) !important;
}

#moco_leads_table tbody tr:hover .text-dark,
#moco_leads_table tbody tr:hover .lead-cell-content,
#moco_leads_table tbody tr:hover .lead-info-icon,
#moco_leads_table
  tbody
  tr:hover
  td
  > span:not(.badge):not(.lead-action-overdue),
#moco_leads_table tbody tr:hover td > a {
  color: #ffffff !important;
}

/* Überfällige nächste Aktionen: roter Hintergrund (nur Schrift) mit weißem fettem Text */
.lead-action-overdue {
  background-color: #dc3545 !important;
  color: #ffffff !important;
  font-weight: 700 !important;
  padding: 2px 7px;
  border-radius: 4px;
  display: inline-block;
  line-height: 1.3;
}

#moco_leads_table tbody tr:hover .lead-action-overdue {
  background-color: #dc3545 !important;
  color: #ffffff !important;
  font-weight: 700 !important;
}

/* Dezenter Schatten für Text über farbigen Balken auf dunklem Grund */
#moco_leads_table tbody tr:hover .lead-title-box,
#moco_leads_table tbody tr:hover .lead-cell-content {
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

/* Bei Mouseover: Totalbalken wird weiß-transparent und Rahmen wechselt auf hellgrau */
#moco_leads_table tbody tr:hover .lead-financial-bar-bg {
  background-color: rgba(255, 255, 255, 0.25) !important;
  border-color: #a3a8ac !important; /* Hellgrauer Rahmen auf dunklem Grund */
}

/* Erlaubt dem Überhang-Indikator am rechten Tabellenrand sichtbar zu sein ohne horizontalen Scrollbalken */
.card > .table-responsive {
  overflow: visible;
}

/* Bootstrap Table Anpassungen für nahtlose Integration */
.bootstrap-table .fixed-table-container {
  overflow: visible !important;
  border: none !important;
}

.bootstrap-table .fixed-table-body {
  overflow: visible !important;
}

.bootstrap-table thead th .th-inner.sortable {
  padding-right: 22px !important;
  cursor: pointer;
}

.bootstrap-table th.text-end .th-inner {
  text-align: right;
}

.bootstrap-table th.text-center .th-inner {
  text-align: center;
}

/* Status-Marker-Spalte in Bootstrap Table exakt 6px breit halten */
.bootstrap-table th.lead-col-status-marker,
.bootstrap-table th.lead-col-status-marker .th-inner,
#moco_leads_table td.lead-col-status-marker {
  width: 6px !important;
  min-width: 6px !important;
  max-width: 6px !important;
  padding: 0 !important;
}

/* Der durchgehende Hintergrund-Balken für den Totalbetrag (keine runden Ecken, mit Rahmen) */
.lead-financial-bar-bg {
  position: absolute;
  top: 14px;
  bottom: 14px;
  left: var(--bar-left, 6px);
  width: calc((var(--financial-zone-width, 500px) - 12px) * var(--deal-pct, 0));
  max-width: var(--bar-max-width, var(--financial-zone-max-width, none));
  background-color: var(--lead-bar-total-bg);
  border: 1px solid var(--lead-bar-border-color);
  border-radius: 0;
  pointer-events: none;
  z-index: 1;
  box-sizing: border-box;
}

/* Ragt der Balken an/über den rechten Tabellenrand, schließt die Hauptleiste nahtlos an den Indikator an */
.lead-financial-bar-bg.has-overflow {
  border-right: none;
}

/* Überhang-Indikator (Rechtspfeil / Dreieck), wenn der Betrag die Tabellenbreite übersteigt */
.lead-bar-overflow-indicator {
  display: none;
  position: absolute;
  right: -20px;
  top: -1px;
  bottom: -1px;
  width: 20px;
  background-color: #dee2e6;
  border: 1px solid var(--lead-bar-border-color);
  border-left: none;
  border-top-right-radius: 4px;
  border-bottom-right-radius: 4px;
  align-items: center;
  justify-content: center;
  color: #495057;
  font-size: 11px;
  z-index: 3;
  pointer-events: auto;
  cursor: help;
}

.lead-financial-bar-bg.has-overflow .lead-bar-overflow-indicator {
  display: flex;
}

/* Bei Mouseover: Überhang wird dunkel wie die Zeile (#46484b) mit weißem Pfeil */
#moco_leads_table
  tbody
  tr:hover
  .lead-financial-bar-bg.has-overflow
  .lead-bar-overflow-indicator {
  background-color: #46484b !important;
  border-color: #a3a8ac !important;
  color: #ffffff !important;
}

/* Lead Titel-Link zu MOCO */
.lead-title-link {
  color: inherit;
  cursor: pointer;
}

.lead-title-link:hover {
  text-decoration: underline !important;
  color: #0d6efd !important;
}

#moco_leads_table tbody tr:hover .lead-title-link {
  color: #ffffff !important;
}

/* ==========================================================================
   Zeitraster: Vertikale monatliche Linien & rote Heute-Linie
   ========================================================================== */

/* Spaltenbeschriftungs-Zeile: Sticky & KEINE vertikalen Linien */
#moco_leads_table thead tr.lead-header-main,
#moco_leads_table.timeline-grid-active thead tr.lead-header-main {
  background-color: #f8f9fa !important;
  background-image: none !important;
}

#moco_leads_table thead tr.lead-header-main th,
#moco_leads_table.timeline-grid-active thead tr.lead-header-main th {
  position: sticky;
  top: calc(var(--sb-nav-top, 0px) - var(--navbar-height, 0px));
  z-index: 102;
  background-color: #f8f9fa !important;
  background-image: none !important;
  border-bottom: 1px solid #b8bec5 !important;
  box-shadow: 0 1px 0 #b8bec5; /* Verhindert Subpixel-Lücken beim Zoomen (z. B. bei 80%) */
  transition: top 0.3s ease-in-out;
}

/* Rechter Rand für die letzte Spaltenkopf-Zelle (Zust.) mit Puffer gegen Subpixel-Blitzer */
#moco_leads_table thead tr.lead-header-main th:last-child {
  border-right: 1px solid #b8bec5 !important;
  box-shadow: 0 1px 0 #b8bec5, 1px 0 0 #f8f9fa, 2px 0 0 #b8bec5;
}

/* Zeitraster-Monatsleiste direkt unter den Spaltenköpfen (halb so hoch, weißer Tabellen-Hintergrund) */
.lead-timeline-header-row {
  display: table-row !important;
  height: 18px;
  max-height: 18px;
  line-height: 18px;
  background-color: #ffffff !important;
  border: none !important;
  border-bottom: none !important;
}

/* Wenn Zeitraster inaktiv ist: Inhalt der Subheader-Zeile ausblenden, Zeile bleibt jedoch mit 18px bestehen */
#moco_leads_table:not(.timeline-grid-active) .lead-timeline-header-row,
#moco_leads_table:not(.timeline-grid-active) .lead-timeline-header-cell {
  background-image: none !important;
}

#moco_leads_table:not(.timeline-grid-active) .lead-timeline-header-row .lead-timeline-month-label {
  visibility: hidden !important;
}

#moco_leads_table thead th.lead-timeline-header-cell,
.lead-timeline-header-cell {
  position: sticky;
  top: calc(var(--sb-nav-top, 0px) - var(--navbar-height, 0px) + var(--lead-header-main-height, 37px) - 2px);
  z-index: 101;
  height: 18px;
  padding: 0 !important;
  border: none !important;
  border-top: 1px solid #b8bec5 !important;
  border-bottom: none !important;
  border-bottom-width: 0 !important;
  border-right: 1px solid #b8bec5 !important;
  background-color: #ffffff !important;
  overflow: visible;
  vertical-align: middle;
  transition: top 0.3s ease-in-out;
}

.lead-timeline-header-track {
  position: relative;
  width: 100%;
  height: 18px;
  overflow: visible;
}

/* Obere 1px-Begrenzungslinie (überlagert Nahtstelle zu den Spaltenköpfen) */
.lead-timeline-header-track::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background-color: #b8bec5;
  z-index: 105;
  pointer-events: none;
}

/* Untere 1px-Abschlusslinie: Als Block-Element auf der Sticky-Ebene dauerhaft beim Scrollen sichtbar */
.lead-timeline-header-track::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background-color: #b8bec5;
  z-index: 105;
  pointer-events: none;
}

.lead-timeline-month-label {
  position: absolute;
  top: 1px;
  font-size: 0.65rem;
  line-height: 16px;
  color: #6c757d;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
  letter-spacing: 0.2px;
  z-index: 106;
}

.lead-timeline-month-label.label-heute {
  color: #dc3545;
  font-weight: 800;
}

.lead-timeline-month-label.label-cap {
  color: #495057;
  font-weight: 700;
  letter-spacing: 0.3px;
}

/* Vertikale Linien & rote Heute-Linie auf der Timeline-Leiste und den Tabellenzeilen */
#moco_leads_table.timeline-grid-active .lead-timeline-header-row,
#moco_leads_table.timeline-grid-active .lead-timeline-header-cell,
#moco_leads_table.timeline-grid-active tbody tr {
  background-image:
    /* Markierte Heute-Linie in ROT */
    linear-gradient(
      to right,
      transparent calc(var(--anchor-left, 450px) - 1px),
      rgba(220, 53, 69, 0.85) calc(var(--anchor-left, 450px) - 1px),
      rgba(220, 53, 69, 0.85) calc(var(--anchor-left, 450px) + 1px),
      transparent calc(var(--anchor-left, 450px) + 1px)
    ),
    /* Vertikale monatliche Rasterlinien (beginnen exakt bei 0px pro Monatsintervall) */
    repeating-linear-gradient(
      to right,
      rgba(0, 0, 0, 0.06) 0px,
      rgba(0, 0, 0, 0.06) 1px,
      transparent 1px,
      transparent var(--month-width, 45px)
    );
  background-position:
    0 0,
    calc(var(--anchor-left, 450px) - (var(--raster-past-months, 3) * var(--month-width, 45px))) 0;
  background-size:
    100% 100%,
    calc((var(--raster-past-months, 3) + var(--raster-future-months, 13)) * var(--month-width, 45px) + 1px) 100%;
  background-repeat: no-repeat;
}

#moco_leads_table.timeline-grid-active tbody tr:hover {
  background-image:
    /* Markierte Heute-Linie auf dunklem Grund in leuchtendem Rot */
    linear-gradient(
      to right,
      transparent calc(var(--anchor-left, 450px) - 1px),
      rgba(255, 99, 99, 0.95) calc(var(--anchor-left, 450px) - 1px),
      rgba(255, 99, 99, 0.95) calc(var(--anchor-left, 450px) + 1px),
      transparent calc(var(--anchor-left, 450px) + 1px)
    ),
    /* Vertikale monatliche Rasterlinien auf dunklem Grund */
    repeating-linear-gradient(
      to right,
      rgba(255, 255, 255, 0.12) 0px,
      rgba(255, 255, 255, 0.12) 1px,
      transparent 1px,
      transparent var(--month-width, 45px)
    );
}

/* Der farbige Monatsanteil innerhalb des Totalbetrag-Balkens (exakt 2px Rahmen auf allen 4 Seiten) */
.lead-financial-bar-monthly {
  position: absolute;
  top: -1px;
  bottom: -1px;
  left: -1px;
  width: calc((100% + 2px) * var(--monthly-pct, 0));
  border-radius: 0;
  box-sizing: border-box;
  z-index: 2;
}

/* ==========================================================================
   Farb-Skala nach Startzeitpunkt des Zeitraums (Individuell anpassbar)
   Vergleich des Monats von 'service_period_from' mit aktuellem Monat (heute):
   - Überfällig (< heute): Pink / Magenta
   - Aktueller Monat:      Rot / Koralle
   - +1 Monat:             Orange
   - +2 Monate:            Gelb-Orange / Amber
   - +3 bis 5 Monate:      Türkis / Cyan
   - +6+ Monate:           Sanftes Blau
   - Ohne Zeitraum:        Neutrales Grau
   ========================================================================== */

/* Überfällig (Start lag vor dem aktuellen Monat) */
.period-start-overdue {
  background-color: rgba(214, 51, 132, 0.45) !important; /* Pink / Magenta */
  border: 2px solid #d63384;
}

/* Aktueller Monat (Startet jetzt) */
.period-start-current {
  background-color: rgba(220, 53, 69, 0.45) !important; /* Signalrot */
  border: 2px solid #dc3545;
}

/* Nächster Monat (+1 Monat) */
.period-start-m1 {
  background-color: rgba(253, 126, 20, 0.45) !important; /* Warmes Orange */
  border: 2px solid #fd7e14;
}

/* In 2 Monaten (+2 Monate) */
.period-start-m2 {
  background-color: rgba(
    255,
    193,
    7,
    0.55
  ) !important; /* Gelb-Orange / Amber */
  border: 2px solid #ffc107;
}

/* In 3 bis 5 Monaten */
.period-start-future {
  background-color: rgba(13, 202, 240, 0.45) !important; /* Türkis / Cyan */
  border: 2px solid #0dcaf0;
}

/* In 6+ Monaten (Langfristig) */
.period-start-far {
  background-color: rgba(13, 110, 253, 0.35) !important; /* Sanftes Blau */
  border: 2px solid #0d6efd;
}

/* Kein Zeitraum hinterlegt */
.period-start-none {
  background-color: rgba(108, 117, 125, 0.25) !important; /* Neutrales Grau */
  border: 2px solid #6c757d;
}
