:root {
    --bg: #eef4fb;
    --surface: #ffffff;
    --surface-alt: #f5f9ff;
    --text: #111111;
    --text-soft: #3b3f46;
    --muted: #687385;
    --primary: #1d4ed8;
    --primary-dark: #163ea7;
    --success: #3ca9ff;
    --success-dark: #1d8fe8;
    --navy: #111827;
    --navy-dark: #0b1220;
    --navy-light: #1f2d3d;
    --blue: #3ca9ff;
    --blue-soft: #7ecbff;
    --border: #dfe7f3;
    --shadow: rgba(17, 24, 39, 0.12);
    --overlay: rgba(17, 24, 39, 0.55);
    --rating-red: #e14646;
    --rating-yellow: #f4c542;
    --rating-green: #16834a;
    --metal-light: #edf1f4;
    --metal-mid: #c3cbd2;
    --metal-dark: #8996a2;
    --metal-edge: #778591;

    /* Dialog: cambia il preset scegliendo modal-pirouette-in, modal-zoom-in o modal-slide-up-in. */
    --modal-dialog-animation: modal-pirouette-in;
    --modal-dialog-duration: 0.7s;
    /* Linear mantiene costante la velocità della rotazione fino alla posa finale. */
    --modal-dialog-easing: linear;
    --modal-dialog-start-scale: 0.08;
    --modal-dialog-start-rotation: -720deg;
    --modal-dialog-overshoot-scale: 1.03;
    --modal-dialog-mid-rotation: -216deg;
    --modal-dialog-start-blur: 7px;
    --modal-overlay-duration: 300ms;
    --modal-close-duration: 260ms;
}

/* ==========================================================================
   1. RESET E VARIABILI BASE
   ========================================================================== */
body {
    font-family: Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding-top: 80px;
    overflow-x: hidden;
    touch-action: pan-y;
}

body.menu-open,
body.athlete-dialog-open {
    overflow: hidden;
}

/* ==========================================================================
   2. HEADER FISSO E NAVIGAZIONE
   ========================================================================== */
.main-header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(135deg, rgba(17, 24, 39, 0.98), rgba(29, 78, 216, 0.94));
    min-height: 70px;
    box-shadow: 0 8px 24px rgba(17, 24, 39, 0.22);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.header-top {
    display: flex;
    width: 100%;
    max-width: 1200px;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    box-sizing: border-box;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 1;
    min-width: 0;
}

.header-brand {
    min-width: 0;
}

.society-name {
    display: block;
    width: fit-content;
    max-width: 100%;
    overflow: hidden;
    color: #fff;
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.13em;
    line-height: 1.2;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
    background: linear-gradient(100deg, #fff 10%, #7ecbff 35%, #fff 50%, #c4b5fd 70%, #fff 90%);
    background-size: 220% auto;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: society-shimmer 5s linear infinite, society-float 3s ease-in-out infinite;
}

.page-title-line {
    display: flex;
    align-items: center;
    min-width: 0;
}

.header-logo {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    object-fit: cover;
}

.main-header h1 {
    margin: 0;
    min-width: 0;
    flex: 0 1 auto;
    font-size: 1rem;
    color: #f8fbff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.pingpong-ball-track {
    position: relative;
    display: inline-block;
    flex: 0 0 44px;
    height: 22px;
    margin-left: 8px;
}

.pingpong-ball-track::before {
    position: absolute;
    right: 1px;
    bottom: 5px;
    left: 1px;
    height: 3px;
    border-radius: 2px;
    background: linear-gradient(180deg, var(--blue-soft), var(--primary));
    box-shadow: 0 2px 5px rgba(60, 169, 255, 0.45);
    content: "";
}

.pingpong-ball-track::after {
    position: absolute;
    bottom: 8px;
    left: 50%;
    height: 7px;
    border-left: 1px dashed rgba(255, 255, 255, 0.9);
    content: "";
}

.pingpong-ball {
    position: absolute;
    bottom: 5px;
    left: 2px;
    z-index: 1;
    width: 9px;
    height: 9px;
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    background: radial-gradient(circle at 30% 28%, #fff 0 25%, #e9f5ff 65%, #a9d9ff 100%);
    box-shadow: 0 0 8px rgba(126, 203, 255, 0.8);
    animation: pingpong-rally 1.1s ease-in-out infinite alternate;
}

@keyframes society-shimmer {
    to {
        background-position: 220% center;
    }
}

@keyframes society-float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-2px);
    }
}

/* Animazione Logo */
.rotate-vert-center {
    animation: rotate-vert-center 2s cubic-bezier(.455, .03, .515, .955) 1s infinite both;
}

@keyframes rotate-vert-center {
    0% {
        transform: rotateY(0);
    }

    100% {
        transform: rotateY(360deg);
    }
}

@keyframes pingpong-rally {
    0% {
        left: 2px;
        transform: translateY(0);
    }

    50% {
        left: 50%;
        transform: translate(-50%, -10px);
    }

    100% {
        left: calc(100% - 11px);
        transform: translateY(0);
    }
}

@media (max-width: 480px) {
    .pingpong-ball-track {
        flex-basis: 32px;
        margin-left: 4px;
    }
}

@media (prefers-reduced-motion: reduce) {

    .society-name,
    .rotate-vert-center,
    .pingpong-ball {
        animation: none;
    }
}

/* ==========================================================================
   3. AREA AUTENTICAZIONE (LOGIN)
   ========================================================================== */
.auth-area {
    display: flex;
    align-items: center;
    z-index: 20000;
    position: relative;
}

.user-logged {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #fff;
}

.user-name {
    color: #fff;
    font-size: 0.9rem;
    font-weight: 600;
}

.user-name strong {
    color: #fff;
}

.auth-area input {
    padding: 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    outline: none;
    width: 120px;
    font-size: 0.8rem;
    transition: border 0.3s;
}

.auth-area input:focus {
    border: 2px solid var(--success) !important;
}

.google-login-button {
    display: inline-grid;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    place-items: center;
    border: 1px solid #cbd5e1;
    border-radius: 50%;
    background: #fff;
    box-sizing: border-box;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.google-login-button svg {
    display: block;
    width: 20px;
    height: 20px;
}

.google-login-button:hover {
    background: #f8fafc;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.16);
    transform: translateY(-1px);
}

.google-login-button:focus-visible {
    outline: 3px solid rgba(66, 133, 244, 0.35);
    outline-offset: 2px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.auth-area button {
    background: linear-gradient(135deg, var(--success), var(--blue));
    color: white;
    border: none;
    padding: 7px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    box-shadow: 0 4px 12px rgba(60, 169, 255, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.auth-area button:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(60, 169, 255, 0.45);
}

.impersonation-switcher {
    position: relative;
    margin-left: 10px;
    color: #fff;
}

.impersonation-switcher summary {
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 700;
    white-space: nowrap;
    padding: 7px 9px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 7px;
    background: rgba(60, 169, 255, 0.22);
}

.impersonation-switcher form {
    position: absolute;
    top: calc(100% + 12px);
    right: 0;
    z-index: 20001;
    display: grid;
    width: min(300px, calc(100vw - 24px));
    gap: 9px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    box-shadow: 0 10px 28px rgba(17, 24, 39, 0.24);
}

.impersonation-switcher select {
    width: 100%;
    min-width: 0;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}

.impersonation-banner {
    position: fixed;
    top: 70px;
    left: 0;
    z-index: 9999;
    display: flex;
    width: 100%;
    min-height: 38px;
    box-sizing: border-box;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 6px 12px;
    background: #fff3cd;
    color: #664d03;
    text-align: center;
    box-shadow: 0 2px 8px rgba(17, 24, 39, 0.16);
}

.impersonation-banner form {
    flex: 0 0 auto;
    margin: 0;
}

.impersonation-banner button {
    padding: 6px 10px;
    border: 0;
    border-radius: 6px;
    background: #664d03;
    color: #fff;
    cursor: pointer;
    font-weight: 700;
}

body.is-impersonating {
    padding-top: 120px;
}

/* --- FIX: LOGIN DROPDOWN MOBILE --- */
.login-form {
    display: flex;
    gap: 5px;
}

.mobile-login-toggle {
    display: none;
}

/* ==========================================================================
   4. SIDEBAR E MENU TRIGGER
   ========================================================================== */
.menu-trigger {
    position: fixed;
    top: 15px;
    left: 15px;
    background: linear-gradient(135deg, var(--primary), var(--blue));
    color: white;
    border: none;
    padding: 10px;
    cursor: pointer;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 11001;
    box-shadow: 0 6px 16px rgba(29, 78, 216, 0.35);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.menu-item-group {
    padding: 10px 0 5px 0;
}

.menu-label {
    display: block;
    padding: 10px 15px;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--muted);
    /* Grigio sobrio */
    letter-spacing: 1px;
}

.submenu {
    padding-left: 15px;
    /* Crea l'effetto rientro */
}

.sub-link {
    font-size: 13px !important;
    padding: 8px 15px !important;
    opacity: 0.9;
}

.sub-link:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.05);
}



/* FIX 1: IL TASTONE ROSSO SPARISCE SU MOBILE QUANDO APERTO */
@media (max-width: 768px) {
    body.menu-open .menu-trigger {
        display: none !important;
    }
}

/* Gestione locale squadre e rose */
.team-admin-page .team-new-button {
    text-decoration: none;
}

.team-admin-sidebar-heading {
    display: flex;
    justify-content: space-between;
    padding: 14px 15px;
    color: var(--navy);
    font-size: 0.86rem;
    font-weight: 800;
}

.team-admin-sidebar-heading span {
    color: var(--muted);
}

.team-import-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.team-import-summary span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 9px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-soft);
    font-size: 0.78rem;
}

.team-import-summary strong {
    color: var(--primary-dark);
}

.team-admin-list {
    max-height: min(68vh, 700px);
    border-top: 1px solid var(--border);
}

.team-admin-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 13px;
}

.team-admin-fields .athlete-admin-field:first-child,
.team-admin-fields .athlete-admin-field:nth-child(2),
.team-admin-fields .athlete-admin-field:last-child {
    grid-column: 1 / -1;
}

.team-photo-manager {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
}

.team-photo-manager h4 {
    margin: 0;
    color: var(--navy);
}

.team-photo-manager p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.team-photo-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
}

.team-photo-manager-card {
    display: grid;
    min-width: 0;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface-alt);
}

.team-photo-manager-card img {
    width: 100%;
    height: 92px;
    border-radius: 6px;
    object-fit: cover;
    background: #e8eef7;
}

.team-photo-cover,
.team-photo-remove {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-soft);
    font-size: 0.78rem;
    cursor: pointer;
}

.team-photo-cover input {
    accent-color: var(--primary);
}

.team-photo-filename {
    overflow: hidden;
    color: var(--muted);
    font-size: 0.72rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.team-photo-remove input {
    accent-color: #b42318;
}

.team-photo-upload {
    margin: 0;
}

.team-photo-upload-preview:empty {
    display: none;
}

.team-roster-picker {
    min-width: 0;
    margin: 0;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.team-roster-picker legend {
    padding: 0 6px;
    color: var(--navy);
    font-weight: 800;
}

.roster-search {
    width: 100%;
    margin: 0 0 9px;
}

.team-roster-list {
    display: grid;
    max-height: 310px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px 8px;
    overflow: auto;
}

.team-roster-item {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 7px;
    padding: 7px 8px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: var(--surface-alt);
    cursor: pointer;
}

.team-roster-item:hover {
    border-color: var(--blue-soft);
    background: #eef6ff;
}

.team-roster-item[hidden] {
    display: none;
}

.team-roster-item input {
    flex: 0 0 auto;
    accent-color: var(--primary);
}

.roster-player-name {
    min-width: 0;
    flex: 1;
    overflow: hidden;
    color: var(--navy);
    font-size: 0.82rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.team-roster-item small {
    color: var(--muted);
    font-size: 0.68rem;
}

.roster-no-results {
    margin: 0;
    padding: 10px;
    color: var(--muted);
    text-align: center;
}

.team-status-controls {
    align-items: center;
    justify-content: space-between;
}

.team-order-field {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.team-order-field input {
    width: 78px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 7px;
}

.team-delete-form {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.team-delete-button {
    padding: 8px 12px;
    border: 1px solid #e3b7b7;
    border-radius: 8px;
    background: #fff5f5;
    color: #a43232;
    cursor: pointer;
    font: inherit;
    font-size: 0.83rem;
    font-weight: 700;
}

.teams-page .team-card.team-public-card {
    position: relative;
    display: block;
    padding: 0;
    overflow: hidden;
}

.team-card-open {
    position: absolute;
    z-index: 2;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    border-radius: inherit;
    background: transparent;
    cursor: pointer;
}

.team-public-card:focus-within {
    outline: 3px solid var(--primary);
    outline-offset: 3px;
}

.team-open-hint {
    position: absolute;
    z-index: 3;
    top: 12px;
    right: 12px;
    visibility: hidden;
    opacity: 0;
    padding: 7px 10px;
    border: 1px solid rgba(255, 255, 255, 0.65);
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.78);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    pointer-events: none;
    transition: opacity 0.18s ease, visibility 0.18s ease;
}

@media (hover: hover) and (pointer: fine) {
    .team-public-card:hover .team-open-hint {
        visibility: visible;
        opacity: 1;
    }
}

.team-open-hint span {
    margin-left: 3px;
}

.team-photo {
    display: block;
    width: 100%;
    height: 190px;
    object-fit: cover;
    background: var(--surface-alt);
}

.teams-page .team-public-card>.team-card-icon {
    margin: 16px 18px 0;
}

.teams-page .team-public-card .team-card-content {
    padding: 18px;
}

.team-season {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.team-roster-public {
    margin-top: 15px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.team-roster-public>strong {
    color: var(--navy);
    font-size: 0.9rem;
}

.team-roster-public>strong span {
    color: var(--muted);
}

.team-roster-public ul {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 15px;
    margin: 9px 0 0;
    padding-left: 18px;
    color: var(--text-soft);
    font-size: 0.88rem;
}

.team-roster-player {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 2px;
}

.team-player-name {
    color: var(--text-soft);
}

.team-player-stats {
    color: var(--muted);
    font-size: 0.75rem;
    line-height: 1.35;
}

.team-roster-public p {
    margin: 7px 0 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.team-details-dialog {
    position: fixed;
    width: min(760px, calc(100vw - 28px));
    max-width: none;
    max-height: min(92dvh, 900px);
    padding: 0;
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.55);
    border-radius: 20px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.38);
}

.team-details-dialog[open] {
    animation: team-dialog-in 220ms ease-out both;
}

.team-details-dialog::backdrop {
    background: rgba(15, 23, 42, 0.72);
    backdrop-filter: blur(4px);
}

.team-dialog-panel {
    position: relative;
    max-height: min(92dvh, 900px);
    overflow-y: auto;
}

.team-dialog-close {
    position: absolute;
    z-index: 1;
    top: 12px;
    right: 12px;
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.75);
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.76);
    color: #fff;
    font-size: 1.7rem;
    line-height: 1;
    cursor: pointer;
}

.team-dialog-photo,
.team-dialog-photo-placeholder {
    display: grid;
    width: 100%;
    height: min(48vh, 400px);
    place-items: center;
    object-fit: contain;
    background: #0f172a;
    color: #fff;
    font-size: 4rem;
}

.team-dialog-gallery {
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    overflow-x: auto;
    background: #0f172a;
}

.team-dialog-thumbnail {
    flex: 0 0 82px;
    width: 82px;
    height: 62px;
    padding: 3px;
    overflow: hidden;
    border: 2px solid transparent;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
}

.team-dialog-thumbnail[aria-pressed="true"] {
    border-color: #7ecbff;
}

.team-dialog-thumbnail img {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 4px;
    object-fit: cover;
}

.team-dialog-details {
    padding: 24px clamp(18px, 5vw, 36px) 30px;
}

.team-dialog-details .teams-eyebrow {
    margin: 0 0 8px;
}

.team-dialog-details h2 {
    margin: 0;
    color: var(--navy);
    font-size: clamp(1.5rem, 5vw, 2rem);
    overflow-wrap: anywhere;
}

.team-dialog-league {
    margin: 10px 0 0;
    color: var(--primary-dark);
    font-size: 1.08rem;
    font-weight: 800;
}

.team-dialog-season,
.team-dialog-scope {
    margin: 6px 0 0;
    color: var(--muted);
}

.team-dialog-roster {
    margin-top: 20px;
    padding-top: 17px;
    border-top: 1px solid var(--border);
}

.team-dialog-roster h3 {
    margin: 0;
    color: var(--navy);
}

.team-dialog-roster ul {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    gap: 8px 20px;
    margin: 12px 0 0;
    padding-left: 22px;
    color: var(--text-soft);
}

.team-dialog-roster .team-roster-player {
    gap: 4px;
    padding: 2px 0;
}

.team-dialog-roster .team-player-stats {
    font-size: 0.8rem;
}

.team-dialog-roster p {
    margin: 8px 0 0;
    color: var(--muted);
}

.team-dialog-fitet {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.team-dialog-fitet h3 {
    margin: 0 0 12px;
    color: var(--navy);
}

.team-dialog-fitet-tabs {
    display: flex;
    gap: 8px;
    border-bottom: 1px solid var(--border);
}

.team-dialog-fitet-tab {
    padding: 9px 14px;
    border: 0;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: var(--text-soft);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.team-dialog-fitet-tab[aria-selected="true"] {
    border-bottom-color: var(--primary);
    color: var(--primary-dark);
}

.team-dialog-fitet-tab:focus-visible,
.team-dialog-fitet-open:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

.team-dialog-fitet-external {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    gap: 8px;
    margin: 14px 0;
    padding: 8px 14px;
    border: 1px solid var(--primary);
    border-radius: 9px;
    background: var(--surface);
    color: var(--primary-dark);
    font-size: 0.9rem;
    font-weight: 750;
    text-decoration: none;
    transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.team-dialog-fitet-external:hover {
    transform: translateY(-1px);
    background: var(--primary);
    color: #fff;
}

.team-dialog-fitet-external span:first-child {
    font-size: 1.05rem;
}

.team-dialog-fitet-content {
    min-height: 100px;
}

.team-dialog-fitet-status,
.team-dialog-fitet-error {
    margin: 12px 0;
    padding: 13px 15px;
    border-radius: 9px;
    background: var(--surface-alt);
    color: var(--text-soft);
}

.team-dialog-fitet-error {
    border: 1px solid #f0caca;
    background: #fff6f5;
    color: #8c2929;
}

.team-dialog-fitet-retry {
    min-height: 38px;
    padding: 7px 13px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--primary-dark);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.team-dialog-standings-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}

.team-dialog-standings {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    box-shadow: none;
    color: var(--text);
    font-size: 0.82rem;
    text-align: center;
}

.team-dialog-standings thead {
    background: var(--surface-alt);
    color: var(--muted);
}

.team-dialog-standings th,
.team-dialog-standings td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.team-dialog-standings thead th {
    background: var(--surface-alt);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 750;
    letter-spacing: 0.025em;
    text-shadow: none;
}

.team-dialog-standings tbody tr:last-child th,
.team-dialog-standings tbody tr:last-child td {
    border-bottom: 0;
}

.team-dialog-standings tbody tr:nth-child(even) {
    background: color-mix(in srgb, var(--surface-alt) 58%, transparent);
}

.team-dialog-standings .team-dialog-col-team,
.team-dialog-standings .team-dialog-team-name {
    text-align: left;
}

.team-dialog-standings .team-dialog-team-name {
    min-width: 185px;
    background: transparent;
    color: var(--navy);
    font-weight: 650;
    text-shadow: none;
    white-space: normal;
}

.team-dialog-standings .team-dialog-rank {
    width: 42px;
    color: var(--muted);
    font-weight: 700;
}

.team-dialog-standings .team-dialog-points {
    color: var(--primary-dark);
    font-size: 0.95rem;
    font-weight: 800;
}

.team-dialog-standings .team-dialog-record {
    color: var(--text-soft);
    font-variant-numeric: tabular-nums;
    font-weight: 650;
}

.team-dialog-standings .is-local-team {
    background: rgba(37, 99, 235, 0.09);
}

.team-dialog-standings tbody tr.is-local-team > * {
    background: rgba(37, 99, 235, 0.09);
}

.team-dialog-standings .is-local-team .team-dialog-team-name {
    color: var(--primary-dark);
}

.team-dialog-calendar {
    display: grid;
    gap: 10px;
}

.team-dialog-round {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface);
}

.team-dialog-round summary {
    display: flex;
    min-height: 46px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    background: var(--surface-alt);
    color: var(--navy);
    cursor: pointer;
    font-weight: 750;
    list-style-position: inside;
}

.team-dialog-round-count {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 550;
}

.team-dialog-matches {
    display: grid;
    gap: 9px;
    padding: 10px;
}

.team-dialog-match {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
}

.team-dialog-match.has-local-team {
    border-color: rgba(29, 78, 216, 0.48);
    box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.08);
}

.team-dialog-leg {
    padding: 10px 12px;
}

.team-dialog-return-leg {
    border-top: 1px dashed var(--border);
    background: color-mix(in srgb, var(--surface-alt) 54%, transparent);
}

.team-dialog-leg-date {
    margin: 0 0 7px;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 650;
    letter-spacing: 0.025em;
}

.team-dialog-leg:first-child .team-dialog-leg-date {
    color: var(--primary-dark);
}

.team-dialog-return-leg .team-dialog-leg-date {
    color: var(--muted);
}

.team-dialog-fixture {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
}

.team-dialog-fixture-team {
    color: var(--text-soft);
    font-size: 0.82rem;
    overflow-wrap: anywhere;
}

.team-dialog-fixture-team:last-child {
    text-align: right;
}

.team-dialog-fixture-team.is-local-team {
    color: var(--primary-dark);
    font-weight: 800;
}

.team-dialog-fixture-score {
    min-width: 46px;
    padding: 4px 7px;
    border-radius: 7px;
    background: var(--surface-alt);
    color: var(--navy);
    font-size: 0.88rem;
    text-align: center;
}

.team-dialog-fixture-button {
    width: 100%;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.team-dialog-fixture-button:hover .team-dialog-fixture-score,
.team-dialog-fixture-button:focus-visible .team-dialog-fixture-score {
    background: var(--primary);
    color: #fff;
}

.team-dialog-fixture-button:focus-visible {
    border-radius: 7px;
    outline: 3px solid var(--primary);
    outline-offset: 4px;
}

.team-match-details-dialog {
    width: min(880px, calc(100vw - 28px));
}

.team-match-dialog-content {
    padding: 26px;
}

.team-match-dialog-content .teams-eyebrow {
    margin: 0 42px 8px 0;
}

.team-match-dialog-title {
    margin: 0;
    color: var(--navy);
    font-size: clamp(1.2rem, 3vw, 1.65rem);
    line-height: 1.25;
}

.team-match-dialog-meta {
    margin: 7px 0 20px;
    color: var(--muted);
    font-size: 0.9rem;
}

.team-match-game-list {
    display: grid;
    gap: 10px;
}

.team-match-game {
    padding: 13px 15px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}

.team-match-game-heading,
.team-match-game-players {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
}

.team-match-game-heading {
    grid-template-columns: 1fr auto;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.team-match-game-number {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.team-match-game-result {
    min-width: 42px;
    padding: 3px 7px;
    border-radius: 7px;
    background: var(--surface-alt);
    color: var(--navy);
    text-align: center;
}

.team-match-game-players {
    padding-top: 9px;
    color: var(--text-soft);
    font-size: 0.9rem;
}

.team-match-game-players span:last-child {
    grid-column: 3;
    text-align: right;
}

.team-match-game-players .is-game-winner {
    color: var(--primary-dark);
    font-weight: 800;
}

.team-match-game-sets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.team-match-set {
    padding: 4px 7px;
    border-radius: 6px;
    background: var(--surface-alt);
    color: var(--text-soft);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

.team-match-dialog-empty {
    padding: 14px;
    border-radius: 10px;
    background: var(--surface-alt);
    color: var(--muted);
}

.team-match-official-link {
    margin-top: 16px;
}

.team-dialog-postponed {
    display: block;
    padding: 7px 12px 0;
    color: #986018;
    font-size: 0.75rem;
    font-weight: 700;
}

.team-dialog-fitet-external:focus-visible,
.team-dialog-fitet-retry:focus-visible,
.team-dialog-round summary:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

@media (max-width: 680px) {
    .team-dialog-standings .team-dialog-col-detail,
    .team-dialog-standings .team-dialog-detail-stat {
        display: none;
    }

    .team-dialog-standings .team-dialog-team-name {
        min-width: 150px;
    }

    .team-dialog-standings .team-dialog-col-record,
    .team-dialog-standings .team-dialog-record {
        display: none;
    }
}

@keyframes team-dialog-in {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .team-details-dialog[open] {
        animation: none;
    }
}

.team-heading-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 9px;
}

.team-heading-actions form {
    margin: 0;
}

.team-import-button {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--primary-dark);
    box-shadow: none;
}

.team-import-button:hover {
    background: var(--surface-alt);
}

.imported-roster-panel {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-alt);
}

.imported-roster-panel summary {
    padding: 11px 13px;
    color: var(--navy);
    cursor: pointer;
    font-weight: 700;
}

.imported-roster-panel summary span {
    color: var(--muted);
    font-weight: 500;
}

.imported-roster-panel ul {
    display: grid;
    max-height: 240px;
    gap: 5px;
    overflow: auto;
    margin: 0;
    padding: 0 13px 10px;
    list-style: none;
}

.imported-roster-panel li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px 10px;
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface);
    color: var(--navy);
    font-size: 0.83rem;
}

.imported-roster-panel li small {
    color: var(--muted);
}

.imported-roster-status {
    margin-left: auto;
    color: #986018;
    font-size: 0.72rem;
}

.imported-roster-status.is-linked {
    color: #176b3b;
}

.imported-roster-panel>p {
    margin: 0;
    padding: 0 13px 12px;
    color: var(--muted);
    font-size: 0.78rem;
}

@media (max-width: 800px) {
    .team-roster-list {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .team-heading-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .team-heading-actions .admin-save-button {
        width: 100%;
        text-align: center;
    }

    .team-admin-fields {
        grid-template-columns: 1fr;
    }

    .team-admin-fields .athlete-admin-field {
        grid-column: auto !important;
    }

    .team-roster-public ul {
        grid-template-columns: 1fr;
    }
}

.side-menu {
    height: 100%;
    width: 280px;
    position: fixed;
    z-index: 11000;
    top: 0;
    left: -280px;
    background-color: var(--navy);
    transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.3);
    color: white;
    display: flex;
    flex-direction: column;
}

.side-menu.open {
    left: 0 !important;
}

.sidebar-header {
    display: flex;
    padding: 20px;
    align-items: center;
    gap: 12px;
    background: linear-gradient(180deg, rgba(11, 18, 32, 1), rgba(17, 24, 39, 0.95));
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-logo {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    border: 2px solid rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    object-fit: cover;
}

.sidebar-header h3 {
    min-width: 0;
    margin: 0;
    font-size: 1rem;
}

.mobile-impersonation-slot {
    display: none;
}

.mobile-impersonation-slot.has-impersonation-switcher {
    display: block;
    padding: 12px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.mobile-impersonation-slot .impersonation-switcher {
    margin: 0;
}

.mobile-impersonation-slot .impersonation-switcher summary {
    width: fit-content;
    color: #fff;
}

.mobile-impersonation-slot .impersonation-switcher form {
    position: static;
    width: auto;
    margin-top: 10px;
}

.sidebar-header .closebtn {
    display: flex;
    flex: 0 0 auto;
    margin-left: auto;
    align-items: center;
}

.sidebar-nav a {
    padding: 15px 20px;
    text-decoration: none;
    font-size: 16px;
    color: #dfe7f7;
    display: block;
    transition: 0.3s;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
    background: linear-gradient(90deg, rgba(60, 169, 255, 0.18), rgba(29, 78, 216, 0.08));
    color: white;
    padding-left: 30px;
    border-left-color: var(--success);
}

.menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10999;
    backdrop-filter: blur(2px);
}

.menu-overlay.show {
    display: block;
}

/* ==========================================================================
   5. TABELLA E CONTENUTI PRINCIPALI
   ========================================================================== */
.container {
    max-width: 1150px;
    margin: 2rem auto;
    padding: 0 15px;
}

.responsive-table-wrap {
    max-width: 100%;
}

.responsive-table-wrap:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

table {
    border-collapse: collapse;
    width: 100%;
    background: var(--surface);
    box-shadow: 0 2px 6px rgba(0, 0, 0, .1);
}

th,
td {
    padding: .8rem 1rem;
    border: 1px solid var(--border);
    text-align: left;
}

th {
    background: linear-gradient(180deg, var(--blue) 0%, var(--navy) 100%);
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

th.sortable {
    cursor: pointer;
    position: relative;
    user-select: none;
}

#tabellaAtleti .ranking-current-header small {
    display: block;
    margin-top: 2px;
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
}

tr:nth-child(even) td {
    background: var(--surface-alt);
}

.atleta-row {
    cursor: pointer;
    transition: background 0.2s;
}

.atleta-row:hover {
    background: #eef5ff !important;
}

.badge {
    background: #e1e8ed;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
}

.col-numero {
    width: 40px;
    background: #eee;
    font-weight: bold;
    text-align: center;
}

.athlete-photo-header,
.athlete-photo-cell {
    width: 48px;
    padding: .35rem;
    text-align: center;
}

.athlete-list-avatar {
    display: inline-flex;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 50%;
    background: #e2e5e9;
    color: #263442;
    vertical-align: middle;
}

.athlete-list-avatar img,
.athlete-list-placeholder {
    display: block;
    width: 100%;
    height: 100%;
}

.athlete-list-avatar [hidden] {
    display: none;
}

.athlete-list-avatar img {
    object-fit: cover;
}

.athlete-list-placeholder {
    width: 27px;
    height: 27px;
}

.top-ranking-cell {
    min-width: 76px;
    white-space: nowrap;
}

.top-ranking-cell strong,
.top-ranking-cell small {
    display: block;
}

.top-ranking-cell small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.72rem;
}

/* FIX 3: TABS SCROLLABILI CORAZZATE */
.tabs {
    display: flex;
    flex-wrap: wrap;
    /* Permette di andare a capo SOLO se lo spazio finisce */
    gap: 8px;
    margin-bottom: -1px;
    padding: 10px 0;
    width: 100%;
}

.athlete-mobile-sort {
    display: none;
}

.tab-btn {
    flex: 0 1 auto;
    padding: 12px 20px;
    border: 1px solid var(--border);
    border-bottom: none;
    background: linear-gradient(180deg, #f6f9ff, #eaf2ff);
    cursor: pointer;
    font-weight: bold;
    border-radius: 10px 10px 0 0;
    transition: 0.3s;
    text-align: center;
    font-size: 0.9rem;
    white-space: nowrap;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.tab-btn.active {
    background: linear-gradient(180deg, #ffffff, #eef7ff);
    border-top: 4px solid var(--blue);
    color: var(--navy);
    position: relative;
    z-index: 2;
    box-shadow: 0 -4px 14px rgba(29, 78, 216, 0.08);
}

/* ==========================================================================
   6. MODALE E LOADER
   ========================================================================= */
/* ... (Rimasti invariati dal tuo codice) ... */
#loader {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    z-index: 12000;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 12001;
    align-items: center;
    justify-content: center;
    padding: 10px;
    animation: modal-overlay-appear var(--modal-overlay-duration) ease-out both;
}

.modal-content {
    background: transparent;
    width: 100%;
    max-width: 600px;
    max-height: 85vh;
    border-radius: 0;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: visible;
    box-shadow: none;
    transform-origin: center center;
    animation: var(--modal-dialog-animation) var(--modal-dialog-duration) var(--modal-dialog-easing) both;
}

.modal-overlay.is-closing {
    animation: modal-overlay-fade-out var(--modal-close-duration) ease-in both;
    pointer-events: none;
}

.modal-overlay.is-closing .modal-content {
    animation: modal-dialog-fade-out var(--modal-close-duration) ease-in both;
}

@keyframes modal-overlay-appear {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes modal-pirouette-in {
    0% {
        opacity: 0;
        filter: blur(var(--modal-dialog-start-blur));
        transform: scale(var(--modal-dialog-start-scale)) rotate(var(--modal-dialog-start-rotation));
    }

    70% {
        opacity: 1;
        filter: blur(0);
        transform: scale(var(--modal-dialog-overshoot-scale)) rotate(var(--modal-dialog-mid-rotation));
    }

    100% {
        opacity: 1;
        filter: blur(0);
        transform: scale(1) rotate(0);
    }
}

/* Preset alternativo: zoom con piccolo rimbalzo, senza rotazione.
   Per usarlo imposta --modal-dialog-animation: modal-zoom-in in :root. */
@keyframes modal-zoom-in {
    0% {
        opacity: 0;
        filter: blur(var(--modal-dialog-start-blur));
        transform: scale(var(--modal-dialog-start-scale));
    }

    75% {
        opacity: 1;
        filter: blur(0);
        transform: scale(var(--modal-dialog-overshoot-scale));
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Preset alternativo: entrata dal basso, senza rotazione.
   Per usarlo imposta --modal-dialog-animation: modal-slide-up-in in :root. */
@keyframes modal-slide-up-in {
    0% {
        opacity: 0;
        filter: blur(var(--modal-dialog-start-blur));
        transform: translateY(35px) scale(0.92);
    }

    100% {
        opacity: 1;
        filter: blur(0);
        transform: translateY(0) scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {

    .modal-overlay,
    .modal-content {
        animation: none;
    }
}

#modalBody {
    padding: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    flex-grow: 1;
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 30px;
    cursor: pointer;
    z-index: 10;
}

.scheda-container .athlete-card-close {
    position: absolute;
    top: 10px;
    right: 10px;
    display: grid;
    width: 32px;
    height: 32px;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    background: linear-gradient(145deg, #f7fafc, #aab6c1);
    color: #172536;
    font-size: 23px;
    line-height: 1;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35), inset 0 1px 0 #fff;
}

.scheda-container .athlete-card-close:hover {
    background: linear-gradient(145deg, #fff, #c9d4dd);
    transform: scale(1.06);
}

/* Scheda atleta effetto tessera in acciaio spazzolato */
.scheda-container {
    position: relative;
    box-sizing: border-box;
    overflow: hidden;
    padding: 18px;
    border: 1px solid var(--metal-edge);
    border-radius: 16px;
    background:
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.22) 0 1px, rgba(52, 65, 77, 0.035) 1px 2px),
        linear-gradient(135deg, #f3f5f6 0%, var(--metal-mid) 24%, var(--metal-light) 44%, #aeb8c1 69%, #e3e8ec 100%);
    color: var(--navy);
    box-shadow:
        0 12px 28px rgba(11, 18, 32, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.95),
        inset 0 -1px 0 rgba(65, 77, 89, 0.35);
}

.scheda-container::before {
    position: absolute;
    inset: 5px;
    z-index: 0;
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 11px;
    content: "";
    pointer-events: none;
}

.scheda-container>*:not(.athlete-card-close) {
    position: relative;
    z-index: 1;
}

.scheda-container .scheda-top {
    padding: 17px;
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 11px;
    background:
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.035) 0 1px, rgba(0, 0, 0, 0.035) 1px 2px),
        linear-gradient(135deg, #172332, #34485a 48%, #172536);
    color: #f6f9fc;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.24), 0 5px 12px rgba(16, 28, 40, 0.2);
}

.scheda-container .foto-box {
    flex: 0 0 auto;
    border-color: rgba(224, 237, 248, 0.8) !important;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3), 0 0 0 3px rgba(255, 255, 255, 0.08);
}

.scheda-container .info-box {
    color: #edf4fa;
}

.scheda-container .atleta-nome {
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
}

.scheda-container .atleta-nome small {
    color: #c6d2de !important;
}

.scheda-container .info-box p {
    margin: 8px 0;
    color: #dce6ef;
}

.scheda-container .info-box strong {
    color: #fff;
}

.scheda-container .info-box .badge {
    color: #111827;
}

.athlete-profile-edit-trigger,
.athlete-profile-save,
.athlete-profile-cancel {
    min-height: 38px;
    padding: 8px 12px;
    border: 1px solid var(--blue);
    border-radius: 8px;
    background: var(--blue);
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.athlete-profile-edit-trigger {
    margin-top: 8px;
}

.athlete-profile-editor[hidden],
.athlete-profile-edit-trigger[hidden] {
    display: none;
}

.athlete-profile-editor {
    display: grid;
    gap: 12px;
    margin-top: 14px;
    padding: 16px;
    border: 1px solid rgba(108, 123, 137, 0.65);
    border-radius: 11px;
    background: linear-gradient(145deg, #f3f5f6, #d7dfe5);
}

.athlete-profile-editor h3 {
    margin: 0;
    color: #1b2a38;
}

.athlete-profile-field {
    display: grid;
    gap: 5px;
    color: #1b2a38;
    font-weight: 700;
}

.athlete-profile-field input,
.athlete-profile-field textarea {
    box-sizing: border-box;
    width: 100%;
    min-height: 40px;
    padding: 9px 10px;
    border: 1px solid #9aa9b5;
    border-radius: 7px;
    background: #fff;
    color: #17212b;
    font: inherit;
    font-weight: 400;
}

.athlete-profile-field textarea {
    min-height: 110px;
    resize: vertical;
}

.athlete-profile-field input[type="file"] {
    padding: 6px;
}

.athlete-profile-status {
    min-height: 1.3em;
    margin: 0;
    color: #17653c;
}

.athlete-profile-status.is-error {
    color: #a32222;
}

.athlete-profile-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
}

.athlete-profile-save:disabled {
    cursor: wait;
    opacity: 0.65;
}

.athlete-profile-cancel {
    border-color: #788896;
    background: #fff;
    color: #263442;
}

.scheda-container .athlete-extra-card {
    border-color: rgba(108, 123, 137, 0.65);
    background:
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.18) 0 1px, rgba(57, 68, 79, 0.025) 1px 2px),
        linear-gradient(145deg, #f3f5f6, #c8d0d7 54%, #e5e9ec);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.95), 0 4px 10px rgba(40, 51, 62, 0.12);
}

.scheda-container .athlete-extra-card h3,
.scheda-container .athlete-stat-name,
.scheda-container .athlete-material-list dt {
    color: #1b2a38;
}

.scheda-container .scheda-bottom {
    padding: 16px 18px;
    border: 1px solid rgba(108, 123, 137, 0.55);
    border-radius: 11px;
    background:
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.16) 0 1px, rgba(57, 68, 79, 0.02) 1px 2px),
        linear-gradient(145deg, #e8ecef, #c4cdd5);
    color: #283542;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.scheda-container .scheda-bottom h3 {
    color: #1b2a38;
}

.scheda-container .scheda-bottom .descrizione-testo {
    color: #354352 !important;
    line-height: 1.6;
}

.scheda-container .scheda-bottom .descrizione-testo.is-memorial {
    color: #4c5863 !important;
    font-style: italic;
}

.athlete-extras {
    display: grid;
    grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.05fr);
    align-items: stretch;
    gap: 12px;
    margin: 14px 0;
}

.athlete-extra-card {
    min-width: 0;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: linear-gradient(180deg, var(--surface), var(--surface-alt));
    box-shadow: 0 5px 16px rgba(17, 24, 39, 0.07);
}

.athlete-extra-card h3 {
    margin: 0 0 8px;
    color: var(--navy);
    font-size: 1rem;
}

.athlete-stat-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.athlete-stat-row:last-child {
    border-bottom: 0;
}

.athlete-stat-name {
    color: var(--navy);
    font-weight: 700;
}

.athlete-rating {
    display: inline-flex;
    min-width: 0;
    flex: 1;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
}

.athlete-rating-bar {
    position: relative;
    display: block;
    min-width: 45px;
    height: 10px;
    flex: 1;
    overflow: hidden;
    border: 1px solid rgba(31, 41, 55, 0.22);
    border-radius: 999px;
    background: #d8dfe5;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.12);
}

.athlete-rating-bar-fill {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--rating-red) 0%, var(--rating-yellow) 50%, var(--rating-green) 100%);
    clip-path: inset(0 calc(100% - var(--rating-percent)) 0 0);
    transition: clip-path 180ms ease-out;
}

.athlete-rating-bar.is-unrated {
    background: repeating-linear-gradient(135deg, #e1e6ea 0 5px, #f3f5f7 5px 10px);
}

.athlete-rating-bar-average {
    height: 12px;
}

.athlete-rating-value {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
}

.athlete-rating-value.is-unset {
    font-style: italic;
    font-weight: 500;
}

.scheda-container .athlete-stat-row {
    display: grid;
    grid-template-columns: 78px minmax(0, 1fr);
    align-items: center;
    gap: 6px;
    padding: 5px 0;
    border-color: rgba(68, 82, 96, 0.24);
}

.scheda-container .athlete-rating {
    display: flex;
    min-width: 0;
    justify-content: space-between;
    gap: 5px;
    white-space: normal;
}

.scheda-container .athlete-rating-bar {
    display: flex;
    min-width: 25px;
}

.athlete-overall-rating {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 2px solid rgba(48, 72, 58, 0.2);
}

.athlete-overall-label {
    grid-column: 1 / -1;
    color: #1b2a38;
    font-size: 0.88rem;
    font-weight: 800;
}

.list-average-rating {
    display: inline-flex;
    align-items: center;
}

.list-average-rating {
    justify-content: center;
    gap: 5px;
    white-space: nowrap;
}

.list-average-bar {
    min-width: 42px;
    max-width: 88px;
    height: 8px;
}

.list-average-value {
    color: var(--text-soft);
    font-size: 0.72rem;
    font-weight: 800;
}

.list-average-unrated {
    color: var(--muted);
}

.sync-choice-open {
    overflow: hidden;
}

.sync-choice-overlay[hidden] {
    display: none;
}

.sync-choice-overlay {
    position: fixed;
    inset: 0;
    z-index: 13000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 23, 42, 0.72);
}

.sync-choice-card {
    width: min(100%, 480px);
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.3);
}

.sync-choice-card h2 {
    margin: 0 0 10px;
    color: var(--navy);
}

.sync-choice-card p {
    margin: 0 0 20px;
    color: var(--muted);
    line-height: 1.5;
}

.sync-choice-actions {
    display: grid;
    gap: 10px;
}

.sync-choice-button,
.sync-choice-cancel {
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-alt);
    color: var(--text);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.sync-choice-button:hover,
.sync-choice-cancel:hover {
    filter: brightness(0.96);
}

.sync-choice-primary {
    border-color: var(--blue);
    background: var(--blue);
    color: #fff;
}

.sync-choice-cancel {
    border: 0;
    background: transparent;
}

#tabellaAtleti th.sortable {
    cursor: pointer;
}

@media (max-width: 768px) {
    #tabellaAtleti .average-rating-cell {
        min-width: 82px;
    }
}

.athlete-overall-value {
    color: var(--rating-green);
    font-size: 0.82rem;
    font-weight: 800;
    white-space: nowrap;
}

.athlete-overall-result {
    display: grid;
    justify-items: end;
    gap: 2px;
}

.athlete-overall-appellation {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.2;
    text-align: right;
}

.scheda-container .athlete-rating-value {
    font-size: 0.73rem;
    line-height: 1.2;
    white-space: nowrap;
}

@media (max-width: 520px) {
    .athlete-extras {
        grid-template-columns: 1fr;
    }
}

.athlete-material-list {
    display: grid;
    grid-template-columns: minmax(65px, auto) 1fr;
    gap: 9px 12px;
    margin: 0;
}

.athlete-material-list dt {
    color: var(--navy);
    font-weight: 700;
}

.athlete-material-list dd {
    min-width: 0;
    margin: 0;
    color: var(--text-soft);
    overflow-wrap: anywhere;
}

.athlete-admin-group {
    min-width: 0;
    margin: 0;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.athlete-admin-group legend {
    padding: 0 6px;
    color: var(--navy);
    font-weight: 700;
}

.athlete-rating-fields,
.athlete-material-fields {
    display: grid;
    gap: 12px;
}

.athlete-rating-fields {
    grid-template-columns: repeat(auto-fit, minmax(125px, 1fr));
}

.athlete-material-fields {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.athlete-admin-field {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 6px;
    color: var(--text-soft);
    font-weight: 600;
}

.athlete-admin-field input,
.athlete-admin-field select,
.athlete-admin-field textarea {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.athlete-admin-page {
    width: min(1240px, calc(100% - 32px));
    margin: 12px auto 40px;
}

.athlete-admin-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.athlete-admin-heading h2 {
    margin: 2px 0 5px;
    color: var(--navy);
    font-size: clamp(1.5rem, 3vw, 2rem);
}

.admin-eyebrow {
    margin: 0;
    color: var(--primary);
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.admin-subtitle {
    margin: 0;
    color: var(--muted);
}

.admin-count {
    flex: 0 0 auto;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--navy);
    font-size: 0.85rem;
    font-weight: 700;
}

.rating-descriptors-panel {
    padding: clamp(14px, 2vw, 22px);
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(17, 24, 39, 0.08);
}

.rating-descriptors-help p {
    margin: 0 0 16px;
    color: var(--muted);
    line-height: 1.5;
}

.rating-descriptors-table-wrap {
    overflow-x: auto;
}

.rating-descriptors-table {
    width: 100%;
    border-collapse: collapse;
}

.rating-descriptors-table th,
.rating-descriptors-table td {
    padding: 8px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.rating-descriptors-table th {
    color: var(--navy);
    font-size: 0.82rem;
}

.rating-descriptor-row input,
.rating-descriptor-row textarea {
    width: 100%;
    min-width: 84px;
    box-sizing: border-box;
    padding: 8px 9px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    font: inherit;
}

.rating-descriptor-row textarea {
    min-width: 260px;
    resize: vertical;
}

.rating-descriptor-row [data-field="appellation"] {
    min-width: 170px;
}

.rating-descriptor-remove,
.admin-secondary-button {
    padding: 8px 11px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface-alt);
    color: var(--navy);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.rating-descriptor-remove:hover,
.admin-secondary-button:hover {
    background: #e8eef7;
}

.rating-descriptor-remove {
    color: #a12d2d;
}

.rating-descriptor-actions {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 16px;
}

.rating-descriptor-actions button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.admin-notice {
    margin-bottom: 16px;
    padding: 11px 14px;
    border: 1px solid transparent;
    border-radius: 9px;
    font-weight: 600;
}

.admin-notice.success {
    border-color: #a7e3c1;
    background: #ecfbf2;
    color: #176b3b;
}

.admin-notice.error,
.admin-photo-warning {
    border-color: #f2d18a;
    background: #fff8e7;
    color: #805d13;
}

.admin-photo-warning {
    margin: 0 0 14px;
    padding: 9px 12px;
    border: 1px solid;
    border-radius: 8px;
    font-size: 0.85rem;
}

.athlete-admin-layout {
    display: grid;
    grid-template-columns: minmax(230px, 290px) minmax(0, 1fr);
    align-items: start;
    gap: 18px;
}

.athlete-admin-sidebar,
.athlete-admin-editor {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(17, 24, 39, 0.08);
}

.athlete-admin-sidebar {
    position: sticky;
    top: 88px;
    overflow: hidden;
}

.admin-search-label {
    display: block;
    padding: 15px 15px 7px;
    color: var(--navy);
    font-size: 0.82rem;
    font-weight: 700;
}

.admin-search {
    width: calc(100% - 30px);
    margin: 0 15px 12px;
    box-sizing: border-box;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    outline: none;
    font: inherit;
}

.admin-search:focus,
.athlete-admin-field input:focus,
.athlete-admin-field select:focus,
.athlete-admin-field textarea:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(60, 169, 255, 0.15);
}

.athlete-admin-list {
    max-height: min(66vh, 680px);
    overflow-y: auto;
    border-top: 1px solid var(--border);
}

.athlete-admin-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 10px 13px;
    border-bottom: 1px solid var(--border);
    color: inherit;
    text-decoration: none;
    transition: background 0.15s ease;
}

.athlete-admin-list-item:last-of-type {
    border-bottom: 0;
}

.athlete-admin-list-item:hover,
.athlete-admin-list-item.is-selected {
    background: #eef6ff;
}

.athlete-admin-list-item.is-selected {
    box-shadow: inset 3px 0 var(--primary);
}

.athlete-admin-list-item[hidden] {
    display: none;
}

.admin-avatar {
    position: relative;
    display: grid;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    overflow: hidden;
    place-items: center;
    border-radius: 50%;
    background: linear-gradient(140deg, var(--primary), var(--blue));
    color: #fff;
    font-weight: 800;
}

.admin-avatar-photo,
.admin-avatar-placeholder {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.admin-avatar-photo {
    object-fit: cover;
}

.admin-avatar-placeholder {
    display: grid;
    place-items: center;
}

.admin-avatar-placeholder[hidden] {
    display: none;
}

.admin-athlete-summary {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
    gap: 2px;
}

.admin-athlete-summary strong,
.admin-athlete-summary small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-athlete-summary strong {
    color: var(--navy);
    font-size: 0.88rem;
}

.admin-athlete-summary small {
    color: var(--muted);
}

.admin-profile-status {
    width: 9px;
    height: 9px;
    flex: 0 0 9px;
    border-radius: 50%;
    background: #f0ad35;
    box-shadow: 0 0 0 3px rgba(240, 173, 53, 0.14);
}

.admin-profile-status.is-complete {
    background: #27a866;
    box-shadow: 0 0 0 3px rgba(39, 168, 102, 0.14);
}

.admin-no-results {
    margin: 0;
    padding: 18px 14px;
    color: var(--muted);
    font-size: 0.9rem;
    text-align: center;
}

.athlete-admin-editor {
    padding: clamp(16px, 3vw, 26px);
}

.athlete-editor-form {
    display: grid;
    gap: 17px;
}

.editor-profile-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.editor-athlete-photo {
    display: grid;
    width: 62px;
    height: 62px;
    flex: 0 0 62px;
    place-items: center;
    border: 2px solid var(--border);
    border-radius: 13px;
    background: var(--surface-alt);
    color: var(--primary);
    font-size: 1.35rem;
    font-weight: 800;
    object-fit: cover;
}

.editor-athlete-identity h3 {
    margin: 3px 0;
    color: var(--navy);
    font-size: 1.25rem;
}

.editor-athlete-identity p {
    margin: 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.athlete-admin-editor .athlete-admin-group {
    padding: 13px 15px 15px;
}

.admin-field-hint {
    margin: -3px 0 12px;
    color: var(--muted);
    font-size: 0.82rem;
}

.athlete-admin-editor .athlete-rating-fields {
    grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
}

.athlete-admin-editor .athlete-material-fields {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.athlete-admin-editor .athlete-admin-field input,
.athlete-admin-editor .athlete-admin-field select,
.athlete-admin-editor .athlete-admin-field textarea {
    padding: 10px 11px;
}

.athlete-admin-editor .athlete-admin-field textarea {
    resize: vertical;
}

.admin-advanced-fields {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-alt);
}

.admin-advanced-fields summary {
    padding: 12px 14px;
    color: var(--navy);
    cursor: pointer;
    font-weight: 700;
}

.admin-advanced-content {
    display: grid;
    gap: 14px;
    padding: 0 14px 14px;
}

.admin-status-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 20px;
    color: var(--text-soft);
    font-size: 0.9rem;
}

.admin-status-controls label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.admin-save-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.admin-save-bar>span {
    color: var(--muted);
    font-size: 0.8rem;
}

.admin-permissions-panel {
    display: grid;
    gap: 18px;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
}

.sqlite-editor-access {
    display: grid;
    min-height: 48vh;
    place-items: center;
    padding: 28px 18px;
}

.sqlite-editor-access section {
    width: min(100%, 640px);
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
    box-shadow: 0 12px 32px rgba(17, 24, 39, 0.08);
}

.sqlite-editor-access .admin-save-button {
    display: inline-block;
    margin-top: 8px;
    text-decoration: none;
}

.admin-permissions-levels {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    color: var(--text-soft);
    font-size: 0.88rem;
}

.admin-permissions-table-wrap {
    overflow-x: auto;
}

.admin-permissions-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.admin-permissions-table th,
.admin-permissions-table td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.admin-permissions-table thead th {
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
}

.admin-permissions-table tbody th {
    min-width: 180px;
    color: var(--navy);
}

.admin-permissions-table tbody th a {
    color: inherit;
    text-decoration: none;
}

.admin-permissions-table tbody th a:hover {
    text-decoration: underline;
}

.admin-permission-level select {
    min-width: 205px;
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

.admin-permission-level select:disabled {
    opacity: 0.75;
}

.admin-permissions-panel .admin-save-bar {
    flex-wrap: wrap;
}

@media (max-width: 1024px) {
    .responsive-table-wrap {
        overflow-x: auto;
        overscroll-behavior-x: contain;
        -webkit-overflow-scrolling: touch;
    }

    .responsive-table-wrap>table {
        min-width: max-content;
    }
}

@media (max-width: 640px) {
    .admin-permissions-panel {
        padding: 14px;
    }

    .admin-permissions-table th,
    .admin-permissions-table td {
        padding: 10px 8px;
    }
}

.athlete-admin-role-card {
    margin-top: 16px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: linear-gradient(180deg, var(--surface), var(--surface-alt));
}

.athlete-admin-role-card h3 {
    margin: 0 0 8px;
    color: var(--navy);
}

.athlete-admin-role-card p {
    margin: 8px 0;
    color: var(--text-soft);
}

.athlete-admin-role-status {
    font-weight: 700;
}

.athlete-admin-role-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.athlete-admin-role-form label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--navy);
    font-weight: 700;
}

.athlete-admin-role-hint {
    color: var(--muted) !important;
    font-size: 0.84rem;
}

.admin-save-button {
    flex: 0 0 auto;
    padding: 11px 18px;
    border: 0;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--primary), var(--blue));
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    box-shadow: 0 5px 14px rgba(29, 78, 216, 0.22);
}

.admin-save-button:hover {
    filter: brightness(1.06);
}

.admin-empty-state {
    display: grid;
    min-height: 330px;
    align-content: center;
    justify-items: center;
    padding: 24px;
    color: var(--muted);
    text-align: center;
}

.admin-empty-state>span {
    font-size: 2.5rem;
}

.admin-empty-state h3 {
    margin: 12px 0 4px;
    color: var(--navy);
}

.admin-empty-state p {
    max-width: 360px;
    margin: 0;
}

@media (max-width: 800px) {
    .athlete-admin-layout {
        grid-template-columns: 1fr;
    }

    .athlete-admin-sidebar {
        position: static;
    }

    .athlete-admin-list {
        display: flex;
        max-height: 170px;
        overflow-x: auto;
        overflow-y: hidden;
    }

    .athlete-admin-list-item {
        min-width: 210px;
        border-right: 1px solid var(--border);
        border-bottom: 0;
    }

    .athlete-admin-list-item.is-selected {
        box-shadow: inset 0 -3px var(--primary);
    }
}

@media (max-width: 560px) {
    .athlete-admin-page {
        width: calc(100% - 20px);
        margin-top: 8px;
    }

    .athlete-admin-heading {
        align-items: flex-start;
    }

    .admin-subtitle {
        max-width: 32ch;
        font-size: 0.9rem;
    }

    .admin-count {
        font-size: 0.75rem;
    }

    .athlete-admin-editor .athlete-material-fields {
        grid-template-columns: 1fr;
    }

    .admin-save-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .admin-save-button {
        width: 100%;
    }
}

/* ==========================================================================
   7. NOTIFICHE (TOAST)
   ========================================================================== */
#toast {
    visibility: hidden;
    min-width: 250px;
    background-color: var(--primary);
    color: #fff;
    text-align: center;
    border-radius: 8px;
    padding: 16px;
    position: fixed;
    z-index: 30000;
    left: 50%;
    bottom: 30px;
    transform: translateX(-50%);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    font-weight: bold;
}

#toast.show {
    visibility: visible;
    animation: fadein 0.5s, fadeout 0.5s 2.5s;
}

@keyframes fadein {
    from {
        bottom: 0;
        opacity: 0;
    }

    to {
        bottom: 30px;
        opacity: 1;
    }
}

@keyframes fadeout {
    from {
        bottom: 30px;
        opacity: 1;
    }

    to {
        bottom: 0;
        opacity: 0;
    }
}

/* --- TASTO MENU --- */

body.menu-open .menu-trigger {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

#toast-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    min-width: 280px;
    padding: 15px 25px;
    color: white;
    border-radius: 5px;
    font-weight: bold;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    transition: opacity 0.5s ease;
    animation: slideUp 0.5s ease-out;
}

/* Varianti di colore */
.toast.error {
    background-color: var(--primary);
    border-left: 5px solid var(--primary-dark);
}

.toast.success {
    background-color: var(--success-dark);
    border-left: 5px solid #1e8449;
}

.toast.info {
    background-color: var(--blue-soft);
    border-left: 5px solid #2980b9;
}

.toast-confirm {
    background-color: #2c3e50 !important;
    /* Colore scuro elegante */
    min-width: 300px;
    padding: 20px;
    border-left: 5px solid #3498db;
}

.toast-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 15px;
}

.btn-confirm,
.btn-cancel {
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.85rem;
}

.btn-confirm {
    background-color: #e74c3c;
    color: white;
}

.btn-cancel {
    background-color: #95a5a6;
    color: white;
}

.btn-confirm:hover {
    background-color: #c0392b;
}

.btn-cancel:hover {
    background-color: #7f8c8d;
}

verde {
    display: inline-block;
    /* Trasforma il colore originale dell'emoji in verde */
    filter: sepia(1) saturate(5) hue-rotate(90deg);
    margin-right: 5px;
    vertical-align: middle;
    font-style: normal;
}

nero {
    display: inline-block;
    /* Rende l'emoji completamente in scala di grigi e più scura */
    filter: grayscale(1) brightness(0.3);
    margin-right: 5px;
    vertical-align: middle;
    font-style: normal;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* ==========================================================================
   8. MEDIA QUERIES (MOBILE)
   ========================================================================== */
@media (max-width: 768px) {
    body {
        padding-top: 75px;
    }

    body.is-impersonating {
        padding-top: 125px;
    }

    .impersonation-banner {
        min-height: 50px;
        flex-wrap: wrap;
        gap: 6px 12px;
        padding: 6px 8px;
        font-size: 0.8rem;
    }

    .auth-area {
        max-width: 48%;
    }

    .user-logged {
        gap: 6px;
    }

    .user-name {
        font-size: 0.78rem;
    }

    .impersonation-switcher {
        margin-left: 6px;
    }

    .impersonation-switcher summary {
        display: flex;
        min-height: 42px;
        align-items: center;
        box-sizing: border-box;
        padding: 8px 12px;
        border-color: rgba(255, 255, 255, 0.8);
        background: #1688d4;
        font-size: 0.85rem;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    }

    .header-top {
        padding: 0 10px;
    }

    /* FIX 2: LOGIN MOBILE VISIBILE E POSIZIONATO */
    .mobile-login-toggle {
        display: block;
        background: #2ecc71;
        color: white;
        border: none;
        padding: 8px 12px;
        border-radius: 4px;
        font-size: 1.1rem;
    }

    .login-form {
        display: none;
        /* Default nascosto */
        position: absolute;
        top: 60px;
        /* Sotto l'header */
        right: 0;
        background: white;
        padding: 15px;
        border: 1px solid #ddd;
        box-shadow: 0 8px 15px rgba(0, 0, 0, 0.3);
        /* Ombra più marcata */
        flex-direction: column;
        gap: 10px;
        z-index: 200000 !important;
        /* Forza sopra tutto */
        border-radius: 8px;
        width: 220px;
    }

    .login-form.active {
        display: flex !important;
        /* Mostra al click */
    }

    .login-form input {
        width: 100% !important;
        box-sizing: border-box;
    }

    .container {
        margin: 0.5rem 0;
    }

    table {
        font-size: 0.7rem;
    }

    th,
    td {
        padding: 0.5rem 0.3rem;
    }

    /* 1. ELIMINA DEFINITIVAMENTE IL TASTO ROSSO SU MOBILE */
    .menu-trigger {
        display: none !important;
    }

    /* 2. EVITA LO SCHERMO BIANCO (IL BODY DEVE RESTARE VISIBILE) */
    body.menu-open {
        display: block !important;
        overflow: hidden !important;
        opacity: 1 !important;
        visibility: visible !important;
    }

    .tab-btn {
        flex: 1 1 auto;
        /* Su mobile si allargano per riempire la riga */
        padding: 10px 5px;
        font-size: 0.8rem;
        min-width: 100px;
        /* Evita che diventino troppo piccoli */
    }
}

@media (max-width: 640px) {
    .container {
        width: auto;
        padding-right: 10px;
        padding-left: 10px;
    }

    #searchAtleta {
        box-sizing: border-box;
        width: 100%;
        min-height: 44px;
        padding: 10px 12px;
        font: inherit;
    }

    .athlete-mobile-sort {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: flex-start;
        gap: 8px;
        margin: 2px 0 8px;
        color: var(--muted);
        font-size: 0.8rem;
        font-weight: 700;
    }

    .athlete-mobile-sort label {
        display: inline-flex;
        align-items: center;
        gap: 6px;
    }

    .athlete-mobile-sort select {
        min-height: 38px;
        padding: 6px 30px 6px 10px;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--surface);
        color: var(--navy);
        font: inherit;
    }

    .athlete-sort-direction {
        display: inline-flex;
        width: 40px;
        height: 38px;
        align-items: center;
        justify-content: center;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--surface);
        color: var(--navy);
        cursor: pointer;
        font-size: 1.25rem;
        font-weight: 800;
        line-height: 1;
        touch-action: manipulation;
    }

    .athlete-sort-direction[aria-pressed="true"] {
        border-color: var(--primary);
        background: var(--primary);
        color: #fff;
    }

    #tabellaAtleti {
        display: block;
        width: 100%;
        border-collapse: separate;
        background: transparent;
        box-shadow: none;
    }

    #tabellaAtleti thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        clip-path: inset(50%);
    }

    #tabellaAtleti tbody {
        display: grid;
        gap: 10px;
    }

    #tabellaAtleti .atleta-row {
        display: grid;
        grid-template-columns: 52px repeat(3, minmax(0, 1fr));
        grid-template-areas:
            "photo name name name"
            "photo tessera tessera tessera"
            ". ranking points category"
            ". top average average";
        align-items: center;
        overflow: hidden;
        border: 1px solid var(--border);
        border-radius: 12px;
        background: var(--surface);
        box-shadow: 0 3px 12px rgba(17, 24, 39, 0.08);
    }

    #tabellaAtleti .atleta-row td {
        min-width: 0;
        padding: 9px 10px;
        border: 0;
        background: transparent;
        overflow-wrap: anywhere;
    }

    #tabellaAtleti .atleta-row td:nth-child(1) {
        display: none;
    }

    #tabellaAtleti .athlete-photo-cell {
        grid-area: photo;
        width: auto;
        padding: 10px 0 10px 10px;
    }

    #tabellaAtleti .athlete-list-avatar {
        width: 44px;
        height: 44px;
    }

    #tabellaAtleti .atleta-row td:nth-child(3) {
        grid-area: name;
        padding-bottom: 2px;
        font-size: 0.96rem;
    }

    #tabellaAtleti .atleta-row td:nth-child(4) {
        grid-area: tessera;
        padding-top: 0;
        color: var(--muted);
        font-size: 0.78rem;
    }

    #tabellaAtleti .atleta-row td:nth-child(4)::before {
        content: "Tessera ";
        font-weight: 700;
    }

    #tabellaAtleti .atleta-row td:nth-child(5) {
        grid-area: ranking;
    }

    #tabellaAtleti .atleta-row td:nth-child(6) {
        grid-area: points;
    }

    #tabellaAtleti .atleta-row td:nth-child(7) {
        grid-area: category;
    }

    #tabellaAtleti .atleta-row td:nth-child(8) {
        grid-area: top;
    }

    #tabellaAtleti .atleta-row td:nth-child(9) {
        grid-area: average;
        min-width: 0;
    }

    #tabellaAtleti .atleta-row td:nth-child(5)::before {
        content: "Ranking";
    }

    #tabellaAtleti .atleta-row td:nth-child(6)::before {
        content: "Punti";
    }

    #tabellaAtleti .atleta-row td:nth-child(7)::before {
        content: "Categoria";
    }

    #tabellaAtleti .atleta-row td:nth-child(8)::before {
        content: "Top ranking";
    }

    #tabellaAtleti .atleta-row td:nth-child(9)::before {
        content: "Valutazione media";
    }

    #tabellaAtleti .atleta-row td:nth-child(5)::before,
    #tabellaAtleti .atleta-row td:nth-child(6)::before,
    #tabellaAtleti .atleta-row td:nth-child(7)::before,
    #tabellaAtleti .atleta-row td:nth-child(8)::before,
    #tabellaAtleti .atleta-row td:nth-child(9)::before {
        display: block;
        margin-bottom: 3px;
        color: var(--muted);
        font-size: 0.65rem;
        font-weight: 700;
        line-height: 1.2;
        text-transform: uppercase;
    }

    #tabellaAtleti .top-ranking-cell {
        min-width: 0;
        white-space: normal;
    }

    #tabellaAtleti .top-ranking-cell small {
        font-size: 0.65rem;
    }

    #tabellaAtleti .list-average-rating {
        justify-content: flex-start;
    }

    #tabellaAtleti .list-average-bar {
        min-width: 45px;
        max-width: 100px;
    }

    #tabellaAtleti .list-average-value {
        font-size: 0.7rem;
    }

    #tabellaAtleti.hide-stats .atleta-row {
        grid-template-areas:
            "photo name name name"
            "photo tessera tessera tessera";
    }
}


/* Fix per schermi molto piccoli (es. iPhone SE) */
@media (max-width: 480px) {
    .tab-btn {
        min-width: calc(50% - 10px);
        /* Ne mette 2 per riga */
    }
}

/* ========================================================================== 
   9. GIOCHI: PONG E SNAKE
   Stili circoscritti ai giochi per evitare conflitti con le tabelle globali.
   ========================================================================== */
#pong-container,
#snake-container {
    box-sizing: border-box;
    padding: 0 12px;
}

#pong-container .card,
#snake-container .card {
    background: linear-gradient(180deg, var(--surface), var(--surface-alt));
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 10px 28px rgba(17, 24, 39, 0.12);
    overflow: hidden;
}

#pong-container h3,
#snake-container h3 {
    color: var(--navy);
}

#pongCanvas,
#snakeCanvas {
    display: block;
    max-width: 100%;
    box-sizing: border-box;
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(17, 24, 39, 0.18);
}

#pong-container #leaderboardTable,
#snake-container #leaderboardTable {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    box-shadow: none;
    font-size: 0.95rem;
}

#pong-container #leaderboardTable th,
#snake-container #leaderboardTable th {
    padding: 10px;
    background: linear-gradient(180deg, var(--blue) 0%, var(--navy) 100%);
    border-color: rgba(255, 255, 255, 0.2);
    color: #fff;
    font-weight: 700;
}

#pong-container #leaderboardTable td,
#snake-container #leaderboardTable td {
    padding: 9px 10px;
    color: var(--text);
    border-color: var(--border);
}

#pong-container #leaderboardTable tbody tr:nth-child(even) td,
#snake-container #leaderboardTable tbody tr:nth-child(even) td {
    background: var(--surface-alt);
}

#pong-container .btn,
#snake-container .btn {
    border: 0;
    border-radius: 9px;
    padding: 10px 16px;
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(17, 24, 39, 0.18);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

#pong-container .btn-blue {
    background: linear-gradient(135deg, var(--primary), var(--blue));
}

#snake-container .btn-green {
    background: linear-gradient(135deg, #16834a, #35bd78);
}

#pong-container .btn:hover,
#snake-container .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 7px 16px rgba(17, 24, 39, 0.24);
}

/* ========================================================================== 
   10. SQUADRE FITeT
   ========================================================================== */
.teams-page {
    width: min(1100px, calc(100% - 30px));
    margin: 2rem auto 3rem;
}

.teams-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 22px;
}

.teams-eyebrow {
    margin: 0 0 5px;
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.teams-heading h2 {
    margin: 0 0 6px;
    color: var(--navy);
    font-size: clamp(1.5rem, 4vw, 2rem);
}

.teams-heading p:not(.teams-eyebrow) {
    margin: 0;
    color: var(--muted);
}

.teams-count {
    flex: 0 0 auto;
    padding: 8px 13px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--navy);
    font-size: 0.88rem;
    font-weight: 700;
}

.teams-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 310px), 1fr));
    gap: 14px;
}

.team-card {
    display: flex;
    min-width: 0;
    align-items: flex-start;
    gap: 14px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: linear-gradient(145deg, var(--surface), var(--surface-alt));
    box-shadow: 0 7px 20px rgba(17, 24, 39, 0.08);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.team-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 11px 25px rgba(17, 24, 39, 0.13);
}

.team-card-icon {
    display: grid;
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    place-items: center;
    border-radius: 12px;
    background: linear-gradient(145deg, var(--primary), var(--blue));
    color: #fff;
    font-size: 1.35rem;
    box-shadow: 0 4px 10px rgba(29, 78, 216, 0.22);
}

.team-card-content {
    min-width: 0;
    flex: 1;
}

.team-league {
    display: inline-block;
    margin-bottom: 5px;
    color: var(--primary-dark);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.team-card h3 {
    margin: 0;
    color: var(--navy);
    font-size: 1.08rem;
    overflow-wrap: anywhere;
}

.team-venue {
    margin: 9px 0 0;
    color: var(--text-soft);
    font-size: 0.86rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.team-id {
    flex: 0 0 auto;
    padding: 4px 7px;
    border-radius: 6px;
    background: var(--surface-alt);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
}

.teams-message {
    display: grid;
    gap: 5px;
    padding: 18px 20px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-soft);
    box-shadow: 0 5px 16px rgba(17, 24, 39, 0.06);
}

.teams-message-warning {
    border-color: #edcf8c;
    background: #fff9e9;
    color: #66501b;
}

.teams-message small {
    color: var(--muted);
}

.teams-updated-note {
    margin: 14px 0 0;
    color: var(--muted);
    font-size: 0.78rem;
    text-align: right;
}

@media (max-width: 560px) {
    .teams-page {
        width: calc(100% - 20px);
        margin-top: 1.25rem;
    }

    .teams-heading {
        align-items: flex-start;
    }

    .team-card {
        padding: 15px;
    }
}

@media (max-width: 768px) {

    #pong-container #leaderboardTable,
    #snake-container #leaderboardTable {
        font-size: 0.82rem;
    }

    #pong-container #leaderboardTable th,
    #pong-container #leaderboardTable td,
    #snake-container #leaderboardTable th,
    #snake-container #leaderboardTable td {
        padding: 8px 6px;
    }
}

@keyframes modal-overlay-fade-out {
    to {
        opacity: 0;
    }
}

@keyframes modal-dialog-fade-out {
    from {
        opacity: 1;
        filter: blur(0);
        transform: scale(1) rotate(0);
    }

    to {
        opacity: 0;
        filter: blur(3px);
        transform: scale(0.94) rotate(8deg);
    }
}