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

:root {
    --header-height: 50px;
    --primary: #1565C0;
    --primary-dark: #0D47A1;
    --bg: #FFFFFF;
    --text: #212121;
    --text-light: #757575;
    --border: #E0E0E0;
    --shadow: 0 2px 8px rgba(0,0,0,0.15);
    --radius: 8px;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
}

/* === Header === */
#header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--primary);
    color: white;
    z-index: 1000;
    box-shadow: var(--shadow);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    padding: 0 16px;
}

.header-title {
    min-width: 0;
}

.header-content h1 {
    font-size: 18px;
    font-weight: 600;
    white-space: nowrap;
}

.header-subtitle {
    font-size: 11px;
    font-weight: 400;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-update {
    font-size: 12px;
    font-weight: 400;
    opacity: 0.7;
    white-space: nowrap;
    margin: 0 0 0 auto;
    padding-right: 12px;
}

.header-buttons {
    display: flex;
    gap: 8px;
}

#filter-toggle,
#list-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
}

#filter-toggle:hover,
#list-toggle:hover {
    background: rgba(255,255,255,0.3);
}

/* === Filters Panel === */
.filters-panel {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    background: var(--bg);
    z-index: 999;
    box-shadow: var(--shadow);
    transform: translateY(-100%);
    transition: transform 0.3s ease;
    max-height: calc(100vh - var(--header-height));
    overflow-y: auto;
}

.filters-panel.open {
    transform: translateY(0);
}

.filters-inner {
    padding: 16px;
    max-width: 600px;
    margin: 0 auto;
}

.filter-section {
    margin-bottom: 14px;
}

.filter-section label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

#search-input:focus {
    border-color: var(--primary);
}

.date-range {
    display: flex;
    align-items: center;
    gap: 8px;
}

.date-range input[type="date"] {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    outline: none;
}

.date-range input[type="date"]:focus {
    border-color: var(--primary);
}

.date-range span {
    color: var(--text-light);
}

/* === Category Chips === */
.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    border: 2px solid var(--border);
    background: white;
    color: var(--text);
    transition: all 0.2s;
    user-select: none;
}

.chip:hover {
    border-color: var(--text-light);
}

.chip.active {
    color: white;
    border-color: transparent;
}

.chip .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    flex-shrink: 0;
}

/* === Filter Actions === */
.filter-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.btn {
    padding: 8px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s, transform 0.1s;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: white;
    flex: 1;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    background: #BDBDBD;
}

/* === Map === */
#map {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
}

/* === Event Count Badge === */
.event-count {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.75);
    color: white;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 13px;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
}

.event-count.visible {
    opacity: 1;
}

/* === Loading Overlay === */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

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

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

.loading-overlay p {
    margin-top: 12px;
    color: var(--text-light);
}

/* === Leaflet Popup Customization === */
.event-popup {
    min-width: 220px;
    max-width: 300px;
}

.event-popup h3 {
    font-size: 15px;
    margin-bottom: 6px;
    color: var(--text);
    line-height: 1.3;
}

.event-popup .event-meta {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 8px;
}

.event-popup .event-meta span {
    display: block;
    margin-bottom: 2px;
}

.event-popup .event-img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 4px;
    margin-bottom: 8px;
}

.event-popup .event-desc {
    font-size: 12px;
    color: var(--text);
    margin-bottom: 8px;
    line-height: 1.4;
    max-height: 60px;
    overflow: hidden;
}

.event-popup .event-links {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.event-popup .event-links a {
    font-size: 12px;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.event-popup .event-links a:hover {
    text-decoration: underline;
}

.event-popup .event-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
}

.event-popup .cat-tag {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    color: white;
    font-weight: 500;
}

/* === MarkerCluster Custom Colors === */
.marker-cluster-small {
    background-color: rgba(21, 101, 192, 0.3);
}
.marker-cluster-small div {
    background-color: rgba(21, 101, 192, 0.7);
    color: white;
}
.marker-cluster-medium {
    background-color: rgba(21, 101, 192, 0.4);
}
.marker-cluster-medium div {
    background-color: rgba(21, 101, 192, 0.8);
    color: white;
}
.marker-cluster-large {
    background-color: rgba(21, 101, 192, 0.5);
}
.marker-cluster-large div {
    background-color: rgba(21, 101, 192, 0.9);
    color: white;
}

/* === Active Filter Badges === */
.active-filters {
    position: fixed;
    top: calc(var(--header-height) + 8px);
    right: 12px;
    left: auto;
    max-width: 220px;
    z-index: 998;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
}

.active-filters:empty {
    display: none;
}

.filter-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    background: white;
    color: var(--text);
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    pointer-events: auto;
    white-space: nowrap;
}

.filter-badge .badge-label {
    color: var(--text-light);
    font-weight: 400;
    margin-right: 2px;
}

.filter-badge .badge-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--border);
    border: none;
    color: var(--text);
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    margin-left: 2px;
    transition: background 0.15s;
}

.filter-badge .badge-close:hover {
    background: var(--primary);
    color: white;
}

.filter-badge-category {
    color: white;
}

.filter-badge-category .badge-label {
    color: rgba(255,255,255,0.8);
}

.filter-badge-category .badge-close {
    background: rgba(255,255,255,0.3);
    color: white;
}

.filter-badge-category .badge-close:hover {
    background: rgba(255,255,255,0.5);
}

/* === Event List Panel === */
.list-panel {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: 100%;
    background: var(--bg);
    z-index: 999;
    box-shadow: var(--shadow);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.list-panel.open {
    transform: translateX(0);
}

.list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.list-header h2 {
    font-size: 16px;
    font-weight: 600;
}

#list-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-light);
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

#list-close:hover {
    color: var(--text);
}

.list-content {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.list-item {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    cursor: default;
    transition: background 0.15s;
}

.list-item:hover {
    background: #F5F5F5;
}

.list-item-clickable {
    cursor: pointer;
}

.list-item-img {
    width: 64px;
    height: 64px;
    border-radius: 6px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--border);
}

.list-item-info {
    flex: 1;
    min-width: 0;
}

.list-item-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.list-item-meta {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 4px;
}

.list-item-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.list-item-categories .cat-tag {
    font-size: 10px;
    padding: 1px 7px;
    border-radius: 10px;
    color: white;
    font-weight: 500;
}

.list-date-group {
    position: sticky;
    top: 0;
    background: #F5F5F5;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
    z-index: 1;
}

.multi-venue {
    color: var(--primary);
    font-style: italic;
    font-weight: 500;
}

.list-item-link {
    margin-top: 4px;
}

.list-item-link a {
    font-size: 12px;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.list-item-link a:hover {
    text-decoration: underline;
}

.list-empty {
    padding: 40px 16px;
    text-align: center;
    color: var(--text-light);
}

/* === Responsive === */
@media (min-width: 768px) {
    .filters-panel {
        left: auto;
        right: 0;
        width: 360px;
        transform: translateX(100%);
    }

    .filters-panel.open {
        transform: translateX(0);
    }

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

    .list-panel {
        width: 400px;
    }
}

@media (max-width: 768px) {
    .active-filters {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .header-content h1 {
        font-size: 15px;
    }

    .header-subtitle,
    .header-update {
        display: none;
    }

    .chip {
        font-size: 11px;
        padding: 4px 10px;
    }
}

/* === PWA Install Prompts === */
.pwa-prompt {
    position: fixed;
    bottom: 16px;
    left: 16px;
    right: 16px;
    z-index: 2000;
    animation: slideUp 0.3s ease-out;
}

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

.pwa-prompt-content {
    background: white;
    border-radius: var(--radius);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    padding: 16px;
    max-width: 500px;
    margin: 0 auto;
}

.pwa-prompt-text {
    font-size: 15px;
    color: var(--text);
    margin-bottom: 12px;
    line-height: 1.4;
}

.pwa-prompt-buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.pwa-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.pwa-btn-primary {
    background: var(--primary);
    color: white;
}

.pwa-btn-primary:hover {
    background: var(--primary-dark);
}

.pwa-btn-secondary {
    background: #f5f5f5;
    color: var(--text);
}

.pwa-btn-secondary:hover {
    background: #e0e0e0;
}

/* PWA Instructions Modal */
.pwa-instructions {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 2001;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.pwa-instructions-content {
    background: white;
    border-radius: var(--radius);
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    padding: 24px;
    position: relative;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    animation: scaleIn 0.3s ease-out;
}

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.pwa-instructions-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: none;
    background: #f5f5f5;
    border-radius: 50%;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-light);
    transition: all 0.2s;
}

.pwa-instructions-close:hover {
    background: #e0e0e0;
    color: var(--text);
}

#pwa-instructions-title {
    font-size: 20px;
    color: var(--text);
    margin-bottom: 16px;
    padding-right: 40px;
}

.pwa-instructions-body {
    color: var(--text);
    line-height: 1.6;
}

.pwa-instructions-body h4 {
    font-size: 16px;
    color: var(--primary);
    margin-top: 16px;
    margin-bottom: 8px;
}

.pwa-instructions-body ol {
    margin-left: 20px;
    margin-top: 8px;
}

.pwa-instructions-body li {
    margin-bottom: 12px;
}

.pwa-instructions-body strong {
    color: var(--text);
    font-weight: 600;
}

.pwa-instructions-body .icon-hint {
    display: inline-block;
    padding: 2px 8px;
    background: #f5f5f5;
    border-radius: 4px;
    font-family: monospace;
    font-size: 14px;
    margin: 0 2px;
}

@media (max-width: 480px) {
    .pwa-prompt {
        bottom: 8px;
        left: 8px;
        right: 8px;
    }

    .pwa-prompt-content {
        padding: 12px;
    }

    .pwa-prompt-text {
        font-size: 14px;
    }

    .pwa-btn {
        padding: 8px 16px;
        font-size: 13px;
    }

    .pwa-instructions-content {
        padding: 20px;
    }

    #pwa-instructions-title {
        font-size: 18px;
    }
}
