/* --- THEME VARIABLES --- */
:root {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f9fafb; /* gray-50 */
    --bg-interactive: #e5e7eb; /* gray-200 */
    --text-primary: #1f2937; /* gray-800 */
    --text-secondary: #4b5563; /* gray-600 */
    --text-link: #4f46e5; /* indigo-600 */
    --border-color: #e5e7eb; /* gray-200 */
    --shadow-color: rgba(0,0,0,0.1);
    /* Header uses dark theme for both light and dark mode */
    --bg-header: rgba(31, 41, 55, 0.9); /* dark:bg-gray-800/90 */
    --header-text-primary: #f9fafb; /* gray-50 - light text for dark header */
    --header-text-secondary: #d1d5db; /* gray-300 - light secondary text */
    --header-text-hover: #ffffff; /* white on hover */
    --header-bg-hover: rgba(75, 85, 99, 0.5); /* gray-600 with opacity */
    --header-border-color: #4b5563; /* gray-600 - dark border */
}

html.dark {
    --bg-primary: #111827; /* gray-900 */
    --bg-secondary: #1f2937; /* gray-800 */
    --bg-tertiary: #374151; /* gray-700 */
    --bg-interactive: #4b5563; /* gray-600 */
    --text-primary: #f9fafb; /* gray-50 */
    --text-secondary: #d1d5db; /* gray-300 */
    --text-link: #818cf8; /* indigo-400 */
    --border-color: #4b5563; /* gray-600 */
    --shadow-color: rgba(0,0,0,0.4);
    /* NEW: Header background with opacity for dark mode */
    --bg-header: rgba(31, 41, 55, 0.9); /* dark:bg-gray-800/90 */
}
/* --- END THEME VARIABLES --- */


/* --- ANIMATIONS --- */
@keyframes fadeOutUp {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}

.flash-fade-out {
    animation: fadeOutUp 0.5s ease-out forwards;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes loaderFadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}
/* --- END ANIMATIONS --- */


/* --- NEW: Page Loader Styles --- */
body.loading-active {
    overflow: hidden;
}

.page-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--bg-primary);
    opacity: 0.95;
    z-index: 9998;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.3s ease;
}

.loader-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid var(--border-color);
    border-top-color: var(--text-link);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 9999;
}

.loader-fade-out {
    animation: loaderFadeOut 0.3s ease-out forwards;
}
/* --- END: Page Loader Styles --- */


/* --- BASE STYLES --- */
body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* This container is for the old centered layout */
.main-container {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
    /* This ensures it still works on non-profile pages */
    max-width: 42rem; /* max-w-2xl */
    width: 100%;
    padding: 2rem; /* p-8 */
    border-radius: 0.5rem; /* rounded-lg */
    box-shadow: 0 10px 15px -3px var(--shadow-color), 0 4px 6px -2px var(--shadow-color); /* shadow-xl */
    border-width: 1px;
}

/* This is the new full-width container for profile/etc */
.page-container {
    max-width: 1536px; /* max-w-screen-2xl */
    margin-left: auto;
    margin-right: auto;
    padding-left: 1rem;
    padding-right: 1rem;
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
}

.primary-text {
    color: var(--text-primary);
}

.secondary-text {
    color: var(--text-secondary);
}

.name-link {
    font-weight: 600; /* semibold */
    color: var(--text-primary);
    text-decoration: none;
}
.name-link:hover {
    text-decoration: underline;
}

.post-card {
    background-color: var(--bg-tertiary);
    border-color: var(--border-color);
    border-radius: 0.75rem; /* rounded-xl */
    box-shadow: 0 1px 2px 0 var(--shadow-color); /* shadow-sm */
    border-width: 1px;
}

.comment-section {
    border-color: var(--border-color);
}
/* --- END BASE STYLES --- */


/* --- NEW: Profile Layout Styles --- */
.sticky-header {
    position: sticky;
    top: 0;
    z-index: 40;
    backdrop-filter: blur(10px);
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--header-border-color);
}

.header-nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem; /* space between icon and text */
    padding: 0.5rem 1rem; /* py-2 px-4 */
    font-size: 0.875rem; /* text-sm */
    font-weight: 500; /* font-medium */
    color: var(--header-text-secondary);
    border-radius: 0.5rem; /* rounded-lg */
    transition: background-color 0.2s ease, color 0.2s ease;
    white-space: nowrap;
}
.header-nav-link:hover {
    background-color: var(--header-bg-hover);
    color: var(--header-text-hover);
}

/* Active state */
.header-nav-link.active {
    background-color: var(--header-bg-hover);
    color: var(--header-text-primary);
    font-weight: 600;
}

/* Mobile: hide text, show only icons */
@media (max-width: 768px) {
    .header-nav-link .nav-text {
        display: none;
    }
    .header-nav-link {
        padding: 0.5rem; /* Back to standard padding for proper icon sizing */
    }
    /* Very small gap between nav items on mobile - profile pic is hidden so we have space */
    #main-navigation {
        gap: 0.125rem; /* 2px gap - just enough */
    }
    /* Reduce padding in main container on mobile */
    .sticky-header .max-w-screen-2xl {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    /* Remove margin on notification bell on mobile */
    .notification-button {
        margin-left: 0 !important;
    }
}

/* Mid-width (tablet): hide text to prevent overlap with logo */
@media (min-width: 769px) and (max-width: 1023px) {
    .header-nav-link .nav-text {
        display: none;
    }
    .header-nav-link {
        padding: 0.5rem;
    }
    #main-navigation {
        gap: 0.25rem;
    }
}

/* Desktop (lg and up): show text again */
@media (min-width: 1024px) {
    .header-nav-link .nav-text {
        display: inline;
    }
    .header-nav-link {
        padding: 0.5rem 1rem; /* Restore full padding */
    }
    #main-navigation {
        gap: 0.25rem;
    }
    /* Increase icon size on desktop to match larger logo */
    .header-nav-link svg {
        width: 1.5rem;  /* 24px (w-6) */
        height: 1.5rem; /* 24px (h-6) */
    }
    /* Also increase notification bell and settings icons */
    .notification-button svg,
    button[onclick*="openSettingsModal"] svg {
        width: 1.75rem;  /* 28px (w-7) */
        height: 1.75rem; /* 28px (h-7) */
    }
}

/* Mobile: hide profile picture */
@media (max-width: 768px) {
    .profile-pic-link {
        display: none;
    }
}

/* Tablet and up: show profile picture */
@media (min-width: 769px) {
    .profile-pic-link {
        display: block;
    }
}

.profile-sidebar {
    position: sticky;
    top: 80px; /* Adjust based on sticky-header height */
    height: calc(100vh - 96px); /* Adjust based on sticky-header height + padding */
    overflow-y: auto;
}

.custom-scrollbar::-webkit-scrollbar {
    width: 8px;
}
.custom-scrollbar::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: #555;
}
html.dark .custom-scrollbar::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
/* --- END Profile Layout Styles --- */

/* --- Mobile Sidebar Toggle --- */
/* Hide sidebar off-screen on mobile by default */
@media (max-width: 1023px) {
    aside.lg\:col-span-3 {
        position: fixed;
        top: 0;
        left: -100%;
        width: 80%;
        max-width: 320px;
        height: 100vh;
        z-index: 50;
        background-color: var(--bg-primary);
        transition: left 0.3s ease;
        overflow-y: auto;
        padding-top: 70px; /* Account for header */
        box-shadow: 2px 0 10px var(--shadow-color);
    }
    
    aside.lg\:col-span-3.sidebar-open {
        left: 0;
    }
    
    /* Mobile sidebar toggle button */
    #mobile-sidebar-toggle {
        display: flex;
        position: fixed;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        z-index: 45;
        background-color: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-left: none;
        border-radius: 0 0.5rem 0.5rem 0;
        padding: 0.75rem 0.5rem;
        cursor: pointer;
        box-shadow: 2px 0 8px var(--shadow-color);
        transition: left 0.3s ease;
    }
    
    #mobile-sidebar-toggle:hover {
        background-color: var(--bg-tertiary);
    }
    
    #mobile-sidebar-toggle svg {
        width: 1.25rem;
        height: 1.25rem;
        color: var(--text-primary);
        transition: transform 0.3s ease;
    }
    
    /* Rotate arrow when sidebar is open */
    .sidebar-open ~ #mobile-sidebar-toggle svg {
        transform: rotate(180deg);
    }
    
    /* Overlay when sidebar is open */
    #sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 49;
    }
    
    #sidebar-overlay.active {
        display: block;
    }
    
    /* Adjust main content to be full width on mobile */
    main.lg\:col-span-9 {
        width: 100%;
    }
}

/* Hide toggle button on desktop */
@media (min-width: 1024px) {
    #mobile-sidebar-toggle {
        display: none;
    }
    
    #sidebar-overlay {
        display: none !important;
    }
}
/* --- END Mobile Sidebar Toggle --- */

/* --- FLASH MESSAGES --- */
.flash-message {
    padding: 1rem;
    margin-bottom: 1rem;
    border-radius: 0.5rem;
    font-weight: 500;
}
.flash-success {
    background-color: #dcfce7; /* green-100 */
    color: #166534; /* green-800 */
    border: 1px solid #86efac; /* green-300 */
}
html.dark .flash-success {
    background-color: #14532d; /* green-900 */
    color: #dcfce7; /* green-100 */
    border-color: #22c55e; /* green-500 */
}
.flash-danger {
    background-color: #fee2e2; /* red-100 */
    color: #991b1b; /* red-800 */
    border: 1px solid #fca5a5; /* red-300 */
}
html.dark .flash-danger {
    background-color: #7f1d1d; /* red-900 */
    color: #fee2e2; /* red-100 */
    border-color: #ef4444; /* red-500 */
}
.flash-info {
    background-color: #e0f2fe; /* sky-100 */
    color: #0c4a6e; /* sky-800 */
    border: 1px solid #7dd3fc; /* sky-300 */
}
html.dark .flash-info {
    background-color: #0c4a6e; /* sky-900 */
    color: #e0f2fe; /* sky-100 */
    border-color: #0ea5e9; /* sky-500 */
}
.flash-warning {
    background-color: #fef3c7; /* amber-100 */
    color: #92400e; /* amber-800 */
    border: 1px solid #fcd34d; /* amber-300 */
}
html.dark .flash-warning {
    background-color: #78350f; /* amber-900 */
    color: #fef3c7; /* amber-100 */
    border-color: #f59e0b; /* amber-500 */
}
/* --- END FLASH MESSAGES --- */


/* --- DROPDOWN --- */
.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    background-color: var(--bg-secondary);
    min-width: 120px;
    box-shadow: 0px 8px 16px 0px var(--shadow-color);
    z-index: 10;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    overflow: hidden;
}
.dropdown-menu a, .dropdown-menu button {
    color: var(--text-primary);
    padding: 12px 16px;
    text-decoration: none;
    display: block;
    text-align: left;
    width: 100%;
}
.dropdown-menu a:hover, .dropdown-menu button:hover {
    background-color: var(--bg-tertiary);
}
/* --- END DROPDOWN --- */


/* --- MODAL STYLES --- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes slideIn {
    from { transform: translateY(-30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.6);
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.2s ease-out;
}

.modal-content {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    margin: auto;
    padding: 20px;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 4px 6px var(--shadow-color);
    position: relative;
    border: 1px solid var(--border-color);
    animation: slideIn 0.3s ease-out;
}
.close-button {
    position: absolute;
    top: 10px;
    right: 20px;
    color: var(--text-secondary);
    font-size: 30px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
}
.close-button:hover {
    color: var(--text-primary);
}
/* --- END MODAL STYLES --- */


/* --- MEDIA CAROUSEL --- */
#mediaCarouselModal {
    background-color: rgba(0,0,0,0.9);
    overflow: hidden;
}
.modal-content-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    max-width: 90%;
    max-height: 90%;
}
.media-carousel-display {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    max-width: 800px;
    max-height: 600px;
}
.media-carousel-display img,
.media-carousel-display video {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
.media-carousel-caption {
    color: white;
    margin-top: 10px;
    font-size: 1rem;
    text-align: center;
    max-width: 80%;
    word-wrap: break-word;
}
.modal-close.media-carousel-close {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
}
.modal-nav-button {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: white;
    font-size: 50px;
    cursor: pointer;
    padding: 16px;
    user-select: none;
    -webkit-user-select: none;
    z-index: 101;
}
.modal-nav-button.left { left: 0; }
.modal-nav-button.right { right: 0; }
/* --- END MEDIA CAROUSEL --- */


/* --- CROPPER MODAL --- */
#cropperModal .modal-content {
    max-width: 900px;
    width: 90%;
    padding: 1.5rem;
}
#cropper-container {
    width: 100%;
    height: 550px;
    margin-bottom: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--bg-tertiary);
    overflow: hidden;
}
#imageToCrop {
    display: block;
    max-width: 100%; 
    max-height: 100%;
}
.cropper-view-box,
.cropper-face {
    border-radius: 50%;
}
.cropper-face { pointer-events: all; }
.cropper-line, .cropper-point { display: none !important; }
/* --- END CROPPER MODAL --- */


/* --- PROFILE INFO MODAL --- */
#profileInfoModal .modal-content {
    max-width: 700px;
    width: 90%;
    padding: 1.5rem;
    max-height: 90vh;
    overflow-y: auto;
}
.privacy-toggle-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    font-size: 0.875rem;
    color: var(--text-secondary);
}
.privacy-toggle-group label {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
}
.privacy-toggle-group input[type="checkbox"] {
    margin-right: 0.25rem;
}
/* --- END PROFILE INFO MODAL --- */


/* --- SETTINGS MODAL & ACCORDION --- */
#settingsModal .modal-content {
    max-width: 700px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}
#settingsModal .modal-body {
    overflow-y: auto;
    padding-right: 10px;
}
.settings-accordion-button {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    padding: 1rem;
    width: 100%;
    border: none;
    text-align: left;
    outline: none;
    font-size: 1.125rem;
    font-weight: 600;
    transition: background-color 0.2s ease-in-out;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}
.settings-accordion-button:hover, .settings-accordion-button.active {
    background-color: var(--bg-interactive);
}
.settings-accordion-button .accordion-icon {
    transition: transform 0.3s ease;
    width: 1.5rem;
    height: 1.5rem;
}
.settings-accordion-button.active .accordion-icon {
    transform: rotate(180deg);
}
.settings-accordion-panel {
    padding: 0 1.5rem 1.5rem 1.5rem;
    background-color: var(--bg-secondary);
    display: none;
    overflow: hidden;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    border-bottom-left-radius: 0.5rem;
    border-bottom-right-radius: 0.5rem;
}
/* --- END SETTINGS MODAL --- */

/* --- ABOUT MODAL --- */
#aboutModal {
    z-index: 1050; /* Higher than settings modal (1000) */
}
#aboutModal .modal-content {
    max-width: 500px;
    padding: 2rem;
}
.about-node-button {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    padding: 1rem;
    width: 100%;
    border: none;
    text-align: left;
    outline: none;
    font-size: 1.125rem;
    font-weight: 600;
    transition: background-color 0.2s ease-in-out;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}
.about-node-button:hover {
    background-color: var(--bg-interactive);
}
.about-section {
    margin-bottom: 1.5rem;
}
.about-section h3 {
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}
.about-section p, .about-section a {
    font-size: 0.875rem;
    color: var(--text-secondary);
}
.about-section a {
    color: #3b82f6;
    text-decoration: none;
}
.about-section a:hover {
    text-decoration: underline;
}
.about-version {
    display: inline-block;
    background-color: var(--bg-tertiary);
    padding: 0.25rem 0.75rem;
    border-radius: 0.375rem;
    font-family: monospace;
    font-size: 0.875rem;
}
/* --- END ABOUT MODAL --- */

/* --- NOTIFICATION STYLES --- */
.notification-button {
    position: relative;
    background-color: var(--bg-tertiary);
    border-radius: 9999px;
    padding: 0.5rem;
    color: var(--text-secondary);
    transition: background-color 0.2s ease-in-out;
}
.notification-button:hover {
    background-color: var(--bg-interactive);
}
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background-color: #ef4444; /* red-500 */
    color: white;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: bold;
    border: 2px solid var(--bg-secondary);
}
#notificationModal .modal-content {
    max-width: 450px;
    padding: 0;
}
.notification-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}
.notification-list {
    max-height: 60vh;
    overflow-y: auto;
    padding: 0.5rem;
}
.notification-item {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.2s ease-in-out;
}
.notification-item:hover {
    background-color: var(--bg-tertiary);
}
.notification-item.unread {
    background-color: #eff6ff; /* blue-50 */
}
html.dark .notification-item.unread {
    background-color: #374151; /* gray-700 */
}
.notification-item-content {
    flex-grow: 1;
    margin-left: 0.75rem;
}
.notification-footer {
    text-align: center;
    padding: 0.75rem;
    border-top: 1px solid var(--border-color);
}
/* --- END NOTIFICATION STYLES --- */


/* --- POST/COMMENT STYLES --- */
.profile-picture-thumbnail {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 8px;
    display: inline-block;
    vertical-align: middle;
}

.privacy-indicator {
    display: inline-block;
    margin-left: 0.5rem;
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    vertical-align: middle;
}
.privacy-public { background-color: #dcfce7; color: #16a34a; }
.privacy-local { background-color: #e0f2fe; color: #2563eb; }
.privacy-friends { background-color: #fef9c3; color: #d97706; }
.privacy-private { background-color: #fee2e2; color: #dc2626; }
.privacy-followers { background-color: #e9d5ff; color: #5b21b6; }
.privacy-group { background-color: #ccfbf1; color: #0f766e; }

html.dark .privacy-public { background-color: #14532d; color: #86efac; }
html.dark .privacy-local { background-color: #1e3a8a; color: #93c5fd; }
html.dark .privacy-friends { background-color: #78350f; color: #fde047; }
html.dark .privacy-private { background-color: #7f1d1d; color: #fca5a5; }
html.dark .privacy-followers { background-color: #5b21b6; color: #ddd6fe; }
html.dark .privacy-group { background-color: #042f2e; color: #5eead4; }

.comment-reply {
    margin-top: 1rem;
    border-left: 2px solid var(--border-color);
}
.replies-container > .replies-list > div > .comment-reply {
    margin-left: 2rem;
    padding-left: 1rem;
    width: calc(100% - 2rem);
}
.replies-container .replies-container > .replies-list > div > .comment-reply {
    margin-left: 4rem;
    width: calc(100% - 4rem);
}
.replies-container .replies-container .replies-container > .replies-list > div > .comment-reply {
    margin-left: 6rem;
    width: calc(100% - 6rem);
}
.replies-container .replies-container .replies-container .replies-container > .replies-list > div > .comment-reply {
    margin-left: 6rem;
    width: calc(100% - 6rem);
}

.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
}
.post-media-item {
    position: relative;
    width: 100%;
    padding-bottom: 100%;
    overflow: hidden;
    border-radius: 8px;
    cursor: pointer;
}
.post-media-item img,
.post-media-item video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.post-media-item .play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    color: white;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.comment-media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
    gap: 4px;
    margin-top: 8px;
}
.comment-media-grid-item {
    position: relative;
    width: 100%;
    padding-bottom: 100%;
    overflow: hidden;
    border-radius: 4px;
    cursor: pointer;
}
.comment-media-grid-item img,
.comment-media-grid-item video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.comment-media-grid-item .play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.2rem;
    color: white;
    background-color: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    padding: 0.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Media toggle buttons for posts with many photos */
.media-toggle-container {
    text-align: center;
}

.show-more-media-button,
.show-less-media-button {
    transition: color 0.2s ease;
    cursor: pointer;
    border: none;
    background: none;
    padding: 0.25rem 0.5rem;
}

.show-more-media-button:hover,
.show-less-media-button:hover {
    text-decoration: underline;
}

.extra-media.hidden {
    display: none !important;
}
/* --- END POST/COMMENT STYLES --- */


/* --- FORM & INPUT STYLES --- */
.selected-comment-media-preview-item {
    position: relative;
    width: 70px;
    height: 70px;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}
.selected-comment-media-preview-item img,
.selected-comment-media-preview-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.selected-comment-media-preview-item .remove-media-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    background-color: rgba(239, 68, 68, 0.8);
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    cursor: pointer;
    line-height: 1;
    padding-bottom: 1px;
}

.selected-media-preview-item {
    position: relative;
    width: 100px;
    height: 100px;
    border-radius: 0.5rem;
    overflow: hidden;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}
.selected-media-preview-item img,
.selected-media-preview-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.selected-media-preview-item .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    background-color: rgba(239, 68, 68, 0.8);
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    cursor: pointer;
    line-height: 1;
    padding-bottom: 1px;
    z-index: 10;
}
.selected-media-preview-item .alt-text-input {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    font-size: 0.75rem;
    padding: 4px;
    border: none;
    outline: none;
}

/* Base styles for themed inputs */
.form-input {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}
.form-input::placeholder {
  color: #9ca3af; /* gray-400 */
}
html.dark .form-input::placeholder {
  color: #6b7280; /* gray-500 */
}
input[type="text"],
input[type="password"],
input[type="email"],
input[type="url"],
input[type="date"],
input[type="time"],
input[type="tel"],
input[type="search"],
textarea,
select {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-color);
}
input::placeholder,
textarea::placeholder {
  color: #9ca3af; /* gray-400 */
}
html.dark input::placeholder,
html.dark textarea::placeholder {
  color: #6b7280; /* gray-500 */
}

.disabled-comment-box {
    padding: 0.75rem;
    border-radius: 0.375rem;
    background-color: #f3f4f6;
    border: 1px solid var(--border-color);
    text-align: center;
    margin-bottom: 1rem;
}
html.dark .disabled-comment-box {
    background-color: var(--bg-tertiary);
}

/* Auto-growing textarea for create post form */
textarea#content {
    min-height: 3rem !important; /* Minimum 2 rows worth of height */
    resize: vertical !important; /* Allow manual resize */
    overflow-y: hidden !important; /* Hide scrollbar initially */
    transition: height 0.1s ease;
    height: auto; /* Start with auto height */
}
/* --- END FORM & INPUT STYLES --- */



/* --- MEDIA BROWSER STYLES --- */
.media-item {
    position: relative;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s ease-in-out;
}
.media-item.selected {
    border-color: #3b82f6;
}
.media-item img,
.media-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
    pointer-events: none;
}
.media-item .overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
    border-radius: 8px;
    pointer-events: none;
}
.media-item:hover .overlay {
    opacity: 1;
}
.media-item.selected .overlay {
    opacity: 1;
    background-color: rgba(59, 130, 246, 0.7);
}
.media-item .check-icon {
    font-size: 2rem;
    line-height: 1;
}
.folder-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    box-shadow: 0 1px 2px 0 var(--shadow-color);
    transition: background-color 0.2s ease-in-out;
    height: 100px;
    text-align: center;
}
.folder-item:hover {
    background-color: var(--bg-interactive);
}
.folder-item svg {
    margin-bottom: 0.5rem;
}
.folder-item span {
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}
.media-item video::-webkit-media-controls { display: none !important; }
.media-item video::-webkit-media-controls-enclosure { display: none !important; }
.media-item video::-webkit-media-controls-panel { display: none !important; }
.media-item video::-webkit-media-controls-play-button { display: none !important; }
.media-item video::-webkit-media-controls-start-playback-button { display: none !important; }
.media-item video::-webkit-media-controls-current-time-display { display: none !important; }
.media-item video::-webkit-media-controls-time-remaining-display { display: none !important; }
.media-item video::-webkit-media-controls-timeline { display: none !important; }
.media-item video::-webkit-media-controls-volume-slider { display: none !important; }
.media-item video::-webkit-media-controls-mute-button { display: none !important; }
.media-item video::-webkit-media-controls-fullscreen-button { display: none !important; }
.media-item video::--moz-media-controls { display: none !important; }
.media-item video::-ms-media-controls { display: none !important; }
/* --- END MEDIA BROWSER STYLES --- */


/* --- CUSTOM MESSAGE MODAL --- */
.custom-message-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.6);
    justify-content: center;
    align-items: center;
}
.custom-message-modal-content {
    background-color: var(--bg-secondary);
    margin: auto;
    padding: 20px;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 6px var(--shadow-color);
    text-align: center;
}
/* --- END CUSTOM MESSAGE MODAL --- */


/* --- THEME TOGGLE SWITCH --- */
.theme-switch-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.theme-switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}
.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 34px;
}
.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
input:checked + .slider {
  background-color: #4f46e5; /* indigo-600 */
}
input:checked + .slider:before {
  transform: translateX(26px);
}
.slider svg {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    transition: opacity 0.4s;
}
.sun-icon {
    left: 7px;
    opacity: 1;
    color: #f59e0b; /* amber-500 */
}
.moon-icon {
    right: 7px;
    opacity: 0;
    color: #f0f2f5;
}
input:checked + .slider .sun-icon { opacity: 0; }
input:checked + .slider .moon-icon { opacity: 1; }
/* --- END THEME TOGGLE SWITCH --- */

/* Smooth scroll to anchors */
html {
    scroll-behavior: smooth;
}

/* Adjust scroll position to account for fixed header */
:target {
    scroll-margin-top: 100px;
}

/* Optional highlight animation */
.post-highlight {
    animation: highlightPulse 2s ease-out;
}

@keyframes highlightPulse {
    0%, 100% {
        background-color: transparent;
    }
    50% {
        background-color: rgba(59, 130, 246, 0.15);
    }
}

/* ========================================
   TOAST NOTIFICATION SYSTEM
   ======================================== */

#toast-container {
    position: fixed;
    top: 80px; /* Below your header */
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
    pointer-events: none; /* Allow clicks through container */
}

.toast {
    pointer-events: all; /* But enable clicks on individual toasts */
    background: white;
    border-left: 4px solid #3b82f6; /* Blue by default */
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-width: 300px;
    max-width: 400px;
    animation: slideIn 0.3s ease-out;
    transition: all 0.3s ease;
}

/* Dark mode support */
html.dark .toast {
    background: #1f2937;
    color: #f3f4f6;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* Toast types */
.toast.success {
    border-left-color: #10b981; /* Green */
}

.toast.error,
.toast.danger {
    border-left-color: #ef4444; /* Red */
}

.toast.warning {
    border-left-color: #f59e0b; /* Orange */
}

.toast.info {
    border-left-color: #3b82f6; /* Blue */
}

/* Toast icon */
.toast-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.toast.success .toast-icon {
    background: #d1fae5;
    color: #059669;
}

html.dark .toast.success .toast-icon {
    background: #065f46;
    color: #6ee7b7;
}

.toast.error .toast-icon,
.toast.danger .toast-icon {
    background: #fee2e2;
    color: #dc2626;
}

html.dark .toast.error .toast-icon,
html.dark .toast.danger .toast-icon {
    background: #7f1d1d;
    color: #fca5a5;
}

.toast.warning .toast-icon {
    background: #fef3c7;
    color: #d97706;
}

html.dark .toast.warning .toast-icon {
    background: #78350f;
    color: #fcd34d;
}

.toast.info .toast-icon {
    background: #dbeafe;
    color: #2563eb;
}

html.dark .toast.info .toast-icon {
    background: #1e3a8a;
    color: #93c5fd;
}

/* Toast content */
.toast-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.toast-message {
    font-size: 13px;
    color: #111827;
    line-height: 1.4;
}

html.dark .toast-message {
    color: #f9fafb;
}

/* Toast close button */
.toast-close {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
    color: #9ca3af;
}

.toast-close:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #4b5563;
}

html.dark .toast-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #d1d5db;
}

/* Animations */
@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(400px);
        opacity: 0;
    }
}

.toast.removing {
    animation: slideOut 0.3s ease-out forwards;
}

/* Progress bar for auto-dismiss */
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: currentColor;
    opacity: 0.3;
    animation: progressShrink linear forwards;
}

@keyframes progressShrink {
    from {
        width: 100%;
    }
    to {
        width: 0%;
    }
}

/* Mobile responsive */
@media (max-width: 640px) {
    #toast-container {
        top: auto;
        bottom: 20px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    .toast {
        min-width: auto;
        max-width: none;
    }
}

/* ========================================
   LOAD MORE BUTTON STYLES
   ======================================== */

.load-more-container {
    margin-top: 2rem;
    margin-bottom: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.load-more-btn {
    background: var(--bg-interactive);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 12px 32px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.load-more-btn:hover:not(:disabled) {
    background: var(--text-link);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.load-more-btn:active:not(:disabled) {
    transform: translateY(0);
}

.load-more-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.load-more-btn .btn-spinner {
    animation: spin 1s linear infinite;
}

.end-message {
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
    padding: 1rem;
}

/* Dark mode adjustments */
html.dark .load-more-btn {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

html.dark .load-more-btn:hover:not(:disabled) {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}

/* ========================================
   Media Gallery Filter Buttons
   ======================================== */

.filter-button {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    font-weight: 500;
}

.filter-button:hover {
    background: var(--bg-hover);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.filter-button.active {
    background-color: rgb(59 130 246);
    color: white;
    border-color: rgb(59 130 246);
}

.filter-button svg {
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.25rem;
}

/* Hide filtered media items */
.gallery-media-item-link[style*="display: none"] {
    display: none !important;
}

/* Year section styling for media galleries */
.year-section {
    margin-top: 1.5rem;
}

.year-section h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    margin-top: 1.5rem;
}

.year-section h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    margin-top: 1rem;
}

.month-grid {
    margin-bottom: 1rem;
}

/* Dark mode adjustments for filters */
html.dark .filter-button {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

html.dark .filter-button:hover {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}

html.dark .filter-button.active {
    background-color: rgb(59 130 246);
    color: white;
}

/* ========================================
   Tab Buttons (Events & Friends Pages)
   Shared styling for all tabbed interfaces
   ======================================== */

.tab-button {
    border-bottom: 2px solid transparent;
    transition: color 0.2s ease, border-color 0.2s ease;
}

.tab-button.active {
    color: rgb(59 130 246); /* blue-500 */
    border-bottom-color: rgb(59 130 246);
}

html.dark .tab-button.active {
    color: rgb(96 165 250); /* blue-400 */
    border-bottom-color: rgb(96 165 250);
}

/* ========================================
   Connection Tabs (Friends Page) - DEPRECATED
   Use tab-button class instead
   ======================================== */

.connection-tab-button {
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease;
    min-width: 44px; /* Minimum touch target size */
    min-height: 44px; /* Minimum touch target size */
}

.connection-tab-button:hover {
    color: rgb(55 65 81);
}

.connection-tab-button.active {
    color: rgb(59 130 246); /* blue-500 */
    border-bottom-color: rgb(59 130 246);
}

.connection-tab-content {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Dark mode for connection tabs */
html.dark .connection-tab-button {
    color: var(--text-secondary);
}

html.dark .connection-tab-button:hover {
    color: rgb(209 213 219);
}

html.dark .connection-tab-button.active {
    color: rgb(96 165 250); /* blue-400 */
    border-bottom-color: rgb(96 165 250);
}

/* ========================================
   Connection Cards (Friends/Pages Lists)
   ======================================== */

/* Prevent username/email overflow in cards */
.connection-item .flex.items-center {
    min-width: 0; /* Allow flex items to shrink below content size */
    flex: 1;
}

.connection-item .flex.items-center > div {
    min-width: 0; /* Allow text container to shrink */
    overflow: hidden;
}

.connection-item .flex.items-center a,
.connection-item .flex.items-center p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Unfollow button styling - red like a removal action */
.connection-item button[onclick^="unfollowPageFromList"] {
    border: 1px solid rgb(239 68 68); /* red-500 border */
    background-color: rgb(239 68 68); /* red-500 background */
    color: white;
}

.connection-item button[onclick^="unfollowPageFromList"]:hover {
    background-color: rgb(220 38 38); /* red-600 - darker on hover */
    border-color: rgb(220 38 38);
}

html.dark .connection-item button[onclick^="unfollowPageFromList"] {
    border-color: rgb(239 68 68);
    background-color: rgb(239 68 68);
    color: white;
}

html.dark .connection-item button[onclick^="unfollowPageFromList"]:hover {
    background-color: rgb(220 38 38);
    border-color: rgb(220 38 38);
}

/* ========================================
   MEDIA VIEW MODAL MOBILE STYLES
   ======================================== */

/* Ensure modal doesn't overflow on mobile */
#mediaViewModal {
    overflow-x: hidden;
    overflow-y: auto;
}

/* Constrain the modal wrapper */
#mediaViewModal > div {
    max-width: 100vw;
    overflow-x: hidden;
}

/* Mobile responsive adjustments for media view content */
@media (max-width: 1023px) {
    /* Remove any horizontal padding that might cause overflow */
    #mediaViewModal .min-h-screen {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    
    /* Stack layout on mobile/tablet */
    #mediaViewModalContent .grid {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.5rem;
    }
    
    /* Media display area - constrain size on mobile */
    #mediaViewModalContent .lg\:col-span-2 {
        width: 100%;
        max-width: 100vw;
        overflow: hidden;
    }
    
    /* Reduce min-height on mobile */
    #mediaViewModalContent .bg-black.rounded-lg {
        min-height: 300px !important;
        max-height: 60vh;
    }
    
    /* Make images/videos fit mobile screen */
    #mediaViewModalContent .bg-black.rounded-lg img,
    #mediaViewModalContent .bg-black.rounded-lg video {
        max-height: 60vh !important;
        max-width: calc(100vw - 1rem) !important;
        width: auto !important;
        height: auto !important;
        object-fit: contain;
    }
    
    /* Sidebar section */
    #mediaViewModalContent .lg\:col-span-1 {
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    /* Navigation buttons - smaller on mobile */
    #mediaViewModalContent button[onclick*="navigateToMediaInModal"] {
        padding: 0.5rem !important;
    }
    
    #mediaViewModalContent button[onclick*="navigateToMediaInModal"] svg {
        width: 1.25rem !important;
        height: 1.25rem !important;
    }
    
    /* Comments section - limit height on mobile */
    #media-comments-list {
        max-height: 300px !important;
    }
    
    /* Ensure all nested containers don't overflow */
    #mediaViewModalContent * {
        max-width: 100%;
    }
}

/* Extra small devices */
@media (max-width: 640px) {
    /* Media counter badge */
    #mediaViewModalContent .absolute.top-2 {
        top: 0.5rem !important;
        right: 0.5rem !important;
    }
    
    /* Further constrain images on very small screens */
    #mediaViewModalContent .bg-black.rounded-lg img,
    #mediaViewModalContent .bg-black.rounded-lg video {
        max-width: calc(100vw - 0.5rem) !important;
    }
}

/* Poll Styles */
.poll-container {
    background: var(--post-card-bg, #f9fafb);
}

.poll-option {
    position: relative;
    overflow: hidden;
}

.poll-option-voted {
    border-color: #3b82f6 !important;
}

.poll-option-bar {
    transition: width 0.3s ease;
}

.poll-option:hover .poll-option-bar {
    opacity: 0.5 !important;
}

.poll-percentage {
    min-width: 3rem;
    text-align: right;
}

.poll-radio {
    transition: all 0.2s ease;
}

.poll-voters-link {
    transition: color 0.2s ease;
}

/* Dark mode adjustments */
.dark .poll-container {
    background: var(--post-card-bg-dark, #1f2937);
}

/* ========================================
   Link Preview Cards
   ======================================== */

.link-preview-card {
    max-width: 500px;
    background-color: var(--bg-secondary);
    text-decoration: none;
    display: block;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    width: 100%; /* NEW: Ensure it respects parent width */
    box-sizing: border-box; /* NEW: Include padding/border in width calculation */
}

.link-preview-card:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--text-secondary);
}

.link-preview-image {
    flex-shrink: 0;
    background-color: var(--bg-interactive);
    overflow: hidden; /* NEW: Prevent image overflow */
}

.link-preview-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.link-preview-content {
    flex-grow: 1;
    min-width: 0; /* Allows text truncation to work */
    overflow: hidden; /* NEW: Prevent content overflow */
    padding: 0.75rem; /* Ensure there's padding */
}

/* Text truncation utility */
.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}

.link-previews-container {
    margin-top: 0.75rem;
    max-width: 100%; /* NEW: Prevent container overflow */
    overflow: hidden; /* NEW: Clip any overflow */
}

/* Ensure link preview cards don't inherit link styling from linkify_urls */
.link-preview-card .primary-text {
    color: var(--text-primary);
}

.link-preview-card .text-gray-500 {
    color: var(--text-secondary);
}

.link-preview-card .text-gray-400 {
    color: var(--text-secondary);
    opacity: 0.8;
}

/* Dark mode adjustments */
html.dark .link-preview-card {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
}

html.dark .link-preview-card:hover {
    background-color: var(--bg-tertiary);
    border-color: var(--text-secondary);
}

html.dark .link-preview-image {
    background-color: var(--bg-interactive);
}

/* Responsive adjustments */
@media (max-width: 640px) {
    .link-preview-card {
        max-width: 100%; /* Full width on mobile */
        width: 100%; /* Force full width */
    }
    
    .link-preview-card .flex {
        flex-wrap: nowrap; /* Prevent wrapping */
    }
    
    .link-preview-image {
        width: 80px !important; /* Smaller image on mobile */
        height: 80px !important;
        min-width: 80px; /* Prevent shrinking */
    }
    
    .link-preview-content {
        padding: 0.5rem; /* Less padding on mobile */
        font-size: 0.875rem; /* Slightly smaller text */
    }
    
    .link-preview-content .text-xs {
        font-size: 0.75rem; /* Even smaller for URL */
    }
}

/* Extra safety for preventing overflow in comment sections */
.comment-media-grid + .link-previews-container,
.primary-text + .link-previews-container {
    max-width: 100%;
    overflow-x: hidden;
}

/* ========================================
   FORCE CONSTRAIN LINK PREVIEWS IN COMMENTS/POSTS
   ======================================== */

/* Ensure all content within post cards and comments respects boundaries */
.post-card .link-previews-container,
.comment-reply .link-previews-container,
[id^="comment-"] .link-previews-container {
    max-width: 100%;
    overflow: hidden;
}

.post-card .link-preview-card,
.comment-reply .link-preview-card,
[id^="comment-"] .link-preview-card {
    max-width: 100% !important;
    width: 100% !important;
}

/* Force the flex container inside the card to also respect boundaries */
.link-preview-card > div {
    max-width: 100%;
    overflow: hidden;
}

/* Constrain the content area */
.link-preview-content {
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Make sure long URLs break */
.link-preview-content .truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

/* Mobile-specific aggressive constraints */
@media (max-width: 640px) {
    .link-preview-card {
        max-width: calc(100vw - 4rem) !important; /* Account for padding */
    }
    
    /* In comments, account for avatar space */
    [id^="comment-"] .link-preview-card,
    .comment-reply .link-preview-card {
        max-width: calc(100vw - 6rem) !important; /* Avatar + padding */
    }
    
    .link-preview-image {
        width: 70px !important;
        height: 70px !important;
        min-width: 70px !important;
        max-width: 70px !important;
    }
    
    .link-preview-content {
        max-width: calc(100% - 70px); /* Subtract image width */
        padding: 0.5rem !important;
    }
}

/* ========================================
   FIX: Constrain comment flex-grow container
   ======================================== */

/* The flex-grow div in comments needs a max-width to prevent overflow */
[id^="comment-"] > .flex-grow,
.comment-reply > .flex-grow {
    max-width: calc(100% - 4rem); /* Account for avatar (3rem) + spacing (1rem) */
    min-width: 0; /* Critical for flex items to shrink below content size */
}

/* Mobile: even tighter constraints */
@media (max-width: 640px) {
    [id^="comment-"] > .flex-grow,
    .comment-reply > .flex-grow {
        max-width: calc(100vw - 5rem); /* Avatar + padding + margins */
    }
}

/* Album media selection modal */
.active-modal-filter {
    background-color: var(--primary-color);
    color: white;
}

.media-selection-item {
    position: relative;
    cursor: pointer;
    aspect-ratio: 1;
    border: 3px solid transparent;
    border-radius: 0.5rem;
    overflow: hidden;
    transition: border-color 0.2s;
}

.media-selection-item:hover {
    border-color: var(--primary-color);
    opacity: 0.9;
}

.media-selection-item.selected {
    border-color: var(--primary-color);
}

.media-selection-item .selection-checkbox {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 1.5rem;
    height: 1.5rem;
    background: white;
    border: 2px solid #ddd;
    border-radius: 0.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.media-selection-item.selected .selection-checkbox {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.media-selection-item .selection-checkbox svg {
    width: 1rem;
    height: 1rem;
    color: white;
    display: none;
}

.media-selection-item.selected .selection-checkbox svg {
    display: block;
}

/* Discover Modal - Mobile-Friendly Profile Cards */
.discover-profile-card {
    transition: background-color 0.2s ease;
}

.discover-profile-card:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.dark .discover-profile-card:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Avatar sizes - responsive */
.discover-avatar {
    width: 48px;
    height: 48px;
}

/* Name and username sizing - responsive */
.discover-name {
    font-size: 14px;
}

.discover-username {
    font-size: 13px;
}

/* Bio hidden by default on desktop (keeps compact 2-column layout) */
.discover-bio {
    display: none;
}

/* Action buttons - keep normal on desktop */
.discover-action-button button[onclick*="sendFriendRequest"],
.discover-action-button button[onclick*="followProfile"] {
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
}

/* Line clamp utility for bio text */
.discover-bio {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
}

/* MOBILE IMPROVEMENTS (under 640px) */
@media (max-width: 639px) {
    /* Switch to single column layout */
    #discoverUsersDiscoverContent .grid-cols-2,
    #discoverUsersHiddenContent .grid-cols-2 {
        grid-template-columns: 1fr !important;
    }
    
    /* Larger avatars on mobile */
    .discover-avatar {
        width: 56px;
        height: 56px;
    }
    
    /* Larger text on mobile */
    .discover-name {
        font-size: 16px;
    }
    
    .discover-username {
        font-size: 14px;
    }
    
    /* Show bio on mobile */
    .discover-bio {
        display: -webkit-box;
    }
    
    /* Full-width action buttons on mobile */
    .discover-action-button button[onclick*="sendFriendRequest"],
    .discover-action-button button[onclick*="followProfile"] {
        width: 100%;
        justify-content: center;
    }
}

/* Discover Groups Modal - Mobile-Friendly Cards */
.discover-group-card {
    transition: background-color 0.2s ease;
}

.discover-group-card:hover {
    background-color: rgba(0, 0, 0, 0.02);
}

.dark .discover-group-card:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

/* Group avatar sizes - responsive */
.discover-group-avatar {
    width: 48px;
    height: 48px;
}

/* Group name and host sizing - responsive */
.discover-group-name {
    font-size: 14px;
}

.discover-group-host {
    font-size: 13px;
}

/* Description hidden by default on desktop (keeps compact layout) */
.discover-group-description {
    display: none;
}

/* Action buttons - keep normal on desktop */
.discover-group-action-button button {
    font-size: 0.875rem;
    padding: 0.5rem 1rem;
}

/* MOBILE IMPROVEMENTS FOR GROUPS (under 640px) */
@media (max-width: 639px) {
    /* Larger avatars on mobile */
    .discover-group-avatar {
        width: 56px;
        height: 56px;
    }
    
    /* Larger text on mobile */
    .discover-group-name {
        font-size: 16px;
    }
    
    .discover-group-host {
        font-size: 14px;
    }
    
    /* Show description on mobile */
    .discover-group-description {
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        line-height: 1.4;
    }
    
    /* Full-width action buttons on mobile */
    .discover-group-action-button button {
        width: 100%;
        justify-content: center;
    }
}

/* ========================================
   BACK TO TOP BUTTON
   ======================================== */

.back-to-top-button {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 3.5rem;
    height: 3.5rem;
    background-color: var(--text-link);
    color: white;
    border: none;
    border-radius: 50%;
    box-shadow: 0 4px 12px var(--shadow-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateY(100px);
    transition: opacity 0.3s ease, transform 0.3s ease, background-color 0.2s ease;
    z-index: 100;
    pointer-events: none;
}

.back-to-top-button.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

.back-to-top-button:hover {
    background-color: #4338ca; /* Darker indigo */
}

.back-to-top-button svg {
    width: 1.5rem;
    height: 1.5rem;
}

@media (max-width: 768px) {
    .back-to-top-button {
        bottom: 1rem;
        right: 1rem;
        width: 3rem;
        height: 3rem;
    }
    
    .back-to-top-button svg {
        width: 1.25rem;
        height: 1.25rem;
    }
}

/* ========================================
   NEW POSTS INDICATOR
   ======================================== */

.new-posts-indicator {
    position: fixed;
    top: 5rem; /* Below sticky header */
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: linear-gradient(135deg, var(--text-link) 0%, #6366f1 100%);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: 2rem;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 0.875rem;
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    white-space: nowrap;
}

.new-posts-indicator.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: all;
}

.new-posts-indicator:hover {
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.5);
    transform: translateX(-50%) translateY(-2px);
}

.new-posts-indicator svg {
    width: 1.25rem;
    height: 1.25rem;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-5px);
    }
    60% {
        transform: translateY(-3px);
    }
}

@media (max-width: 768px) {
    .new-posts-indicator {
        top: 4.5rem;
        font-size: 0.8rem;
        padding: 0.6rem 1.2rem;
    }
}

/* Nebula Breathing Animation */
@keyframes nebula-breathe {
    0%, 100% {
        filter: blur(2px);
        transform: scale(1);
    }
    50% {
        filter: blur(4px);
        transform: scale(1.05);
    }
}

.nebula-breathing {
    animation: nebula-breathe 8s ease-in-out infinite;
}

/* Admin dropdown positioning fix */
.dropdown-menu {
    display: none;
    position: absolute;
    right: 0;
    margin-top: 0.5rem;
    width: 14rem;
    border-radius: 0.375rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    z-index: 1000;
}

.dropdown-menu[style*="display: block"] {
    display: block !important;
}