/* --- 1. VARIABILI E RESET --- */
:root {
    --primary: #0047ff;
    --dark: #1d1d1f;
    --text-muted: #86868b;
    --bg-light: #f5f5f7;
    --glass: rgba(255, 255, 255, 0.85);
    --border: #d2d2d7;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.04);
    --success: #28a745;
    --danger: #ff3b30;
}

* {
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-light);
    color: var(--dark);
    line-height: 1.6;
}

/* --- 2. LAYOUT GENERALE --- */
.public-container, .header-container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
}

.main-content {
    min-height: calc(100vh - 180px);
    padding-top: 20px;
}

/* --- 3. NAVBAR ELEGANTE (GLASSMORPHISM) --- */
.navbar-custom {
    background: var(--glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1000;
    padding: 12px 0;
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-link img {
    height: 48px;
    display: block;
    transition: transform 0.2s ease;
}

.logo-link:hover img {
    transform: scale(1.03);
}

/* --- 4. DROPDOWN E BOTTONI NAV --- */
.custom-dropdown {
    position: relative;
}

.btn-user {
    background: white;
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 10px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 10px;
    background: white;
    min-width: 220px;
    border-radius: 14px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.12);
    border: 1px solid rgba(0,0,0,0.05);
    padding: 8px 0;
    list-style: none;
}

.page-header {
    display: flex;
    align-items: flex-start;
    gap: 15px;
    margin-top: 30px;
    margin-bottom: 25px;
}

.page-header-icon {
    font-size: 2.2rem;
    line-height: 1; /* Fondamentale per non spingere giù il testo */
}

.page-header-text {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    padding: 0;
    line-height: 1.1; /* Stringe l'altezza della riga del titolo */
    color: var(--dark);
}

.page-header p {
    color: var(--text-muted);
    margin: 0; /* Rimosso ogni margine superiore */
    padding: 0;
    font-size: 0.9rem;
    line-height: 1.1; /* Stringe l'altezza della riga della descrizione */
}




    .dropdown-content.show {
        display: block;
        animation: slideDown 0.2s ease-out;
    }

    .dropdown-content a {
        display: block;
        padding: 10px 20px;
        color: var(--dark);
        text-decoration: none;
        font-size: 0.9rem;
    }

        .dropdown-content a:hover {
            background: var(--bg-light);
            color: var(--primary);
        }

.divider {
    height: 1px;
    background: #eee;
    margin: 8px 0;
}

.menu-header {
    font-size: 0.75rem;
    color: var(--danger);
    font-weight: 700;
    text-transform: uppercase;
    padding: 5px 20px;
}

.logout-link {
    color: var(--danger) !important;
}

/* --- 5. HERO E RICERCA (HOME PAGE) --- */
.hero-section {
    text-align: center;
    padding: 80px 0;
}

    .hero-section h1 {
        font-size: 3.5rem;
        letter-spacing: -0.03em;
        margin: 0;
    }

    .hero-section p {
        color: var(--text-muted);
        font-size: 1.3rem;
        margin-bottom: 40px;
    }

.search-box {
    display: flex;
    justify-content: center;
    gap: 12px;
    max-width: 550px;
    margin: 0 auto;
}

    .search-box input {
        flex: 1;
        padding: 16px 20px;
        border-radius: 14px;
        border: 1px solid var(--border);
        font-size: 1.1rem;
        outline: none;
        transition: 0.2s;
    }

        .search-box input:focus {
            border-color: var(--primary);
            box-shadow: 0 0 0 4px rgba(0,71,255,0.1);
        }

.btn-search {
    background: var(--dark);
    color: white;
    border: none;
    padding: 0 30px;
    border-radius: 14px;
    font-weight: 600;
    cursor: pointer;
}

/* --- 6. GRID E CARD TORNEI --- */
.tournament-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 25px;
}

.t-card {
    background: white;
    border-radius: 22px;
    padding: 30px;
    border: 1px solid rgba(0,0,0,0.03);
    transition: 0.3s ease;
    display: flex;
    flex-direction: column;
    position: relative;
}

    .t-card:hover {
        transform: translateY(-5px);
        box-shadow: 0 20px 40px rgba(0,0,0,0.06);
    }

.t-badge {
    position: absolute;
    top: 20px;
    right: 20px;
    background: var(--danger);
    color: white;
    font-size: 0.7rem;
    font-weight: 800;
    padding: 4px 12px;
    border-radius: 20px;
}

/* --- 7. DASHBOARD E TABELLE --- */
.custom-table-card {
    background: white;
    border-radius: 18px;
    border: 1px solid var(--border);
}
/* Aggiungiamo questa regola per fare in modo che l'ultima cella (azioni) 
   non blocchi il posizionamento assoluto del menu */
.custom-table td:last-child {
    position: relative;
    overflow: visible !important;
}

.custom-table {
    width: 100%;
    border-collapse: collapse;
}

    .custom-table th {
        background: #f9f9fb;
        padding: 16px;
        text-align: left;
        font-size: 0.8rem;
        text-transform: uppercase;
        color: #666;
    }

    .custom-table td {
        padding: 18px 16px;
        border-top: 1px solid #f0f0f0;
    }

.status-badge {
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
}

.active {
    background: #e7f5ff;
    color: var(--primary);
}

.finished {
    background: #f8f9fa;
    color: #666;
}

/* --- 8. CARD MATCH LIVE --- */
.match-card {
    background: white;
    border-radius: 24px;
    padding: 25px;
    border: 1px solid rgba(0,0,0,0.04);
}

.score-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--dark);
    padding: 20px 30px;
    border-radius: 18px;
    margin: 15px 0;
}

.score-number {
    font-family: 'Inter', monospace;
    font-size: 3.5rem;
    font-weight: 800;
    color: #00ff41; /* Verde neon sportivo */
}

/* --- 9. DOPPIO PARITARIO --- */
.player-container {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 1.1rem;
}

.name-divider {
    color: var(--border);
    font-weight: 300;
    font-size: 1.4rem;
}

.serving-dot {
    width: 10px;
    height: 10px;
    background: #ffcc00;
    border-radius: 50%;
    box-shadow: 0 0 10px #ffcc00;
}

/* --- 10. ANIMAZIONI --- */
@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.flash-update {
    animation: flash 0.6s ease-out;
}

@keyframes flash {
    0% {
        background-color: rgba(0,71,255,0.1);
    }

    100% {
        background-color: transparent;
    }
}

/* --- 11. FOOTER --- */
.footer-custom {
    margin-top: 80px;
    padding: 40px 0;
    border-top: 1px solid var(--border);
    text-align: center;
    background: white;
}

/* Rende il link della card invisibile ma cliccabile su tutta l'area */
.t-card-link {
    text-decoration: none;
    color: inherit;
    display: block;
}

.t-card {
    background: white;
    border-radius: 24px;
    padding: 32px;
    height: 100%;
    position: relative;
    border: 1px solid rgba(0,0,0,0.04);
    transition: all 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

    .t-card:hover {
        transform: translateY(-8px);
        box-shadow: 0 20px 40px rgba(0,0,0,0.08);
        border-color: var(--primary);
    }

.t-title {
    font-size: 1.5rem;
    margin: 10px 0;
    line-height: 1.2;
}

.t-organizer {
    margin-top: 10px;
    font-size: 0.95rem;
    color: var(--text-muted);
}

    .t-organizer strong {
        display: block;
        color: var(--primary);
        margin-top: 2px;
    }

.t-footer {
    margin-top: 30px;
    padding-top: 15px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: var(--primary);
    font-size: 0.9rem;
}

    .t-footer .arrow {
        transition: transform 0.2s;
    }

.t-card:hover .arrow {
    transform: translateX(5px);
}

.card-icon {
    font-size: 2.5rem;
    margin-bottom: 15px;
    display: block;
}



/* Griglia dei tavoli */
.match-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 25px;
}

/* La Card del Tavolo */
.match-card {
    background: white;
    border-radius: 24px;
    padding: 24px;
    border: 1px solid rgba(0,0,0,0.04);
    box-shadow: 0 4px 20px rgba(0,0,0,0.03);
    transition: transform 0.3s ease;
}




/* CONTAINER TABELLONE GOOGLE STYLE */
.match-card {
    background: #ffffff;
    border-radius: 8px; /* Meno arrotondato, più sobrio */
    border: 1px solid #e0e0e0;
    padding: 0; /* Il padding lo gestiamo internamente alle righe */
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    font-family: 'Roboto', arial, sans-serif;
}

/* RIGA GIOCATORE */
.player-row-google {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #f1f1f1;
    min-height: 52px;
}

    .player-row-google:last-child {
        border-bottom: none;
    }

/* Nomi e Battuta */
.player-info {
    display: flex;
    align-items: center;
    flex: 1; /* Prende tutto lo spazio a sinistra */
}

.serving-indicator {
    width: 8px;
    height: 8px;
    background: #f4b400; /* Giallo Google Tennis */
    border-radius: 50%;
    margin-right: 10px;
    visibility: hidden; /* Gestito da JS */
}

.name-container {
    display: flex;
    flex-direction: column; /* Incolonna i nomi */
    justify-content: center;
    line-height: 1.2;
    color: #202124;
}

/* Nome singolo giocatore */
.name-item {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}

/* Quando la riga o il contenitore ha la classe match-winner, 
   tutti i nomi al suo interno diventano neri e in grassetto */
.match-winner .name-item {
    font-weight: 700 !important;
    color: #000 !important;
}



/* Se è un doppio, rimpiccioliamo leggermente per eleganza */
.is-doubles .name-item {
    font-size: 13px;
    font-weight: 400;
}

.is-winner {
    color: #000 !important;
    font-weight: 700 !important;
}
/* Per chi vince il set o il match */

/* PUNTEGGI INCOLONNATI (SET) */
.score-columns {
    display: flex;
    align-items: center;
    gap: 0;
}

.set-score {
    width: 32px; /* Ridotto da 40px */
    text-align: center;
    font-size: 13px;
    color: #70757a;
    border-left: 1px solid #f1f1f1;
    line-height: 52px; /* Allinea al centro della riga */
}

/* PUNTEGGIO LIVE (L'ultimo a destra) */
.live-points {
    width: 50px;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    color: #202124;
    background: #f8f9fa; /* Sfondo leggero per evidenziare il punto attuale */
}

/* Rimuoviamo il vecchio divisore pipe | che non serve più */
.name-divider {
    display: none;
}


/* Intestazione della Card (Tavolo + Stato) */
.match-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
}

.tavolo-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: #202124;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Badge degli Stati */
.stato-badge {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 50px;
    border: 1px solid transparent;
}

.stato-in-corso {
    background: #e6f4ea;
    color: #137333;
    border-color: #ceead6;
}

.stato-concluso {
    background: #f1f3f4;
    color: #3c4043;
    border-color: #dadce0;
}

.stato-sospeso {
    background: #fef7e0;
    color: #b06000;
    border-color: #feebd0;
}

.stato-annullato {
    background: #fce8e6;
    color: #c5221f;
    border-color: #fad2cf;
}

/* Effetto Blink/Pulse per i match in corso */
.pulse-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    background-color: #137333;
    border-radius: 50%;
    margin-right: 6px;
    animation: pulseAnimation 1.5s infinite ease-in-out;
    vertical-align: middle;
}

@keyframes pulseAnimation {
    0% {
        transform: scale(0.8);
        opacity: 0.5;
    }

    50% {
        transform: scale(1.2);
        opacity: 1;
    }

    100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
}


/* --- 13. KEBAB MENU (3 PALLINI VERTICALI) --- */
.action-menu-container {
    position: relative;
    display: inline-block;
}

.btn-kebab {
    background: none;
    border: none;
    font-size: 1.3rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 50%;
    transition: background 0.2s, color 0.2s;
    line-height: 1;
}

    .btn-kebab:hover {
        background: rgba(0, 0, 0, 0.05);
        color: var(--dark);
    }

.kebab-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    z-index: 9999 !important; /* <-- FORZA LO Z-INDEX AL MASSIMO */
    background: white;
    min-width: 180px; /* Leggermente più largo per comodità */
    border-radius: 10px;
    border: 1px solid var(--border);
    box-shadow: 0 10px 30px rgba(0,0,0,0.15); /* Ombra più pronunciata per staccarsi dallo sfondo */
    padding: 6px 0;
    list-style: none;
    margin: 4px 0 0 0;
}

    .kebab-dropdown.show {
        display: block;
        animation: slideDown 0.15s ease-out;
    }

    .kebab-dropdown a, .kebab-dropdown button {
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        padding: 10px 16px;
        color: var(--dark);
        text-decoration: none;
        font-size: 0.85rem;
        font-weight: 500;
        border: none;
        background: none;
        text-align: left;
        cursor: pointer;
        font-family: inherit;
    }

        .kebab-dropdown a:hover, .kebab-dropdown button:hover {
            background: var(--bg-light);
            color: var(--primary);
        }

    .kebab-dropdown .delete-item:hover {
        color: var(--danger);
        background: rgba(255, 59, 48, 0.05);
    }

/* --- 14. POPUP MODAL GESTIONALE --- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 2000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

    .modal-overlay.show {
        display: flex;
    }

.modal-content-custom {
    background: white;
    border-radius: 20px;
    width: 100%;
    max-width: 500px;
    padding: 30px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.15);
    animation: zoomIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.1) forwards;
}

@keyframes zoomIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(20px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-footer {
    display: flex;
    gap: 12px;
    margin-top: 25px;
}

.btn-cancel {
    flex: 1;
    background: #f5f5f7;
    color: var(--dark);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
}

/* --- 15. GRIGLIA MOBILE-FIRST CARD --- */
.mobile-match-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.match-manage-card {
    background: white;
    border-radius: 16px;
    border: 1px solid var(--border);
    padding: 16px;
    position: relative;
    box-shadow: 0 2px 10px rgba(0,0,0,0.02);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.card-top-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
}

.card-fase-badge {
    background: rgba(0, 71, 255, 0.06);
    color: var(--primary);
    padding: 3px 8px;
    border-radius: 6px;
    text-transform: uppercase;
}

.card-teams {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 4px 0;
}

.card-team-row {
    font-weight: 600;
    font-size: 0.95rem;
    color: #202124;
}

    .card-team-row span {
        font-weight: 400;
        font-size: 0.85rem;
        color: var(--text-muted);
    }

/* --- 16. MINI-CARD TORNEI AMMINISTRAZIONE --- */
.mobile-tournament-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.tournament-manage-card {
    background: white;
    border-radius: 16px;
    border: 1px solid var(--border);
    padding: 18px;
    position: relative;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
}

.tournament-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.tournament-card-title {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--dark);
    margin: 0;
    line-height: 1.2;
    padding-right: 25px; /* Lascia spazio al kebab menu */
}

.tournament-card-dates {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-light);
    padding: 6px 10px;
    border-radius: 8px;
    width: fit-content;
}


/* --- 17. CARD TORNEI PUBBLICI (HOME PAGE) --- */
.public-tournament-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 16px;
    margin-top: 25px;
}

.tournament-public-card {
    background: white;
    border-radius: 16px;
    border: 1px solid var(--border);
    padding: 18px;
    position: relative;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
    text-decoration: none; /* Rimuove la sottolineatura dal link */
    color: inherit;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

    .tournament-public-card:hover {
        transform: translateY(-2px);
        border-color: var(--primary);
    }

.public-card-societa {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 2px 0;
}

.public-card-title {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--dark);
    margin: 0;
    line-height: 1.2;
}


/* --- 18. GRIGLIA TABELLARE SET PASSATI --- */
.past-sets-table {
    display: flex;
    align-items: center;
    gap: 0; /* Rimuove lo spazio vuoto per unire i bordi */
    background: var(--bg-light);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.set-cell {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    padding: 4px 8px;
    min-width: 28px;
    text-align: center;
    font-family: monospace;
}

    /* Linea verticale grigia di divisione tra un set e l'altro */
    .set-cell:not(:last-child) {
        border-right: 1px solid var(--border);
    }


/* --- 19. ACCENTRAZIONE INPUT MODAL RESPONSIVE --- */
.form-control-custom {
    display: block;
    width: 100%;
    max-width: 100%;
    height: 44px;
    padding: 0 12px;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.5;
    color: var(--dark, #1d1d1f);
    background-color: #ffffff;
    background-clip: padding-box;
    border: 1px solid var(--border, #d2d2d7);
    border-radius: 10px;
    box-sizing: border-box; /* IMPEDISCE LO STRABORDAMENTO: include padding e bordi nella larghezza */
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

    /* Effetto focus stile iOS quando l'organizzatore tocca il campo dallo smartphone */
    .form-control-custom:focus {
        color: #1d1d1f;
        background-color: #ffffff;
        border-color: var(--primary, #0071e3);
        outline: 0;
        box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.15);
    }

    /* Uniforma l'estetica dei placeholder grigi su tutti i browser */
    .form-control-custom::placeholder {
        color: var(--text-muted, #86868b);
        opacity: 1;
    }