/* Phone experience. Desktop and tablet retain the workspace layout. */
#mobile-nav, #mobile-menu, .phone-only, .user-bid-bar-head { display: none; }
@media (max-width: 767px) {
    /* Su :root, come --user-bid-bar-h: cosi' chi misura da JS (lista.js) la vede. */
    :root { --mobile-nav-h: calc(66px + var(--safe-bottom)); }
    body.mobile-menu-open { overflow: hidden; }
    .phone-only { display: block; }
    body > header .hdr-bar { flex-wrap: wrap; min-height: 64px; padding: 10px 16px; gap: 6px; }
    .hdr-bar #btn-menu, .workspace-nav { display: none !important; }
    .hdr-bar .workspace-brand { flex: 1; gap: 8px; }
    .hdr-bar .workspace-brand strong { display: block; font-size: 1.1rem; }
    .hdr-bar .workspace-brand .site-logo { width: 32px; height: 36px; }
    .hdr-bar .header-icon-btn { width: 42px; height: 42px; border-radius: 14px; }
    .hdr-bar .conn-status { order: 2; padding: 5px; }
    .hdr-bar .conn-status .ui-ico { font-size: .85rem; }
    .hdr-bar .hdr-search { order: 10; }
    .hdr-bar .hdr-search-input { font-size: 16px; height: 48px; padding-right: 12px; }
    .hdr-search-results { max-height: 60dvh; }
    .hdr-result { min-height: 60px; padding: 10px; }
    .hdr-result-face { width: 36px; height: 36px; }
    body > main.workspace-main { padding: 16px 14px calc(var(--mobile-nav-h) + var(--user-bid-bar-h, 0px) + 24px) !important; }
    .workspace-heading { margin-bottom: 16px; }
    .workspace-heading h1 { font-size: 1.55rem; letter-spacing: -.04em; }
    .workspace-heading p { display: none; }
    #mobile-nav { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; bottom: 0; left: 0; right: 0; height: var(--mobile-nav-h); padding: 6px 10px calc(6px + var(--safe-bottom)); background: var(--bg-surface); border-top: 1px solid var(--line); z-index: var(--z-nav); box-shadow: 0 -4px 18px #14385f08; }
    #mobile-nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 4px 2px; min-height: 0; border: 0; border-radius: 14px; background: none; color: var(--ink-3); font: 500 .72rem var(--font-ui); min-width: 0; }
    #mobile-nav button .bi { font-size: 1.3rem; line-height: 1.2; }
    #mobile-nav button span { flex-shrink: 0; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    #mobile-nav button[aria-current], #mobile-nav button.is-current { background: var(--navy-tint); color: var(--navy); font-weight: 600; }
    #mobile-menu[open] { display: block; animation: sheet-up var(--t-base) var(--ease) both; }
    #mobile-menu[open]::backdrop { animation: backdrop-in var(--t-base) var(--ease) both; }
    @keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
    @keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
    #mobile-menu { position: fixed; inset: auto 0 0; margin: 0; width: 100%; max-width: none; max-height: 90dvh; overflow: auto; border: 0; border-radius: 24px 24px 0 0; padding: 0 20px calc(24px + var(--safe-bottom)); background: var(--bg-surface); color: var(--ink-1); }
    #mobile-menu::backdrop { background: rgb(12 28 48 / 45%); }
    .mobile-sheet-handle { position: sticky; top: 0; z-index: 1; margin: 0 -20px 16px; padding: 8px 20px 0; background: var(--bg-surface); cursor: grab; }
    .mobile-sheet-grip { display: block; width: 36px; height: 4px; margin: 0 auto 10px; border-radius: 2px; background: var(--line-strong); }
    .mobile-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 8px; }
    .mobile-sheet-head h2 { font-size: 1.35rem; margin: 0; }
    .mobile-sheet-close { width: 44px; height: 44px; border: 0; border-radius: 50%; color: var(--navy); background: var(--bg-raised); }
    .mobile-sheet-section { margin-bottom: 20px; }
    .mobile-sheet-label { margin: 0 0 8px; font: 600 var(--fs-micro) var(--font-ui); letter-spacing: var(--tracking-micro); text-transform: uppercase; color: var(--ink-3); }
    /* La sezione admin sparisce quando i suoi bottoni sono nascosti per ruolo. */
    .mobile-sheet-admin:not(:has(#mobile-settings > :not([hidden]))) { display: none; }
    #mobile-install { margin-top: 4px; }
    .mobile-install-btn { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px; min-height: 54px; background: var(--navy); color: white; border: 0; border-radius: 12px; text-align: left; font: 600 .95rem var(--font-ui); }
    .mobile-install-hint { margin: 0; padding: 12px 14px; border-radius: 12px; background: var(--bg-sunken); color: var(--ink-2); font-size: .85rem; line-height: 1.5; }
    #mobile-account { display: flex; flex-direction: column; gap: 12px; }
    #mobile-account .hdr-league { width: 100%; max-width: none; height: 48px; font-size: 16px; }
    #mobile-account .user-identity { justify-content: flex-start; flex-wrap: wrap; margin: 0; }
    #mobile-account .ident-link { display: inline-flex; min-height: 40px; align-items: center; }
    #mobile-phase .phase-switch { display: flex; width: 100%; margin: 0; border-radius: 14px; padding: 4px; }
    #mobile-phase .phase-switch button { flex: 1; min-height: 44px; font-size: .85rem; border-radius: 10px; }
    #mobile-links { display: grid; gap: 8px; }
    #mobile-links button { display: flex; align-items: center; gap: 14px; padding: 14px; min-height: 54px; background: var(--bg-sunken); color: var(--navy); border: 1px solid var(--line); border-radius: 12px; text-align: left; font: 500 .95rem var(--font-ui); }
    #mobile-settings { display: flex; gap: 12px; }
    #mobile-settings [hidden] { display: none !important; }
    #mobile-settings .header-icon-btn { min-width: 48px; min-height: 48px; margin: 0; }
    #mobile-settings #btn-setup::after { content: 'Impostazioni asta'; }
    #mobile-settings #btn-admin::after { content: 'Admin'; }
    #mobile-settings .header-icon-btn { width: auto; padding: 10px; gap: 8px; font-size: .8rem; }
    .workspace-main :is(.form-control, .form-select) { min-height: 44px; font-size: 16px; }
    .workspace-main :is(.btn, .fw-seg-item, .fw-tab, .fw-chip) { min-height: 44px; }
    .workspace-main .fw-band { padding: 14px; border-radius: 18px; }
    .workspace-main .fw-band-inner { padding: 0; gap: 12px; }
    .workspace-main .fw-band-title { font-size: 1.15rem; }
    .workspace-main .fw-band-sub { font-size: .85rem; }
    .workspace-main .fw-panel { border-radius: 16px; box-shadow: none; }
    .workspace-main .fw-panel-head { padding: 14px; }
    .fw-actionbar { bottom: calc(var(--mobile-nav-h) + var(--user-bid-bar-h, 0px) + 8px); }

    /* Asta: la barra offerte e' un foglio a due stati. Compatto: una riga sopra
       la nav (faccia, nome, offerta in testa, timer, "Rilancia a N K").
       Espanso: scende a filo schermo sopra la nav e mostra importo e OFFRI. */
    #user-bid-bar { bottom: var(--mobile-nav-h); flex-direction: column; align-items: stretch; gap: 0; padding: 0; background: var(--bg-surface); border-top: 1px solid var(--line); box-shadow: 0 -6px 24px #14385f14; }
    #user-bid-bar:not(.is-expanded) :is(.user-bid-bar-inner, .user-bid-bar-player-card) { display: none; }
    #user-bid-bar.is-expanded { bottom: 0; z-index: var(--z-sheet); border-radius: 20px 20px 0 0; border-top: 0; padding-bottom: calc(8px + var(--safe-bottom)); box-shadow: var(--shadow-lg); }
    #user-bid-bar.is-expanded :is(.user-bid-bar-player-card, .user-bid-bar-quick) { display: none; }
    #user-bid-bar.is-expanded .user-bid-bar-inner { padding: 0 12px 4px; animation: bid-sheet-in var(--t-base) var(--ease) both; }
    @keyframes bid-sheet-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
    .user-bid-bar-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; min-height: 64px; min-width: 0; overflow: hidden; }
    .user-bid-bar-quick-ico { display: none; font-size: 1.2rem; line-height: 1; }
    @media (max-width: 359px) {
        /* Sui telefoni piu' stretti il verbo non ci sta: resta la freccia e la cifra. */
        .user-bid-bar-quick-verb { display: none; }
        .user-bid-bar-quick-ico { display: inline-block; }
        .user-bid-bar-quick { padding: 0 10px; }
    }
    .user-bid-bar-face { flex: 0 0 auto; width: 44px; height: 44px; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--bg-raised); color: var(--ink-2); font: 600 .85rem var(--font-ui); }
    .user-bid-bar-face img { width: 100%; height: 100%; object-fit: cover; }
    .user-bid-bar-summary { flex: 1; min-width: 0; min-height: 44px; display: flex; align-items: center; gap: 8px; padding: 0; border: 0; background: none; color: var(--ink-1); text-align: left; }
    .user-bid-bar-sum-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
    .user-bid-bar-sum-name { font: 600 .95rem/1.25 var(--font-ui); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .user-bid-bar-summary .user-bid-bar-player-bid { font-size: .8rem; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .user-bid-bar-summary .user-bid-bar-current-bid { color: var(--navy); }
    #bidbar-timer { flex: 0 0 auto; margin: 0; padding: 2px 8px; min-width: 0; font-size: 1rem; }
    #bidbar-timer:empty { display: none; }
    .user-bid-bar-chevron { flex: 0 0 auto; color: var(--ink-3); transition: transform var(--t-base) var(--ease); }
    #user-bid-bar.is-expanded .user-bid-bar-chevron { transform: rotate(180deg); }
    .user-bid-bar-quick { flex: 0 0 auto; min-height: 44px; padding: 0 14px; border-radius: 12px; font-weight: 700; white-space: nowrap; }
    .user-bid-bar-quick:disabled { opacity: .5; }
    #user-bid-bar .user-bid-bar-meta { font-size: .8rem; }

    /* Tabellone: prima il giocatore chiamato e le offerte, poi le rose. La card
       "in testa" e' ridondante con il foglio e con la card del giocatore. */
    #tab-dashboard .active-player-layout { flex-direction: column; gap: 12px; }
    #tab-dashboard .bidder-card-left { display: none; }
    #tab-dashboard .bids-history-right { max-width: none; opacity: 1; min-height: 180px; }
    #tab-dashboard .active-player-card-centered .active-player-top { gap: 12px; }
    /* La foto (o il segnaposto con le iniziali) non deve mangiare mezzo schermo. */
    #tab-dashboard .player-image-container { width: 96px; height: 120px; min-height: 0; flex: 0 0 auto; }
    #tab-dashboard .player-image-container :is(.player-image, .player-image-fallback) { width: 100%; height: 100%; font-size: 1.8rem; }
    #tab-dashboard .active-player-info { flex: 1 1 100%; min-width: 0; }
    #tab-dashboard .active-player-header { flex-wrap: wrap; justify-content: flex-start; align-items: center; gap: 4px 8px; }
    #tab-dashboard .player-name-big { font-size: 1.2rem; margin: 0; overflow-wrap: anywhere; }
    #tab-dashboard .player-team-serie-a { flex-basis: 100%; }
    .modal-dialog { margin: 8px; }
    .modal-content { border-radius: 20px; }
    .modal-body { padding: 14px; }
    .modal-header .btn-close { min-width: 44px; min-height: 44px; padding: 0; margin: -8px; }
    .hdr-notif-panel { z-index: var(--z-dropdown); max-height: 70dvh; overflow: auto; }

    /* Cambio di vista: dissolvenza breve. Solo opacita': una trasformazione
       farebbe da contenitore ai bottoni fissi dentro il tab (Salva formazione). */
    .tab-content.active { animation: tab-in 180ms var(--ease) both; }
    @keyframes tab-in { from { opacity: 0; } to { opacity: 1; } }

    /* Modali a foglio (.fw-sheet): salgono dal basso a tutta altezza, con
       una maniglia; il corpo scorre da solo. La scheda giocatore le usa. */
    .modal-dialog.fw-sheet { margin: 0; width: 100%; max-width: 100%; height: 100dvh; min-height: 0; align-items: flex-end; }
    .modal-dialog.fw-sheet .modal-content { height: calc(100dvh - 24px); max-height: none; border: 0; border-radius: 20px 20px 0 0; }
    .modal-dialog.fw-sheet .modal-header { position: relative; padding-top: 22px; cursor: grab; }
    .modal-dialog.fw-sheet .modal-header::before { content: ""; position: absolute; top: 8px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--line-strong); z-index: 1; }
    .modal-dialog.fw-sheet .modal-header.modal-header-band::before { background: rgb(255 255 255 / 60%); }
    .modal-dialog.fw-sheet .modal-body { overflow-y: auto; overscroll-behavior: contain; padding-bottom: calc(16px + var(--safe-bottom)); }
    .modal.fade .modal-dialog.fw-sheet { transform: translateY(100%); transition: transform var(--t-base) var(--ease); }
    .modal.show .modal-dialog.fw-sheet { transform: none; }

    /* Toast: in basso sopra barra e foglio offerta, a tutta larghezza, salgono. */
    #notifications { top: auto; bottom: calc(var(--mobile-nav-h) + var(--user-bid-bar-h, 0px) + 12px); left: 12px; right: 12px; pointer-events: none; }
    #notifications .notification { max-width: none; pointer-events: auto; animation: toast-up var(--t-base) var(--ease); }
    #notifications .notification.fade-out { animation: fade-out .3s ease forwards; }
    @keyframes toast-up { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }

    /* Lineup: compact context, then one task at a time. */
    .fm-wrap { padding: 0; gap: 12px; }
    #fm-body { scroll-margin-top: calc(var(--workspace-header) + 12px); }
    .fm-band .fw-band-crest { display: none; }
    .fm-band .fm-band-id { width: 100%; }
    .fm-band .fm-band-kpis { width: auto; gap: 16px; }
    .fm-band-kpi { min-width: 0; }
    .fm-band-val { font-size: 1.15rem; }
    .fm-band-sub { display: none; }
    .fm-toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
    .fm-toolbar .fm-team-picker { grid-column: 1 / -1; }
    .fm-field-label :is(input, select) { width: 100%; min-width: 0; }
    .fm-field-label { font-size: .7rem; }
    .fm-actions { grid-column: 1 / -1; margin: 0; gap: 8px; }
    .fm-actions .btn-primary { margin-left: auto; min-width: 100px; }
    #tab-formazione.active .fm-actions .btn-primary { position: fixed; bottom: calc(var(--mobile-nav-h) + var(--user-bid-bar-h, 0px) + 10px); left: 14px; right: 14px; width: calc(100% - 28px); min-height: 48px; margin: 0; background: var(--navy); color: white; border-color: var(--navy); border-radius: 14px; box-shadow: var(--shadow-md); z-index: calc(var(--z-nav) - 10); }
    body:has(#tab-formazione.active .fm-actions .btn-primary) > main.workspace-main { padding-bottom: calc(var(--mobile-nav-h) + var(--user-bid-bar-h, 0px) + 88px) !important; }
    .fm-phone-tabs, .fr-phone-tabs { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--bg-raised); margin-bottom: 12px; }
    .fm-phone-tabs button, .fr-phone-tabs button { flex: 1; min-height: 44px; border: 0; border-radius: 10px; background: transparent; font: 500 .85rem var(--font-ui); color: var(--ink-2); }
    .fm-phone-tabs button[aria-pressed="true"], .fr-phone-tabs button[aria-pressed="true"] { background: var(--bg-surface); color: var(--navy); box-shadow: var(--shadow-sm); }
    #fm-body[data-phone-view="campo"] :is(.fm-side, .fm-giornata, .fm-analysis),
    #fm-body[data-phone-view="rosa"] :is(.fm-main, .fm-giornata, .fm-analysis),
    #fm-body[data-phone-view="giornata"] .fm-layout { display: none; }
    #fm-body .fm-layout { grid-template-columns: minmax(0, 1fr); gap: 0; }
    .fm-main.fr-top11-col { padding: 6px; border-radius: 16px; }
    .fm-pitch.formation-field { min-height: 440px; }
    .fm-side { max-height: none; overflow: visible; position: static; }
    .fm-rosa { max-height: none; padding: 12px; }
    .fm-rosa-row { min-height: 56px; padding: 8px 4px; gap: 10px; border-bottom: 1px solid var(--line); font-size: .9rem; }
    .fm-rosa-img { width: 36px; height: 36px; }
    .fm-rosa-media { font-size: .8rem; }
    .fm-rosa-head { padding-bottom: 12px; }
    .fm-rosa-group { margin-top: 16px; }
    .fm-rosa-title { font-size: .75rem; }
    .fm-phone-selection { padding: 12px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--navy-tint); color: var(--navy); margin-bottom: 12px; font-size: .85rem; }
    .fm-phone-selection p { margin: 0 0 8px; }
    .fm-phone-selection .btn { margin: 4px 4px 0 0; }
    .fm-bench-btn { min-width: 44px; min-height: 44px; }
    .fm-bench-row { min-height: 56px; }
    .fm-analysis { margin-top: 12px; }

    /* Squad: scan people first; the recommended XI has its own view. */
    .fr-wrap { gap: 12px; }
    .fr-team-picker { max-width: none; }
    .fr-band-avatar .avatar { width: 48px !important; height: 48px !important; }
    .fr-band .fr-band-inner { gap: 16px; }
    .fr-band-id { gap: 12px; }
    .fr-band-motto, .fr-band-manca { font-size: .8rem; }
    .fr-band-destra { width: 100%; gap: 8px; }
    .fr-band-kpis { width: 100%; justify-content: space-between; gap: 8px; }
    .fr-band-kpi { min-width: 0; gap: 0; }
    .fr-band-kpi-ico, .fr-band-sub, .fr-maglia-thumb { display: none; }
    .fr-band-val { font-size: 1.2rem; }
    .fr-band-identita:has(.fr-band-azioni) { margin-top: 8px; }
    .fr-band-identita:not(:has(.fr-band-azioni)) { display: none; }
    .fr-phone-tabs { margin-top: 14px; }
    .fr-body-grid { display: block; }
    .fr-body-grid[data-phone-view="rosa"] > .fr-top11-col,
    .fr-body-grid[data-phone-view="campo"] > .fr-roster-col { display: none; }
    .fr-role-filters { display: flex; gap: 6px; padding: 10px 12px; }
    .fr-role-filters button { flex: 1; min-height: 42px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg-surface); color: var(--ink-2); font: 500 .85rem var(--font-ui); }
    .fr-role-filters button[aria-pressed="true"] { background: var(--navy); color: white; border-color: var(--navy); }
    .fr-tabella-wrap[data-role-filter="P"] .fr-gruppo:not([data-role="P"]),
    .fr-tabella-wrap[data-role-filter="D"] .fr-gruppo:not([data-role="D"]),
    .fr-tabella-wrap[data-role-filter="C"] .fr-gruppo:not([data-role="C"]),
    .fr-tabella-wrap[data-role-filter="A"] .fr-gruppo:not([data-role="A"]) { display: none; }
    .fr-tabella .fr-row { height: 62px; }
    .fr-tabella .lst-face { width: 32px; height: 36px; }
    .fr-tabella .fr-nome { font-size: .875rem; white-space: normal; }
    .fr-tabella .fr-c-fv { font-size: .9rem; font-weight: 600; }
    .fr-tabella .fr-c-stato .etichetta-chip { white-space: normal; font-size: .68rem; }
    .fr-toolbar { flex-wrap: wrap; gap: 8px; }
    .fr-toolbar .fw-seg { width: 100%; height: auto; }
    .fr-toolbar .fr-modulo { width: 100%; height: 44px; }
    .fr-bench-rows { grid-template-columns: 1fr; }

    /* League: readable standings, with full statistics one tap away. */
    .lg-band-kpis { gap: 16px; width: 100%; }
    .lg-band-kpi { min-width: 0; }
    .lg-band-val { font-size: 1.2rem; }
    .lg-band-sub { display: none; }
    .lg-classifica:not(.is-detailed) .lg-tab-classifica :is(th, td):is(:nth-child(4), :nth-child(5), :nth-child(6), :nth-child(7), :nth-child(8), :nth-child(10), :nth-child(11)) { display: none; }
    .lg-classifica.is-detailed .lg-tab-classifica { min-width: 720px; }
    .lg-classifica.is-detailed .lg-tab-classifica :is(th, td) { display: table-cell; }
    .lg-tab-classifica :is(th, td) { padding: 14px 8px; }
    .lg-tab-classifica .lg-nome { white-space: normal; font-size: .875rem; }
    .lg-tab-classifica .lg-c-nome { width: auto; max-width: none; }
    .lg-tab-classifica .lg-squadra .avatar { width: 28px !important; height: 28px !important; }
    .lg-classifica .phone-only { margin: 0 12px 12px; width: calc(100% - 24px); }
    .lg-spiega { font-size: .8rem; line-height: 1.6; }
    .lg-wrap .fw-tabs { flex-wrap: nowrap; overflow-x: auto; }
    .lg-wrap .fw-tab { flex: 1 0 auto; justify-content: center; padding-inline: 12px; }
    .lg-riga { min-height: 44px; }
}
