/* ======================================
   KK Leaflet Map – Design System
   Uses CSS custom properties from admin
   ====================================== */

/* Outer Frame Container - Now fully responsive and fills width */
.kk-leaflet-map-frame {
    position: relative;
    display: block;
    width: 100vw !important; /* Full width of the viewport */
    height: 100vh; /* Full viewport height */
    box-sizing: border-box;
    margin: 0 !important;
    padding: 0;
    overflow: hidden;

    /* BREAKOUT: Force full width even inside constrained WP containers */
    left: 50% !important;
    right: 50% !important;
    margin-left: -50vw !important;
    margin-right: -50vw !important;
    max-width: none !important;
}

/* Decorative Background Border - Adjusted for edge-to-edge */
.kk-leaflet-map-frame-border {
    position: absolute;
    inset: 0;
    z-index: 0;
    background: linear-gradient(135deg, var(--kk-frame-bg-start, #1a1a2e) 0%, var(--kk-frame-bg-end, #0f3460) 100%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* Handle WordPress Admin Bar overlap */
.admin-bar .kk-leaflet-map-frame {
    height: calc(100vh - 32px) !important;
}
@media screen and (max-width: 782px) {
    .admin-bar .kk-leaflet-map-frame {
        height: calc(100vh - 46px) !important;
    }
}

/* Gold corner accents - hidden in full-page to save space */
.kk-leaflet-map-frame-border::before,
.kk-leaflet-map-frame-border::after {
    display: none;
}

/* Inner stacking container - Use Flexbox for vertical stacking */
.kk-leaflet-map-inner {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* ======================================
   Map Menu (above the map)
   ====================================== */
.kk-map-menu {
    flex: 0 0 auto;
    display: flex;
    gap: 2px;
    background: rgba(0,0,0,0.2);
    padding: 6px 8px;
    overflow-x: auto;
    border-bottom: 1px solid color-mix(in srgb, var(--kk-frame-accent, #e0b068) 20%, transparent);
    width: 100%;
    box-sizing: border-box;
    white-space: nowrap;
}

.kk-map-menu-item {
    padding: 8px 18px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
    color: var(--kk-legend-text, #d4d4d4);
    text-decoration: none;
    border-radius: 6px;
    transition: all 0.2s ease;
    white-space: nowrap;
    cursor: pointer;
    border: 1px solid transparent;
}
.kk-map-menu-item:hover {
    background: color-mix(in srgb, var(--kk-frame-accent, #e0b068) 12%, transparent);
    color: var(--kk-frame-accent, #e0b068);
    text-decoration: none;
}
.kk-map-menu-item.active {
    background: color-mix(in srgb, var(--kk-frame-accent, #e0b068) 18%, transparent);
    color: var(--kk-frame-accent, #e0b068);
    border-color: color-mix(in srgb, var(--kk-frame-accent, #e0b068) 35%, transparent);
}

/* Menu scrollbar */
.kk-map-menu::-webkit-scrollbar { height: 3px; }
.kk-map-menu::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 10px; }

/* ======================================
   Map + Legend Wrapper - Use Flexbox to fill remaining space
   ====================================== */
.kk-leaflet-map-wrapper {
    flex: 1; 
    position: relative;
    z-index: 1;
    display: flex;
    gap: 0;
    align-items: stretch;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Sidebar Legend - Flexible but with minimum width */
.kk-map-sidebar-legend {
    flex: 0 0 320px;
    background: rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    height: 100%;
    border-right: 1px solid rgba(255,255,255,0.05);
}
.kk-map-sidebar-legend.hidden { display: none; }

/* Legend on the left (default) */
.kk-leaflet-map-wrapper.kk-legend-left .kk-map-sidebar-legend {
    order: 0;
    border-radius: 0 0 0 8px;
}
.kk-leaflet-map-wrapper.kk-legend-left .kk-leaflet-map-container {
    order: 1;
    border-radius: 0 0 8px 0;
}

/* Legend on the right */
.kk-leaflet-map-wrapper.kk-legend-right .kk-map-sidebar-legend {
    order: 2;
    border-radius: 0 0 8px 0;
}
.kk-leaflet-map-wrapper.kk-legend-right .kk-leaflet-map-container {
    order: 1;
    border-radius: 0 0 0 8px;
}

/* No legend */
.kk-leaflet-map-wrapper.kk-legend-none .kk-leaflet-map-container {
    border-radius: 0 0 8px 8px;
}

/* When no menu, fix top corners */
.kk-leaflet-map-inner > .kk-leaflet-map-wrapper:first-child .kk-map-sidebar-legend {
    border-top-left-radius: 8px;
}
.kk-leaflet-map-inner > .kk-leaflet-map-wrapper:first-child .kk-leaflet-map-container {
    border-top-right-radius: 8px;
}

/* ======================================
   Sidebar Legend
   ====================================== */
/* Legend Header & Controls */
.kk-map-legend-header {
    padding: 18px;
    background: linear-gradient(90deg, color-mix(in srgb, var(--kk-legend-title, #e0b068) 15%, transparent) 0%, transparent 100%);
    border-bottom: 1px solid color-mix(in srgb, var(--kk-frame-accent, #e0b068) 20%, transparent);
}
.kk-map-legend-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.kk-map-legend-header h4 {
    margin: 0 !important;
    padding: 0 !important;
}

/* Search Bar */
.kk-legend-search-wrap {
    margin-bottom: 10px;
    position: relative;
    padding: 0 18px;
}
.kk-legend-search {
    width: 100%;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: #fff;
    padding: 8px 12px 8px 32px;
    font-size: 11px;
    outline: none;
    transition: all 0.2s;
}
.kk-legend-search:focus {
    background: rgba(255,255,255,0.1);
    border-color: var(--kk-frame-accent, #e0b068);
}
.kk-legend-search-icon {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.5;
    font-size: 12px;
}

/* Global Buttons */
.kk-legend-global-actions {
    display: flex;
    gap: 6px;
    padding: 0 18px 12px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.kk-legend-btn {
    flex: 1;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    color: #fff;
    font-size: 10px;
    padding: 5px;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    font-weight: 700;
}
.kk-legend-btn:hover {
    background: rgba(255,255,255,0.12);
    border-color: var(--kk-frame-accent, #e0b068);
}

.kk-legend-switch {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.kk-legend-switch {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}
.kk-legend-switch .switch-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--kk-legend-text, #888);
}
.kk-legend-switch .switch-ui {
    width: 32px;
    height: 16px;
    background: rgba(255,255,255,0.1);
    border-radius: 20px;
    position: relative;
    transition: all 0.3s ease;
}
.kk-legend-switch .switch-ui::before {
    content: '';
    position: absolute;
    width: 12px;
    height: 12px;
    top: 2px;
    left: 2px;
    background: #fff;
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.kk-legend-switch.active .switch-ui {
    background: var(--kk-frame-accent, #e0b068);
}
.kk-legend-switch.active .switch-ui::before {
    left: 18px;
}
.kk-legend-switch.active .switch-label {
    color: var(--kk-legend-title, #e0b068);
}

.kk-map-legend-scrollable {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
}

/* Scrollbar */
.kk-map-legend-scrollable::-webkit-scrollbar { width: 5px; }
.kk-map-legend-scrollable::-webkit-scrollbar-track { background: rgba(255,255,255,0.03); }
.kk-map-legend-scrollable::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--kk-frame-accent, #e0b068) 35%, transparent); border-radius: 10px; }

/* Sections */
.kk-legend-section-wrap {
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    padding-bottom: 6px;
}
.kk-legend-section-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    cursor: pointer;
}
.kk-legend-section-title {
    flex: 1;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--kk-legend-title, #e0b068);
}
.kk-legend-chevron {
    font-size: 9px;
    transition: transform 0.2s;
    opacity: 0.5;
}
.kk-legend-section-wrap.collapsed .kk-legend-chevron {
    transform: rotate(-90deg);
}
.kk-legend-section-content {
    display: block;
}
.kk-legend-section-wrap.collapsed .kk-legend-section-content {
    display: none;
}

.kk-section-toggle {
    width: 22px;
    height: 11px;
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
    position: relative;
    cursor: pointer;
}
.kk-section-toggle::after {
    content: '';
    position: absolute;
    left: 2px;
    top: 2px;
    width: 7px;
    height: 7px;
    background: #fff;
    border-radius: 50%;
    transition: left 0.2s;
}
.kk-section-toggle.active { background: #4ecdc4; }
.kk-section-toggle.active::after { left: 13px; }

/* Legend Sections (legacy fallback) */
.legend-section {
    display: none;
}

.legend-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 2px;
    padding: 5px 8px;
    border-radius: 4px;
    color: var(--kk-legend-text, #ccc);
    transition: all 0.2s ease;
    background: rgba(255,255,255,0.02);
}
.legend-item.clickable { cursor: pointer; }
.legend-item:hover:not(.disabled) { background: rgba(255, 255, 255, 0.08); }
.legend-item.disabled { opacity: 0.3; filter: grayscale(0.8); }
.legend-item.hidden { display: none !important; }

.legend-item-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.legend-count {
    font-size: 10px;
    font-family: monospace;
    background: rgba(255,255,255,0.08);
    padding: 1px 6px;
    border-radius: 10px;
    opacity: 0.6;
}

.marker-bullet {
    font-size: 12px;
    line-height: 1;
}

.legend-placeholder {
    color: #888;
    font-size: 13px;
    padding: 10px;
}

/* ======================================
   Map Container
   ====================================== */
.kk-leaflet-map-container {
    position: relative;
    overflow: hidden;
    flex: 1; /* Take all remaining width */
    height: 100%;
    background: #000;
    border: none !important;
    outline: none !important;
}

.kk-leaflet-map {
    width: 100% !important;
    height: 100% !important;
    display: block;
    background: transparent !important; /* Remove the "graue Rand" */
}

/* Ensure the wrapper doesn't have a background leak */
.leaflet-container {
    background: transparent !important;
    outline: none !important;
}

/* ======================================
   Markers & Pins
   ====================================== */
.kk-json-ping .kk-ping-inner {
    width: 10px;
    height: 10px;
    background: #007bff;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 8px rgba(0, 123, 255, 0.8);
    animation: kk-ping-pulse 2s infinite;
}

@keyframes kk-ping-pulse {
    0%   { transform: scale(0.9); opacity: 1; }
    50%  { transform: scale(1.2); opacity: 0.6; }
    100% { transform: scale(0.9); opacity: 1; }
}

/* ======================================
   Tooltip / Info Box
   ====================================== */
.kk-leaflet-tooltip {
    background: color-mix(in srgb, var(--kk-tooltip-bg, #16213e) 96%, transparent);
    border: 1px solid color-mix(in srgb, var(--kk-frame-accent, #e0b068) 35%, transparent);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    padding: 10px 12px;
    font-family: 'Segoe UI', system-ui, sans-serif;
    pointer-events: none;
    color: var(--kk-tooltip-text, #d4d4d4);
}

.kk-info-box strong {
    display: block;
    font-size: 13px;
    color: var(--kk-legend-title, #e0b068);
    margin-bottom: 3px;
}

.kk-info-box small {
    color: #aaa;
    font-weight: 600;
}

/* ======================================
   Coordinates Display
   ====================================== */
.kk-map-coords-display {
    background: color-mix(in srgb, var(--kk-coords-bg, #16213e) 85%, transparent) !important;
    color: var(--kk-coords-text, #e0b068) !important;
    border: 1px solid color-mix(in srgb, var(--kk-frame-accent, #e0b068) 25%, transparent) !important;
    border-radius: 4px !important;
    padding: 4px 10px !important;
    font-size: 11px !important;
    font-family: 'Segoe UI', monospace !important;
    letter-spacing: 0.5px;
}

/* ======================================
   Standalone Legend (separate shortcode)
   ====================================== */
.kk-standalone-legend-wrap {
    display: inline-block;
}
.kk-standalone-legend {
    height: auto !important;
    max-height: var(--kk-map-height, 600px);
    border-radius: 8px !important;
    border: 1px solid color-mix(in srgb, var(--kk-frame-accent, #e0b068) 30%, transparent);
}

/* ======================================
   Old in-map legend (hidden)
   ====================================== */
.kk-map-legend {
    display: none;
}
