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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.header {
    background: #1a1a1a;
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    z-index: 1000;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.header-stats {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.status {
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 500;
}

.status.connected {
    background: #10b981;
    color: white;
}

.status.disconnected {
    background: #ef4444;
    color: white;
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-email {
    font-size: 0.875rem;
    color: #d1d5db;
}

.btn-logout {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-settings {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.btn-header-action {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

/* Dropdown Panels */
.dropdown-panel {
    display: none;
    position: absolute;
    top: 70px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    width: 320px;
    max-height: 500px;
    overflow: hidden;
    z-index: 1000;
    animation: slideDown 0.2s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dropdown-panel.show {
    display: flex;
    flex-direction: column;
}

#layers-panel {
    right: 220px;
}

#athletes-panel {
    right: 400px;
}

#events-panel {
    right: 310px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid #e5e7eb;
    background: #f9fafb;
}

.panel-header h3 {
    font-size: 16px;
    color: #1f2937;
    margin: 0;
    font-weight: 600;
}

.btn-close-panel {
    background: none;
    border: none;
    font-size: 24px;
    color: #6b7280;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.btn-close-panel:hover {
    color: #1f2937;
}

.panel-content {
    padding: 1rem;
    overflow-y: auto;
    max-height: 400px;
}

.control-group-compact {
    margin-bottom: 1rem;
}

.control-group-compact h4 {
    font-size: 13px;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.control-group-compact label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
}

.control-group-compact label:hover {
    background: #f9fafb;
}

/* Map */
#map {
    flex: 1;
    position: relative;
}

/* Controls Panel */
.controls-panel {
    position: absolute;
    top: 80px;
    right: 20px;
    width: 300px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 1rem;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    z-index: 100;
}

.control-group {
    margin-bottom: 1.5rem;
}

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

.control-group h3 {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #6b7280;
    margin-bottom: 0.75rem;
}

.control-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
}

.control-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.control-group select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.btn-primary {
    width: 100%;
    padding: 0.625rem;
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #2563eb;
}

/* Athlete List */
.athlete-list {
    max-height: 300px;
    overflow-y: auto;
}

.athlete-item {
    padding: 0.75rem;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.athlete-item:hover {
    background: #f3f4f6;
    border-color: #3b82f6;
}

.athlete-item-name {
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 0.25rem;
}

.athlete-item-stats {
    font-size: 0.75rem;
    color: #6b7280;
    display: flex;
    gap: 1rem;
}

.empty-state {
    text-align: center;
    color: #9ca3af;
    font-size: 0.875rem;
    padding: 1rem;
}

/* Athlete Info Panel */
.athlete-info {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 350px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 1.5rem;
    z-index: 100;
    max-height: 400px;
    overflow-y: auto;
}

.athlete-info.hidden {
    display: none;
}

.athlete-info h3 {
    margin-bottom: 1rem;
    color: #1f2937;
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6b7280;
    line-height: 1;
    padding: 0;
    width: 24px;
    height: 24px;
}

.close-btn:hover {
    color: #1f2937;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid #e5e7eb;
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    font-weight: 500;
    color: #6b7280;
}

.info-value {
    color: #1f2937;
}

/* Layer Control Groups */
.control-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.control-group-header:hover {
    opacity: 0.8;
}

.toggle-icon {
    font-size: 0.75rem;
    color: #6b7280;
    transition: transform 0.2s;
}

.toggle-icon.collapsed {
    transform: rotate(-90deg);
}

.layer-group-content {
    margin-top: 0.75rem;
    max-height: 500px;
    overflow-y: auto;
    transition: max-height 0.3s ease-out;
}

.layer-group-content.collapsed {
    max-height: 0;
    overflow: hidden;
    margin-top: 0;
}

.layer-category {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e5e7eb;
}

.layer-category:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.layer-category h4 {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #9ca3af;
    margin-bottom: 0.5rem;
    letter-spacing: 0.025em;
}

.layer-category label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
    cursor: pointer;
    font-size: 0.875rem;
}

.layer-category label:last-child {
    margin-bottom: 0;
}

/* MapLibre Popup Overrides */
.maplibregl-popup-content {
    padding: 1rem;
    border-radius: 8px;
}

.maplibregl-popup-close-button {
    font-size: 1.25rem;
    padding: 0.25rem 0.5rem;
}

/* Events Panel Styles */
.events-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: calc(100vh - 200px);
    overflow-y: auto;
}

.event-list-item {
    background: white;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    cursor: pointer;
    transition: all 0.2s;
}

.event-list-item:hover {
    background: #f9fafb;
    border-color: #3b82f6;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.1);
}

.event-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.event-status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

.event-status-badge.status-active {
    background: #fef3c7;
    color: #92400e;
}

.event-status-badge.status-soon {
    background: #dbeafe;
    color: #1e3a8a;
}

.event-status-badge.status-upcoming {
    background: #f3f4f6;
    color: #374151;
}

.event-status-badge.status-past {
    background: #f3f4f6;
    color: #9ca3af;
}

.event-status-badge.status-undefined {
    background: #f3f4f6;
    color: #374151;
}

.event-distance {
    font-size: 0.75rem;
    color: #6b7280;
}

.event-item-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: #111827;
    margin-bottom: 4px;
}

.event-item-date {
    font-size: 0.75rem;
    color: #6b7280;
}

.event-item-participants {
    font-size: 0.75rem;
    color: #9ca3af;
    margin-top: 4px;
}

/* Event Details Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: white;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #111827;
}

.btn-close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #6b7280;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
}

.btn-close-modal:hover {
    background: #f3f4f6;
    color: #111827;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.event-detail-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.event-detail-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.event-detail-label {
    font-weight: 600;
    color: #374151;
    min-width: 100px;
    font-size: 0.875rem;
}

.event-detail-value {
    color: #6b7280;
    font-size: 0.875rem;
    flex: 1;
}

.modal-actions {
    padding: 16px 24px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.event-member-badge {
    padding: 8px 16px;
    background: #dbeafe;
    color: #1e3a8a;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    margin-right: auto;
}

.invite-request-section {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    /* Dropdown Panels */
    .dropdown-panel {
        background: #1f2937;
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    }

    .panel-header {
        background: #111827;
        border-bottom-color: #374151;
    }

    .panel-header h3 {
        color: #f9fafb;
    }

    .btn-close-panel {
        color: #9ca3af;
    }

    .btn-close-panel:hover {
        color: #f9fafb;
        background: #374151;
    }

    .panel-content {
        background: #1f2937;
    }

    .empty-state {
        color: #9ca3af;
    }

    /* Events List */
    .event-list-item {
        background: #111827;
        border-color: #374151;
    }

    .event-list-item:hover {
        background: #1f2937;
        border-color: #3b82f6;
    }

    .event-item-name {
        color: #f9fafb;
    }

    .event-item-date,
    .event-distance {
        color: #9ca3af;
    }

    .event-item-participants {
        color: #6b7280;
    }

    /* Modal */
    .modal {
        background-color: rgba(0, 0, 0, 0.75);
    }

    .modal-content {
        background-color: #1f2937;
    }

    .modal-header {
        background: #111827;
        border-bottom-color: #374151;
    }

    .modal-header h2 {
        color: #f9fafb;
    }

    .btn-close-modal {
        color: #9ca3af;
    }

    .btn-close-modal:hover {
        background: #374151;
        color: #f9fafb;
    }

    .modal-body {
        background: #1f2937;
    }

    .event-detail-label {
        color: #d1d5db;
    }

    .event-detail-value {
        color: #9ca3af;
    }

    .modal-actions {
        background: #111827;
        border-top-color: #374151;
    }

    /* Control Groups */
    .control-group-compact h4,
    .control-group-header h4 {
        color: #d1d5db;
    }

    .control-group-compact label {
        color: #e5e7eb;
    }

    /* Athlete List */
    .athlete-list {
        color: #e5e7eb;
    }

    .athlete-item {
        background: #111827;
        border-color: #374151;
    }

    .athlete-item:hover {
        background: #1f2937;
        border-color: #3b82f6;
    }

    .athlete-name {
        color: #f9fafb;
    }

    .athlete-status {
        color: #9ca3af;
    }

    /* Status Badges - Dark Mode Text Colors */
    .event-status-badge.status-active {
        color: #fef3c7;
        background: #92400e;
    }

    .event-status-badge.status-soon {
        color: #dbeafe;
        background: #1e3a8a;
    }

    .event-status-badge.status-upcoming {
        color: #d1d5db;
        background: #4b5563;
    }

    .event-status-badge.status-past {
        color: #9ca3af;
        background: #374151;
    }

    .event-status-badge.status-undefined {
        color: #d1d5db;
        background: #4b5563;
    }
}

/* Leaderboard */
.leaderboard-route {
    margin-bottom: 24px;
}

.leaderboard-route h4 {
    margin: 0 0 12px 0;
    color: #111827;
    font-size: 16px;
    font-weight: 600;
}

.leaderboard-table {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
}

.leaderboard-header {
    display: flex;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    font-weight: 600;
    font-size: 14px;
    color: #374151;
}

.leaderboard-row {
    display: flex;
    border-bottom: 1px solid #f3f4f6;
}

.leaderboard-row:last-child {
    border-bottom: none;
}

.leaderboard-col {
    padding: 12px;
    display: flex;
    align-items: center;
}

.leaderboard-col.rank {
    width: 60px;
    justify-content: center;
    font-weight: 600;
    color: #6b7280;
}

.leaderboard-col.athlete {
    flex: 1;
    font-weight: 500;
}

.leaderboard-col.progress {
    width: 100px;
    justify-content: center;
}

.leaderboard-col.distance {
    width: 120px;
    justify-content: center;
}

.leaderboard-col.status {
    width: 120px;
    justify-content: center;
}

.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
}

.status-badge.status-moving {
    background: #dcfce7;
    color: #166534;
}

.status-badge.status-stopped {
    background: #fef3c7;
    color: #92400e;
}

.status-badge.status-offline {
    background: #f3f4f6;
    color: #6b7280;
}

/* Route Management Styles */
.route-upload-section {
    margin-bottom: 16px;
    text-align: center;
}

.routes-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.route-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: #f9fafb;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
}

.dark-mode .route-item {
    background: #374151;
    border-color: #4b5563;
}

.route-item.route-primary {
    border-color: #10b981;
    background: #ecfdf5;
}

.dark-mode .route-item.route-primary {
    background: #064e3b;
    border-color: #10b981;
}

.route-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.route-name {
    font-weight: 600;
    color: #111827;
}

.dark-mode .route-name {
    color: #f3f4f6;
}

.route-stats {
    font-size: 0.875rem;
    color: #6b7280;
}

.route-actions {
    display: flex;
    gap: 4px;
}

.btn-small {
    padding: 4px 8px;
    font-size: 0.875rem;
    border-radius: 4px;
    cursor: pointer;
    background: #e5e7eb;
    border: none;
    transition: background 0.2s;
}

.btn-small:hover {
    background: #d1d5db;
}

.dark-mode .btn-small {
    background: #4b5563;
    color: #f3f4f6;
}

.dark-mode .btn-small:hover {
    background: #6b7280;
}

.btn-small.btn-danger {
    background: #fee2e2;
    color: #dc2626;
}

.btn-small.btn-danger:hover {
    background: #fecaca;
}

.dark-mode .btn-small.btn-danger {
    background: #7f1d1d;
    color: #fca5a5;
}

.dark-mode .btn-small.btn-danger:hover {
    background: #991b1b;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-primary {
    background: #10b981;
    color: white;
}
