@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* Portale Famiglie: palette e design del sito (rosso/bianco/oro, glass, font Bauhaus di Malnate) */
@font-face {
    font-family: 'TitleFont';
    src: url('/malnate/branding/font/font.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

:root {
    --red: #e40613;
    --red-dark: #ae0f0b;
    --red-soft: #ae0f0b;
    --gold: #af9a63;
    --gold-soft: #af9a63;
    --green: #1f9d55;
    --green-soft: #e7f7ee;
    --bg-primary: #faf6f4;
    --panel: rgba(255, 255, 255, 0.86);
    --panel-strong: rgba(255, 255, 255, 0.95);
    --text-primary: #2a0e0b;
    --text-secondary: #8a5048;
    --ink-on-gold: #3a2400;
    --card-border: rgba(42, 14, 11, 0.08);
    --shadow-subtle: 0 1px 2px rgba(42, 14, 11, 0.04), 0 6px 18px rgba(42, 14, 11, 0.06);
    --shadow-hover: 0 2px 6px rgba(42, 14, 11, 0.05), 0 18px 44px rgba(42, 14, 11, 0.10);
    --title-font: 'TitleFont', 'Inter', sans-serif;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background-color: var(--bg-primary);
    background-image:
        radial-gradient(1200px 600px at 100% -5%, rgba(228, 6, 19, 0.06), transparent 60%),
        radial-gradient(900px 500px at 0% 105%, rgba(175, 154, 99, 0.08), transparent 60%);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    overflow-x: clip;
}

/* ===================== BOTTONI ===================== */
.btn {
    padding: 11px 22px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-family: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none !important; }
.btn-primary { background: var(--red); color: #fff; box-shadow: 0 6px 18px rgba(228, 6, 19, 0.35); }
.btn-primary:hover { background: var(--red-soft); transform: translateY(-2px); }
.btn-gold { background: var(--gold); color: #3a2400; box-shadow: 0 6px 18px rgba(175, 154, 99, 0.35); }
.btn-gold:hover { background: var(--gold-soft); transform: translateY(-2px); }
.btn-ghost { background: #fff; color: var(--red); border: 1px solid var(--red); }
.btn-ghost:hover { background: var(--red); color: #fff; }
.btn-danger { background: #fff; color: var(--red-dark); border: 1px solid var(--red-dark); }
.btn-danger:hover { background: var(--red-dark); color: #fff; }
.btn-sm { padding: 7px 14px; font-size: 12px; border-radius: 999px; }
.link-btn { background: none; border: none; color: var(--red); font-size: 12px; cursor: pointer; text-decoration: underline; font-family: inherit; }

/* ===================== FORM ===================== */
.input, select.input, textarea.input {
    width: 100%;
    min-width: 0;      /* i campi data/select hanno larghezza intrinseca: senza questo sforano nei flex */
    max-width: 100%;
    padding: 12px 15px;
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}
input[type="date"].input {
    -webkit-appearance: none;
    appearance: none;
    min-height: 44px;
}
.input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(228, 6, 19, 0.12); }
.input-group { margin-bottom: 12px; text-align: left; min-width: 0; }
.input-group label { display: block; font-size: 12px; font-weight: 700; color: var(--text-secondary); margin-bottom: 5px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.form-hint { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

/* ===================== AUTH (index.html) ===================== */
.auth-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 24px 16px 0;
}
/* pannello centrato nello spazio libero, footer sempre ancorato al fondo */
.auth-body .auth-panel { margin-top: auto; margin-bottom: auto; }
.auth-body .mini-footer { margin-top: 24px; }
.auth-panel {
    width: 100%;
    max-width: 420px;
    background: var(--panel-strong);
    backdrop-filter: blur(24px) saturate(170%);
    -webkit-backdrop-filter: blur(24px) saturate(170%);
    border: 1px solid var(--card-border);
    border-top: 3px solid var(--gold);
    border-radius: 24px;
    padding: 34px 30px;
    box-shadow: var(--shadow-hover);
    text-align: center;
}
.auth-panel .logo-img { max-width: 96px; height: auto; margin-bottom: 12px; filter: drop-shadow(0 4px 12px rgba(174, 15, 11, 0.25)); }
.auth-panel .logo-row { display: flex; justify-content: center; align-items: center; gap: 16px; }
.auth-panel .logo-row .logo-img { max-width: 82px; }
.auth-panel h1 { font-family: var(--title-font); font-weight: 400; font-size: 26px; color: var(--red); margin-bottom: 4px; }
.auth-panel h1 .accent { color: var(--gold); }
.auth-panel .subtitle { font-size: 13px; color: var(--text-secondary); margin-bottom: 22px; }

.tabs-container {
    background: rgba(228, 6, 19, 0.08);
    padding: 4px;
    border-radius: 50px;
    display: flex;
    position: relative;
    margin-bottom: 20px;
    border: 1px solid var(--card-border);
}
.tab { flex: 1; text-align: center; padding: 9px 0; font-size: 12px; font-weight: 700; color: var(--text-secondary); cursor: pointer; position: relative; z-index: 2; transition: color 0.3s; letter-spacing: 0.5px; }
.tab.active { color: #fff; }
.tab-slider {
    position: absolute; top: 4px; left: 4px; bottom: 4px;
    width: calc(50% - 4px);
    background: linear-gradient(135deg, var(--red), var(--red-dark));
    border-radius: 50px; z-index: 1;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 10px rgba(228, 6, 19, 0.4);
}
.tabs-container.right-active .tab-slider { transform: translateX(100%); }

.form-section { display: none; animation: fadeIn 0.4s ease forwards; }
.form-section.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.err-msg { font-size: 12px; margin-top: 12px; min-height: 18px; font-weight: 600; color: var(--red-dark); }

.str-rule { font-size: 12px; padding: 2px 0; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; text-align: left; }
.str-rule::before { content: '✗'; }
.str-rule.ok { color: var(--green); }
.str-rule.ok::before { content: '✓'; }
.pwd-box { background: rgba(228, 6, 19, 0.05); padding: 10px 12px; border-radius: 10px; border: 1px solid var(--card-border); margin: 8px 0 12px; }

.pwd-wrap { position: relative; }
.pwd-wrap .input { padding-right: 44px; }
.pwd-toggle { position: absolute; right: 6px; top: 0; height: 100%; width: 36px; display: flex; align-items: center; justify-content: center; background: none; border: none; cursor: pointer; opacity: 0.55; color: var(--text-primary); }
.pwd-toggle:hover { opacity: 1; }

/* ===================== FOOTER RIDOTTO ===================== */
.mini-footer {
    text-align: center;
    padding: 18px 16px;
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.7;
}
.mini-footer a { color: var(--red); font-weight: 600; text-decoration: none; }
.mini-footer a:hover { text-decoration: underline; }
.mini-footer .sep { margin: 0 6px; opacity: 0.5; }

/* ===================== DASHBOARD LAYOUT ===================== */
.dash-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 250px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--red) 0%, var(--red-dark) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 22px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    border-right: 3px solid var(--gold);
}
.sidebar .side-logo { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; border-bottom: 1px solid rgba(255,255,255,0.25); margin-bottom: 16px; text-decoration: none; color: #fff; }
.sidebar .side-logo img { height: 38px; filter: drop-shadow(0 2px 6px rgba(0,0,0,0.3)); }
.sidebar .side-logo span { font-family: var(--title-font); font-size: 18px; line-height: 1.2; }
.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side-nav button, .side-nav a {
    display: flex; align-items: center; gap: 10px;
    background: none; border: none; color: rgba(255,255,255,0.85);
    font-family: inherit; font-size: 14px; font-weight: 600;
    padding: 11px 14px; border-radius: 12px; cursor: pointer;
    transition: all 0.2s; text-align: left; width: 100%;
    text-decoration: none; box-sizing: border-box;
}
.side-nav button:hover, .side-nav a:hover { background: rgba(255,255,255,0.12); color: #fff; }
.side-nav button.active { background: #fff; color: var(--red); box-shadow: 0 4px 14px rgba(0,0,0,0.15); }
.side-nav .nav-sep { font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; color: rgba(255,255,255,0.5); padding: 14px 14px 4px; font-weight: 700; }
.sidebar .side-user { border-top: 1px solid rgba(255,255,255,0.25); padding: 14px 8px 0; font-size: 12px; overflow-wrap: anywhere; }
.sidebar .side-user strong { display: block; font-size: 13px; }
.sidebar .side-user .role-tag { display: inline-block; margin-top: 4px; background: var(--gold); color: #3a2400; padding: 2px 10px; border-radius: 10px; font-size: 10px; font-weight: 800; letter-spacing: 0.5px; text-transform: uppercase; }
.sidebar .logout-btn { margin-top: 10px; width: 100%; background: rgba(255,255,255,0.14); color: #fff; border: 1px solid rgba(255,255,255,0.35); padding: 8px; border-radius: 10px; font-size: 12px; font-weight: 700; cursor: pointer; font-family: inherit; }
.sidebar .logout-btn:hover { background: #fff; color: var(--red); }

.dash-main {
    flex: 1;
    padding: 30px 34px 0;
    width: 100%;   /* senza, i margini auto restringono la colonna su mobile (layout in colonna) */
    max-width: 1200px;
    min-width: 0;
    /* oltre i 1200px la colonna si centra nello spazio dopo la sidebar invece di restare a sinistra */
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.dash-main #views { flex: 1; }
.dash-main .mini-footer { margin-top: auto; }

/* ===================== BANNER TELEGRAM ===================== */
.tg-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    margin-bottom: 18px;
    border-radius: 14px;
    background: rgba(34, 158, 217, 0.09);
    border: 1px solid rgba(34, 158, 217, 0.35);
    font-size: 13px;
    color: var(--text-primary);
}
.tg-banner .tg-banner-text { flex: 1; min-width: 0; }
.tg-banner .tg-banner-btn { background: #229ED9; color: #fff; flex-shrink: 0; }
.tg-banner .tg-banner-btn:hover { background: #1d8dc2; transform: translateY(-1px); }
.tg-banner .tg-banner-close {
    background: none; border: none; cursor: pointer;
    font-size: 20px; line-height: 1; color: var(--text-secondary);
    padding: 2px 6px; flex-shrink: 0;
}
.tg-banner .tg-banner-close:hover { color: var(--text-primary); }

/* ===================== ICONE SVG ===================== */
.icon {
    width: 1.15em;
    height: 1.15em;
    display: inline-block;
    vertical-align: -0.22em;
    flex-shrink: 0;
}
.dash-main h2.page-title { font-family: var(--title-font); font-weight: 400; font-size: 32px; color: var(--red); margin-bottom: 4px; }
.dash-main h2.page-title .accent { color: var(--gold); }
/* Grechina: piccola silhouette del ponte (branding Malnate) sopra il titolo vista */
.dash-main h2.page-title::before {
    content: '';
    display: block;
    width: 88px;
    aspect-ratio: 1313 / 500;
    margin-bottom: 8px;
    background-color: var(--gold);
    -webkit-mask: url('/malnate/branding/design.svg') left / contain no-repeat;
    mask: url('/malnate/branding/design.svg') left / contain no-repeat;
}
.dash-main .page-subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }

.view { display: none; }
.view.active { display: block; animation: fadeIn 0.3s ease; }

/* ===================== CARD / PANEL ===================== */
.panel {
    background: var(--panel);
    backdrop-filter: blur(16px) saturate(160%);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    border: 1px solid var(--card-border);
    box-shadow: var(--shadow-subtle);
    border-radius: 18px;
    padding: 24px;
    margin-bottom: 20px;
}
.panel h3 { font-size: 17px; font-weight: 800; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--panel-strong); border: 1px solid var(--card-border); border-top: 2px solid var(--gold); border-radius: 16px; padding: 18px; box-shadow: var(--shadow-subtle); }
.stat-card .stat-value { font-size: 28px; font-weight: 800; color: var(--red); }
.stat-card .stat-label { font-size: 12px; color: var(--text-secondary); font-weight: 600; margin-top: 2px; }

.athlete-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: 16px; }
.athlete-card { background: var(--panel-strong); border: 1px solid var(--card-border); border-top: 2px solid var(--gold); border-radius: 18px; padding: 20px; box-shadow: var(--shadow-subtle); transition: all 0.25s; }
.athlete-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
.athlete-card h4 { font-size: 17px; margin-bottom: 2px; }
.athlete-card .cf { font-size: 11px; color: var(--text-secondary); font-family: monospace; letter-spacing: 0.5px; }
.athlete-card .meta { font-size: 13px; color: var(--text-secondary); margin: 10px 0; line-height: 1.7; }

/* ===================== BADGE ===================== */
.badge { display: inline-block; padding: 3px 11px; border-radius: 12px; font-size: 11px; font-weight: 800; letter-spacing: 0.3px; }
.badge-red { background: rgba(228, 6, 19, 0.12); color: var(--red-dark); }
.badge-gold { background: rgba(175, 154, 99, 0.2); color: #3a2400; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-gray { background: rgba(0,0,0,0.07); color: var(--text-secondary); }

/* ===================== TABELLE ===================== */
.table-wrap { overflow-x: auto; border-radius: 14px; border: 1px solid var(--card-border); background: var(--panel-strong); }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 640px; }
table.data th { text-align: left; padding: 12px 14px; background: rgba(228, 6, 19, 0.07); color: var(--red-dark); font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; }
table.data td { padding: 11px 14px; border-top: 1px solid rgba(228, 6, 19, 0.08); vertical-align: middle; }
table.data tr:hover td { background: rgba(228, 6, 19, 0.03); }

.filters-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters-bar .input { width: auto; flex: 1; min-width: 160px; max-width: 100%; }
.filters-bar select.input { flex: 0 1 auto; }

/* ===================== MODAL ===================== */
.modal-overlay {
    position: fixed; inset: 0; z-index: 3000;
    display: none; align-items: center; justify-content: center;
    padding: 24px;
    background: rgba(174, 15, 11, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}
.modal-overlay.show { display: flex; }
.modal {
    background: #fff;
    border-radius: 22px;
    padding: 28px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 24px 70px rgba(0,0,0,0.35);
    border: 1px solid var(--card-border);
}
.modal h3 { font-size: 19px; font-weight: 800; margin-bottom: 16px; color: var(--red-dark); }
.modal .modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }

/* ===================== TOAST ===================== */
#toast {
    position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(200%);
    visibility: hidden; opacity: 0;
    background: var(--text-primary); color: #fff;
    padding: 13px 24px; border-radius: 30px; font-size: 13px; font-weight: 600;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3); z-index: 4000;
    transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.25s, visibility 0.35s;
    max-width: 90vw; text-align: center;
}
#toast.show { transform: translateX(-50%) translateY(0); visibility: visible; opacity: 1; }
#toast.success { background: var(--green); }
#toast.error { background: var(--red-dark); }

/* ===================== PAGAMENTO ONLINE SIMULATO (Satispay) ===================== */
.pay-sim { text-align: center; padding: 10px 0; }
/* logo vettoriale Satispay (style/satispay.svg; il metodo sul DB resta 'paypal_sim') */
.pay-sim .sp-logo { display: inline-block; height: 26px; width: auto; margin-bottom: 10px; }
.pay-sim .demo-tag { display: inline-block; background: var(--gold); color: #3a2400; font-size: 10px; font-weight: 800; padding: 2px 10px; border-radius: 10px; letter-spacing: 1px; margin-bottom: 14px; }
.pay-sim .pp-amount { font-size: 30px; font-weight: 800; margin: 8px 0 16px; }

/* ===================== LOADING ===================== */
#loading-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: var(--bg-primary);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
    color: var(--red); font-weight: 700; font-size: 14px;
}
.spinner { width: 38px; height: 38px; border: 4px solid rgba(228, 6, 19, 0.2); border-top-color: var(--red); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== MOBILE ===================== */
.mobile-topbar { display: none; }

@media (max-width: 860px) {
    .dash-layout { flex-direction: column; }
    .sidebar {
        position: fixed; z-index: 2500; height: 100vh; left: -270px; top: 0;
        transition: left 0.3s cubic-bezier(0.22, 1, 0.36, 1);
        box-shadow: 0 0 60px rgba(0,0,0,0.3);
    }
    .sidebar.open { left: 0; }
    .mobile-topbar {
        display: flex; align-items: center; gap: 12px;
        position: sticky; top: 0; z-index: 2000;
        padding: 12px 16px;
        background: rgba(255,255,255,0.85);
        backdrop-filter: blur(16px) saturate(160%);
        -webkit-backdrop-filter: blur(16px) saturate(160%);
        border-bottom: 2px solid var(--red);
    }
    .mobile-topbar img { height: 32px; }
    .mobile-topbar .mt-title { font-family: var(--title-font); color: var(--red); font-size: 17px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .mobile-topbar .burger { background: none; border: none; font-size: 24px; color: var(--red); cursor: pointer; }
    .dash-main { padding: 20px 14px 0; }
    .row { flex-direction: column; }
    .row > * { flex: 1 1 auto; }

    .dash-main h2.page-title { font-size: 26px; }
    .panel { padding: 18px 14px; }
    .stat-card { padding: 14px; }
    .stat-card .stat-value { font-size: 23px; }

    .auth-panel { padding: 26px 18px; }

    .modal-overlay { padding: 14px; }
    .modal { padding: 22px 16px; }
    .modal .modal-actions .btn { flex: 1 1 auto; }

    .filters-bar .input,
    .filters-bar select.input { flex: 1 1 100%; min-width: 0; }

    .athlete-card { padding: 16px 14px; }
    .athlete-card .cf { overflow-wrap: anywhere; }

    /* Tabelle a schede su mobile: ogni riga diventa una card "etichetta: valore" (data-label da portal.js), niente scroll orizzontale */
    .table-wrap.stacked { overflow: visible; border: none; background: none; border-radius: 0; }
    table.data.stack { min-width: 0; display: block; }
    table.data.stack thead { display: none; }
    table.data.stack tbody { display: block; }
    table.data.stack tr {
        display: block;
        background: var(--panel-strong);
        border: 1px solid var(--card-border);
        border-radius: 14px;
        padding: 5px 14px;
        box-shadow: var(--shadow-subtle);
    }
    table.data.stack tr + tr { margin-top: 10px; }
    table.data.stack tr:hover td { background: none; }
    table.data.stack td {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: flex-end;
        gap: 4px 12px;
        padding: 8px 0;
        border-top: 1px solid rgba(228, 6, 19, 0.08);
        white-space: normal !important;
        text-align: right;
        overflow-wrap: anywhere;
    }
    table.data.stack td:first-child { border-top: none; }
    table.data.stack td::before {
        content: attr(data-label);
        margin-right: auto;
        font-size: 10px;
        font-weight: 800;
        text-transform: uppercase;
        letter-spacing: 0.6px;
        color: var(--red-dark);
        opacity: 0.75;
        text-align: left;
    }
    /* celle senza intestazione = azioni: bottoni larghi, comodi da toccare */
    table.data.stack td.cell-plain { gap: 8px 10px; padding: 10px 0; }
    table.data.stack td.cell-plain::before { content: none; }
    table.data.stack td.cell-plain .btn { flex: 1 1 auto; }
    table.data.stack td.cell-empty { display: none; }

    #toast { bottom: 16px; }
}
