/**
 * PROZESSDIAGRAM.CSS
 * ===================
 * 
 * Ein umfassendes CSS-Framework für interaktive Prozessdiagramme mit Grid-Layout,
 * dynamischer Pfeil-Generierung und responsivem Design.
 * 
 * Funktionen:
 * - Dynamische Grid-Layouts (optimiert basierend auf Content)
 * - SVG-Pfeil-Verbindungen zwischen Elementen
 * - Responsive Design mit Container Queries
 * - Tooltip-System für zusätzliche Informationen
 * - Verschiedene Box-Typen (process, side-element, infrastructure)
 * - Min/Max-Width-Constraints (600px-1200px)
 * 
 * Verwendung:
 * 1. Einbinden: <link rel="stylesheet" href="prozessdiagram.css">
 * 2. Container: <div class="ki-workflow-container" id="my-diagram">
 * 3. Boxen: <div class="process-box" style="grid-column: 1/span 3; grid-row: 1/span 3;">
 * 4. JavaScript: prozessdiagram.js für Pfeil-Generierung laden
 */

/* ===== WORKFLOW CONTAINER STYLING ===== */
.ki-workflow-container {
  display: grid;
  grid-template-columns: repeat(36, minmax(0, 1fr)); /* Default 36x36 Grid, wird von JavaScript überschrieben */
  grid-template-rows: repeat(36, minmax(0, 1fr));
  gap: 2px;
  width: 100%; /* Responsive: passt sich dem umgebenden Container an */
  min-width: 300px; /* Reduzierte Minimum-Breite für mobile Geräte */
  max-width: 1200px; /* Maximum-Breite für optimale Darstellung */
  box-sizing: border-box;
  position: relative;
  justify-items: stretch;
  align-items: stretch;
  margin: 2rem auto; /* Zentrierte optimierte Container */
  container-type: inline-size; /* Ermöglicht Container Queries */
  container-name: workflow-container;
}

/* Grid-Hintergrund mit dynamischen Linien */
.ki-workflow-container::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to right, rgba(200,200,200,0.3) 1px, transparent 1px) 0 0 / 
    calc(100% / var(--grid-cols, 36)) 100% repeat,
    linear-gradient(to bottom, rgba(200,200,200,0.3) 1px, transparent 1px) 0 0 / 
    100% calc(100% / var(--grid-rows, 36)) repeat;
}

/* ===== BOX-STYLING ===== */

/**
 * Basis-Styling für alle Box-Typen
 * 
 * Box-Typen:
 * - .process-box: Hauptprozess-Schritte (höchste z-index: 20)
 * - .side-element: Seitliche Elemente (z-index: 15)  
 * - .infrastructure-box: Infrastruktur-Komponenten (z-index: 15)
 * 
 * Grid-Positionierung:
 * style="grid-column: START / span BREITE; grid-row: START / span HÖHE;"
 * Beispiel: style="grid-column: 1 / span 3; grid-row: 7 / span 3;"
 */
.process-box,
.side-element,
.infrastructure-box {
  margin: 0;
  padding: 12px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center; /* Zentrierte Inhalte */
  width: 100%;
  height: 100%;
  min-width: 100%;
  min-height: 44px; /* Touch-freundliche Mindesthöhe */
  overflow: visible;
  font-size: 1em; /* Einheitliche Basis-Schriftgröße */
  line-height: 1.3;
  word-break: break-word;
  text-align: center;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  justify-self: stretch;
  align-self: stretch;
  position: relative; /* Erforderlich für absolute Positionierung der Info-Icons */
  transition: all 0.3s ease;
}

/* Z-Index-Hierarchie für Layering */
.process-box {
  z-index: 20; /* Hauptprozess-Boxen im Vordergrund */
}

.side-element,
.infrastructure-box {
  z-index: 15; /* Seitliche und Infrastruktur-Elemente im Hintergrund */
}

/* ===== TEXT-STYLING ===== */

/* Box-Titel */
.box-title {
    font-size: 1.1em; /* Einheitliche Größe für alle Charts */
    margin-bottom: 0;
    margin-top: 0;
    color: #333;
    font-weight: bold;
}

/* ===== INFO-BOX & TOOLTIP-SYSTEM ===== */

/**
 * Info-Box-System für zusätzliche Informationen
 * 
 * Verwendung:
 * <div class="process-box info-box-enabled" data-info="Tooltip-Text hier">
 * 
 * Das data-info Attribut enthält den HTML-Inhalt des Tooltips.
 * <br> Tags werden als Zeilenumbrüche interpretiert.
 */
.info-box-enabled::after {
    content: "Details »";
    font-size: 0.7em;
    color: #007cba;
    cursor: pointer;
    position: absolute;
    bottom: 4px;
    right: 8px;
    opacity: 0.7;
    transition: opacity 0.3s ease, color 0.3s ease;
    z-index: 10;
    font-weight: normal;
    letter-spacing: 0.5px;
}

.info-box-enabled:hover::after {
    opacity: 1;
    color: #005a87;
}

/* Legacy support for existing .info-icon class (falls noch verwendet) */
.info-icon {
    font-size: 0.8em;
    color: #007cba;
    cursor: pointer;
    position: absolute;
    bottom: 4px;
    right: 4px;
    opacity: 0.7;
    transition: opacity 0.3s ease, color 0.3s ease;
    z-index: 10;
}

.info-icon:hover {
    opacity: 1;
    color: #005a87;
}

/* Tooltip-Styling */
.tooltip {
    position: absolute;
    background: var(--color-bg-primary);
    border: 2px solid var(--color-primary);
    border-radius: 8px;
    padding: 10px;
    font-size: 0.7em;
    line-height: 1.3;
    color: #333;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 1000;
    max-width: 250px;
    min-width: 200px;
    word-wrap: break-word;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.tooltip.show {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.tooltip-close {
    position: absolute;
    top: 4px;
    right: 6px;
    background: none;
    border: none;
    font-size: 14px;
    color: #666;
    cursor: pointer;
    padding: 0;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 2px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.tooltip-close:hover {
    background-color: #eee;
    color: #333;
}

/* ===== SVG-PFEIL-SYSTEM ===== */

/**
 * SVG-Layer für Verbindungslinien zwischen Elementen
 * 
 * Die Pfeile werden automatisch von JavaScript generiert basierend auf data-arrows Attributen:
 * data-arrows="ziel-id:typ,anderes-ziel:anderer-typ"
 * 
 * Verfügbare Pfeil-Typen:
 * - horizontal: Direkte horizontale Verbindung
 * - vertical: Direkte vertikale Verbindung  
 * - L-top: L-förmiger Pfeil nach oben
 * - L-bottom: L-förmiger Pfeil nach unten
 * - L-right: L-förmiger Pfeil nach rechts
 * 
 * Beispiel:
 * <div data-arrows="next-step:horizontal,feedback:L-bottom:dashed">
 */
.connections-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5; /* Zwischen Hintergrund und Boxen */
    overflow: visible;
    color: #333; /* Standard-Farbe für Pfeilspitzen (via currentColor) */
}

/* Pfeil-Linien-Styling */
.connection-line {
    stroke: #333;
    stroke-width: 2;
    fill: none;
    transition: stroke 0.3s ease;
}

/* Gestrichelte Linien für optionale/Feedback-Verbindungen */
.dashed-line {
    stroke-dasharray: 5 3;
}

/* Multi-Target T-Junction Path Styling */
.multi-target-path {
    stroke: #333;
    stroke-width: 2;
    fill: none;
    transition: stroke 0.3s ease;
}

/* T-Junction Point Styling */
.junction-point {
    fill: #333;
    r: 2px;
    transition: fill 0.3s ease;
}

/* Branch-Line spezifische Styles */
.branch-line {
    stroke: #333;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: stroke 0.3s ease;
}

/* ===== FARBSCHEMA ===== */

/**
 * Standard-Farbschema für verschiedene Box-Typen
 * 
 * Verwendung als inline-style:
 * style="background-color: #E8F4F8;" (Process Blue)
 * 
 * Verfügbare Farben:
 * - Process Blue: #E8F4F8 (Hauptprozess-Schritte)
 * - Process Yellow: #FFF3CD (Entscheidungen/Eingaben)  
 * - Process Red: #FFE5E5 (Kritische Schritte)
 * - Process Light Blue: #E5F3FF (Ausgaben/Ergebnisse)
 * - Process Green: #E8F8E8 (Erfolg/Abschluss)
 * - Side Yellow: #FFFACD (Seitliche Elemente)
 * - Side Light Blue: #F0F8FF (Seitliche Elemente Alt)
 * - Side Light Green: #F0FFF0 (Seitliche Elemente Alt)
 * - Infrastructure: #FFF5EE (Infrastruktur-Komponenten)
 */

/* ===== RESPONSIVE DESIGN ===== */

/**
 * Container Queries für optimale Darstellung bei verschiedenen Breiten
 * Automatische Anpassung von Schriftgrößen, Padding und Abständen
 */
@container workflow-container (max-width: 1000px) {
    .process-box,
    .side-element,
    .infrastructure-box {
        padding: 10px;
        font-size: 0.9em;
    }
    
    .box-title {
        font-size: 1.0em;
    }
    
    .ki-workflow-container {
        gap: 1.5px;
    }
}

@container workflow-container (max-width: 800px) {
    .process-box,
    .side-element,
    .infrastructure-box {
        padding: 8px;
        font-size: 0.8em;
    }
    
    .box-title {
        font-size: 0.95em;
    }
    
    .ki-workflow-container {
        gap: 1px;
    }
    
    .info-icon {
        font-size: 0.9em;
        bottom: 2px;
        right: 2px;
    }
    
    .tooltip {
        font-size: 0.8em;
        max-width: 200px;
        min-width: 150px;
        padding: 8px;
    }
}

@container workflow-container (max-width: 600px) {
    .process-box,
    .side-element,
    .infrastructure-box {
        padding: 4px; /* Reduzierte Abstände zum Rand */
        font-size: 0.65em; /* Kleinere Schrift für kompakte Darstellung */
        border-radius: 4px;
    }
    
    .box-title {
        font-size: 0.8em; /* Deutlich kleinere Titel */
        font-weight: normal; /* Nicht bold für bessere Lesbarkeit */
        line-height: 1.2; /* Kompaktere Zeilenhöhe */
    }
    
    .info-box-enabled::after {
        font-size: 0.6em; /* Kleinere "Details »" Icons */
        bottom: 2px;
        right: 4px;
    }
    
    .info-icon {
        font-size: 0.8em;
        bottom: 1px;
        right: 1px;
    }
    
    .tooltip {
        font-size: 0.75em;
        max-width: 160px;
        min-width: 100px;
        padding: 4px; /* Reduzierte Tooltip-Abstände */
    }
}

/* Mobile-spezifische Pfeil-Optimierung für sehr kleine Displays */
@container workflow-container (max-width: 400px) {
    /* Noch kompaktere Darstellung für sehr kleine Displays */
    .process-box,
    .side-element,
    .infrastructure-box {
        padding: 3px; /* Minimale Abstände */
        font-size: 0.6em; /* Sehr kleine Schrift */
    }
    
    .box-title {
        font-size: 0.75em;
        font-weight: normal;
        line-height: 1.1;
    }
    
    .ki-workflow-container {
        gap: 0.5px; /* Minimaler Abstand zwischen Grid-Zellen */
    }
    
    .info-box-enabled::after {
        font-size: 0.55em;
        bottom: 1px;
        right: 2px;
    }
    
    /* Kleinere Pfeillinien für mobile Darstellung */
    .connection-line {
        stroke-width: 1.5; /* Dünnere Linien */
    }
    
    /* Mobile T-Junction Optimierung */
    .multi-target-path {
        stroke-width: 1.5; /* Dünnere T-Junction Linien */
    }
    
    .junction-point {
        r: 1.5px; /* Kleinere Junction-Punkte */
    }
    
    .branch-line {
        stroke-width: 1.5; /* Dünnere Branch-Linien */
    }
}

/* ===== MOBILE PFEIL-SYSTEM ===== */

/**
 * Responsive Pfeil-Größen basierend auf Container-Größe
 * Desktop: 8x4px Pfeile (Standard)
 * Mobile: 5x3px Pfeile (kompakt)
 */

/* Mobile Pfeil-Marker - werden via JavaScript dynamisch erstellt */
@container workflow-container (max-width: 500px) {
    /* Marker-Größen werden via JavaScript angepasst für mobile */
    .connections-layer {
        /* Mobile-spezifische Pfeil-Einstellungen */
    }
}

/* ===== PRINT-STYLING ===== */
@media print {
    .ki-workflow-container {
        width: 100% !important;
        max-width: none !important;
        break-inside: avoid;
    }
    
    .process-box,
    .side-element,
    .infrastructure-box {
        break-inside: avoid;
        border: 1px solid black !important;
        background: white !important;
        color: black !important;
    }
    
    .info-icon {
        display: none; /* Verstecke interaktive Elemente beim Drucken */
    }
    
    .tooltip {
        display: none;
    }
}

/* ===== ACCESSIBILITY ===== */

/**
 * Accessibility-Verbesserungen
 * - Focus-Styling für Tastatur-Navigation
 * - High-Contrast-Modi Unterstützung
 * - Reduced-Motion Unterstützung
 */
.info-icon:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .process-box,
    .side-element,
    .infrastructure-box,
    .info-icon,
    .tooltip {
        transition: none;
    }
}

@media (prefers-contrast: high) {
    .process-box,
    .side-element,
    .infrastructure-box {
        border-width: 2px;
    }
    
    .connection-line {
        stroke-width: 3;
    }
}

/* ===== DARK MODE SUPPORT ===== */

/**
 * Dark Mode Anpassungen für bessere Sichtbarkeit
 * Pfeile und Pfeilspitzen werden weiß dargestellt im Dark Mode
 */
[data-theme="dark"] .connections-layer {
    color: #ffffff; /* Pfeilspitzen-Farbe über currentColor */
}

[data-theme="dark"] .connections-layer .connection-line {
    stroke: #ffffff !important; /* Pfeillinien-Farbe - erhöhte Spezifität */
}

[data-theme="dark"] .connections-layer .dashed-line {
    stroke: #ffffff !important; /* Gestrichelte Linien-Farbe - erhöhte Spezifität */
}

/* Dark Mode Support für Multi-Target Arrows */
[data-theme="dark"] .multi-target-path {
    stroke: #ffffff !important;
}

[data-theme="dark"] .junction-point {
    fill: #ffffff !important;
}

[data-theme="dark"] .branch-line {
    stroke: #ffffff !important;
}