/* =====================================================================
   Pinpong HUB — mobile first, palette bianco / nero / verde.
   Tema chiaro = default; html[data-theme="dark"] sovrascrive le variabili.
===================================================================== */

:root {
    --green:        #00b86b;
    --green-d:      #008f52;
    --green-soft:   rgba(0,184,107,.12);

    --bg:           #f7f9f8;
    --panel:        #ffffff;
    --panel2:       #f0f2f1;
    --text:         #0a0a0a;
    --muted:        #6b7280;
    --line:         #e3e6e4;
    --shadow:       0 1px 2px rgba(0,0,0,.05), 0 4px 18px rgba(0,0,0,.05);
    --shadow-lg:    0 8px 30px rgba(0,0,0,.10);

    --ok:           #00b86b;
    --warn:         #b58900;
    --err:          #c0392b;
    --info:         #1f6feb;

    --radius:       12px;
    --logo-filter:  none;

    /* dimensioni navigazione */
    --nav-h:        66px;
    --topbar-h:     56px;
}

html[data-theme="dark"] {
    --bg:           #0a0a0a;
    --panel:        #141414;
    --panel2:       #1c1c1c;
    --text:         #f5f5f5;
    --muted:        #9aa0a6;
    --line:         #262626;
    --shadow:       0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.4);
    --shadow-lg:    0 8px 30px rgba(0,0,0,.6);

    --ok:           #1ed286;
    --warn:         #f1c232;
    --err:          #ff6b5e;
    --info:         #66a9ff;

    --logo-filter:  brightness(0) invert(1);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body {
    margin: 0; padding: 0;
    background: var(--bg); color: var(--text);
    font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}
body {
    /* spazio per la bottom nav su mobile */
    padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}

a { color: var(--text); text-decoration: none; }
a:hover { color: var(--green); }

h1 { font-size: 24px; margin: 0 0 12px; }
h2 { font-size: 20px; margin: 0 0 12px; }
h3 { font-size: 17px; margin: 0 0 10px; }

.wrap { max-width: 1140px; margin: 0 auto; padding: 14px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; flex-wrap: wrap; gap: 14px; }
.col { flex: 1 1 320px; min-width: 0; }

/* =========================================================
   TOP BAR — logo centrato, livello (loggato) a destra
   ========================================================= */
.topbar {
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 30;
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
    padding: 0 14px;
    height: var(--topbar-h);
    padding-top: env(safe-area-inset-top, 0px);
}
.topbar .logo {
    justify-self: center;
    display: inline-flex; align-items: center; gap: 8px;
}
.topbar .logo img {
    height: 36px; width: auto; filter: var(--logo-filter); display: block;
}
.topbar-side {
    display: flex; align-items: center; gap: 8px; min-width: 0;
}
.topbar-right { justify-content: flex-end; }

.user-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 999px;
    background: var(--green-soft); color: var(--green);
    font-weight: 600; font-size: 13px;
}
.user-chip .lvl { background: transparent; color: inherit; padding: 0; font-size: 13px; }

.lvl {
    background: var(--green); color: #fff;
    border-radius: 999px; padding: 2px 9px; font-size: 11px; font-weight: 700;
    line-height: 1.4;
}

.theme-toggle {
    width: 40px; height: 40px;
    background: var(--panel2); border: 1px solid var(--line);
    color: var(--text); border-radius: 10px; cursor: pointer;
    font-size: 18px;
    display: inline-flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { border-color: var(--green); }
.theme-toggle:active { transform: scale(.95); }

/* =========================================================
   BOTTOM NAV (mobile) — 5 icone con label
   ========================================================= */
.mainnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--panel);
    border-top: 1px solid var(--line);
    display: flex;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -2px 12px rgba(0,0,0,.05);
}
.nav-item {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px;
    padding: 8px 4px;
    height: var(--nav-h);
    color: var(--muted);
    font-size: 11px; font-weight: 500;
    transition: color .12s;
    -webkit-tap-highlight-color: transparent;
}
.nav-item svg { width: 24px; height: 24px; }
.nav-item.active { color: var(--green); }
.nav-item.active svg { stroke: var(--green); }
.nav-item:active { background: var(--panel2); }
.nav-item:hover { color: var(--green); }

/* =========================================================
   FAB — pulsante "Nuova partita" (pill con icona + testo)
   ========================================================= */
.fab {
    position: fixed; z-index: 45;
    right: 16px;
    bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom, 0px));
    height: 56px; padding: 0 22px 0 18px;
    border-radius: 999px;
    background: var(--green); color: #fff;
    display: inline-flex; align-items: center; gap: 8px;
    font-weight: 700; font-size: 15px;
    box-shadow: 0 6px 20px rgba(0,184,107,.45);
    transition: transform .12s, background .15s;
    white-space: nowrap;
}
.fab:hover { background: var(--green-d); color: #fff; }
.fab:active { transform: scale(.96); }
.fab svg { width: 22px; height: 22px; flex-shrink: 0; }

/* =========================================================
   FOOTER
   ========================================================= */
.footsite {
    border-top: 1px solid var(--line);
    margin-top: 24px; padding: 16px 0;
    font-size: 13px;
    margin-bottom: var(--nav-h); /* clear bottom nav anche su pagine corte */
}
.footsite a { color: var(--muted); }
.footsite a:hover { color: var(--green); }

/* =========================================================
   CARD — superfici principali del contenuto
   ========================================================= */
.card {
    background: var(--panel); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
    box-shadow: var(--shadow);
}
.card h2, .card h3 { margin: 0 0 12px; }

/* =========================================================
   BUTTONS — touch friendly (min 44px)
   ========================================================= */
.btn, .btn-primary, .btn-ghost, .btn-danger, .btn-link {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: 0; cursor: pointer;
    padding: 11px 18px; border-radius: 10px;
    font: 600 15px/1 inherit; color: var(--text); background: var(--panel2);
    text-decoration: none; min-height: 44px;
    -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover, .btn-primary:focus { background: var(--green-d); color: #fff; }
.btn-primary:active { transform: scale(.97); }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn-ghost:hover { border-color: var(--green); color: var(--green); }
.btn-danger { background: var(--err); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }
.btn-link { background: transparent; padding: 8px 4px; min-height: 36px; color: var(--green); }
.btn:disabled, .btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-big { padding: 14px 22px; font-size: 16px; min-height: 52px; border-radius: 12px; }

/* action bar centrato sotto un contenuto */
.action-bar {
    display: flex; gap: 8px; flex-wrap: wrap;
    justify-content: center;
    margin-top: 14px; padding-top: 14px;
    border-top: 1px solid var(--line);
}
.action-bar .btn-primary, .action-bar .btn-ghost { flex: 1 1 auto; max-width: 320px; }

/* =========================================================
   FORMS — input grandi, font 16px per non zoomare su iOS
   ========================================================= */
form .field { margin: 12px 0; }
form label {
    display: block; font-size: 13px; color: var(--muted);
    margin-bottom: 6px; font-weight: 500;
}
form input[type=text], form input[type=email], form input[type=password],
form input[type=number], form input[type=date], form input[type=time],
form select, form textarea {
    width: 100%; padding: 12px 14px;
    background: var(--panel); color: var(--text);
    border: 1px solid var(--line); border-radius: 10px;
    font: 16px/1.4 inherit; /* 16px = no zoom su iOS */
    appearance: none; -webkit-appearance: none;
}
form select { padding-right: 36px;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
}
form input:focus, form select:focus, form textarea:focus {
    outline: 2px solid var(--green); outline-offset: -1px; border-color: var(--green);
}

/* =========================================================
   FLASH MESSAGES
   ========================================================= */
.flash { padding: 12px 14px; border-radius: 10px; margin: 8px 0; border: 1px solid; font-size: 14px; }
.flash-ok   { background: var(--green-soft); border-color: var(--ok); }
.flash-warn { background: rgba(245,166,35,.12); border-color: var(--warn); }
.flash-err  { background: rgba(192,57,43,.12); border-color: var(--err); }

/* =========================================================
   BADGES
   ========================================================= */
.badge {
    display: inline-block; padding: 3px 9px; border-radius: 999px;
    font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
    border: 1px solid var(--line); font-weight: 600;
}
.badge-open      { background: rgba(245,166,35,.15); color: var(--warn); border-color: var(--warn); }
.badge-confirmed { background: var(--green-soft);    color: var(--green); border-color: var(--green); }
.badge-playing   { background: rgba(31,111,235,.15); color: var(--info);  border-color: var(--info); }
.badge-completed { background: var(--panel2);        color: var(--muted); }
.badge-cancelled { background: rgba(192,57,43,.12);  color: var(--err);   border-color: var(--err); }
.badge-admin     { background: #111; color: #fff; }

/* =========================================================
   TABLES — scroll orizzontale su mobile per non spezzare layout
   ========================================================= */
.card table.tbl,
table.tbl { width: 100%; border-collapse: collapse; }
.card { overflow-x: auto; } /* permette scroll su tabelle larghe dentro card */
table.tbl th, table.tbl td {
    padding: 10px 10px; text-align: left; border-bottom: 1px solid var(--line);
    font-size: 14px; white-space: nowrap;
}
table.tbl th {
    font-size: 11px; text-transform: uppercase; color: var(--muted);
    font-weight: 600; background: var(--panel2);
    letter-spacing: .5px;
}
table.tbl tr:hover td { background: var(--panel2); }
table.tbl td.wrap, table.tbl th.wrap { white-space: normal; }

/* =========================================================
   MATCH LIST ITEM
   ========================================================= */
.match {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 12px 0; border-bottom: 1px solid var(--line);
}
.match:last-child { border-bottom: 0; }
.match .vs { color: var(--muted); }
.match .score { font-weight: 700; margin-left: auto; }

/* live dot — animazione GPU-composita (transform + opacity, no box-shadow) */
.live {
    display: inline-block; width: 9px; height: 9px; border-radius: 50%;
    background: var(--green); margin-right: 6px;
    position: relative; vertical-align: middle;
}
.live::after {
    content: '';
    position: absolute; inset: 0;
    border-radius: 50%; background: var(--green);
    will-change: transform, opacity;
    animation: pulse 1.6s ease-out infinite;
    pointer-events: none;
}
@keyframes pulse {
    0%   { transform: scale(1);   opacity: .6; }
    100% { transform: scale(3.2); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
    .live::after { animation: none; }
}

/* View Transitions API: animazione fluida tra navigazioni cross-document
   (Chrome 126+; degrada silenziosamente negli altri browser). */
@view-transition { navigation: auto; }
::view-transition-old(root),
::view-transition-new(root) { animation-duration: .18s; }

/* =========================================================
   PULSE WARNING — card pulsante arancione (HUB chiuso)
   ========================================================= */
.card-pulse-warn {
    position: relative;
    border-color: var(--warn);
    background: linear-gradient(var(--panel), var(--panel)) padding-box,
                rgba(245,166,35,.25) border-box;
}
.card-pulse-warn::before {
    content: '';
    position: absolute; inset: -1px;
    border-radius: inherit;
    border: 2px solid var(--warn);
    pointer-events: none;
    will-change: transform, opacity;
    animation: cardPulseWarn 1.8s ease-out infinite;
}
@keyframes cardPulseWarn {
    0%   { transform: scale(1);    opacity: .85; }
    100% { transform: scale(1.025); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
    .card-pulse-warn::before { animation: none; opacity: .6; }
}

/* =========================================================
   NEXT SLOT CARD — riquadro con prossimo slot + CTA
   ========================================================= */
.next-slot {
    display: flex; align-items: center; gap: 14px;
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 14px;
    margin-top: 14px;
    flex-wrap: wrap;
}
.next-slot .date-box {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    min-width: 72px;
    background: var(--green); color: #fff;
    border-radius: 10px; padding: 8px 10px;
    line-height: 1;
}
.next-slot .date-box .dow {
    font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1px; opacity: .9;
}
.next-slot .date-box .num {
    font-size: 28px; font-weight: 800; margin: 4px 0;
}
.next-slot .date-box .mon {
    font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 1px; opacity: .9;
}
.next-slot .info {
    flex: 1; min-width: 140px;
}
.next-slot .info .time {
    font-size: 20px; font-weight: 700; line-height: 1.2;
}
.next-slot .info .lbl {
    color: var(--muted); font-size: 13px; margin-top: 2px;
}
.next-slot .action { margin-left: auto; }
.next-slot .badge { padding: 6px 12px; font-size: 12px; }
@media (max-width: 480px) {
    .next-slot .action { width: 100%; }
    .next-slot .action .btn-primary,
    .next-slot .action .btn-ghost { width: 100%; }
}

/* sets */
.sets { display: flex; gap: 6px; flex-wrap: wrap; }
.sets .set {
    background: var(--panel2); padding: 4px 12px;
    border-radius: 8px; font-variant-numeric: tabular-nums; font-weight: 600;
    border: 1px solid var(--line);
}

/* hub today */
.hub-now { display: flex; flex-wrap: wrap; gap: 6px; }
.hub-now .chip {
    background: var(--panel2); padding: 6px 12px;
    border-radius: 999px; font-size: 13px; border: 1px solid var(--line);
}
.hub-now .chip.in { border-color: var(--green); background: var(--green-soft); color: var(--green); }

/* stats grid */
.stats-grid { display: grid; gap: 10px; grid-template-columns: repeat(2, 1fr); }
@media (min-width: 480px) { .stats-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); } }
.stat {
    background: var(--panel2); border: 1px solid var(--line);
    border-radius: 10px; padding: 12px;
}
.stat .num { font-size: 22px; font-weight: 800; color: var(--green); line-height: 1.1; }
.stat .lbl { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; margin-top: 4px; }

/* bar chart svg */
.bar { fill: var(--green); }
.bar:hover { fill: var(--green-d); }
.axis { stroke: var(--line); }
.axis text { fill: var(--muted); font-size: 10px; }

/* admin nav */
.admin-nav { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; overflow-x: auto; }
.admin-nav a {
    padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line);
    font-size: 14px; white-space: nowrap;
}
.admin-nav a.active { background: var(--green); color: #fff; border-color: var(--green); }

/* sub-tabs (es. classifica/statistiche) */
.tabs {
    display: flex; gap: 6px; padding: 4px;
    background: var(--panel2); border-radius: 12px; margin-bottom: 14px;
}
.tabs a {
    flex: 1; text-align: center; padding: 10px 12px;
    border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 14px;
}
.tabs a.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

/* =========================================================
   DESKTOP (>= 900px) — la bottom nav diventa una "pill" centrata
   in basso (massimo 560px), elegante e a portata di mouse.
   ========================================================= */
@media (min-width: 900px) {
    :root { --topbar-h: 72px; }

    body { padding-bottom: 96px; }

    .topbar { padding: 0 24px; }
    .topbar .logo img { height: 44px; }

    .mainnav {
        left: 50%;
        right: auto;
        bottom: 18px;
        transform: translateX(-50%);
        max-width: 560px; width: calc(100% - 32px);
        border: 1px solid var(--line);
        border-radius: 999px;
        box-shadow: var(--shadow-lg);
        padding-bottom: 0;
    }
    .nav-item {
        height: 56px;
        padding: 6px 4px;
    }
    .nav-item.active { background: var(--green-soft); border-radius: 999px; }

    .footsite { margin-bottom: 80px; } /* spazio per la pill nav flottante */

    .fab {
        bottom: 96px; /* sopra la pill nav */
    }
}

/* =========================================================
   HELPERS
   ========================================================= */
.hide-mobile { }
@media (max-width: 899px) {
    .hide-mobile { display: none !important; }
    h1 { font-size: 22px; }
    .wrap { padding: 12px; }
    .card { padding: 14px; border-radius: var(--radius); }
}
.show-mobile { display: none; }
@media (max-width: 899px) {
    .show-mobile { display: initial; }
}

/* iPhone notch / homebar */
@supports (padding: max(0px)) {
    body { padding-bottom: max(var(--nav-h), calc(var(--nav-h) + env(safe-area-inset-bottom))); }
}
