:root {
    --tm-loyal-blue: #004165;
    --tm-blissful-blue: #006094;
    --tm-true-maroon: #772432;
    --tm-rich-maroon: #781327;
    --tm-deep-maroon: #3b0104;
    --tm-cool-gray: #a9b2b1;
    --tm-fair-gray: #f5f5f5;
    --tm-happy-yellow: #f2df74;
    --tm-white: #ffffff;
    --tm-charcoal: #1b1f23;
    --tm-slate: #4f5b63;
    --tm-border: #d7dddd;
    --tm-shadow: rgba(0, 33, 52, 0.2);
}

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

body {
    font-family: 'Source Sans 3', 'Myriad Pro', 'Segoe UI', Arial, sans-serif;
    background: linear-gradient(135deg, var(--tm-fair-gray) 0%, var(--tm-cool-gray) 100%);
    min-height: 100vh;
    padding: 20px;
    color: var(--tm-charcoal);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--tm-white);
    border-radius: 12px;
    box-shadow: 0 20px 60px var(--tm-shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

header {
    background: linear-gradient(135deg, var(--tm-blissful-blue) 0%, var(--tm-loyal-blue) 100%);
    color: var(--tm-white);
    padding: 40px 30px;
    text-align: center;
}

.language-switcher {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.language-switcher label {
    font-family: 'Montserrat', 'Gotham', 'Segoe UI', Arial, sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
}

.language-switcher select {
    border: 1px solid rgba(255, 255, 255, 0.6);
    background: rgba(255, 255, 255, 0.14);
    color: var(--tm-white);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.9rem;
}

.language-switcher option {
    color: var(--tm-charcoal);
}

header h1 {
    font-family: 'Montserrat', 'Gotham', 'Segoe UI', Arial, sans-serif;
    font-size: 2.4rem;
    margin-bottom: 10px;
    font-weight: 700;
    letter-spacing: 0.015em;
}

.subtitle {
    font-size: 1rem;
    opacity: 0.95;
    font-weight: 400;
}

main {
    flex: 1;
    padding: 40px 30px;
}

section {
    margin-bottom: 40px;
}

section h2,
section h3 {
    font-family: 'Montserrat', 'Gotham', 'Segoe UI', Arial, sans-serif;
    margin-bottom: 20px;
    color: var(--tm-loyal-blue);
    font-size: 1.5rem;
    border-bottom: 2px solid var(--tm-cool-gray);
    padding-bottom: 10px;
}

section h3 {
    font-size: 1.2rem;
    border-bottom: none;
}

.input-section {
    background: var(--tm-fair-gray);
    padding: 30px;
    border-radius: 8px;
    border: 2px dashed var(--tm-border);
}

.privacy-notice {
    background: #eaf6ee;
    border-left: 4px solid #1a7d3c;
    border-radius: 6px;
    padding: 12px 16px;
    margin-bottom: 20px;
    font-size: 0.9rem;
    color: #1a4d2e;
}

.upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 25px;
}

.upload-card {
    padding: 20px;
    background: var(--tm-white);
    border: 2px solid var(--tm-border);
    border-radius: 8px;
    transition: all 0.2s ease;
}

.upload-card:hover {
    border-color: var(--tm-loyal-blue);
    box-shadow: 0 4px 12px rgba(0, 65, 101, 0.18);
}

.file-label {
    display: block;
    cursor: pointer;
    text-align: center;
}

.file-label input[type="file"] {
    display: none;
}

.label-text {
    display: block;
    font-weight: 700;
    color: var(--tm-loyal-blue);
    margin-bottom: 10px;
}

.file-name {
    display: block;
    font-size: 0.92rem;
    color: var(--tm-slate);
    margin-top: 5px;
    word-break: break-all;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
    font-family: 'Montserrat', 'Gotham', 'Segoe UI', Arial, sans-serif;
}

.btn-primary {
    background: linear-gradient(135deg, var(--tm-blissful-blue) 0%, var(--tm-loyal-blue) 100%);
    color: var(--tm-white);
}

#process-btn {
    width: 100%;
    padding: 14px;
    font-size: 1.06rem;
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(0, 65, 101, 0.35);
}

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

.btn-secondary {
    background: linear-gradient(135deg, var(--tm-rich-maroon) 0%, var(--tm-true-maroon) 100%);
    color: var(--tm-white);
}

.btn-secondary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(119, 36, 50, 0.3);
}

.validation-section {
    background: #fff8d6;
    border: 1px solid #e6c94f;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 30px;
}

.validation-section.hidden {
    display: none;
}

.validation-messages {
    list-style: none;
}

.validation-messages li {
    padding: 8px 0;
    border-bottom: 1px solid #f0dea2;
}

.validation-messages li:last-child {
    border-bottom: none;
}

.validation-messages .error {
    color: #a4001d;
    font-weight: 700;
}

.validation-messages .warning {
    color: #8f5d00;
}

.validation-messages .info {
    color: var(--tm-loyal-blue);
}

.club-representation-section {
    background: var(--tm-fair-gray);
    border-radius: 8px;
    padding: 30px;
    margin-bottom: 30px;
}

.club-representation-section.hidden {
    display: none;
}

.club-representation-summary {
    color: var(--tm-slate);
    font-weight: 700;
    margin-bottom: 20px;
}

.division-group {
    margin-bottom: 24px;
}

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

.division-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--tm-white);
    background: var(--tm-true-maroon);
    padding: 10px 15px;
    border-radius: 6px;
    margin-bottom: 12px;
    font-size: 1.05rem;
}

.division-count {
    font-size: 0.85rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.18);
    padding: 3px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

.area-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px 20px;
    align-items: start;
}

.area-group {
    background: var(--tm-white);
    border: 1px solid var(--tm-border);
    border-radius: 8px;
    padding: 12px 14px;
}

.area-heading {
    color: var(--tm-loyal-blue);
    padding: 0 0 6px;
    margin-bottom: 6px;
    font-size: 0.9rem;
    border-bottom: 2px solid var(--tm-border);
}

.area-group .table-container {
    margin-bottom: 0;
    box-shadow: none;
    border-radius: 4px;
}

.club-representation-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--tm-white);
    font-size: 0.92rem;
}

.club-representation-table thead {
    background: var(--tm-blissful-blue);
    color: var(--tm-white);
}

.club-representation-table thead th {
    padding: 6px 10px;
    text-align: left;
    font-weight: 700;
}

.club-representation-table tbody td {
    padding: 6px 10px;
    border-bottom: 1px solid #dfe6e6;
}

/* Status stays on one line even when space is tight; the Club Name /
   Position / Name columns wrap first to give it room. */
.club-representation-table thead th:last-child,
.club-representation-table td.representation-status {
    white-space: nowrap;
}

@media (max-width: 640px) {
    .area-grid {
        grid-template-columns: 1fr;
    }
}

.club-representation-table tr.club-represented .representation-status {
    color: #1a7d3c;
    font-weight: 700;
}

.club-representation-table tr.club-unrepresented {
    background: #fdecec;
}

.club-representation-table tr.club-unrepresented .representation-status {
    color: #a4001d;
    font-weight: 700;
}

.club-representation-table tr.club-declined {
    background: #fdf3e3;
}

.club-representation-table tr.club-declined .representation-status {
    color: #8f5d00;
    font-weight: 700;
}

.declined-note {
    display: inline-block;
    font-weight: 400;
    font-size: 0.85em;
    color: #8f5d00;
}

.results-section {
    background: var(--tm-fair-gray);
    border-radius: 8px;
    padding: 30px;
}

.results-section.hidden {
    display: none;
}

.results-toolbar {
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
}

.results-toolbar-bottom {
    margin-top: 20px;
    margin-bottom: 20px;
}

.table-container {
    overflow-x: auto;
    margin-bottom: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--tm-white);
}

.results-table thead {
    background: var(--tm-loyal-blue);
    color: var(--tm-white);
}

.results-table thead th {
    padding: 15px;
    text-align: left;
    font-weight: 700;
    border-bottom: 2px solid #05344f;
}

.results-table tbody tr {
    border-bottom: 1px solid #dfe6e6;
    transition: background 0.2s ease;
}

.results-table tbody tr:hover {
    background: #eef2f2;
}

.results-table tbody td {
    padding: 12px 15px;
}

.results-table tbody tr:nth-child(even) {
    background: #fbfcfc;
}

.stats-summary {
    background: var(--tm-white);
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid var(--tm-loyal-blue);
}

.stats-summary p {
    padding: 8px 0;
    font-size: 1rem;
}

.stats-summary strong {
    color: var(--tm-charcoal);
}

.rules-section {
    background: #eef3f4;
    border-left: 4px solid var(--tm-cool-gray);
    padding: 20px;
    border-radius: 8px;
    margin-top: 30px;
}

.rules-section a {
    color: var(--tm-loyal-blue);
    text-decoration: none;
    font-weight: 700;
}

.rules-section a:hover {
    text-decoration: underline;
}

footer {
    background: #f1f4f4;
    padding: 20px 30px;
    text-align: center;
    color: var(--tm-slate);
    font-size: 0.92rem;
    border-top: 1px solid #d8e0e0;
}

.footer-privacy {
    margin-top: 6px;
    font-size: 0.82rem;
    color: var(--tm-slate);
}

.mapping-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.mapping-dialog {
    width: min(980px, 100%);
    max-height: 92vh;
    overflow: auto;
    background: var(--tm-white);
    border-radius: 12px;
    box-shadow: 0 22px 60px rgba(0, 0, 0, 0.35);
    padding: 24px;
}

.mapping-subtitle {
    color: var(--tm-slate);
    margin-bottom: 14px;
}

.mapping-errors {
    min-height: 1.6rem;
    color: #a4001d;
    margin-bottom: 10px;
    font-weight: 600;
}

.mapping-errors p {
    margin-bottom: 4px;
}

.mapping-form h3 {
    margin-top: 20px;
}

.mapping-grid {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 10px 14px;
    align-items: center;
}

.mapping-grid label {
    font-weight: 700;
    color: var(--tm-loyal-blue);
}

.mapping-grid select {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--tm-border);
    border-radius: 6px;
    background: var(--tm-white);
    font-size: 0.95rem;
}

.mapping-grid select:focus {
    outline: 2px solid rgba(0, 65, 101, 0.2);
    border-color: var(--tm-loyal-blue);
}

.mapping-preview-container {
    overflow-x: auto;
    border: 1px solid #dde5e5;
    border-radius: 8px;
}

.mapping-preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.mapping-preview-table th,
.mapping-preview-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #edf2f2;
    text-align: left;
}

.mapping-preview-table thead {
    background: #eef3f4;
}

.mapping-actions {
    margin-top: 16px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.mapping-actions .btn-primary {
    width: auto;
}

.hidden {
    display: none !important;
}

.processing {
    opacity: 0.72;
    pointer-events: none;
}

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #dce5e5;
    border-top: 2px solid var(--tm-loyal-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
}

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

@media (max-width: 768px) {
    .upload-grid {
        grid-template-columns: 1fr;
    }

    header {
        padding: 30px 20px;
    }

    .language-switcher {
        justify-content: center;
        margin-bottom: 10px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    main {
        padding: 20px;
    }

    section h2,
    section h3 {
        font-size: 1.28rem;
    }

    .input-section,
    .results-section {
        padding: 20px;
    }

    .results-toolbar {
        flex-direction: column;
    }

    .btn {
        padding: 10px 16px;
        font-size: 0.95rem;
    }

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

    .mapping-actions {
        flex-direction: column;
    }

    .mapping-actions .btn {
        width: 100%;
    }
}
