body {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
}

.container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

.map-container {
    flex: 2;
    height: 100%;
    position: relative;
}

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

.info-panel {
    flex: 1;
    padding: 20px;
    background-color: #f5f5f5;
    overflow-y: auto;
    min-width: 400px;
    max-width: 500px;
    display: flex;
    flex-direction: column;
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-shrink: 0;
}

.info-panel h2 {
    margin: 0;
    color: #333;
    border-bottom: none;
    padding-bottom: 0;
    flex-shrink: 0;
}

#raceStatus {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9em;
}

.race-status {
    padding: 4px 8px;
    border-radius: 6px;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 0.8em;
}

.race-status.waiting {
    background: #fff3cd;
    color: #856404;
}

.race-status.racing {
    background: #d4edda;
    color: #155724;
}

.race-status.finished {
    background: #f8d7da;
    color: #721c24;
}

.elapsed-time {
    font-family: monospace;
    font-weight: bold;
    color: #333;
    background: #f8f9fa;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid #dee2e6;
}

/* WebSocket Connection Status Styles */
.status-connected {
    color: #28a745;
    font-weight: bold;
    animation: pulse 2s infinite;
}

.status-connecting {
    color: #ffc107;
    font-weight: bold;
}

.status-disconnected {
    color: #dc3545;
    font-weight: bold;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}



.finish-time {
    font-family: monospace;
    font-weight: bold;
    color: #155724;
    background: #d4edda;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    white-space: nowrap;
    display: inline-block;
}

/* Race Info Section */
.race-info-section {
    flex: 1;
    background: white;
    border-radius: 8px;
    padding: 12px 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    margin-bottom: 16px;
}

.race-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: 'Poppins', sans-serif;
    color: #4a5568;
}

.race-id {
    font-size: 14px;
    font-weight: 500;
    color: #718096;
    background: rgba(113, 128, 150, 0.1);
    padding: 4px 8px;
    border-radius: 8px;
    border: 1px solid rgba(113, 128, 150, 0.2);
}

.race-name {
    font-size: 16px;
    font-weight: 600;
    color: #2d3748;
}

.leaderboard-section {
    flex: 1;
    background: white;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    height: 100%;
}

#leaderboardTable {
    overflow-y: auto;
    height: calc(100vh - 120px);
    padding-right: 10px;
    /* Hide scrollbar for Chrome, Safari and Opera */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* Internet Explorer 10+ */
}

#leaderboardTable::-webkit-scrollbar {
    display: none; /* Chrome, Safari and Opera */
}

.leaderboard-row {
    display: flex;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    font-size: 0.9em;
    min-height: 60px;
}

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

.leaderboard-row:hover {
    background-color: #f8f9fa;
    cursor: pointer;
}

.leaderboard-row.selected {
    background-color: #e3f2fd;
    border-left: 4px solid #0077FF;
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.2);
}

/* Athlete Details Panel */
.athlete-details-panel {
    display: none;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 1px solid #dee2e6;
    border-top: none;
    padding: 20px;
    margin: 0 0 10px 0;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.athlete-details-panel.show {
    display: block;
}

.athlete-details-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.athlete-top-section {
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

.athlete-image-section {
    flex-shrink: 0;
}

.athlete-image {
    width: 75px;
    height: 100px;
    border-radius: 8px;
    object-fit: cover;
    border: 3px solid #0077FF;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    background: #f8f9fa;
    transition: transform 0.2s ease;
}

.athlete-image:hover {
    transform: scale(1.05);
}

.athlete-basic-info {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.athlete-info-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9em;
}

.athlete-info-label {
    font-weight: 600;
    color: #495057;
    min-width: 40px;
}

.athlete-info-value {
    color: #212529;
    font-weight: 500;
}

.athlete-info-value.na {
    color: #6c757d;
    font-style: italic;
}

.athlete-chart-section {
    background: white;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.chart-title {
    font-size: 0.8em;
    font-weight: 600;
    color: #495057;
    margin-bottom: 10px;
    text-align: center;
}

.speed-chart {
    width: 100%;
    height: 80px;
    background: #f8f9fa;
    border-radius: 4px;
    position: relative;
    padding: 5px;
    overflow: hidden;
}

.speed-chart canvas {
    width: 100% !important;
    height: 100% !important;
}

/* Responsive design for athlete details */
@media (max-width: 768px) {
    .athlete-top-section {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
    
    .athlete-details-panel {
        padding: 15px;
    }
}

/* Group styling */
.group-container {
    margin-bottom: 8px;
    border-radius: 6px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    overflow: hidden;
}

.group-athlete {
    background: white;
    margin: 0;
    border-bottom: 1px solid #e9ecef;
    border-radius: 0;
}

.group-athlete:last-child {
    border-bottom: none;
}

.gap-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 0;
    margin: 4px 0;
    background: linear-gradient(90deg, #e9ecef 0%, #dee2e6 50%, #e9ecef 100%);
    border-radius: 4px;
    position: relative;
}

.gap-line {
    flex: 1;
    height: 1px;
    background: #6c757d;
    margin: 0 8px;
}

.gap-text {
    background: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    color: #495057;
    border: 1px solid #6c757d;
    white-space: nowrap;
}

.cheer-button {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all 0.2s;
    margin-left: 12px;
    opacity: 0.5;
    flex-shrink: 0;
}

.cheer-button:disabled {
    cursor: not-allowed;
    opacity: 0.3;
}

.cheer-button:not(:disabled):hover {
    background-color: #fff3cd;
    transform: scale(1.1);
    opacity: 1;
}

.cheer-button:not(:disabled):active {
    transform: scale(0.95);
}

.cheer-leaderboard {
    background: linear-gradient(135deg, #ffd700, #ffed4e);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.3);
}

.cheer-leaderboard h4 {
    margin: 0 0 8px 0;
    color: #333;
    font-size: 14px;
    text-align: center;
}

.cheer-team {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
    font-size: 12px;
    color: #333;
    font-weight: bold;
}

.position {
    font-weight: bold;
    color: #0077FF;
    min-width: 30px;
    text-align: center;
}

.bib-number {
    background: #0077FF;
    color: white;
    padding: 8px;
    border-radius: 8px;
    font-size: 0.8em;
    font-weight: bold;
    width: 32px;
    height: 32px;
    text-align: center;
    margin-right: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.athlete-info {
    flex: 1;
    margin-left: 8px;
}

.athlete-name {
    font-weight: bold;
    color: #333;
    margin-bottom: 2px;
}

.athlete-name.sos {
    color: #FF0000;
    font-weight: bold;
}

.athlete-name.sos::before {
    content: "SOS - ";
    color: #FF0000;
    font-weight: bold;
}

.athlete-team {
    font-size: 1.0em;
    color: #666;
    margin-bottom: 2px;
}

.athlete-details {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1.0em;
    color: #666;
    margin-top: 2px;
}

.athlete-details .athlete-team {
    margin-bottom: 0;
    font-weight: 500;
    line-height: 1.0;
}

.athlete-details .distance {
    color: #00C851;
    font-weight: 500;
    line-height: 1.0;
}

.athlete-details .status {
    font-weight: 500;
    line-height: 1.0;
}

.athlete-details .finish-time {
    color: #666;
    line-height: 1.0;
}

.athlete-stats {
    font-size: 1.0em;
    color: #888;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.distance {
    font-weight: bold;
    color: #00C851;
}

.status {
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
    text-transform: uppercase;
}

.status.waiting {
    background: #e3f2fd;
    color: #1976d2;
}

.status.ready {
    background: #e3f2fd;
    color: #1976d2;
}

.status.racing {
    background: #e8f5e8;
    color: #2e7d32;
}

.status.finished {
    background: #fff3e0;
    color: #f57c00;
}

.status.dnf {
    background: #ffebee;
    color: #d32f2f;
}

.status.not_boarded {
    background: #f3e5f5;
    color: #7b1fa2;
}

/* Weather Card Styles - Always 2x2 grid */
.weather-card {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 1300;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 12px 20px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 12px;
    font-family: 'Poppins', sans-serif;
    color: #4a5568;
    max-height: 120px;
    min-width: 140px;
    max-width: 200px;
}

.weather-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    white-space: nowrap;
    flex: 0 0 45%;
    justify-content: center;
    text-align: center;
}

.weather-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #63b3ed;
}

.weather-icon-img {
    width: 20px;
    height: 20px;
    filter: invert(66%) sepia(26%) saturate(1267%) hue-rotate(177deg) brightness(100%) contrast(86%);
    /* This filter converts the PNG to light blue (#63b3ed) */
}

.weather-value {
    font-weight: 600;
    color: #2d3748;
    font-size: 18px;
    font-family: 'Poppins', sans-serif;
}

.weather-unit {
    color: #718096;
    font-size: 14px;
    font-weight: 400;
    font-family: 'Poppins', sans-serif;
}

.wind-direction-container {
    position: relative;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wind-circle {
    width: 32px;
    /*height: 32px;*/
    aspect-ratio: 1;
    border: 2px solid #63b3ed;
    border-radius: 50%;
    position: relative;
    background: rgba(99, 179, 237, 0.01);
}

.wind-arrow {
    position: absolute;
    top: 50%;
    left: 50%;
    transform-origin: center;
    color: #63b3ed;
    aspect-ratio: 1;
}

/* Responsive sizing based on map width */
@media (max-width: 600px) {
    .weather-card {
        padding: 8px 12px;
        gap: 8px;
        max-height: 100px;
        min-width: 120px;
        max-width: 140px;
    }
    
    .weather-item {
        font-size: 11px;
        gap: 2px;
    }
    
    .weather-value {
        font-size: 12px;
    }
    
    .weather-unit {
        font-size: 10px;
    }
    
    .weather-icon {
        width: 14px;
        height: 14px;
        font-size: 12px;
    }
    
    .weather-icon-img {
        width: 14px;
        height: 14px;
    }
    
    .wind-direction-container {
        width: 16px;
        height: 16px;
    }
    
    .wind-circle {
        width: 16px;
        height: 16px;
    }
}

/* Course styling */
.course-polyline {
    stroke: #0077FF;
    stroke-opacity: 0.3;
    stroke-width: 6;
    fill-opacity: 0.1;
}

/* Sponsor Banner Styles - Height matches weather card */
.sponsor-banner {
    position: absolute;
    z-index: 1200;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 12px;
    padding: 6px 10px;
    max-width: 400px;
    height: 120px; /* Match weather card height */
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
    transition: opacity 0.3s, top 0.4s cubic-bezier(0.4,0,0.2,1), left 0.4s cubic-bezier(0.4,0,0.2,1);
    pointer-events: auto;
}
.sponsor-banner--dynamic {
    left: 10px;
    top: 10px;
}
.sponsor-banner img {
    height: 100%;
    width: auto;
    max-width: 100%;
    object-fit: contain;
    display: block;
}
.sponsor-banner a {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

/* Mobile: scale down and ensure inside map */
@media (max-width: 600px) {
    .sponsor-banner {
        height: 100px; /* Match mobile weather card height */
        max-width: 140px;
        padding: 4px 8px;
        top: 10px;
        left: 10px;
        border-radius: 8px;
    }
    
    .sponsor-banner img {
        max-height: 90px; /* Adjust to fit new height */
        width: auto;
    }
}

/* Phone horizontal: smaller sponsor banner */
@media (max-width: 900px) and (min-width: 600px) and (orientation: landscape) {
    .sponsor-banner {
        height: 40px !important;
        max-width: 90px !important;
        padding: 2px 4px !important;
    }
    .sponsor-banner img {
        max-height: 36px !important;
    }
}

/* Responsive Layout - Desktop/Tablet */
@media (min-width: 768px) {
    .container {
        flex-direction: row;
    }
    #map {
        flex: 2;
        min-width: 0;
        height: 100%;
    }
    .info-panel {
        flex: 1;
        min-width: 400px;
        max-width: 500px;
        padding: 20px;
    }
}

/* Sponsor banner positioning for desktop */
@media (min-width: 768px) {
    .sponsor-banner--dynamic {
        left: 10px;
        top: 10px;
    }
}

/* Responsive Layout - Mobile */
@media (max-width: 767px) {
    .container {
        flex-direction: column;
        height: auto;
    }
    #map {
        width: 100vw;
        min-height: 220px;
        height: 60vh;
        flex: none;
    }
    .info-panel {
        width: 100vw;
        min-width: 0;
        max-width: none;
        padding: 12px 6px;
        height: auto;
    }
    #leaderboardTable {
        height: auto;
        max-height: 300px;
    }
}

/* Phone Horizontal - Side by side layout */
@media (max-width: 767px) and (orientation: landscape) {
    .container {
        flex-direction: row;
        height: calc(100vh - 20px);
    }
    #map {
        flex: 2;
        width: auto;
        height: 100%;
        min-height: auto;
    }
    .info-panel {
        flex: 1;
        width: auto;
        min-width: 200px;
        max-width: 300px;
        padding: 8px;
        height: 100%;
    }
    #leaderboardTable {
        height: calc(100vh - 60px);
        max-height: none;
    }
    
    /* Smaller text for mobile horizontal view */
    .info-panel h2 {
        font-size: 16px;
    }
    
    #raceStatus {
        font-size: 0.75em;
    }
    
    .race-status {
        font-size: 0.7em;
        padding: 3px 6px;
    }
    
    .elapsed-time {
        font-size: 0.8em;
        padding: 3px 6px;
    }
    
    .leaderboard-row {
        font-size: 0.75em;
        padding: 6px 0;
    }
    
    .athlete-name {
        font-size: 0.9em;
    }
    
    .athlete-team {
        font-size: 0.7em;
    }
    
    .athlete-stats {
        font-size: 0.7em;
    }
    
    .bib-number {
        font-size: 0.7em;
        width: 28px;
        height: 28px;
        padding: 6px;
    }
    
    .position {
        font-size: 0.8em;
        min-width: 25px;
    }
    
    .status {
        font-size: 0.6em;
        padding: 1px 4px;
    }
}

/* Make sure .container is position:relative for absolute children */
.container {
    position: relative;
}

/* Chat UI Styles */
.input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.picture-btn, .send-btn {
    background: #4dabf7;
    border: none;
    border-radius: 6px;
    color: white;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    min-width: 32px;
    height: 32px;
}

.picture-btn:hover, .send-btn:hover {
    background: #0056CC;
}

.picture-btn:disabled, .send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.picture-btn svg, .send-btn svg {
    width: 16px;
    height: 16px;
}

/* Chat Modal Styles */
.chat-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.chat-modal {
    background: white;
    padding: 24px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.chat-modal h2 {
    margin: 0 0 16px 0;
    color: #333;
    font-size: 1.2em;
}

.chat-modal p {
    margin: 0 0 20px 0;
    color: #666;
    font-size: 0.9em;
    line-height: 1.4;
}

.modal-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #ddd;
    border-radius: 4px;
    font-size: 1em;
    margin-bottom: 16px;
    box-sizing: border-box;
}

.modal-input:focus {
    outline: none;
    border-color: #0077FF;
}

.modal-btn {
    background: #0077FF;
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 4px;
    font-size: 1em;
    cursor: pointer;
    margin-bottom: 12px;
    transition: background-color 0.2s;
}

.modal-btn:hover {
    background: #0056CC;
}

.modal-cancel {
    font-size: 0.8em;
    color: #999;
    margin-top: 8px;
}

.cancel-link {
    color: #0077FF;
    cursor: pointer;
    text-decoration: underline;
    transition: color 0.2s;
}

.cancel-link:hover {
    color: #0056CC;
}

.error-message {
    color: #ff4444;
    font-size: 0.9em;
    margin-top: 8px;
}

.hidden {
    display: none !important;
} 