/* ====================================
   GUANXI PHONE - Telefono Guanxi (v2 smartphone)
   ==================================== */

/* Wrapper iniettato via fetch: non deve alterare il layout */
#gx-phone-root {
    position: static;
    width: 0;
    height: 0;
    overflow: visible;
}

/* ---------- Floating tab (basso a sinistra) ---------- */
.gx-phone-tab[hidden],
.gx-phone-tab.hidden {
    display: none !important;
}

.gx-phone-tab {
    position: fixed;
    left: 16px;
    bottom: 84px; /* sopra home-dashboard-toggle (bottom 24px) */
    z-index: 300;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 14px;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, #0b93df 0%, #0d69ad 100%);
    color: #fff;
    font: inherit;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.02em;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(13, 80, 130, 0.4);
    transition: transform 180ms ease, box-shadow 180ms ease;
}

.gx-phone-tab:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(13, 80, 130, 0.5);
}

.gx-phone-tab-icon {
    font-size: 18px;
    line-height: 1;
}

.gx-phone-tab-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    display: grid;
    min-width: 19px;
    height: 19px;
    padding: 0 4px;
    place-items: center;
    border: 2px solid #0a1626;
    border-radius: 999px;
    color: #fff;
    background: #e5485d;
    font: 700 10px/1 Manrope, sans-serif;
}

.gx-phone-tab-badge[hidden] {
    display: none;
}

.gx-phone-tab.has-new-notification .gx-phone-tab-icon {
    animation: gx-phone-notification-ring 900ms ease-in-out;
}

@keyframes gx-phone-idle-pulse {
    0%, 78%, 100% { transform: scale(1); }
    82% { transform: scale(1.1); }
    86% { transform: scale(1); }
    90% { transform: scale(1.06); }
    94% { transform: scale(1); }
}

@keyframes gx-phone-notification-ring {
    0%, 100% { transform: rotate(0) scale(1); }
    15%, 45%, 75% { transform: rotate(-13deg) scale(1.08); }
    30%, 60%, 90% { transform: rotate(13deg) scale(1.08); }
}

.gx-phone-sound-toggle {
    align-self: flex-start;
    margin-top: 7px;
    padding: 6px 9px;
    border: 1px solid rgba(216, 236, 255, 0.2);
    border-radius: 999px;
    color: #d8ecff;
    background: rgba(255, 255, 255, 0.06);
    font: 600 11px/1.2 Manrope, sans-serif;
    cursor: pointer;
}

.gx-phone-sound-toggle:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

@media (max-width: 480px) {
    .gx-phone-tab-label {
        display: none;
    }
    .gx-phone-tab {
        width: 44px;
        height: 44px;
        padding: 0;
        left: 12px;
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
        border-radius: 50%;
        justify-content: center;
        transition: none;
    }
    .gx-phone-tab:hover {
        transform: none;
    }
    .gx-phone-tab-icon {
        font-size: 20px;
    }

    .gx-phone-tab:not(.has-new-notification):not([aria-expanded="true"]) .gx-phone-tab-icon {
        animation: gx-phone-idle-pulse 14s ease-in-out infinite;
    }
}

/* ---------- Telefono (shell smartphone) ---------- */
.gx-phone {
    position: fixed;
    left: 20px;
    bottom: 132px; /* sopra il tab floating */
    z-index: 310;
    width: 340px;
    max-width: calc(100vw - 28px);
    height: 560px;
    max-height: calc(100vh - 156px);
    display: flex;
    background: #0a1626;
    border: 1px solid rgba(122, 190, 235, 0.35);
    border-radius: 30px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
    overflow: hidden;
}

.gx-phone[hidden] {
    display: none;
}

/* Cornice interna: notch e schermo */
.gx-phone-shell {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    margin: 10px;
    background: linear-gradient(180deg, #0d2137 0%, #07182b 100%);
    border-radius: 22px;
    overflow: hidden;
}

/* Notch */
.gx-phone-shell::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 84px;
    height: 18px;
    background: #0a1626;
    border-radius: 999px;
    z-index: 40;
}

/* ---------- Status bar ---------- */
.gx-phone-statusbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px 6px;
    color: #d8ecff;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.gx-phone-time {
    font-variant-numeric: tabular-nums;
    padding-left: 8px;
}

.gx-phone-sysicons {
    display: flex;
    gap: 5px;
    font-size: 11px;
    padding-right: 8px;
}

/* ---------- Header home screen ---------- */
.gx-phone-homehead {
    display: flex;
    flex-direction: column;
    padding: 2px 18px 4px;
    flex-shrink: 0;
}

.gx-phone-title {
    font-size: 22px;
    font-weight: 800;
    color: #e9f6ff;
    letter-spacing: 0.01em;
}

.gx-phone-subtitle {
    font-size: 12px;
    color: #9cc9e8;
}

/* ---------- Launcher (griglia compatta) ---------- */
.gx-phone-launcher {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 8px 12px 4px;
    align-content: start;
}

/* ---------- App (compact tile) ---------- */
.gx-phone-app {
    position: relative;
    appearance: none;
    border: 0;
    background: transparent;
    color: #e9f6ff;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 2px 6px;
    border-radius: 14px;
    transition: background 160ms ease, transform 120ms ease;
}

.gx-phone-app:hover,
.gx-phone-app:focus-visible {
    background: rgba(122, 190, 235, 0.14);
    transform: translateY(-1px);
    outline: none;
}

.gx-phone-app-iconwrap {
    display: grid;
    place-items: center;
    width: 46px;
    height: 46px;
    border-radius: 13px;
    background: var(--gx-app-color, #0b93df);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.28);
    position: relative;
}

.gx-phone-app-icon {
    font-size: 22px;
    line-height: 1;
}

.gx-phone-app-name {
    font-size: 10.5px;
    font-weight: 700;
    text-align: center;
    line-height: 1.15;
    color: #d8ecff;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Lucchetto su app protette non accessibili */
.gx-phone-app.is-locked .gx-phone-app-iconwrap {
    filter: saturate(0.65) brightness(0.8);
}

.gx-phone-app-lock {
    position: absolute;
    top: 2px;
    right: calc(50% - 26px);
    font-size: 10px;
    line-height: 1;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

/* Badge contatore (messaggi/notifiche) */
.gx-phone-app-badge {
    position: absolute;
    top: -2px;
    left: calc(50% + 12px);
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.gx-phone-app-badge[hidden] {
    display: none;
}

/* ---------- Dock (barra app principali fissa) ---------- */
.gx-phone-dock {
    display: flex;
    justify-content: center;
    gap: 18px;
    padding: 10px 12px 6px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.04);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.gx-phone-dock .gx-phone-app {
    flex: 0 0 auto;
}

/* ---------- Homebar ---------- */
.gx-phone-homebar {
    width: 96px;
    height: 4px;
    border-radius: 999px;
    background: rgba(216, 236, 255, 0.5);
    margin: 4px auto 6px;
    flex-shrink: 0;
}

/* ---------- Schermate (home / app / lock) ---------- */
.gx-phone-screen {
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.gx-phone-screen.is-active {
    display: flex;
}

.gx-phone-apps {
    flex: 1;
    min-height: 0;
    overflow-y: auto;    /* Scroll interno quando ci sono tante app */
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

.gx-phone-empty {
    color: #9cc9e8;
    text-align: center;
    padding: 24px 12px;
    font-size: 13px;
}
/* ---------- Lock screen (app protette, utente non loggato) ---------- */
.gx-phone-lock {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px 20px;
    text-align: center;
}

.gx-phone-lock-icon {
    font-size: 44px;
    line-height: 1;
    width: 76px;
    height: 76px;
    display: grid;
    place-items: center;
    border-radius: 20px;
    background: rgba(122, 190, 235, 0.12);
}

.gx-phone-lock-title {
    margin: 0;
    font-size: 18px;
    color: #e9f6ff;
}

.gx-phone-lock-copy {
    margin: 0;
    font-size: 13px;
    color: #9cc9e8;
    max-width: 24ch;
}

.gx-phone-lock-actions {
    display: flex;
    gap: 12px;
    margin-top: 6px;
}

.gx-phone-lock-login,
.gx-phone-lock-register {
    appearance: none;
    border: 0;
    border-radius: 999px;
    padding: 10px 20px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 160ms ease, transform 160ms ease;
}

.gx-phone-lock-login {
    background: linear-gradient(135deg, #0b93df 0%, #0d69ad 100%);
    color: #fff;
}

.gx-phone-lock-register {
    background: rgba(255, 255, 255, 0.12);
    color: #e9f6ff;
}

.gx-phone-lock-login:hover,
.gx-phone-lock-register:hover {
    transform: translateY(-1px);
    opacity: 0.9;
}

.gx-phone-lock-back {
    appearance: none;
    border: 0;
    background: transparent;
    color: #9cc9e8;
    font-size: 13px;
    cursor: pointer;
}

.gx-phone-lock-back:hover {
    color: #e9f6ff;
}

/* Anima apertura/chiusura */
@keyframes gxPhoneIn {
    from { transform: translateY(20px) scale(0.97); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.gx-phone:not([hidden]) {
    animation: gxPhoneIn 220ms ease-out;
}
/* ========== Chat "Chiedi a Guanxi" (schermata app) ========== */
.gx-chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
    color: #e9f6ff;
    flex-shrink: 0;
}

.gx-chat-mascot {
    font-size: 24px;
    flex: 0 0 auto;
}

.gx-chat-back {
    appearance: none;
    border: 0;
    background: transparent;
    color: #9cc9e8;
    font-size: 26px;
    line-height: 1;
    padding: 0 4px 0 0;
    cursor: pointer;
    flex: 0 0 auto;
}

.gx-chat-back:hover {
    color: #e9f6ff;
}

.gx-chat-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.gx-chat-header strong {
    display: block;
    font-size: 14px;
}

.gx-chat-status {
    font-size: 11px;
    color: #7ae0c8;
}

.gx-chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding: 14px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(7, 24, 43, 0.35);
}

.gx-chat-bubble-row {
    display: flex;
    width: 100%;
}

.gx-chat-bubble-row.is-user {
    justify-content: flex-end;
}

.gx-chat-bubble {
    max-width: 78%;
    padding: 8px 11px;
    border-radius: 15px;
    font-size: 12.5px;
    line-height: 1.45;
    color: #eef7ff;
    background: rgba(255, 255, 255, 0.1);
}

.gx-chat-bubble-row.is-user .gx-chat-bubble {
    background: linear-gradient(135deg, #0b93df, #0d69ad);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.gx-chat-bubble-row.is-mascot .gx-chat-bubble {
    border-bottom-left-radius: 4px;
}

.gx-chat-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 4px 0;
}

.gx-chat-quick-btn {
    appearance: none;
    border: 1px solid rgba(122, 190, 235, 0.4);
    background: rgba(122, 190, 235, 0.12);
    color: #cfe9ff;
    border-radius: 999px;
    padding: 6px 11px;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background 160ms ease;
}

.gx-chat-quick-btn:hover {
    background: rgba(122, 190, 235, 0.24);
}

.gx-chat-input-row {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(13, 33, 55, 0.9);
    flex-shrink: 0;
}

.gx-chat-input {
    flex: 1;
    min-width: 0;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    padding: 8px 14px;
    font-size: 13px;
    outline: none;
}

.gx-chat-input:focus {
    border-color: #7ae0c8;
}

.gx-chat-send {
    appearance: none;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, #0b93df, #0d69ad);
    color: #fff;
    font-weight: 700;
    padding: 0 15px;
    font-size: 12px;
    cursor: pointer;
    transition: opacity 160ms ease;
}

.gx-chat-send:hover {
    opacity: 0.88;
}
/* ========== Responsive ========== */
/* Desktop: smartphone fluttuante stretto (definito sopra). */

/* Mobile: il telefono diventa un'interfaccia quasi a pieno schermo */
@media (max-width: 520px) {
    .gx-phone {
        left: 8px;
        right: 8px;
        top: calc(var(--gx-menu-stack-height, 92px) + 8px);
        bottom: calc(136px + env(safe-area-inset-bottom, 0px));
        width: auto;
        height: auto;
        max-height: none;
        border-radius: 26px;
    }

    .gx-phone-tab {
        z-index: 740;
    }

    .gx-phone-shell {
        margin: 8px;
        border-radius: 20px;
    }
}

@media (max-width: 380px) {
    .gx-phone-launcher {
        grid-template-columns: repeat(3, 1fr);
        gap: 4px;
        padding: 6px 8px 4px;
    }

    .gx-phone-app-iconwrap {
        width: 42px;
        height: 42px;
    }

    .gx-phone-app-icon {
        font-size: 20px;
    }
}

/* ========== Pagina fullscreen (guanxi-mobile.html) ========== */
body.gx-phone-fullscreen #gx-phone-tab {
    display: none;
}

body.gx-phone-fullscreen .gx-phone {
    position: fixed;
    left: 8px;
    right: 8px;
    top: 52px; /* sotto la topbar della pagina guanxi-mobile */
    bottom: 8px;
    width: auto;
    height: auto;
    max-height: none;
    border-radius: 28px;
    z-index: 60;
}

body.gx-phone-fullscreen .gx-phone-shell {
    margin: 10px;
    border-radius: 22px;
}

body.gx-phone-fullscreen .gx-phone-launcher {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 12px 18px;
}

/* Evita overflow orizzontale globale quando il telefono e aperto */
body.gx-phone-open {
    overflow-x: hidden;
}

@media (prefers-reduced-motion: reduce) {
    #gx-phone-tab .gx-phone-tab-icon {
        animation: none;
    }
}