/* =====================================================
   TORNEO AGNOSINE - STYLE GLOBALE (mobile-first)
===================================================== */

:root {
    --bg: #0b1220;
    --surface: #111827;
    --surface-2: #1f2937;
    --surface-3: #0f172a;
    --accent: #22c55e;
    --accent-hover: #16a34a;
    --text: #ffffff;
    --text-muted: #9ca3af;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #2563eb;
    --radius: 16px;
    --radius-sm: 12px;
    --touch-min: 48px;
    --page-pad: max(16px, env(safe-area-inset-left));
    --page-pad-r: max(16px, env(safe-area-inset-right));
    --bottom-nav-h: calc(64px + env(safe-area-inset-bottom, 0px));
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding-bottom: var(--bottom-nav-h);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    overflow-x: hidden;
}

@media (min-width: 768px) {
    body {
        padding-bottom: 24px;
    }
}

a {
    color: inherit;
    text-decoration: none;
}

/* ====================== NAVBAR ====================== */
.navbar-custom {
    background: var(--surface);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding: max(10px, env(safe-area-inset-top)) var(--page-pad) 12px var(--page-pad-r);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.navbar-brand {
    color: var(--accent) !important;
    font-weight: 800;
    font-size: clamp(17px, 4.5vw, 22px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 52px);
}

.nav-links {
    display: flex;
    gap: 6px;
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-link {
    color: white !important;
    font-size: 15px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
    display: inline-block;
    min-height: var(--touch-min);
    line-height: 1.2;
    display: inline-flex;
    align-items: center;
}

.nav-link:hover,
.nav-link:active {
    background: var(--surface-2);
}

.nav-toggler {
    display: none;
    background: var(--surface-2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: white;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 20px;
    cursor: pointer;
    min-width: var(--touch-min);
    min-height: var(--touch-min);
    flex-shrink: 0;
}

/* ====================== MOBILE BOTTOM BAR ====================== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    background: var(--surface);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    padding: 6px max(4px, env(safe-area-inset-left)) env(safe-area-inset-bottom, 8px) max(4px, env(safe-area-inset-right));
    z-index: 999;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
}

.bottom-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
    flex: 1;
    min-width: 0;
    padding: 6px 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: var(--touch-min);
    transition: color 0.15s;
}

.bottom-link div {
    font-size: 22px;
    line-height: 1;
}

.bottom-link.active,
.bottom-link:hover,
.bottom-link:active {
    color: var(--accent);
}

@media (min-width: 768px) {
    .bottom-nav {
        display: none;
    }
}

@media (max-width: 767px) {
    .nav-links {
        display: none;
        width: 100%;
        flex-direction: column;
        padding-top: 8px;
    }

    .nav-links.open {
        display: flex;
    }

    .nav-toggler {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .nav-links .nav-link {
        width: 100%;
        padding: 14px 16px;
    }
}

/* ====================== LAYOUT ====================== */
.container,
.calendar-wrap,
.admin-wrap,
.remote,
.tv-container,
.login-wrapper {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px var(--page-pad) 20px var(--page-pad-r);
}

.calendar-wrap {
    max-width: 1000px;
}

.admin-wrap {
    max-width: 900px;
}

.remote {
    max-width: 700px;
}

.tv-container {
    max-width: 900px;
    text-align: center;
}

.page-title,
h2 {
    font-weight: 800;
    margin: 0 0 20px;
    font-size: clamp(22px, 5.5vw, 28px);
    line-height: 1.2;
}

.page-title {
    text-align: center;
}

h4 {
    color: var(--accent);
    margin: 28px 0 12px;
    font-size: 17px;
}

/* ====================== FORMS & BUTTONS ====================== */
input,
select,
textarea,
.form-control {
    font-family: inherit;
    font-size: 16px;
}

button,
.btn {
    font-family: inherit;
    cursor: pointer;
    touch-action: manipulation;
    min-height: var(--touch-min);
}

.form-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
}

.form-control {
    width: 100%;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--surface-2);
    color: white;
    margin-bottom: 10px;
}

.btn {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    border: none;
    color: white;
    font-weight: 700;
    font-size: 15px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary { background: var(--info); }
.btn-success { background: var(--accent); color: #0b1220; }
.btn-warning { background: var(--warning); color: #0b1220; }
.btn-danger  { background: var(--danger); }

/* ====================== LISTS (admin) ====================== */
.admin-list {
    list-style: none;
    padding: 0;
    margin: 15px 0 0;
}

.admin-list li {
    background: var(--surface-3);
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.admin-list li span {
    flex: 1;
    min-width: 0;
    word-break: break-word;
}

.admin-list .btn {
    flex-shrink: 0;
    min-height: 44px;
    padding: 10px 14px;
}

/* ====================== TABLES (desktop) ====================== */
.table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 12px;
    border-radius: var(--radius-sm);
}

.match-table,
.table-light {
    width: 100%;
    background: var(--surface);
    border-collapse: collapse;
    min-width: 520px;
}

.table-light {
    background: var(--surface-3);
    min-width: 480px;
}

.match-table th,
.table-light th {
    background: var(--surface-2);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 12px 10px;
    text-align: center;
    color: white;
}

.table-light th,
.table-light td {
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid var(--surface-2);
}

.match-table td {
    padding: 12px 10px;
    text-align: center;
    border-top: 1px solid var(--surface-2);
    vertical-align: middle;
}

.match-table tr:hover td {
    background: var(--surface-3);
}

/* Mobile: tabelle → card */
@media (max-width: 767px) {
    .table-scroll {
        overflow: visible;
    }

    .match-table,
    .table-light {
        min-width: 0;
        display: block;
        background: transparent;
    }

    .match-table thead,
    .table-light thead {
        display: none;
    }

    .match-table tbody,
    .table-light tbody {
        display: block;
    }

    .match-table tr,
    .table-light tr {
        display: block;
        background: var(--surface);
        border-radius: var(--radius);
        margin-bottom: 12px;
        padding: 4px 0;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
        overflow: hidden;
    }

    .table-light tr {
        background: var(--surface-3);
    }

    .match-table td,
    .table-light td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        text-align: right;
        padding: 11px 16px;
        border: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    }

    .match-table td:last-child,
    .table-light td:last-child {
        border-bottom: none;
    }

    .match-table td::before,
    .table-light td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.4px;
        color: var(--text-muted);
        text-align: left;
        flex-shrink: 0;
    }

    .match-table td[data-label=""]::before,
    .table-light td[data-label=""]::before {
        display: none;
    }

    .table-light td:last-child {
        justify-content: flex-end;
    }
}

/* ====================== CALENDARIO ====================== */
.giornata-block {
    margin-bottom: 28px;
}

.giornata-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--accent);
}

.match-name {
    font-weight: 600;
    text-align: right;
    word-break: break-word;
}

.match-score {
    font-size: 18px;
    font-weight: 800;
    color: var(--accent);
}

.badge,
.match-status {
    padding: 6px 10px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 700;
    display: inline-block;
    white-space: nowrap;
}

.live     { background: var(--danger); color: white; }
.paused   { background: var(--warning); color: #0b1220; }
.finished { background: var(--accent); color: #0b1220; }
.upcoming { background: #64748b; color: white; }

.empty,
.empty-msg {
    text-align: center;
    opacity: 0.7;
    margin-top: 48px;
    padding: 20px;
    font-size: clamp(16px, 4vw, 22px);
}

/* ====================== TELECOMANDO LISTA ====================== */
.match-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: white;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    min-height: var(--touch-min);
}

.match-card:active {
    background: var(--surface-2);
    transform: scale(0.99);
}

.match-info {
    font-size: 16px;
    font-weight: 700;
    flex: 1;
    min-width: 0;
    line-height: 1.35;
}

.match-sport {
    font-size: 13px;
    font-weight: 600;
    color: #facc15;
    margin-bottom: 4px;
}

/* ====================== TELECOMANDO PARTITA ====================== */
#root {
    padding: 16px var(--page-pad) 24px var(--page-pad-r);
    max-width: 700px;
    margin: 0 auto;
}

.remote-match .match-card {
    flex-direction: column;
    text-align: center;
    background: linear-gradient(135deg, var(--surface), var(--surface-2));
    padding: 20px 16px;
}

.remote-match .match-title {
    font-size: clamp(18px, 5vw, 22px);
    font-weight: bold;
    word-break: break-word;
}

.remote-match .score {
    font-size: clamp(36px, 12vw, 48px);
    font-weight: bold;
    color: var(--accent);
    margin-top: 8px;
}

.remote-match .timer {
    font-size: clamp(20px, 5vw, 26px);
    margin-top: 10px;
    color: #facc15;
}

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

.remote-match .btn-grid.timer-grid {
    grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 380px) {
    .remote-match .btn-grid:not(.timer-grid) {
        grid-template-columns: 1fr;
    }

    .remote-match .btn-grid.timer-grid {
        grid-template-columns: 1fr;
    }
}

.remote-section {
    margin-top: 16px;
    background: var(--surface);
    padding: 16px;
    border-radius: var(--radius);
}

.remote-section h4 {
    margin: 0 0 12px;
    font-size: 15px;
}

button.btn-remote {
    width: 100%;
    padding: 18px 12px;
    border: none;
    border-radius: 14px;
    font-size: 15px;
    font-weight: bold;
    color: white;
    min-height: 56px;
}

.btn-remote.start  { background: var(--accent); color: #0b1220; }
.btn-remote.stop   { background: #facc15; color: #0b1220; }
.btn-remote.reset  { background: #60a5fa; color: #0b1220; }
.btn-remote.home   { background: #16a34a; }
.btn-remote.away   { background: var(--info); }
.btn-remote.minus  { background: var(--danger); }
.btn-remote.finish {
    background: #dc2626;
    margin-top: 16px;
    width: 100%;
    font-size: 17px;
    min-height: 58px;
}

.btn-next {
    display: block;
    width: 100%;
    margin-top: 16px;
    padding: 20px 16px;
    border-radius: var(--radius);
    text-align: center;
    font-size: clamp(17px, 4.5vw, 22px);
    font-weight: 800;
    background: var(--info);
    color: white;
    box-shadow: 0 8px 25px rgba(37, 99, 235, 0.4);
    min-height: var(--touch-min);
    line-height: 1.2;
}

.btn-next:active {
    background: #1d4ed8;
}

/* ====================== TV LIVE ====================== */
.scoreboard {
    background: linear-gradient(135deg, var(--surface), var(--surface-2));
    border-radius: var(--radius);
    padding: clamp(20px, 5vw, 32px) clamp(12px, 4vw, 24px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    margin-bottom: 24px;
}

.sport-badge {
    display: inline-block;
    font-size: clamp(16px, 4vw, 22px);
    font-weight: 700;
    color: #facc15;
    background: rgba(250, 204, 21, 0.12);
    padding: 8px 16px;
    border-radius: 999px;
    margin-bottom: 16px;
    max-width: 100%;
    word-break: break-word;
}

.teams {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px 12px;
    font-size: clamp(15px, 4.2vw, 28px);
    font-weight: bold;
}

.team {
    word-break: break-word;
    hyphens: auto;
}

.team:first-child {
    text-align: right;
}

.team:last-child {
    text-align: left;
}

.scoreboard .score {
    font-size: clamp(32px, 10vw, 60px);
    font-weight: bold;
    color: var(--accent);
    white-space: nowrap;
}

.status {
    margin-top: 14px;
    font-size: clamp(13px, 3.5vw, 16px);
    opacity: 0.85;
}

.time {
    font-weight: 800;
    letter-spacing: 1px;
}

/* ====================== LOGIN ====================== */
body.page-login {
    padding-bottom: var(--bottom-nav-h);
    min-height: 100vh;
    background:
        linear-gradient(rgba(5, 11, 24, 0.9), rgba(5, 11, 24, 0.95)),
        url('https://images.unsplash.com/photo-1574629810360-7efbbe195018?q=80&w=1600&auto=format&fit=crop');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
}

.login-wrapper {
    min-height: calc(100dvh - var(--bottom-nav-h) - 60px);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px var(--page-pad);
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: rgba(17, 24, 39, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 24px;
    padding: 28px 20px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.logo {
    text-align: center;
    margin-bottom: 22px;
}

.logo-icon {
    font-size: clamp(52px, 14vw, 70px);
}

.logo h1 {
    margin: 10px 0 4px;
    font-size: clamp(26px, 7vw, 34px);
    font-weight: 900;
    color: var(--accent);
}

.logo p {
    color: var(--text-muted);
    font-size: 15px;
    margin: 0;
}

.input-group-custom {
    margin-bottom: 16px;
}

.input-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 700;
    font-size: 15px;
    color: #d1d5db;
}

.input-custom {
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 14px;
    background: var(--surface-2);
    color: white;
    font-size: 16px;
}

.input-custom:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--accent);
}

.login-btn {
    width: 100%;
    padding: 18px;
    border: none;
    border-radius: 14px;
    background: var(--accent);
    color: #0b1220;
    font-size: 18px;
    font-weight: 900;
    margin-top: 8px;
    min-height: 56px;
}

.login-btn:active {
    background: var(--accent-hover);
    transform: scale(0.98);
}

.error {
    background: #7f1d1d;
    padding: 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 14px;
    text-align: center;
    display: none;
    font-size: 14px;
}

.footer-text {
    text-align: center;
    margin-top: 18px;
    color: var(--text-muted);
    font-size: 14px;
}

/* ====================== UTILITIES ====================== */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.loading-center {
    text-align: center;
    margin-top: 80px;
    padding: 20px;
    font-size: 18px;
}

@media (min-width: 768px) {
    .match-card:hover {
        background: var(--surface-2);
        transform: translateY(-2px);
        transition: 0.2s;
    }

    .login-btn:hover {
        transform: scale(1.02);
        background: var(--accent-hover);
    }

    .btn-next:hover {
        background: #1d4ed8;
    }
}

/* ====================== SPLASH SCREEN ====================== */
body.splash-active {
    overflow: hidden;
}

body.splash-active > *:not(#splash-screen) {
    opacity: 0;
    pointer-events: none;
}

#splash-screen {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    gap: 36px;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#splash-screen.splash-hide {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.splash-logo {
    width: clamp(140px, 38vw, 210px);
    height: auto;
    animation: splash-pulse 2.2s ease-in-out infinite;
}

@keyframes splash-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.92; }
}

.splash-bar-track {
    width: min(280px, 72vw);
    height: 5px;
    background: var(--surface-2);
    border-radius: 999px;
    overflow: hidden;
}

.splash-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #0071BC, #92278F);
    border-radius: 999px;
    transition: width 0.25s ease;
}
