/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #2c3e50;
    background: linear-gradient(135deg, #2e7d32 0%, #1b5e20 100%);
    min-height: 100vh;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 15px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    margin-top: 20px;
    margin-bottom: 20px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 40px;
    padding: 30px 0 25px 0;
    background: linear-gradient(135deg, rgba(46, 125, 50, 0.05) 0%, rgba(27, 94, 32, 0.05) 100%);
    border-radius: 12px;
    border-bottom: 3px solid #2e7d32;
}

header h1 {
    font-size: 2.8rem;
    color: #1b5e20;
    margin-bottom: 15px;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.subtitle {
    font-size: 1.2rem;
    color: #34495e;
    font-weight: 500;
    max-width: 800px;
    margin: 0 auto 5px auto;
    line-height: 1.5;
}

.organization {
    font-size: 1rem;
    color: #7f8c8d;
    font-weight: 400;
    max-width: 800px;
    margin: 0 auto;
    line-height: 1.4;
    font-style: italic;
}

/* Stats Overview */
.stats-overview {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 40px;
}

.stat-card {
    background: white;
    color: #2c3e50;
    padding: 20px 15px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    overflow: hidden;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: 2px solid #f0f0f0;
    position: relative;
}

.stat-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    border-color: #2e7d32;
}

.stat-number {
    font-size: 2.4rem;
    font-weight: 700;
    margin-bottom: 8px;
    word-wrap: break-word;
    line-height: 1.1;
    color: #1a1a1a;
}

.stat-label {
    font-size: 0.85rem;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 600;
    color: #555;
}

.stat-sublabel {
    font-size: 0.75rem;
    text-transform: none;
    opacity: 0.7;
    font-weight: normal;
}

/* Stat Card Types */
.participants-card {
    border-left: 4px solid #2196f3;
}

.average-card {
    border-left: 4px solid #ff9800;
}

.best-score-card {
    border-left: 4px solid #4caf50;
}

/* Controls */
.controls {
    display: flex;
    gap: 25px;
    margin-bottom: 30px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-width: 180px;
}

.control-group label {
    font-weight: 600;
    color: #555;
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.control-group select, .control-group input {
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 14px;
    background: white;
    transition: all 0.3s ease;
    min-width: 200px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.control-group select:focus, .control-group input:focus {
    outline: none;
    border-color: #2e7d32;
    box-shadow: 0 4px 15px rgba(46, 125, 50, 0.2);
    transform: translateY(-1px);
}

.control-group select:hover, .control-group input:hover {
    border-color: #bbb;
}

/* Dashboard Grid */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
    margin-bottom: 40px;
}

.chart-container, .table-container {
    background: white;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
    border: 1px solid #f0f0f0;
}

.chart-container h2, .table-container h2 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-size: 1.4rem;
    font-weight: 600;
}

.chart-container {
    position: relative;
    height: 500px;
    padding: 20px;
    overflow: hidden;
}

#main-chart {
    height: 420px !important;
    max-width: 100%;
}

/* Table Styles */
.table-controls {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

.table-controls input, .table-controls select {
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    flex: 1;
    min-width: 150px;
}

.table-controls input:focus, .table-controls select:focus {
    outline: none;
    border-color: #2e7d32;
    box-shadow: 0 4px 15px rgba(46, 125, 50, 0.2);
}

.table-wrapper {
    max-height: 800px;
    overflow-y: auto;
    overflow-x: auto;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #ccc #f0f0f0;
}

.table-wrapper::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: #f0f0f0;
    border-radius: 4px;
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: #999;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

th {
    background: linear-gradient(135deg, #34495e, #2c3e50);
    color: white;
    padding: 12px 8px;
    text-align: left;
    font-weight: 600;
    font-size: 0.9rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Sortable Table Headers */
th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease;
    position: relative;
}

th.sortable:hover {
    background: linear-gradient(135deg, #3d5a75, #34495e);
}

.sort-indicator {
    font-size: 0.7em;
    margin-left: 5px;
    opacity: 0.3;
    transition: opacity 0.2s ease;
}

.sort-indicator::after {
    content: '↕';
}

th.sortable.sort-asc .sort-indicator {
    opacity: 1;
}

th.sortable.sort-asc .sort-indicator::after {
    content: '↑';
}

th.sortable.sort-desc .sort-indicator {
    opacity: 1;
}

th.sortable.sort-desc .sort-indicator::after {
    content: '↓';
}

td {
    padding: 10px 8px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.9rem;
}

tr:hover {
    background-color: #f8f9fa;
}

.score-cell {
    font-weight: 600;
    color: #27ae60;
}

.clubs-cell {
    font-size: 0.8rem;
    color: #7f8c8d;
    max-width: 250px;
    min-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Details Section */
.details-section {
    display: grid;
    grid-template-columns: 1fr;
    gap: 30px;
    margin-bottom: 40px;
}

.year-details, .statistics-panel {
    background: white;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
    border: 1px solid #f0f0f0;
}

/* Year details when shown at top */
.year-details {
    margin-bottom: 30px;
}

.year-details-spacer {
    min-height: 1px; /* Just to maintain structure */
}

/* Cancelled event styling */
.cancelled-event {
    border-left: 4px solid #e74c3c;
    padding-left: 15px;
}

.cancelled-label {
    color: #e74c3c;
    font-weight: bold;
    text-transform: uppercase;
}

.cancellation-notice {
    background: #fff5f5;
    border: 1px solid #fed7d7;
    border-radius: 8px;
    padding: 15px;
    margin-top: 20px;
}

.cancellation-notice p {
    color: #742a2a;
    margin: 0;
}

.year-details h2, .statistics-panel h2 {
    color: #2c3e50;
    margin-bottom: 20px;
    font-size: 1.4rem;
    font-weight: 600;
}

.year-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 20px;
}

.info-column {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.info-item {
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
}

.info-item:last-child {
    border-bottom: none;
}

.info-item strong {
    color: #555;
    margin-right: 10px;
}

.podium {
    margin-top: 25px;
}

.podium h3 {
    color: #2c3e50;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.podium-entry {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
}

.podium-entry:last-child {
    border-bottom: none;
}

.podium-entry .rank {
    font-weight: bold;
    font-size: 1.1rem;
    min-width: 25px;
}

.rank-1 .rank { color: #f39c12; }
.rank-2 .rank { color: #95a5a6; }
.rank-3 .rank { color: #cd7f32; }

.podium-entry .name {
    font-weight: 600;
    flex: 1;
}

.podium-entry .score {
    font-weight: bold;
    color: #27ae60;
}

.podium-entry .club {
    font-size: 0.8rem;
    color: #7f8c8d;
}

/* Participant details rows */
.participant-details-row {
    background: #f8f9fa;
}

.participant-details-cell {
    padding: 15px 20px !important;
}

.year-details-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.year-details-container strong {
    color: #2c3e50;
    font-size: 0.9rem;
    margin-bottom: 5px;
}

.year-details-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
}

.year-detail-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: white;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    font-size: 0.85rem;
}

.year-detail-header {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.year-badge {
    font-weight: 700;
    color: #2c3e50;
    background: #e8f5e9;
    padding: 4px 10px;
    border-radius: 4px;
    min-width: 50px;
    text-align: center;
}

.rank-badge {
    color: #555;
    background: #f5f5f5;
    padding: 4px 10px;
    border-radius: 4px;
}

.score-badge {
    font-weight: 600;
    color: #27ae60;
    background: #e8f5e9;
    padding: 4px 10px;
    border-radius: 4px;
}

.club-badge {
    color: #7f8c8d;
    font-size: 0.75rem;
    font-style: italic;
    background: #fafafa;
    padding: 4px 8px;
    border-radius: 4px;
}

.individual-scores {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding-top: 4px;
    border-top: 1px solid #f0f0f0;
}

.individual-score {
    font-size: 0.8rem;
    color: #555;
    background: #f8f9fa;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid #e9ecef;
    font-family: 'Courier New', monospace;
    font-weight: 500;
}

/* Statistics Panel */
.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
}

.stat-item:last-child {
    border-bottom: none;
}

.stat-name {
    color: #555;
    font-weight: 500;
}

.stat-value {
    font-weight: 600;
    color: #2c3e50;
}

/* Analytics Section */
.analytics-section {
    margin-top: 30px;
    margin-bottom: 30px;
}

.analytics-accordion {
    background: white;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.analytics-accordion-button {
    width: 100%;
    background: #f8f9fa;
    border: none;
    padding: 15px 20px;
    font-size: 1rem;
    font-weight: 600;
    color: #555;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
}

.analytics-accordion-button:hover {
    background: #e9ecef;
    color: #2c3e50;
}

.analytics-accordion-button:focus {
    outline: none;
    box-shadow: inset 0 0 0 2px #2e7d32;
}

.accordion-icon {
    font-size: 0.8rem;
    transition: transform 0.3s ease;
}

.analytics-accordion-button.active .accordion-icon {
    transform: rotate(180deg);
}

.analytics-accordion-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, padding 0.4s ease;
    padding: 0;
}

.analytics-accordion-content.active {
    max-height: 850px;
    padding: 20px;
}

.analytics-iframe-wrapper {
    width: 100%;
    position: relative;
}

.analytics-iframe {
    width: 100%;
    height: 800px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background: #f8f9fa;
}

.analytics-fallback {
    margin-top: 15px;
    text-align: center;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

.analytics-fallback a {
    color: #2e7d32;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    border-bottom: 1px solid #2e7d32;
    transition: all 0.2s ease;
}

.analytics-fallback a:hover {
    color: #1b5e20;
    border-bottom-color: #1b5e20;
}

/* Footer */
footer {
    text-align: center;
    padding: 20px;
    color: #7f8c8d;
    font-size: 0.9rem;
    border-top: 1px solid #e0e0e0;
    margin-top: 30px;
}

footer p {
    margin: 5px 0;
}

.data-source {
    font-size: 0.75rem !important;
    opacity: 0.7;
}

.data-source a {
    color: #7f8c8d;
    text-decoration: none;
    border-bottom: 1px dotted #bdc3c7;
    transition: all 0.2s ease;
}

.data-source a:hover {
    color: #2e7d32;
    border-bottom-color: #2e7d32;
}

.footer-info {
    font-size: 0.8rem !important;
    opacity: 0.6;
    margin-top: 8px;
    font-style: italic;
}

.data-timestamp {
    font-size: 0.75rem !important;
    opacity: 0.7;
    margin-top: 5px;
}

.analytics-link {
    font-size: 0.8rem !important;
    margin-top: 8px;
}

.analytics-link a {
    color: #2e7d32;
    text-decoration: none;
    border-bottom: 1px dotted #2e7d32;
    transition: all 0.2s ease;
    font-weight: 500;
}

.analytics-link a:hover {
    color: #1b5e20;
    border-bottom-color: #1b5e20;
}

/* Error Message */
.error-message {
    text-align: center;
    padding: 60px 20px;
}

.error-message h2 {
    color: #e74c3c;
    margin-bottom: 20px;
}

.error-message p {
    color: #7f8c8d;
    font-size: 1.1rem;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .container {
        max-width: 95%;
        padding: 20px 15px;
    }
}

@media (max-width: 768px) {
    .container {
        margin: 5px;
        padding: 15px 10px;
        border-radius: 10px;
    }
    
    .analytics-section {
        margin-top: 20px;
        margin-bottom: 20px;
    }
    
    .analytics-accordion-button {
        padding: 12px 15px;
        font-size: 0.9rem;
    }
    
    .analytics-accordion-content.active {
        max-height: 650px;
    }
    
    .analytics-iframe {
        height: 600px;
    }
    
    header {
        padding: 20px 0 15px 0;
        margin-bottom: 30px;
    }
    
    header h1 {
        font-size: 1.8rem;
        line-height: 1.3;
    }
    
    .subtitle {
        font-size: 1rem;
        padding: 0 10px;
    }
    
    .organization {
        font-size: 0.9rem;
        padding: 0 10px;
    }
    
    .stats-overview {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        margin-bottom: 30px;
    }
    
    .stat-card {
        padding: 16px 12px;
        min-height: 90px;
    }
    
    .stat-card:nth-child(3) {
        grid-column: 1 / -1;
    }
    
    .stat-number {
        font-size: 1.9rem;
    }
    
    .stat-label {
        font-size: 0.8rem;
    }
    
    .controls {
        flex-direction: column;
        gap: 15px;
        margin-bottom: 25px;
    }
    
    .control-group {
        width: 100%;
    }
    
    .control-group select,
    .control-group input {
        min-width: auto;
        width: 100%;
        padding: 14px 16px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
    
    .table-controls {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }
    
    .chart-container {
        height: 350px;
        padding: 15px;
    }
    
    #main-chart {
        height: 300px !important;
    }
    
    .chart-container h2, .table-container h2 {
        font-size: 1.2rem;
        margin-bottom: 15px;
    }
    
    th, td {
        padding: 10px 8px;
        font-size: 0.85rem;
    }
    
    .table-container {
        padding: 15px;
    }
    
    .table-wrapper {
        max-height: 500px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .year-info {
        grid-template-columns: 1fr;
        gap: 15px;
    }
}

@media (max-width: 480px) {
    body {
        font-size: 14px;
    }
    
    .container {
        margin: 2px;
        padding: 12px 8px;
    }
    
    header h1 {
        font-size: 1.6rem;
    }
    
    .subtitle {
        font-size: 0.9rem;
    }
    
    .stats-overview {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .stat-card {
        padding: 12px 10px;
        min-height: 80px;
    }
    
    .stat-number {
        font-size: 1.6rem;
        margin-bottom: 6px;
    }
    
    .stat-label {
        font-size: 0.75rem;
        line-height: 1.2;
    }
    
    .stat-sublabel {
        font-size: 0.65rem;
    }
    
    .control-group select,
    .control-group input {
        padding: 12px 14px;
    }
    
    .chart-container {
        height: 300px;
        padding: 12px;
    }
    
    #main-chart {
        height: 250px !important;
    }
    
    th, td {
        padding: 8px 6px;
        font-size: 0.8rem;
    }
    
    .podium-entry {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
        padding: 10px 0;
    }
    
    .info-item {
        padding: 8px 0;
    }
}

/* Extra small screens */
@media (max-width: 360px) {
    .stats-overview {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .stat-card {
        padding: 12px 10px;
        min-height: 100px;
    }
    
    .stat-number {
        font-size: 1.4rem;
    }
    
    .chart-container {
        height: 280px;
        padding: 10px;
    }
    
    #main-chart {
        height: 230px !important;
    }
}