/* ===========================
   Global Styles
   =========================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    height: 100vh;
    overflow: hidden;
    background-color: #f0f2f5;
}

/* ===========================
   Sidebar Styles
   =========================== */
.sidebar {
    width: 320px;
    background: linear-gradient(180deg, #2c3e50 0%, #34495e 100%);
    color: white;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

.sidebar-header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 5px;
}

.sidebar-header .subtitle {
    font-size: 14px;
    color: #bdc3c7;
    font-weight: 300;
}

/* ===========================
   Statistics Cards
   =========================== */
.stats-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 30px;
}

.stat-card {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 15px;
    display: flex;
    align-items: center;
    gap: 15px;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.stat-card:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateX(5px);
}

.stat-icon {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stat-content {
    flex: 1;
}

.stat-content h3 {
    font-size: 13px;
    font-weight: 500;
    color: #bdc3c7;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: white;
}

.stat-value.small {
    font-size: 14px;
    font-weight: 400;
}

/* ===========================
   Legend Styles
   =========================== */
.legend {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 20px;
}

.legend h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid white;
}

.legend-color.red {
    background-color: #e74c3c;
}

.legend-color.orange {
    background-color: #f39c12;
}

.legend-color.yellow {
    background-color: #f1c40f;
}

.legend-color.blue {
    background-color: #3498db;
}

/* ===========================
   Referers Section
   =========================== */
.referers {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 20px;
}

.referers h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-indicator {
    font-size: 11px;
    background: #667eea;
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 500;
    text-transform: none;
}

.filter-indicator.hidden {
    display: none;
}

.clear-referer-btn {
    width: 100%;
    background: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
    border: 1px solid rgba(231, 76, 60, 0.3);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease;
    margin-top: 10px;
}

.clear-referer-btn:hover {
    background: rgba(231, 76, 60, 0.2);
    border-color: rgba(231, 76, 60, 0.5);
}

.clear-referer-btn.hidden {
    display: none;
}

/* ===========================
   Pages Section
   =========================== */
.pages {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 20px;
}

.pages h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.pages-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 5px;
}

/* Scrollbar styling for pages list */
.pages-list::-webkit-scrollbar {
    width: 6px;
}

.pages-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.pages-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.pages-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.page-item {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
    border: 2px solid transparent;
}

.page-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(102, 126, 234, 0.3);
}

.page-item.active {
    background: rgba(102, 126, 234, 0.2);
    border-color: #667eea;
}

.page-name {
    font-size: 12px;
    flex: 1;
    word-break: break-all;
    line-height: 1.4;
}

.page-name i {
    margin-right: 6px;
    color: #3498db;
}

.page-stats {
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-count {
    font-size: 14px;
    font-weight: 600;
    color: #667eea;
}

.page-percentage {
    font-size: 12px;
    color: #bdc3c7;
}

.page-bar {
    width: 60px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.page-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transition: width 0.3s ease;
}

.clear-page-btn {
    width: 100%;
    background: rgba(231, 76, 60, 0.1);
    color: #e74c3c;
    border: 1px solid rgba(231, 76, 60, 0.3);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease;
    margin-top: 10px;
}

.clear-page-btn:hover {
    background: rgba(231, 76, 60, 0.2);
    border-color: rgba(231, 76, 60, 0.5);
}

.clear-page-btn.hidden {
    display: none;
}

.referers-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 5px;
}

/* Scrollbar styling for referers list */
.referers-list::-webkit-scrollbar {
    width: 6px;
}

.referers-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.referers-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.referers-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.referer-item {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
    border: 2px solid transparent;
}

.referer-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(102, 126, 234, 0.3);
}

.referer-item.active {
    background: rgba(102, 126, 234, 0.2);
    border-color: #667eea;
}

.referer-name {
    font-size: 12px;
    flex: 1;
    word-break: break-all;
    line-height: 1.4;
}

.referer-name i {
    margin-right: 6px;
    color: #3498db;
}

.referer-name a {
    color: #ecf0f1;
    text-decoration: none;
}

.referer-name a:hover {
    color: #3498db;
    text-decoration: underline;
}

.referer-stats {
    display: flex;
    align-items: center;
    gap: 10px;
}

.referer-count {
    font-size: 14px;
    font-weight: 600;
    color: #667eea;
}

.referer-percentage {
    font-size: 12px;
    color: #bdc3c7;
}

.referer-bar {
    width: 60px;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.referer-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transition: width 0.3s ease;
}

.loading-text {
    text-align: center;
    color: #bdc3c7;
    font-size: 13px;
}

/* ===========================
   Sources Filter Section
   =========================== */
.sources {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 20px;
}

.sources h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.source-filters {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.source-filter {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background 0.2s ease;
}

.source-filter:hover {
    background: rgba(255, 255, 255, 0.05);
}

.source-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
    margin-right: 10px;
    accent-color: #667eea;
}

.source-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    flex: 1;
}

.source-label i {
    color: #3498db;
    width: 18px;
    text-align: center;
}

.toggle-all-btn {
    width: 100%;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.toggle-all-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.toggle-all-btn i {
    font-size: 11px;
}

/* ===========================
   Refresh Button
   =========================== */
.refresh-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 15px 20px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s ease;
    margin-top: auto;
}

.refresh-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.refresh-btn:active {
    transform: translateY(0);
}

.refresh-btn i {
    transition: transform 0.6s ease;
}

.refresh-btn:hover i {
    transform: rotate(360deg);
}

/* ===========================
   Main Content (Map)
   =========================== */
.main-content {
    flex: 1;
    position: relative;
    overflow: hidden;
}

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

/* ===========================
   Loading Overlay
   =========================== */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(44, 62, 80, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-overlay p {
    color: white;
    margin-top: 20px;
    font-size: 16px;
    font-weight: 500;
}

/* ===========================
   Leaflet Custom Styles
   =========================== */
.leaflet-popup-content-wrapper {
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.leaflet-popup-content {
    margin: 15px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.leaflet-popup-content b {
    color: #2c3e50;
    font-size: 16px;
    display: block;
    margin-bottom: 8px;
}

/* ===========================
   Responsive Design
   =========================== */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        max-height: 40vh;
        padding: 15px;
    }

    .sidebar-header h1 {
        font-size: 20px;
    }

    .stats-container {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 10px;
    }

    .stat-card {
        flex: 1 1 calc(50% - 10px);
        min-width: 150px;
    }

    .legend,
    .sources {
        display: none;
    }

    #map {
        height: 60vh;
    }
}

/* ===========================
   Animations
   =========================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stat-card {
    animation: fadeIn 0.5s ease forwards;
}

.stat-card:nth-child(1) {
    animation-delay: 0.1s;
}

.stat-card:nth-child(2) {
    animation-delay: 0.2s;
}

.stat-card:nth-child(3) {
    animation-delay: 0.3s;
}

.stat-card:nth-child(4) {
    animation-delay: 0.4s;
}

.stat-card:nth-child(5) {
    animation-delay: 0.5s;
}
