/**
 * EE Pipeline Map — Karten-Overlay in der Organisations-Ansicht.
 *
 * v2: Helles Design (analog Organization-View), Full-Screen Modal mit
 *     extrem hohem z-index damit es UEBER dem Divi-Site-Menue liegt.
 *
 * Aufbau:
 *   - Full-Screen Modal (z-index 2147483600) ueber allem
 *   - Header (Titel + Owner-Dropdown + Status-Switch + Close)
 *   - Legende (Sub-Phase-Pillen, klickbar)
 *   - Map-Canvas (Mapbox Satellite)
 *   - KPI-Bar (count / MWp / ha / Provision) als Overlay unten
 *   - Hover-Card (folgt der Maus auf Polygon/Pin)
 *
 * @since 2.23.0
 */

/* ---------- Toggle-Button im Toolbar ---------- */
.viewToggleButton.ee-pmap-toggle.is-active,
.ee-pipeline-settings-btn[data-action="open-pipeline-map"].is-active {
    background: rgba(34, 197, 94, 0.18);
    color: #16a34a;
}

/* ---------- Modal-Container (Full-Screen, helles Theme) ---------- */
#ee-pipeline-map-modal {
    display: none;
    position: fixed;
    inset: 0;
    /* Max-Int z-index. KOMBINIERT mit dem Portal-Pattern in openMap()
       (Modal wird an <body> re-attached), damit z-index nicht in einem
       geschachtelten Divi-Stacking-Context (transform/will-change) gefangen
       ist. Erst beides zusammen liegt zuverlaessig UEBER der Divi-Top-Bar. */
    z-index: 2147483647;
    flex-direction: column;
    background: #f8fafc;
    color: #1f2937;
}
#ee-pipeline-map-modal.is-open { display: flex; }
body.ee-map-open { overflow: hidden; }

/* ---------- Header (hell) ---------- */
.ee-pmap-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 20px;
    background: #ffffff;
    color: #111827;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.ee-pmap-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.2px;
    color: #111827;
}
.ee-pmap-header-title svg {
    width: 20px; height: 20px;
    color: #16a34a;
}
.ee-pmap-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* Owner-Filter Dropdown — visuell IDENTISCH zum Status-Switch-Pill.
   Native <select>, aber gestyled wie ein .ee-pmap-status-btn.is-active. */
.ee-pmap-owner-filter {
    appearance: none;
    -webkit-appearance: none;
    background: #ffffff
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'><polyline points='6 9 12 15 18 9'/></svg>")
        no-repeat right 10px center / 11px 11px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    color: #111827;
    padding: 5px 28px 5px 14px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    line-height: 1.4;
    height: 30px;            /* exakt gleiche Hoehe wie .ee-pmap-status-btn (5px+1.4em+5px) */
    min-width: 160px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: all 0.15s ease;
    font-family: inherit;
}
.ee-pmap-owner-filter:hover { border-color: #d1d5db; box-shadow: 0 1px 3px rgba(0,0,0,0.10); }
.ee-pmap-owner-filter:focus { outline: none; border-color: #16a34a; box-shadow: 0 0 0 3px rgba(22,163,74,0.15); }
.ee-pmap-owner-filter option { color: #1f2937; background: #ffffff; }

/* Status-Switch (Aktiv / On Hold / Lost) */
.ee-pmap-status-switch {
    display: inline-flex;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 2px;
    gap: 2px;
}
.ee-pmap-status-btn {
    background: transparent;
    border: 0;
    color: #6b7280;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    line-height: 1.4;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.ee-pmap-status-btn:hover { color: #111827; }
.ee-pmap-status-btn.is-active {
    background: #ffffff;
    color: #111827;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
/* Farbpunkt vor dem Label — gibt jedem Status seine Farbe */
.ee-pmap-status-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #9ca3af;
    flex: 0 0 9px;
}
.ee-pmap-status-btn[data-status="active"]  .ee-pmap-status-dot { background: #22c55e; }
.ee-pmap-status-btn[data-status="on_hold"] .ee-pmap-status-dot { background: #f59e0b; }
.ee-pmap-status-btn[data-status="lost"]    .ee-pmap-status-dot { background: #ef4444; }
/* Aktiver Status: linker Border in der Farbe als zusaetzlicher Indikator */
.ee-pmap-status-btn.is-active[data-status="active"]  { color: #15803d; }
.ee-pmap-status-btn.is-active[data-status="on_hold"] { color: #b45309; }
.ee-pmap-status-btn.is-active[data-status="lost"]    { color: #b91c1c; }
/* Count-Badge im Pill — neutrales Grau, im aktiven Pill in Status-Farbe */
.ee-pmap-status-count {
    background: #e5e7eb;
    color: #374151;
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
    line-height: 1.4;
}
.ee-pmap-status-btn.is-active[data-status="active"]  .ee-pmap-status-count { background: #dcfce7; color: #15803d; }
.ee-pmap-status-btn.is-active[data-status="on_hold"] .ee-pmap-status-count { background: #fef3c7; color: #b45309; }
.ee-pmap-status-btn.is-active[data-status="lost"]    .ee-pmap-status-count { background: #fee2e2; color: #b91c1c; }

/* Close-Button */
.ee-pmap-close {
    background: transparent;
    border: 0;
    color: #6b7280;
    width: 36px; height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.ee-pmap-close:hover { background: #f3f4f6; color: #111827; }
.ee-pmap-close svg { width: 20px; height: 20px; }

/* ---------- Legende (Sub-Phase-Pillen) ---------- */
.ee-pmap-legend {
    display: flex;
    gap: 6px;
    padding: 10px 20px;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: thin;
}
.ee-pmap-legend::-webkit-scrollbar { height: 4px; }
.ee-pmap-legend::-webkit-scrollbar-thumb {
    background: #e5e7eb;
    border-radius: 4px;
}

.ee-pmap-legend-pill {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    color: #4b5563;
    padding: 5px 11px;
    border-radius: 999px;
    cursor: pointer;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
    white-space: nowrap;
    font-family: inherit;
    line-height: 1.4;
}
.ee-pmap-legend-pill:hover {
    background: #ffffff;
    color: #111827;
    border-color: var(--c, #d1d5db);
}
.ee-pmap-legend-pill.is-active {
    background: #ffffff;
    color: #111827;
    border-color: var(--c);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 22%, transparent);
}
.ee-pmap-legend-pill .dot {
    width: 9px; height: 9px;
    background: var(--c);
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.ee-pmap-legend-pill .cnt {
    background: rgba(0,0,0,0.06);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
    margin-left: 2px;
    color: #4b5563;
    font-weight: 500;
}
.ee-pmap-legend-pill.is-active .cnt {
    background: var(--c);
    color: #fff;
}

/* Sub-Phase-Gruppen-Trenner — feiner vertikaler Strich zwischen Mainphasen */
.ee-pmap-legend-divider {
    width: 1px;
    background: #e5e7eb;
    margin: 2px 4px;
    flex-shrink: 0;
}

/* ---------- Map-Canvas ---------- */
.ee-pmap-canvas-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
}
#ee-pipeline-map-canvas {
    position: absolute;
    inset: 0;
}

/* ---------- Layer-Toolbar (Top-Right-Overlay, neben Mapbox-Navigation) ---------- */
/* Sitzt UNTER der Mapbox-NavigationControl (top-right) damit beide gestapelt
   in derselben Spalte stehen. Zoom-Buttons sind ~30px breit; wir matchen das. */
.ee-pmap-layertools {
    position: absolute;
    top: 90px;             /* unter NavigationControl (Zoom-in + Zoom-out ~70px) */
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 11;
    background: rgba(255,255,255,0.96);
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 4px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.12);
}
.ee-pmap-layertools-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.ee-pmap-layertools-sep {
    height: 1px;
    background: #e5e7eb;
    margin: 2px 4px;
}
.ee-pmap-layerbtn {
    width: 32px; height: 32px;
    background: transparent;
    border: 0;
    border-radius: 6px;
    color: #4b5563;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: all 0.15s ease;
}
.ee-pmap-layerbtn svg {
    width: 18px; height: 18px;
    /* Original-SVGs nutzen path fill="..."; mit currentColor folgen sie der Text-Farbe */
    fill: currentColor;
}
.ee-pmap-layerbtn svg path,
.ee-pmap-layerbtn svg circle,
.ee-pmap-layerbtn svg polygon {
    fill: currentColor;
}
/* Standard-Style-Button hat ein Outline-SVG (Globus) — Outline statt Fill */
.ee-pmap-layerbtn[data-style="standard"] svg,
.ee-pmap-layerbtn[data-style="standard"] svg path,
.ee-pmap-layerbtn[data-style="standard"] svg polygon,
.ee-pmap-layerbtn[data-style="standard"] svg line {
    fill: none;
    stroke: currentColor;
}
.ee-pmap-layerbtn:hover {
    background: #f3f4f6;
    color: #111827;
}
.ee-pmap-layerbtn.is-active {
    background: #16a34a;
    color: #ffffff;
}
.ee-pmap-layerbtn.is-active:hover {
    background: #15803d;
}

/* ---------- Layer-Legenden (sichtbar nur bei aktivem Overlay) ---------- */
.ee-pmap-layerlegends {
    position: absolute;
    top: 90px;
    right: 60px; /* links neben der Layer-Toolbar (32px btn + paddings + gap) */
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 11;
    max-width: 240px;
    pointer-events: none;
}
.ee-pmap-legend-section {
    background: rgba(255,255,255,0.96);
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 8px 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.12);
    font-size: 12px;
    color: #1f2937;
    pointer-events: auto;
}
.ee-pmap-legend-header {
    font-weight: 600;
    margin-bottom: 6px;
    color: #111827;
}
.ee-pmap-legend-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.ee-pmap-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.3;
}
.ee-pmap-legend-color {
    flex: 0 0 14px;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.15);
    display: inline-block;
}
.ee-pmap-legend-text {
    flex: 1 1 auto;
}

/* ---------- KPI-Bar (Bottom-Overlay, hell) ---------- */
.ee-pmap-kpis {
    position: absolute;
    left: 50%;
    bottom: 18px;
    transform: translateX(-50%);
    display: flex;
    gap: 0;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 4px 4px;
    color: #1f2937;
    font-size: 13px;
    z-index: 10;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}
.ee-pmap-kpi {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-right: 1px solid #e5e7eb;
    white-space: nowrap;
}
.ee-pmap-kpi:last-child { border-right: 0; }
.ee-pmap-kpi svg {
    width: 16px; height: 16px;
    color: #6b7280;
    flex-shrink: 0;
}
.ee-pmap-kpi-commission svg { color: #16a34a; }
.ee-pmap-kpi span { font-weight: 600; color: #111827; }

/* ---------- Hover-Card (hell, mit Schatten) ---------- */
#ee-pipeline-map-card {
    position: absolute;
    display: none;
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
    border: 1px solid #e5e7eb;
    padding: 12px 14px;
    min-width: 280px;
    max-width: 340px;
    pointer-events: none;
    font-size: 13px;
    z-index: 20;
    color: #1f2937;
    line-height: 1.4;
}
.ee-pmap-card-head {
    border-left: 4px solid #888;
    padding-left: 10px;
    margin-bottom: 10px;
}
.ee-pmap-card-title {
    font-weight: 600;
    font-size: 14px;
    color: #111827;
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.3;
}
.ee-pmap-card-sub {
    color: #6b7280;
    font-size: 12px;
    margin-top: 2px;
}
.ee-pmap-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
    align-items: center;
}
.ee-pmap-pill {
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.4;
}
.ee-pmap-card-status {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.ee-pmap-card-status.on_hold { background: #fef3c7; color: #92400e; }
.ee-pmap-card-status.lost    { background: #fee2e2; color: #991b1b; }
.ee-pmap-days {
    color: #9ca3af;
    font-size: 11px;
    margin-left: auto;
    white-space: nowrap;
}
.ee-pmap-card-kpis {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
    border-top: 1px solid #f3f4f6;
    padding-top: 8px;
    color: #374151;
}
.ee-pmap-card-kpis .ee-pmap-kpi {
    padding: 0;
    border: 0;
    font-size: 12px;
}
.ee-pmap-card-kpis .ee-pmap-kpi svg {
    width: 14px; height: 14px;
    color: #6b7280;
}
.ee-pmap-card-kpis .ee-pmap-kpi-commission svg { color: #16a34a; }
.ee-pmap-card-kpis .ee-pmap-kpi-commission span { color: #16a34a; font-weight: 600; }
.ee-pmap-card-kpis .ee-pmap-kpi-battery svg { color: #2563eb; }

.ee-pmap-card-owner {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #f3f4f6;
    color: #6b7280;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.ee-pmap-card-owner svg {
    width: 14px; height: 14px;
    color: #9ca3af;
}
.ee-pmap-card-hint {
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px dashed #e5e7eb;
    color: #2563eb;
    font-size: 11px;
    font-style: italic;
    text-align: center;
}

/* ---------- Loading-Overlay (hell) ---------- */
#ee-pipeline-map-loading {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(2px);
    z-index: 15;
}
.ee-pmap-spinner {
    width: 44px; height: 44px;
    border: 3px solid #e5e7eb;
    border-top-color: #16a34a;
    border-radius: 50%;
    animation: ee-pmap-spin 0.8s linear infinite;
}
@keyframes ee-pmap-spin { to { transform: rotate(360deg); } }

/* ---------- Empty-State (hell) ---------- */
.ee-pmap-empty {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: #374151;
    text-align: center;
    z-index: 12;
    pointer-events: none;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    padding: 18px 24px;
    border-radius: 10px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}
.ee-pmap-empty h4 { margin: 0 0 6px; font-size: 15px; color: #111827; }
.ee-pmap-empty p  { margin: 0; font-size: 13px; color: #6b7280; }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
    .ee-pmap-header { padding: 10px 12px; flex-wrap: wrap; gap: 10px; }
    .ee-pmap-header-title { font-size: 14px; }
    .ee-pmap-header-actions { gap: 8px; }
    .ee-pmap-owner-filter { min-width: 0; flex: 1; }
    .ee-pmap-status-switch { order: 3; flex: 1 0 100%; }
    .ee-pmap-status-btn { padding: 5px 10px; font-size: 11px; }

    .ee-pmap-legend { padding: 8px 12px; gap: 4px; }
    .ee-pmap-legend-pill { font-size: 11px; padding: 4px 9px; }

    .ee-pmap-kpis {
        width: calc(100% - 16px);
        bottom: 12px;
        font-size: 12px;
        flex-wrap: wrap;
        justify-content: center;
    }
    .ee-pmap-kpi { padding: 4px 8px; }
    .ee-pmap-kpi svg { width: 14px; height: 14px; }

    #ee-pipeline-map-card { max-width: 78vw; min-width: 220px; font-size: 12px; }
}
