/* CSS Reset og Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #1e3a8a;
    --secondary-color: #3b82f6;
    --accent-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    font-size: 16px;
}

.container {
    min-height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

/* Header Styles */
.header {
    text-align: center;
    margin-bottom: 2rem;
    padding: 2rem 0;
}

.header-home-link {
    text-decoration: none;
    color: inherit;
    display: inline-flex;
    align-items: center;
    gap: 1rem;
}

.header-logo {
    width: 96px;
    height: 96px;
    border-radius: var(--radius-lg);
    object-fit: contain;
    flex-shrink: 0;
}

.main-title {
    font-size: 3rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(30, 58, 138, 0.1);
}

.subtitle {
    font-size: 1.125rem;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.05em;
}

.header-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1rem;
    min-height: 2rem;
}

.header-user {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Main Content */
.main-content {
    max-width: 800px;
    margin: 0 auto;
}

/* ===== Landing Cards ===== */
.landing-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    padding: 1rem 0;
}

.landing-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 3rem 2rem;
    text-decoration: none;
    color: var(--text-primary);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border: 2px solid transparent;
}

.landing-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    border-color: var(--secondary-color);
}

.landing-card-icon {
    color: var(--secondary-color);
    margin-bottom: 1.5rem;
}

.landing-card h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.landing-card p {
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

/* ===== Leaderboard (scores view) ===== */
.leaderboard {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.section-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin: 0;
}

.refresh-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-md);
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.refresh-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(180deg);
}

/* Scoring Info */
.scoring-info {
    background: var(--surface-color);
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    text-align: center;
}

.scoring-info p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    margin: 0;
}

/* Search Bar */
.search-bar {
    padding: 0.75rem 1.5rem;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
}

.search-bar input {
    width: 100%;
    padding: 0.625rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.9375rem;
    background: var(--background-color);
    color: var(--text-primary);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-bar input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
    background: var(--surface-color);
}

/* Loading State */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error State */
.error-message {
    text-align: center;
    padding: 2rem;
    color: var(--danger-color);
}

.error-message button {
    background: var(--danger-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 500;
    margin-top: 1rem;
    transition: background-color 0.2s ease;
}

.error-message button:hover {
    background: #dc2626;
}

/* Leaderboard Table */
.leaderboard-table {
    overflow-x: auto;
}

.table-header, .table-row {
    display: grid;
    grid-template-columns: 60px 1fr 80px 100px 90px;
    gap: 1rem;
    padding: 1rem 1.5rem;
    align-items: center;
}

.table-header {
    background: var(--background-color);
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

.table-row {
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
}

.table-row:hover {
    background: var(--background-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

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

.rank {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.875rem;
}

.rank.gold {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: white;
}

.rank.silver {
    background: linear-gradient(135deg, #9ca3af, #6b7280);
    color: white;
}

.rank.bronze {
    background: linear-gradient(135deg, #d97706, #b45309);
    color: white;
}

.rank.other {
    background: var(--background-color);
    color: var(--text-secondary);
}

.player-info {
    display: flex;
    flex-direction: column;
}

.player-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
}

.player-team {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.125rem;
}

.score {
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--accent-color);
}

.winrate {
    font-weight: 600;
    font-size: 0.875rem;
}

.winrate.excellent {
    color: var(--accent-color);
}

.winrate.good {
    color: var(--warning-color);
}

.winrate.average {
    color: var(--text-secondary);
}

.attendance {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--secondary-color);
}

.sortable-col {
    cursor: pointer;
    user-select: none;
    transition: color 0.2s ease;
}

.sortable-col.active {
    color: var(--text-primary);
}

/* ===== Auth Forms ===== */
.auth-card {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 440px;
    margin: 0 auto;
    overflow: hidden;
}

.auth-header {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 1.5rem;
}

.auth-header h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

.auth-description {
    padding: 1rem 1.5rem 0;
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

.auth-form {
    padding: 1.5rem;
}

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
    margin-bottom: 0.375rem;
}

.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: var(--surface-color);
    color: var(--text-primary);
}

.form-group input:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-error {
    background: #fef2f2;
    color: var(--danger-color);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    border: 1px solid #fecaca;
}

.form-success {
    background: #f0fdf4;
    color: var(--accent-color);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    margin-bottom: 1rem;
    border: 1px solid #bbf7d0;
}

.auth-footer {
    padding: 1rem 1.5rem;
    text-align: center;
    border-top: 1px solid var(--border-color);
    background: var(--background-color);
}

.auth-footer p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.auth-footer a {
    color: var(--secondary-color);
    font-weight: 600;
    text-decoration: none;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* ===== Buttons ===== */
.btn {
    display: inline-block;
    font-family: inherit;
    font-weight: 600;
    font-size: 1rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.btn-primary:hover:not(:disabled) {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.btn-small {
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
}

.btn-outline {
    background: transparent;
    color: var(--primary-color);
    border: 1px solid var(--border-color);
}

.btn-outline:hover:not(:disabled) {
    background: var(--background-color);
}

/* ===== Team Select ===== */
.team-list {
    padding: 1.5rem;
}

.team-option {
    display: block;
    width: 100%;
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
    background: var(--background-color);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    text-align: left;
    transition: all 0.2s ease;
}

.team-option:hover {
    border-color: var(--secondary-color);
    background: white;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.team-option:last-child {
    margin-bottom: 0;
}

/* ===== Trainings List ===== */
.trainings-section {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.training-list {
    max-height: 70vh;
    overflow-y: auto;
}

.training-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    text-decoration: none;
    color: var(--text-primary);
    transition: background 0.2s ease;
}

.training-item:hover {
    background: var(--background-color);
}

.training-item:last-child {
    border-bottom: none;
}

.training-date {
    font-weight: 600;
    font-size: 1rem;
}

.training-meta {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

/* ===== Filter Panel ===== */
.filter-panel {
    padding: 1rem 1.5rem;
    background: var(--background-color);
    border-bottom: 1px solid var(--border-color);
}

.filter-row {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
}

.filter-field {
    flex: 1;
    min-width: 140px;
}

.filter-field label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.filter-field input[type="date"] {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.875rem;
    background: var(--surface-color);
    color: var(--text-primary);
    transition: border-color 0.2s ease;
}

.filter-field input[type="date"]:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.filter-clear-btn {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--surface-color);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.filter-clear-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

/* ===== Training Detail ===== */
.training-detail {
    max-width: 800px;
    margin: 0 auto;
}

.detail-header-bar {
    margin-bottom: 1rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    color: var(--secondary-color);
    font-weight: 600;
    text-decoration: none;
    font-size: 0.9375rem;
    transition: color 0.2s ease;
}

.back-link:hover {
    color: var(--primary-color);
}

.detail-card {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.detail-top {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    padding: 1.5rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.detail-logo {
    width: 64px;
    height: 64px;
    flex-shrink: 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
}

.detail-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.detail-info h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.detail-section {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.detail-section:last-child {
    border-bottom: none;
}

.detail-section-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.winners-title {
    color: var(--accent-color);
}

.losers-title {
    color: var(--danger-color);
}

.player-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.player-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9375rem;
}

.player-list li:last-child {
    border-bottom: none;
}

/* ===== Modal Styles ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    transition: background-color 0.2s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.modal-content {
    padding: 1.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: var(--background-color);
    border-radius: var(--radius-md);
    padding: 1.5rem 1rem;
    text-align: center;
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    line-height: 1;
    margin-bottom: 0.5rem;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
    .container {
        padding: 0.5rem;
    }

    .main-title {
        font-size: 2.5rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .table-header, .table-row {
        grid-template-columns: 50px 1fr 60px 70px 70px;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
    }

    .player-name {
        font-size: 0.875rem;
    }

    .player-team {
        font-size: 0.75rem;
    }

    .score {
        font-size: 1rem;
    }

    .winrate {
        font-size: 0.75rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .modal {
        margin: 0.5rem;
    }

    .modal-header, .modal-content {
        padding: 1rem;
    }

    .landing-cards {
        grid-template-columns: 1fr;
    }

    .landing-card {
        padding: 2rem 1.5rem;
    }

    .detail-top {
        flex-direction: column;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .main-title {
        font-size: 2rem;
    }

    .table-header, .table-row {
        grid-template-columns: 40px 1fr 45px 55px 55px;
        gap: 0.25rem;
        padding: 0.5rem 0.75rem;
        font-size: 0.75rem;
    }

    .player-name {
        font-size: 0.75rem;
    }

    .score {
        font-size: 0.875rem;
    }

    .winrate {
        font-size: 0.625rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .auth-form {
        padding: 1rem;
    }
}

/* Extra small screens */
@media (max-width: 360px) {
    .table-header, .table-row {
        grid-template-columns: 30px 1fr 40px 45px 45px;
        gap: 0.15rem;
        padding: 0.4rem 0.5rem;
        font-size: 0.7rem;
    }

    .player-name {
        font-size: 0.7rem;
    }

    .score {
        font-size: 0.8rem;
    }

    .winrate {
        font-size: 0.6rem;
    }

    .rank {
        width: 30px;
        height: 30px;
        font-size: 0.75rem;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus styles for keyboard navigation */
.table-row:focus,
.refresh-btn:focus,
.close-btn:focus,
button:focus {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .refresh-btn, .modal, .header-actions {
        display: none !important;
    }

    .leaderboard {
        box-shadow: none;
        border: 1px solid var(--border-color);
    }
}
