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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: white;
    height: 100vh;
    overflow: hidden;
    padding: 0;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    background: white;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: white;
    color: #333;
    padding: 20px;
    border-bottom: 1px solid #ddd;
    flex-shrink: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 1600px;
    margin: 0 auto;
    position: relative;
}

.logo {
    width: 80px;
    height: 80px;
    position: absolute;
    left: 0;
}

.header-text {
    text-align: center;
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

header h2 {
    font-size: 1.2em;
    font-weight: 300;
    opacity: 0.9;
}

.stats-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    padding: 20px;
    background: white;
    border-bottom: 1px solid #ddd;
    flex-shrink: 0;
    z-index: 90;
}

.stat-card {
    background: white;
    padding: 15px;
    text-align: center;
    border: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.stat-value {
    font-size: 1.8em;
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
    text-align: center;
}

.stat-label {
    color: #666;
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}

.filters {
    padding: 20px;
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    background: white;
    border-bottom: 1px solid #ddd;
    flex-shrink: 0;
    z-index: 80;
}

.search-wrapper {
    position: relative;
    flex: 1;
    min-width: 250px;
}

.filters input,
.filters select {
    flex: 1;
    min-width: 200px;
    padding: 8px 12px;
    border: 1px solid #ddd;
    font-size: 16px; /* Prevents zoom on iOS */
}

.filters input {
    width: 100%;
    padding-right: 35px;
}

.filters input:focus,
.filters select:focus {
    outline: none;
    border-color: #999;
}

.clear-search {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 20px;
    color: #999;
    cursor: pointer;
    padding: 5px 10px;
    display: none;
}

.clear-search:hover {
    color: #333;
}

.search-wrapper.has-text .clear-search {
    display: block;
}

.export-btn, .stats-btn {
    padding: 8px 20px;
    background: #fa6432;
    color: white;
    border: none;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    display: none; /* Hidden by default */
}

.export-btn:hover, .stats-btn:hover:not(:disabled) {
    background: #e5531f;
}

.stats-btn {
    display: block; /* Visible by default for all events */
}

.stats-btn:disabled {
    background: #ccc;
    color: #666;
    cursor: not-allowed;
}

.logout-btn {
    position: absolute;
    right: 0;
    padding: 8px 20px;
    background: none;
    color: #666;
    border: 1px solid #ddd;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
}

.logout-btn:hover {
    background: #f5f5f5;
    color: #333;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #666;
    font-size: 1.1em;
}

.table-container {
    flex: 1;
    overflow: auto;
    padding: 0 20px 20px 20px;
    position: relative;
    min-height: 0; /* Important for flex child scrolling */
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0;
}

thead {
    background: white;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
}

th {
    padding: 10px;
    text-align: left;
    font-weight: 600;
    color: #333;
    border-bottom: 2px solid #ddd;
    font-size: 0.9em;
}

tbody tr {
    border-bottom: 1px solid #eee;
}

tbody tr:hover {
    background-color: #f9f9f9;
}

td {
    padding: 10px;
    color: #444;
    font-size: 0.95em;
}

td:last-child {
    max-width: 250px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

td a {
    color: #0066cc;
    text-decoration: none;
}

td a:hover {
    text-decoration: underline;
}




.no-data {
    text-align: center;
    padding: 60px 20px;
    color: #999;
    font-size: 1.1em;
}

@media (max-width: 768px) {
    body {
        height: auto;
        overflow: auto;
        padding: 0;
    }
    
    .container {
        margin: 0;
        border-radius: 0;
        height: auto;
    }
    
    header {
        padding: 15px 10px;
        position: sticky;
        top: 0;
    }
    
    .header-content {
        padding: 0 60px; /* Space for logo and logout button */
    }
    
    .logo {
        width: 50px;
        height: 50px;
        left: 10px;
    }
    
    .header-text {
        text-align: center;
    }
    
    header h1 {
        font-size: 1.3em;
        margin-bottom: 5px;
    }
    
    header h2 {
        font-size: 0.9em;
    }
    
    .logout-btn {
        right: 10px;
        padding: 6px 12px;
        font-size: 12px;
    }
    
    .stats-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 15px 10px;
        position: sticky;
        top: 85px; /* Adjusted for mobile header height */
    }
    
    .stat-card {
        padding: 10px;
    }
    
    .stat-value {
        font-size: 1.2em;
    }
    
    .stat-label {
        font-size: 0.75em;
    }
    
    .filters {
        flex-direction: column;
        padding: 15px 10px;
        position: sticky;
        top: 170px; /* Adjusted for mobile header + stats height */
    }
    
    .filters input,
    .filters select {
        width: 100%;
    }
    
    table {
        font-size: 0.85em;
    }
    
    thead {
        top: 0; /* Sticky to table container top */
    }
    
    th, td {
        padding: 10px 5px;
    }
    
    .table-container {
        padding: 0 10px 10px 10px;
        max-height: calc(100vh - 290px); /* Adjusted for mobile */
    }
}

.error-message {
    background: #fef2f2;
    color: #991b1b;
    padding: 10px;
    margin: 20px;
    text-align: center;
    border: 1px solid #fecaca;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
}

.modal-content {
    background-color: white;
    margin: 2% auto;
    padding: 0;
    border: 1px solid #888;
    width: 90%;
    max-width: 1200px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    padding: 20px;
    background-color: #f5f5f5;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.modal-header h2 {
    margin: 0;
    color: #333;
}

.close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
}

.modal-body {
    padding: 20px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 30px;
    margin-bottom: 40px;
}

.chart-container {
    background: white;
    padding: 20px;
    border: 1px solid #ddd;
}

.chart-container h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 1.1em;
}

.chart-container canvas {
    max-height: 300px;
}

.rankings-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 30px;
}

.ranking-list {
    background: white;
    padding: 20px;
    border: 1px solid #ddd;
}

.ranking-list h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 1.1em;
}

.ranking-list ol {
    padding-left: 25px;
}

.ranking-list li {
    margin: 10px 0;
    color: #666;
    line-height: 1.5;
}

.ranking-list li strong {
    color: #333;
}

@media (max-width: 768px) {
    .modal-content {
        width: 100%;
        height: 100%;
        margin: 0;
        max-height: 100vh;
        border: none;
    }
    
    .modal-header {
        padding: 15px;
    }
    
    .modal-header h2 {
        font-size: 1.2em;
    }
    
    .close {
        font-size: 24px;
        padding: 5px;
    }
    
    .modal-body {
        padding: 15px;
    }
    
    .stats-grid,
    .rankings-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .chart-container,
    .ranking-list {
        padding: 15px;
    }
    
    .chart-container h3,
    .ranking-list h3 {
        font-size: 1em;
        margin-bottom: 10px;
    }
    
    .chart-container canvas {
        max-height: 250px;
    }
    
    .ranking-list ol {
        padding-left: 20px;
    }
    
    .ranking-list li {
        margin: 8px 0;
        font-size: 0.9em;
    }
}