/* ===== CSS RESPONSIVE MOBILE ===== */
@media (max-width: 768px) {
    /* Layout principale */
    body {
        font-size: 16px; /* Reset to reasonable value */
        line-height: 1.5;
        overflow-x: hidden;
        touch-action: manipulation;
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Disabilita completamente il pinch-to-zoom */
    * {
        touch-action: manipulation !important;
        -webkit-touch-callout: none !important;
        -webkit-user-select: none !important;
        -moz-user-select: none !important;
        -ms-user-select: none !important;
        user-select: none !important;
    }
    
    /* Larghezza fissa per mobile/tablet */
    .layout-grid {
        width: 100% !important; 
        max-width: 100% !important;
        min-width: 100% !important;
        box-sizing: border-box;
        padding: 0 !important; /* Azzerato padding laterale */
    }
    
    /* Assicura che tutti i contenitori si adattino */
    * {
        box-sizing: border-box !important;
        max-width: 100% !important;
    }
    
    /* Fix per contenitori principali */
    .content-wrapper,
    .main-content,
    .main-feed,
    .sidebar,
    .friends-sidebar,
    .friends-main {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        padding-left: 0 !important; /* Azzerato per touch edge */
        padding-right: 0 !important; /* Azzerato per touch edge */
    }
    
    .app-container {
        padding-left: 0 !important;
        padding-right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Fix specifico per sidebar - NASCONDI DESKTOP SIDEBARS */
    .sidebar-left,
    .sidebar-right,
    .sidebar:not(.mobile-menu-sidebar) {
        display: none !important;
    }
    
    .sidebar-nav {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        padding: 5px !important;
        margin: 0 !important;
    }
    
    .content-wrapper {
        flex-direction: column;
        padding: 10px;
        gap: 15px;
        max-width: 100%;
        overflow-x: hidden;
    }
    
    .main-content {
        width: 100%;
        order: 1;
        max-width: 100%;
        overflow-x: hidden;
    }
    
    .main-feed {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important; /* Forza a 0 per far toccare i bordi */
        margin: 0 !important;
        overflow-x: hidden;
    }
    
    /* Fix principale per layout-grid - converte da 3 colonne a 1 colonna */
    .layout-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px;
        padding: 10px 0 !important; /* Rimosso padding laterale per touch screen edge */
        max-width: 100% !important;
        width: 100% !important;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    
    /* Fix per layout-grid two-column (friends.php) */
    .layout-grid.two-column {
        display: flex !important;
        flex-direction: column !important;
        gap: 15px;
        padding: 10px 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    
    .posts-container {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    
    .friends-main {
        width: 100%;
        max-width: 100%;
        padding: 10px;
        margin: 0;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    
    .sidebar {
        width: 100% !important;
        order: 2;
        margin-top: 0;
        max-width: 100% !important;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    
    .friends-sidebar {
        width: 100% !important;
        order: 2;
        margin-top: 0;
        max-width: 100% !important;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    
    /* Header responsive */
    .header-container {
        flex-direction: column;
        gap: 15px;
        padding: 10px;
    }
    
    .search-section {
        width: 100%;
        order: 2;
    }
    
    .user-menu {
        order: 3;
        justify-content: center;
    }
    
    .search-input {
        font-size: 16px; /* Previene zoom su iOS */
        padding: 12px;
    }
    
    /* Post responsive */
    .post {
        padding: 15px;
        margin-bottom: 0;
        border-bottom: 1px solid #e4e6ea;
    }
    
    .post:last-child {
        border-bottom: none;
    }
    
    .post-header {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: flex-start !important;
        gap: 10px;
    }
    
    .post-content {
        font-size: 1rem;
        line-height: 1.5;
    }
    
    .post-actions {
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .post-action {
        padding: 8px 12px;
        font-size: 14px;
    }
    
    /* Avatar più grandi su mobile */
    .post-avatar {
        width: 32px !important;
        height: 32px !important;
    }
    
    .suggestion-avatar {
        width: 40px !important;
        height: 40px !important;
    }
    
    .comment-avatar {
        width: 32px !important;
        height: 32px !important;
    }
    
    /* Form responsive */
    .form-input, .form-textarea, .form-select {
        font-size: 16px;
        padding: 12px;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    .btn {
        padding: 12px 20px;
        font-size: 16px;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Sidebar responsive */
    .sidebar-item {
        padding: 12px 15px;
        font-size: 16px;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        text-align: left;
    }
    
    .sidebar-title {
        font-size: 18px;
        margin-bottom: 12px;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        text-align: left;
    }
    
    /* Card responsive */
    .card-title {
        font-size: 1.25rem;
        margin-bottom: 15px;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    .card-content {
        font-size: 1rem;
        line-height: 1.5;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Immagini responsive */
    img {
        max-width: 100% !important;
        height: auto !important;
        object-fit: contain !important;
    }
    
    .post-image {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        object-fit: cover !important;
        display: block !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Fix specifico per immagini nei post (esclude gli avatar) */
    .post .post-image,
    .post img:not(.post-avatar),
    .post-content img:not(.post-avatar) {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        object-fit: cover !important;
        display: block !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }
    
    /* Fix per post e contenitori */
    .post,
    .content-card,
    .notification-card,
    .post-card {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding: 0 !important; /* Rimosso padding laterale dalla card */
        border-radius: 0 !important; /* Bordi piatti per app feel */
        border-left: none !important;
        border-right: none !important;
    }
    
    /* Ripristiniamo il padding solo per il contenuto testuale */
    .post-header {
        padding-left: 6px !important;
        padding-right: 6px !important;
    }
    .post-text, 
    .post-footer, 
    .post-rating-section,
    .post-hashtags,
    .post-body {
        padding-left: 6px !important;
        padding-right: 6px !important;
        text-align: left !important;
        display: block !important;
    }
    
    /* Fix per header e search */
    .header-container {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        padding-left: 5px !important;
        padding-right: 5px !important;
    }
    
    .search-section {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Sidebar sections */
    .sidebar-section {
        padding: 15px;
        margin-bottom: 1px;
    }
    
    .sidebar-title {
        font-size: 16px;
        margin-bottom: 12px;
    }
    
    /* Stats grid */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 4px;
        width: 100%;
        box-sizing: border-box;
        margin: 0;
        padding: 0;
    }
    
    .stat-item {
        padding: 10px 4px;
        box-sizing: border-box;
        min-width: 0;
        overflow: hidden;
    }
    
    /* Dropdown menu */
    .dropdown-menu {
        position: fixed !important;
        top: auto !important;
        right: 10px !important;
        left: 10px !important;
        width: auto !important;
        max-width: none !important;
    }
    
    /* Pagine specifiche - Fix overflow mobile */
    .notifications-page,
    .profile-page,
    .saved-posts-page {
        width: 100%;
        max-width: 100%;
        padding: 0 10px;
        box-sizing: border-box;
        overflow-x: hidden;
    }
    
    /* Fix specifico per contenitori che potrebbero causare overflow */
    .profile-container,
    .notifications-container,
    .saved-posts-container {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    
    .page-header {
        padding: 15px 0;
        margin-bottom: 15px;
    }
    
    .page-header h1 {
        font-size: 20px;
        margin: 0;
    }
    
    /* Cards responsive */
    .content-card,
    .notification-card,
    .post-card {
        width: 100%;
        max-width: 100%;
        padding: 15px;
        margin-bottom: 15px;
        box-sizing: border-box;
        overflow-x: hidden;
    }
    
    /* Fix per post e contenuti che potrebbero causare overflow */
    .post,
    .notification-item,
    .suggestion-item {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
        box-sizing: border-box;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    /* Fix per tabelle e contenuti larghi */
    .notification-content,
    .post-content,
    .user-info,
    .suggestion-info,
    .suggestion-name,
    .suggestion-mutual {
        word-wrap: break-word;
        overflow-wrap: break-word;
        max-width: 100%;
    }
    
    /* Fix specifico per index.php */
    .sidebar-nav {
        flex-direction: column;
        gap: 10px; /* Aumentato da 8px */
    }
    
    .sidebar-item {
        padding: 14px 16px; /* Aumentato da 12px 15px */
        font-size: 16px; /* Aumentato da 14px */
        text-align: left;
    }
    
    .suggestion-item {
        flex-direction: column;
        align-items: center;
        text-align: center;
        padding: 18px; /* Aumentato da 15px */
    }
    
    .suggestion-avatar {
        width: 60px;
        height: 60px;
        margin-bottom: 10px;
    }
    
    .suggestion-name {
        font-size: 1.1rem;
        margin-bottom: 5px;
    }
    
    .suggestion-mutual {
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    /* Extra small screens */
    .content-wrapper {
        padding: 20px; /* Aumentato da 16px */
    }
    
    .post {
        padding: 40px; /* Aumentato da 32px */
        margin-bottom: 0; /* Rimosso spazio tra i post */
        border-bottom: 1px solid #e4e6ea;
    }
    
    .post:last-child {
        border-bottom: none;
    }
    
    .sidebar-section {
        padding: 40px; /* Aumentato da 32px */
        margin-bottom: 1px; /* Ridotto a 1px */
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 30px; /* Aumentato da 24px */
    }
    
    .post-actions {
        justify-content: space-around;
    }
    
    .post-action {
        flex: 1;
        text-align: center;
        padding: 12px 8px;
        font-size: 12px;
    }
    
    .header-container {
        padding: 8px;
    }
    
    .search-input {
        padding: 12px 16px;
        font-size: 14px;
    }
    
    /* Avatar ancora più grandi su schermi molto piccoli */
    .post-avatar {
        width: 32px !important;
        height: 32px !important;
    }
    
    .suggestion-avatar {
        width: 170px !important; /* Aumentato da 136px */
        height: 170px !important;
    }
    
    /* Extra fix per pagine problematiche su schermi piccoli */
    .notifications-page,
    .profile-page,
    .saved-posts-page {
        padding: 0 5px;
        overflow-x: hidden;
    }
    
    .content-card,
    .notification-card,
    .post-card {
        padding: 12px;
        margin-bottom: 12px;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    
    /* Fix aggiuntivo per contenitori principali */
    .layout-grid,
    .layout-grid.two-column {
        padding: 5px;
        gap: 10px;
        overflow-x: hidden;
        box-sizing: border-box;
    }
    
    .page-header h1 {
        font-size: 18px;
    }
    
    /* Extra fix per index.php su schermi piccoli - rimosso duplicato */
    
    .sidebar-item {
        padding: 15px 10px; /* Ridotto per evitare overflow */
        font-size: 20px; /* Ridotto per adattarsi meglio */
        text-align: center; /* Centra il testo */
    }
    
    .suggestion-item {
        padding: 20px; /* Ridotto per evitare overflow */
    }
    
    .suggestion-avatar {
        width: 80px; /* Ridotto per evitare overflow */
        height: 80px;
        margin-bottom: 15px; /* Ridotto */
    }
    
    .suggestion-name {
        font-size: 20px; /* Ridotto per adattarsi meglio */
    }
    
    .suggestion-mutual {
        font-size: 16px; /* Ridotto per adattarsi meglio */
    }
}

/* ===== MENU DI CONDIVISIONE (MODAL) ===== */
.share-menu {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.55);
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    transition: opacity 0.2s ease;
}

.share-menu[style*="block"],
.share-menu.is-visible {
    display: flex !important;
}

.share-menu-content {
    background: #ffffff !important;
    border-radius: 16px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
    animation: shareMenuSlideIn 0.25s ease-out;
    overflow: hidden;
    color: #1c1e21 !important;
}

.share-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #e4e6ea;
}

.share-menu-header h3 {
    font-size: 18px;
    color: #1c1e21 !important;
    margin: 0;
}

.share-menu-close {
    background: none;
    border: none;
    font-size: 24px;
    color: #65676b;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.share-menu-close:hover {
    background-color: #f0f2f5;
    color: #1c1e21;
}

.share-menu-options {
    display: flex;
    flex-direction: column;
    padding: 12px 0;
}

.share-option {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 16px 24px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 16px;
    color: #1c1e21 !important;
    gap: 16px;
}

.share-option svg {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
}

.share-option span {
    font-weight: 500;
}

.share-option:hover {
    background-color: #f0f2f5;
}

.share-option.facebook-share svg { color: #1877f2; }
.share-option.twitter-share svg { color: #1d9bf0; }
.share-option.copy-link svg { color: #65676b; }

@keyframes shareMenuSlideIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

@media (max-width: 600px) {
    .share-menu-content {
        max-width: 360px;
        border-radius: 12px;
    }

    .share-option {
        padding: 14px 18px;
        font-size: 15px;
    }
}

/* ==== MOBILE NORMALIZATION OVERRIDES (solo mobile, non impattano desktop) ==== */
@media (max-width: 768px) {
    /* Tipografia globale */
    body { font-size: 14px; line-height: 1.34; }

    /* Post actions su una riga con testo visibile */
    .post-actions { flex-wrap: nowrap; gap: 8px; justify-content: space-between; }
    .post-action {
        padding: 6px 8px;
        font-size: 13px;
        flex: 1 1 0;
        min-width: 0;
        white-space: nowrap;
    }
    /* Rating subito sotto */
    .post-rating-section { margin-top: 8px; }
    /* Testo post dimensione coerente */
    .post-content { font-size: 14px; line-height: 1.4; }

    /* Ridimensiona avatar in liste e commenti */
    .suggestion-avatar { width: 40px !important; height: 40px !important; }
    .comment-avatar { width: 32px !important; height: 32px !important; }
    
    .composer-trigger-left .avatar-sm {
        width: 36px !important;
        height: 36px !important;
    }

    /* Form e bottoni */
    .form-input, .form-textarea, .form-select { font-size: 14px; padding: 12px; }
    .btn { padding: 10px 16px; font-size: 14px; width: auto; }

    /* Profile.php → Informazioni */
    .info-item { padding: 6px 0; }
    .info-item label, .info-item span { font-size: 14px; line-height: 1.4; }
    .info-item label { min-width: 100px; }

    /* Profile.php → Amici */
    .friends-list .friend-avatar { width: 40px !important; height: 40px !important; }
    .friends-list .friend-name {
        font-size: 14px;
        line-height: 1.3;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        text-overflow: ellipsis;
        word-break: break-word;
        text-align: center;
    }

    /* Fix Avatars Header e Menu Mobile */
    .header-avatar {
        width: 28px !important;
        height: 28px !important;
        border-radius: 50% !important;
        object-fit: cover !important;
        flex-shrink: 0;
        border: 1.5px solid var(--border-color);
    }
    
    .mobile-menu-profile {
        padding: 24px 20px;
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 12px;
        border-bottom: 1px solid var(--border-color);
        background: var(--bg-soft);
    }

    .mobile-menu-avatar {
        width: 80px !important;
        height: 80px !important;
        border-radius: 50% !important;
        object-fit: cover !important;
        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        border: 3px solid white;
    }

    .mobile-menu-profile-info {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    .mobile-menu-profile-info .username {
        font-weight: 700;
        font-size: 1.1rem;
        color: var(--text-primary);
        display: block;
    }

    .mobile-menu-profile-info .view-profile {
        font-size: 0.9rem;
        color: var(--primary);
        font-weight: 600;
    }

    /* Immagini post più grandi (Effetto Full-Screen totale) */
    .post-media-container {
        margin: 10px 0 !important;
        width: 100% !important;
        max-width: none !important;
        padding: 0 !important;
        background: transparent !important;
        overflow: hidden !important;
        display: block !important;
    }

    .post-image {
        width: 100% !important;
        min-width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        display: block !important;
        margin: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        object-fit: cover !important;
    }
}

@media (max-width: 480px) {
    .post-actions { justify-content: space-between; gap: 6px; }
    .post-action { padding: 4px 6px; font-size: 12px; min-width: 0; }
}

/* ===== STILI INLINE EDIT POST (Aggiunti per migliorare usabilità e caricamento immagini) ===== */
.inline-edit-form {
    padding: 16px;
    background: #f8f9fa;
    border-radius: 8px;
    margin: 8px 0;
    border: 1px solid #e1e8ed;
}

.inline-edit-form .form-group {
    margin-bottom: 12px;
}

.inline-edit-form .form-label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
    color: #1c1e21;
    font-size: 14px;
}

.inline-edit-form textarea {
    min-height: 80px;
    resize: vertical;
}

.inline-edit-textarea {
    min-height: 350px !important;
    max-height: 70vh !important;
    overflow: auto !important;
    line-height: 1.4 !important;
    resize: vertical !important;
    width: 100% !important;
    padding: 12px !important;
    font-size: 15px !important;
    user-select: text !important;
    -webkit-user-select: text !important;
    -moz-user-select: text !important;
    -ms-user-select: text !important;
}

.inline-edit-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 12px;
}

.inline-edit-actions .btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.inline-edit-actions .btn-secondary {
    background: #e4e6ea;
    color: #1c1e21;
    border: none;
}

.inline-edit-actions .btn-secondary:hover {
    background: #d8dadf;
}

.inline-edit-actions .btn-primary {
    background: #1877f2;
    color: white;
    border: none;
}

.inline-edit-actions .btn-primary:hover {
    background: #166fe5;
}

.inline-edit-actions .btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Stili per la preview e gestione immagini nel form di modifica inline */
.inline-edit-image-group {
    margin-top: 15px;
    border-top: 1px solid #e4e6ea;
    padding-top: 15px;
}

.inline-edit-image-preview-container {
    background: #f0f2f5;
    padding: 10px;
    border-radius: 8px;
    border: 1px dashed #dadde1;
    display: inline-block;
    max-width: 100%;
    margin-bottom: 12px;
}

.inline-edit-image-preview {
    max-width: 100%;
    max-height: 220px;
    border-radius: 6px;
    display: block;
    object-fit: contain;
}

.inline-edit-remove-image-btn {
    display: inline-block;
    margin-top: 8px;
    background-color: #dc3545 !important;
    color: white !important;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    width: auto !important;
}

.inline-edit-remove-image-btn:hover {
    background-color: #bd2130 !important;
}

.inline-edit-file-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.inline-edit-trigger-file-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background-color: #f0f2f5 !important;
    color: #1877f2 !important;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    width: auto !important;
}

.inline-edit-trigger-file-btn:hover {
    background-color: #e4e6ea !important;
}
