/* ===========================
   Hundklubbar.se - Stylesheet
   Nature-inspired design system
   =========================== */

/* Design tokens */
:root {
    --color-primary: #2D5A27;       /* Forest green */
    --color-secondary: #5D4037;     /* Earth brown */
    --color-background: #F5E6D3;    /* Sand */
    --color-text: #333333;          /* Dark text */
    --color-white: #FFFFFF;         /* White accent */
    --color-error: #D32F2F;         /* Error red */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.25);
    --radius: 8px;
    --radius-lg: 12px;
    --z-map: 1;
    --z-controls: 1000;
    --z-search: 1001;
    --z-popup: 1002;
    --z-loading: 2000;
}

/* Reset */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-family);
    color: var(--color-text);
}

/* Map - full viewport */
#map {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: var(--z-map);
}

/* Loading overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--color-background);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: var(--z-loading);
    transition: opacity 0.3s ease;
}

#loading-overlay.hidden {
    display: flex !important;
    opacity: 0;
    pointer-events: none;
}

#loading-overlay.removed {
    display: none !important;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--color-background);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#loading-overlay p {
    margin-top: 16px;
    font-size: 1.1rem;
    color: var(--color-secondary);
    font-weight: 500;
}

/* Error message */
#error-message {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-error);
    color: var(--color-white);
    padding: 12px 24px;
    border-radius: var(--radius);
    z-index: var(--z-popup);
    box-shadow: var(--shadow);
    font-size: 0.95rem;
    max-width: 90%;
    text-align: center;
}

#error-message.hidden {
    display: none;
}

/* Search container */
#search-container {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-search);
    width: 90%;
    max-width: 420px;
}

#search-input {
    width: 100%;
    padding: 12px 16px;
    font-size: 1rem;
    border: 2px solid var(--color-primary);
    border-radius: var(--radius);
    background: var(--color-white);
    color: var(--color-text);
    box-shadow: var(--shadow);
    outline: none;
    font-family: var(--font-family);
}

#search-input:focus {
    border-color: var(--color-secondary);
    box-shadow: var(--shadow-lg), 0 0 0 3px rgba(45, 90, 39, 0.5);
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

#search-input::placeholder {
    color: #767676;
}

/* Ensure native clear button on search input is visible */
#search-input::-webkit-search-cancel-button {
    -webkit-appearance: searchfield-cancel-button;
    cursor: pointer;
}

/* Search results dropdown */
#search-results {
    display: none;
    background: var(--color-white);
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
    max-height: 300px;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

#search-results.visible {
    display: block;
}

.search-result-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    transition: background 0.15s;
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover,
.search-result-item:focus {
    background: var(--color-background);
}

.search-result-item:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

.search-result-item .club-name {
    font-weight: 600;
    color: var(--color-text);
}

.search-result-item .district-name {
    font-size: 0.85rem;
    color: #555;
    margin-top: 2px;
}

.search-no-results {
    padding: 12px 16px;
    color: #555;
    font-style: italic;
    text-align: center;
}

/* Logo */
#logo-container {
    position: fixed;
    bottom: 16px;
    left: 16px;
    z-index: var(--z-controls);
    pointer-events: none;
}

#logo-text {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-primary);
    background: rgba(255, 255, 255, 0.9);
    padding: 4px 10px;
    border-radius: 4px;
    box-shadow: var(--shadow);
}

/* Custom Leaflet popup styling */
.leaflet-popup-content-wrapper {
    background: var(--color-background) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-lg) !important;
    padding: 0 !important;
}

.leaflet-popup-content {
    margin: 0 !important;
    padding: 16px !important;
    min-width: 220px;
}

.leaflet-popup-tip {
    background: var(--color-background) !important;
}

.popup-club-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 4px;
}

.popup-district-name {
    font-size: 0.9rem;
    color: #555;
    margin-bottom: 16px;
}

.popup-nav-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.popup-nav-btn {
    display: block;
    text-align: center;
    padding: 12px 16px;
    border-radius: var(--radius);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: var(--font-family);
    min-height: 44px;
    line-height: 1.3;
    transition: opacity 0.15s;
}

.popup-nav-btn:hover {
    opacity: 0.85;
}

.popup-nav-btn.google {
    background: var(--color-primary);
    color: var(--color-white);
}

.popup-nav-btn.apple {
    background: var(--color-secondary);
    color: var(--color-white);
}

/* Geolocation button */
.geolocation-btn {
    width: 44px;
    height: 44px;
    background: var(--color-white);
    border: 2px solid var(--color-primary);
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    transition: background 0.15s;
}

.geolocation-btn:hover {
    background: var(--color-background);
}

.geolocation-btn:focus {
    outline: 3px solid rgba(45, 90, 39, 0.4);
    outline-offset: 2px;
}

.geolocation-btn svg {
    width: 22px;
    height: 22px;
    fill: var(--color-primary);
}

/* Layer switcher */
.layer-switcher {
    background: var(--color-white);
    border: 2px solid var(--color-primary);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.layer-switcher-toggle {
    width: 44px;
    height: 44px;
    background: var(--color-white);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.layer-switcher-toggle:hover {
    background: var(--color-background);
}

.layer-switcher-toggle:focus {
    outline: 3px solid rgba(45, 90, 39, 0.4);
    outline-offset: -3px;
}

.layer-switcher-toggle svg {
    width: 22px;
    height: 22px;
    fill: var(--color-primary);
}

.layer-options {
    display: none;
    padding: 4px 0;
    min-width: 160px;
}

.layer-options.visible {
    display: block;
}

.layer-option {
    display: block;
    width: 100%;
    padding: 10px 14px;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-size: 0.9rem;
    font-family: var(--font-family);
    color: var(--color-text);
    transition: background 0.15s;
}

.layer-option:hover {
    background: var(--color-background);
}

.layer-option.active {
    font-weight: 700;
    color: var(--color-primary);
    background: rgba(45, 90, 39, 0.08);
}

/* Custom marker icon */
.custom-marker {
    background: none !important;
    border: none !important;
}

/* Leaflet zoom controls - nature theme */
.leaflet-control-zoom a {
    background-color: var(--color-white) !important;
    color: var(--color-primary) !important;
    border-color: rgba(45, 90, 39, 0.3) !important;
    font-weight: 700;
    transition: background 0.15s;
}

.leaflet-control-zoom a:hover {
    background-color: var(--color-background) !important;
    color: var(--color-primary) !important;
}

.leaflet-control-zoom a:focus {
    outline: 3px solid rgba(45, 90, 39, 0.4);
    outline-offset: 2px;
}

.leaflet-control-zoom {
    border: 2px solid var(--color-primary) !important;
    border-radius: var(--radius) !important;
    overflow: hidden;
    box-shadow: var(--shadow) !important;
}

/* Leaflet popup close button - nature theme */
.leaflet-popup-close-button {
    color: var(--color-secondary) !important;
    font-size: 22px !important;
    font-weight: 700;
    width: 28px !important;
    height: 28px !important;
    padding: 2px 0 0 0 !important;
    top: 6px !important;
    right: 6px !important;
}

.leaflet-popup-close-button:hover {
    color: var(--color-primary) !important;
}

.leaflet-popup-close-button:focus {
    outline: 3px solid rgba(45, 90, 39, 0.4);
    outline-offset: 2px;
}

/* Leaflet attribution - subtle styling */
.leaflet-control-attribution {
    background: rgba(255, 255, 255, 0.85) !important;
    color: var(--color-text) !important;
    font-size: 0.7rem;
}

.leaflet-control-attribution a {
    color: var(--color-primary) !important;
}

/* MarkerCluster custom styling */
.marker-cluster-small {
    background-color: rgba(45, 90, 39, 0.3) !important;
}
.marker-cluster-small div {
    background-color: var(--color-primary) !important;
    color: var(--color-white) !important;
    font-weight: 600;
}

.marker-cluster-medium {
    background-color: rgba(93, 64, 55, 0.3) !important;
}
.marker-cluster-medium div {
    background-color: var(--color-secondary) !important;
    color: var(--color-white) !important;
    font-weight: 600;
}

.marker-cluster-large {
    background-color: rgba(45, 90, 39, 0.4) !important;
}
.marker-cluster-large div {
    background-color: var(--color-primary) !important;
    color: var(--color-white) !important;
    font-weight: 600;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    #search-container {
        /* Position below Leaflet controls to avoid overlap */
        top: 80px;
        width: 90%;
        max-width: none;
    }

    #search-input {
        padding: 12px 16px;
        font-size: 1rem; /* Prevent iOS zoom on focus */
    }

    #search-results {
        max-height: 45vh; /* Limit dropdown height on mobile */
    }

    .search-result-item {
        padding: 14px 16px; /* Larger touch targets on mobile */
        min-height: 44px; /* Minimum 44px touch target */
    }

    .popup-nav-btn {
        padding: 14px 16px;
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    #search-container {
        width: 92%;
        top: 80px;
    }

    #logo-text {
        font-size: 0.85rem;
    }
}

/* Screen reader only - visually hidden but accessible */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Utility */
.hidden {
    display: none !important;
}
