/**
 * SightsMap - Interactive Tourist Heatmap
 * Main Stylesheet
 */

/* ==========================================================================
   CSS Custom Properties (Theme)
   ========================================================================== */

:root {
    --color-bg-primary: #1a1a2e;
    --color-bg-secondary: #16213e;
    --color-bg-tertiary: #0f3460;
    --color-text-primary: #eee;
    --color-text-secondary: #888;
    --color-text-muted: #666;
    --color-accent-primary: #b12a90;
    --color-accent-secondary: #f0f921;
    --color-accent-tertiary: #6a00a8;
    --color-border: #0f3460;
    --color-error: #e94560;
    --color-success: #4ade80;
    --sidebar-width: 360px;
    --sidebar-min-width: 280px;
    --sidebar-max-width: 600px;
    --transition-fast: 0.2s;
    --transition-normal: 0.3s;
    --border-radius-sm: 4px;
    --border-radius-md: 8px;
    --border-radius-lg: 10px;
}

/* ==========================================================================
   Base Styles
   ========================================================================== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
}

/* Focus styles for accessibility */
:focus-visible {
    outline: 2px solid var(--color-accent-primary);
    outline-offset: 2px;
}

/* Skip link for accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-accent-primary);
    color: white;
    padding: 8px 16px;
    z-index: 10000;
    text-decoration: none;
    border-radius: 0 0 var(--border-radius-sm) 0;
}

.skip-link:focus {
    top: 0;
}

/* ==========================================================================
   Layout
   ========================================================================== */

#app {
    display: flex;
    height: 100vh;
}

/* ==========================================================================
   Sidebar
   ========================================================================== */

#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-min-width);
    max-width: var(--sidebar-max-width);
    background: var(--color-bg-secondary);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    z-index: 1000;
    position: relative;
}

/* Resize handle - horizontal */
#resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    background: transparent;
    cursor: ew-resize;
    z-index: 1001;
    transition: background var(--transition-fast);
}

#resize-handle:hover,
#resize-handle.active {
    background: linear-gradient(to bottom, var(--color-accent-tertiary), var(--color-accent-primary), var(--color-accent-secondary));
}

#resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 40px;
    background: #444;
    border-radius: 1px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

#resize-handle:hover::after,
#resize-handle.active::after {
    opacity: 1;
    background: #fff;
}

/* Resize handle - vertical */
#resize-handle-v {
    height: 8px;
    background: var(--color-border);
    cursor: ns-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast);
    flex-shrink: 0;
}

#resize-handle-v:hover,
#resize-handle-v.active {
    background: linear-gradient(to right, var(--color-accent-tertiary), var(--color-accent-primary), var(--color-accent-secondary));
}

#resize-handle-v::after {
    content: '';
    width: 40px;
    height: 3px;
    background: #444;
    border-radius: 2px;
    transition: background var(--transition-fast);
}

#resize-handle-v:hover::after,
#resize-handle-v.active::after {
    background: #fff;
}

/* Sidebar header */
#sidebar-header {
    padding: 20px;
    background: linear-gradient(135deg, var(--color-bg-tertiary) 0%, var(--color-bg-secondary) 100%);
    border-bottom: 1px solid var(--color-border);
}

#sidebar-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    background: linear-gradient(90deg, var(--color-accent-primary), var(--color-accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 5px;
}

#sidebar-header p {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

#sidebar-header .data-age {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    margin-top: 8px;
    padding: 4px 8px;
    background: rgba(15, 52, 96, 0.5);
    border-radius: var(--border-radius-sm);
    display: inline-block;
}

/* Sidebar top section (controls) */
#sidebar-top {
    flex-shrink: 0;
    overflow: hidden;
}

/* ==========================================================================
   View Toggle
   ========================================================================== */

#view-toggle {
    display: flex;
    padding: 15px 20px;
    gap: 10px;
    border-bottom: 1px solid var(--color-border);
}

.toggle-btn {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: var(--border-radius-md);
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.toggle-btn.active {
    background: linear-gradient(135deg, #8f0da4, #e16462);
    color: #fff;
}

.toggle-btn:hover:not(.active) {
    background: #1a3a5c;
    color: #fff;
}

/* ==========================================================================
   Dataset Selector
   ========================================================================== */

#dataset-selector {
    padding: 12px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 10px;
}

#dataset-selector label {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

#dataset-select {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: var(--color-bg-tertiary);
    color: #fff;
    font-size: 0.8rem;
    cursor: pointer;
    outline: none;
}

#dataset-select:focus {
    box-shadow: 0 0 0 2px var(--color-accent-primary);
}

/* ==========================================================================
   Heatmap Controls
   ========================================================================== */

#heatmap-controls {
    padding: 15px 20px;
    border-bottom: 1px solid var(--color-border);
    display: none;
}

#heatmap-controls.visible {
    display: block;
}

.control-group {
    margin-bottom: 15px;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

.control-label span {
    color: var(--color-accent-secondary);
    font-weight: 600;
}

.slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--color-bg-tertiary);
    outline: none;
    -webkit-appearance: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-accent-primary), var(--color-accent-secondary));
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(177, 42, 144, 0.4);
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-accent-primary), var(--color-accent-secondary));
    cursor: pointer;
    border: none;
}

/* ==========================================================================
   Search
   ========================================================================== */

#search-container {
    padding: 15px 20px;
    border-bottom: 1px solid var(--color-border);
}

#search-input {
    width: 100%;
    padding: 12px 15px;
    border: none;
    border-radius: var(--border-radius-md);
    background: var(--color-bg-tertiary);
    color: #fff;
    font-size: 0.95rem;
    outline: none;
    transition: box-shadow var(--transition-fast);
}

#search-input:focus {
    box-shadow: 0 0 0 2px var(--color-accent-primary);
}

#search-input::placeholder {
    color: var(--color-text-muted);
}

/* ==========================================================================
   Filters
   ========================================================================== */

#filters {
    padding: 15px 20px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    gap: 10px;
}

.filter-select {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border: none;
    border-radius: var(--border-radius-md);
    background: var(--color-bg-tertiary);
    color: #fff;
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.filter-select:focus {
    box-shadow: 0 0 0 2px var(--color-accent-primary);
}

/* ==========================================================================
   Stats
   ========================================================================== */

#stats {
    padding: 12px 20px;
    background: var(--color-bg-tertiary);
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    display: flex;
    justify-content: space-between;
}

#stats span {
    color: var(--color-accent-secondary);
    font-weight: 600;
}

/* ==========================================================================
   Legend
   ========================================================================== */

#legend {
    padding: 15px 20px;
    border-bottom: 1px solid var(--color-border);
    display: none;
}

#legend.visible {
    display: block;
}

#legend h4 {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    margin-bottom: 10px;
}

.legend-gradient {
    height: 20px;
    border-radius: var(--border-radius-sm);
    background: linear-gradient(to right, 
        #0d0887,
        #46039f,
        #7201a8,
        #9c179e,
        #bd3786,
        #d8576b,
        #ed7953,
        #fb9f3a,
        #fdca26,
        #f0f921
    );
    margin-bottom: 8px;
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

/* ==========================================================================
   Presets
   ========================================================================== */

#presets {
    padding: 10px 20px;
    border-bottom: 1px solid var(--color-border);
    display: none;
}

#presets.visible {
    display: flex;
    gap: 8px;
}

.preset-btn {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.preset-btn:hover {
    border-color: var(--color-accent-primary);
    color: #fff;
}

.preset-btn.active {
    border-color: var(--color-accent-primary);
    background: rgba(177, 42, 144, 0.2);
    color: var(--color-accent-secondary);
}

/* ==========================================================================
   Map Options
   ========================================================================== */

#map-options {
    padding: 10px 20px;
    border-bottom: 1px solid var(--color-border);
    display: none;
}

#map-options.visible {
    display: block;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-accent-primary);
    cursor: pointer;
}

.checkbox-label span {
    user-select: none;
}

#map-options .control-group {
    margin-top: 10px;
}

#borders-opacity-control {
    display: block;
}

#map-options .control-label {
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    margin-bottom: 5px;
    display: block;
}

#map-options .slider {
    width: 100%;
}

/* ==========================================================================
   Export Button
   ========================================================================== */

#export-container {
    padding: 10px 20px;
    border-bottom: 1px solid var(--color-border);
}

#export-btn {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

#export-btn:hover {
    border-color: var(--color-accent-primary);
    background: rgba(177, 42, 144, 0.1);
    color: #fff;
}

/* ==========================================================================
   Results List
   ========================================================================== */

#results {
    flex: 1;
    min-height: 80px;
    overflow-y: auto;
    padding: 10px;
}

.spot-card {
    background: var(--color-bg-tertiary);
    border-radius: var(--border-radius-lg);
    padding: 15px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
}

.spot-card:hover,
.spot-card:focus {
    background: #1a3a5c;
    border-color: var(--color-accent-primary);
    transform: translateX(5px);
}

.spot-card h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 8px;
}

.spot-card .spot-meta {
    display: flex;
    gap: 15px;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
}

.spot-card .spot-meta .country {
    color: var(--color-accent-secondary);
    font-weight: 500;
}

.spot-card .spot-type {
    display: inline-block;
    background: linear-gradient(135deg, var(--color-accent-tertiary), var(--color-accent-primary));
    color: #fff;
    padding: 3px 8px;
    border-radius: var(--border-radius-sm);
    font-size: 0.7rem;
    margin-top: 8px;
}

.spot-card .popularity-bar {
    margin-top: 10px;
    height: 4px;
    background: #0a1628;
    border-radius: 2px;
    overflow: hidden;
}

.spot-card .popularity-fill {
    height: 100%;
    background: linear-gradient(to right, var(--color-accent-tertiary), var(--color-accent-primary), #e16462, var(--color-accent-secondary));
    border-radius: 2px;
    transition: width var(--transition-normal);
}

/* ==========================================================================
   Map Container
   ========================================================================== */

#main-content {
    flex: 1;
    display: flex;
    min-width: 0;
}

#map-container {
    flex: 1;
    position: relative;
}

#map {
    width: 100%;
    height: 100%;
}

/* ==========================================================================
   Leaflet Popup Styling
   ========================================================================== */

.leaflet-popup-content-wrapper {
    background: var(--color-bg-secondary);
    color: #fff;
    border-radius: var(--border-radius-lg);
    box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

.leaflet-popup-content {
    margin: 15px;
}

.leaflet-popup-tip {
    background: var(--color-bg-secondary);
}

.popup-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-accent-secondary);
    margin-bottom: 10px;
}

.popup-info {
    font-size: 0.85rem;
    line-height: 1.6;
}

.popup-info strong {
    color: var(--color-text-secondary);
}

.popup-link {
    display: inline-block;
    margin-top: 10px;
    padding: 8px 15px;
    background: linear-gradient(135deg, var(--color-accent-tertiary), var(--color-accent-primary));
    color: #fff;
    text-decoration: none;
    border-radius: 5px;
    font-size: 0.8rem;
    transition: all var(--transition-fast);
}

.popup-link:hover {
    background: linear-gradient(135deg, #8f0da4, #e16462);
}

/* ==========================================================================
   Loading Screen
   ========================================================================== */

#loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    flex-direction: column;
    gap: 20px;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--color-bg-tertiary);
    border-top-color: var(--color-accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

#loading p {
    color: var(--color-text-secondary);
}

#loading .progress-bar {
    width: 200px;
    height: 4px;
    background: var(--color-bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}

#loading .progress-fill {
    height: 100%;
    background: linear-gradient(to right, var(--color-accent-primary), var(--color-accent-secondary));
    width: 0%;
    transition: width 0.3s ease;
}

/* ==========================================================================
   Error/Notification Toast
   ========================================================================== */

#toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--border-radius-md);
    color: #fff;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    animation: slideIn 0.3s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.error {
    background: var(--color-error);
}

.toast.success {
    background: var(--color-success);
    color: #000;
}

.toast.info {
    background: var(--color-accent-primary);
}

.toast-close {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    opacity: 0.7;
}

.toast-close:hover {
    opacity: 1;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ==========================================================================
   Scrollbar
   ========================================================================== */

#results::-webkit-scrollbar {
    width: 8px;
}

#results::-webkit-scrollbar-track {
    background: var(--color-bg-tertiary);
}

#results::-webkit-scrollbar-thumb {
    background: linear-gradient(to bottom, var(--color-accent-tertiary), var(--color-accent-primary));
    border-radius: var(--border-radius-sm);
}

/* ==========================================================================
   Cluster Styling (Plasma Theme)
   ========================================================================== */

.marker-cluster-small {
    background-color: rgba(106, 0, 168, 0.6);
}
.marker-cluster-small div {
    background-color: rgba(106, 0, 168, 0.9);
    color: #fff;
    font-weight: 600;
}

.marker-cluster-medium {
    background-color: rgba(177, 42, 144, 0.6);
}
.marker-cluster-medium div {
    background-color: rgba(177, 42, 144, 0.9);
    color: #fff;
    font-weight: 600;
}

.marker-cluster-large {
    background-color: rgba(240, 249, 33, 0.6);
}
.marker-cluster-large div {
    background-color: rgba(240, 249, 33, 0.9);
    color: #000;
    font-weight: 600;
}

/* ==========================================================================
   Heatmap Blend Mode
   ========================================================================== */

.leaflet-heatmap-layer {
    mix-blend-mode: screen;
}


/* ==========================================================================
   Mobile Responsive
   ========================================================================== */

@media (max-width: 768px) {
    #app {
        flex-direction: column;
    }

    #sidebar {
        width: 100% !important;
        height: 50vh;
        order: 2;
        max-width: none;
    }

    #map-container {
        height: 50vh;
        order: 1;
    }

    #resize-handle {
        display: none;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    #sidebar {
        display: none;
    }
    
    #map-container {
        width: 100%;
    }
}

/* ==========================================================================
   Reduced Motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
