/* CoreUI Container Classes - Fix scrollbar on mobile */
.c-app {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

.c-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Mobile Styles - Enhanced for screens < 874px */
@media (max-width: 873px) {

    /* Hide body/html scrollbar when right sidebar is open on mobile */
    /* Disabled per user request to allow background scrolling */
    /* body.sidebar-right-open {
        overflow-y: hidden !important;
    } */

    /* html:has(body.sidebar-right-open) {
        overflow-y: hidden !important;
    } */

    .c-app,
    .c-wrapper {
        overflow: visible !important;
        width: 100%;
        max-width: 100%;
    }

    html {
        overflow-x: hidden !important;
    }

    body {
        overflow-x: hidden !important;
    }

    .sidebar {
        width: 85%;
        max-width: 320px;
    }
}

/* CSS Variables */
:root {
    --header-height: 56px;
    --footer-height: 50px;
    --sidebar-left-width: 280px;
    --sidebar-right-width: 300px;
    /*
     * เมนูย่อย dynamicmenu: ระยะจากขอบซ้ายของ li.dropdown-submenu (เทียบ admin/style.css)
     * ไม่ใช้ left:100% ของแถวที่กว้างเต็มแผง — จะทำให้ซับเมนูหลุดไปชิดขวาและห่างจากข้อความมากเกินไป
     */
    --dm-dropdown-submenu-left: 129px;
    --dm-dropdown-submenu-mt: -6px;
}

/* Base Styles */
html {
    width: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    /* Show scrollbar only when needed */
    box-sizing: border-box;
}

body {
    overflow-x: hidden;
    overflow-y: auto;
    /* Show scrollbar only when needed */
    min-height: 100vh;
    position: relative;
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Header Styles */
.header {
    height: var(--header-height);
    transition: box-shadow 0.3s ease;
    z-index: 1030;
    position: fixed;
    width: 100%;
    top: 0;
    left: 0;
    right: 0;
    background-color: #fff;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    /* Prevent expansion - use viewport width calculation */
    max-width: 100%;
}

/* Header Navigation */
.header-nav {
    display: flex;
    align-items: center;
    margin: 0;
    padding: 0;
    list-style: none;
}

.header-nav .nav-link {
    padding: 0.5rem 1rem;
    color: #fff !important;
    text-decoration: none;
    transition: background-color 0.2s;
}

.header-nav .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Sidebar Base Styles */
.sidebar {
    position: fixed;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    background-color: #fff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 1031;
    overflow-y: auto;
    transition: transform 0.3s ease-in-out;
}

/* Left Sidebar - Pure Overlay Style (completely floats above, doesn't affect layout) */
.sidebar-left {
    left: 0;
    width: var(--sidebar-left-width);
    transform: translateX(-100%);
    background-color: #2c3e50;
    transition: transform 0.3s ease-in-out;
    z-index: 1040;
    /* Higher than header (1030) to float above */
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
    /* Add shadow to indicate it's floating */
    pointer-events: none;
    /* Allow clicks to pass through when hidden */
}

.sidebar-left.show {
    transform: translateX(0);
    pointer-events: auto;
    /* Enable clicks when visible */
}

.sidebar-left .nav-item {
    margin: 2px 8px;
}

.sidebar-left .nav-link {
    color: #e9ecef !important;
    padding: 10px 15px;
    border-radius: 5px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-left .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #ffffff !important;
}

.sidebar-left .nav-link.active {
    background-color: rgba(255, 255, 255, 0.15);
    color: #ffffff !important;
    font-weight: 500;
}

.sidebar-left .nav-link i {
    width: 20px;
    text-align: center;
    font-size: 1.1em;
    color: #8395a7;
}

.sidebar-left .nav-title {
    padding: 12px 15px;
    font-size: 0.85em;
    text-transform: uppercase;
    font-weight: 600;
    color: #8395a7;
    margin-top: 10px;
}

/* Submenu Styles */
.sidebar-left .nav-group {
    margin-bottom: 5px;
}

.sidebar-left .nav-group-items {
    padding-left: 20px;
}

.sidebar-left .nav-group-items .nav-link {
    padding: 8px 15px;
    font-size: 0.95em;
    color: #bdc3c7 !important;
}

.sidebar-left .nav-group-items .nav-link:hover {
    color: #ffffff !important;
    background-color: rgba(255, 255, 255, 0.1);
}

.sidebar-left .nav-group-items .nav-link.active {
    background-color: rgba(255, 255, 255, 0.15);
    color: #ffffff !important;
}

/* Show States */
.sidebar.show {
    transform: translateX(0) !important;
}

/* Right Sidebar - Pure Overlay Style (completely floats above, doesn't affect layout) */
.sidebar-end {
    right: 0;
    width: var(--sidebar-right-width);
    transform: translateX(100%);
    transition: transform 0.3s ease-in-out;
    z-index: 1040;
    /* Higher than header (1030) to float above */
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15);
    /* Add shadow to indicate it's floating */
    /* Pure overlay - doesn't affect document flow or layout */
    pointer-events: none;
    /* Allow clicks to pass through when hidden */
}

.sidebar-end.show {
    transform: translateX(0);
    pointer-events: auto;
    /* Enable clicks when visible */
}

/* Main Container and Content Area */
.main-container {
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    position: relative;
    /* Prevent expansion - use percentage width */
    max-width: 100%;
}

.content-area {
    width: 100%;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    position: relative;
    /* Prevent expansion - use percentage width */
    max-width: 100%;
}

/* Main Content */
.main-content {
    top: -5px;
    min-height: calc(100vh - var(--header-height) - var(--footer-height));
    padding: 20px;
    position: relative;
    transition: margin 0.3s ease-in-out;
    width: 100%;
    box-sizing: border-box;
    /* Prevent expansion - use percentage width */
    max-width: 100%;
}

/* Footer Styles */
.c-footer {
    height: var(--footer-height);
    position: relative;
    padding: 1rem;
    transition: margin 0.3s ease-in-out;
    background-color: #f8f9fa;
    border-top: 1px solid #dee2e6;
}

/* Overlay Styles */
.sidebar-overlay {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1025;
    visibility: hidden;
    opacity: 0;
    transition: visibility 0s linear 0.3s, opacity 0.3s ease;
}

.sidebar-overlay.show {
    visibility: visible;
    opacity: 1;
    transition-delay: 0s;
}

/* Flash Messages */
.flash-message {
    margin: 10px 0;
    padding: 10px 15px;
    border-radius: 4px;
    position: relative;
    animation: fadeIn 0.5s;
}

.flash-success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.flash-error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.flash-warning {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}

.flash-info {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

.flash-message .close-btn {
    position: absolute;
    right: 10px;
    top: 10px;
    cursor: pointer;
    color: inherit;
}


/*------------------------------------Dropdown Menu-------------------------------------*/
.dropdown-submenu:hover>.dropdown-menu,
.dropdown-submenu:focus-within>.dropdown-menu {
    display: block;
}

.dropdown-submenu>.dropdown-toggle {
    color: rgb(128, 128, 0);
    display: flex;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
}

/* Caret (::after) ชิดขวาสุดของแถว */
.dropdown-submenu>.dropdown-toggle::after {
    display: inline-block;
    margin-left: auto;
    flex-shrink: 0;
    vertical-align: middle;
}

.icon-text {
    display: flex;
    align-items: center;
    column-gap: 0;
}

.icon-text i {
    flex-shrink: 0;
    margin-right: 0;
    padding-right: 0;
}

.dropdown-submenu {
    position: relative;
}

/*
 * เมนูย่อยหลายระดับ (dynamicmenu.js): ยื่นไปทางขวา — ระยะแนวนอนเทียบ admin (129px / margin-top -6px)
 */
@media (min-width: 768px) {
    .dropdown-submenu > .dropdown-menu {
        top: 0;
        left: var(--dm-dropdown-submenu-left, 129px);
        margin-top: var(--dm-dropdown-submenu-mt, -6px) !important;
        margin-left: 0;
        z-index: 1100;
    }
}

/* จอแคบ / เมนูแนวตั้ง: ซ้อนลงใต้รายการแม่ (ไล่ตาม hoverบนเดสก์ท็อปไม่ได้อยู่แล้ว) */
@media (max-width: 767.98px) {
    .dropdown-submenu > .dropdown-menu {
        position: static !important;
        float: none;
        left: auto !important;
        top: auto !important;
        margin-top: 0.25rem !important;
        margin-left: 1rem;
        z-index: auto;
    }
}

/* แสดงเมนูเมื่อมีคลาส show */
.dropdown-menu.show {
    display: block;
}

/* Responsive Dropdown Menu Titles */
@media (max-width: 1069px) {
    #mainMenu .dropdown-menu-title {
        display: none;
    }
}

@media (min-width: 1070px) {
    #mainMenu .dropdown-menu-title {
        display: inline-block;
    }
}

/*------------------------------------end of Dropdown Menu------------------------------*/
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile Styles */
@media (max-width: 768px) {

    .sidebar {
        width: 85%;
        max-width: 320px;
    }

    .sidebar-left {
        left: 0;
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0) !important;
    }

    .sidebar-end {
        width: 85%;
        max-width: 320px;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    .main-content,
    .main-content.sidebar-left-expanded,
    .main-content.sidebar-right-expanded,
    .c-footer,
    .c-footer.sidebar-left-expanded,
    .c-footer.sidebar-right-expanded {
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100% !important;
    }
}

/* Desktop Styles */
@media (min-width: 769px) {
    .sidebar-left {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0) !important;
    }

    /* Left sidebar is now overlay style - no margin adjustment needed */
    /* .main-content.sidebar-left-expanded { margin-left: var(--sidebar-left-width); } */
    /* .c-footer.sidebar-left-expanded { margin-left: var(--sidebar-left-width); } */
}

/* Dropdown Styles */
.dropdown-menu {
    margin-top: 0.5rem;
    border: none;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Navigation Links */
.nav-link {
    color: #fff;
}

.nav-link:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

/* Post Card in Feed */
.post-card {
    margin-bottom: 20px;
    border-radius: 12px !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
    border: 1px solid rgba(0, 0, 0, 0.05) !important;
    overflow: visible !important;
}

/* Ensure sub-elements respect card curvature */
.post-card .card-body {
    border-radius: 12px;
}

/* Full Width Content (for Single Image/Video & Colorful Quotes) */
.full-width-content {
    margin-left: -16px !important;
    margin-right: -16px !important;
    width: calc(100% + 32px) !important;
    max-width: none !important;
    border-radius: 0 !important;
}

/* Button Styles */
.btn-link.text-white {
    text-decoration: none;
    transition: all 0.2s ease-in-out;
}

.btn-link.text-white:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Post Card Action Buttons (Like, Comment, Share) */
.post-card .btn-light.reaction-button,
.post-card .btn-light.comment-button,
.post-card .btn-light.share-button {
    background-color: transparent !important;
    border-color: transparent !important;
    box-shadow: none !important;
    color: #495057 !important;
    transition: all 0.2s ease;
}

.post-card .btn-light.reaction-button:hover,
.post-card .btn-light.comment-button:hover,
.post-card .btn-light.share-button:hover {
    background-color: rgba(0, 0, 0, 0.05) !important;
    color: #212529 !important;
}

/* Dropdown Styles */
.dropdown-header {
    font-weight: 600;
    color: #6c757d;
}

.dropdown-item {
    padding: 0.5rem 1rem;
    color: #212529;
    /* Dark text for light backgrounds */
    display: flex;
    align-items: center;
}

.dropdown-item i {
    color: inherit;
    margin-right: 8px;
}

.dropdown-item span {
    color: inherit;
}

.dropdown-item:hover {
    background-color: #f8f9fa;
    color: #16181b;
}

/* Transition Styles */
.sidebar,
/*.main-content,*/
.c-footer {
    will-change: transform, margin, visibility;
}

/* ===== Table-Based Media Gallery Layouts ===== */
.media-table-wrapper {
    /* Table defines its own max-height via inline style */
    overflow: hidden;
}

.media-table {
    width: 100%;
    height: 100%;
    border-spacing: 4px;
    border-collapse: separate;
    table-layout: fixed;
}

.media-table td {
    overflow: hidden;
    border-radius: 6px;
    background-color: #f0f0f0;
    vertical-align: middle;
    padding: 0;
    position: relative;
}

.media-table .image-container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    cursor: pointer;
    position: relative;
}

.media-table img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
}

/* Remaining images overlay for 5+ images */
.media-table .remaining-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
}

.media-table .remaining-overlay span {
    color: white;
    font-size: 2rem;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

/* ===== Mobile Responsive Image Layouts ===== */
@media (max-width: 768px) {

    .layout-horizontal,
    .layout-3,
    .layout-4,
    .layout-5 {
        height: min(400px, 80vh) !important;
    }

    /* Remove all container padding on mobile for full-width posts */
    .main-content,
    .main-content .main-container,
    .main-content .content-area,
    .main-content .container,
    .main-content .container-fluid {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    /* Row margin adjustment */
    .main-content .row {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Column padding removal */
    .main-content [class*="col-"] {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    /* Post card full width on mobile */
    .post-card {
        margin-left: 0 !important;
        margin-right: 0 !important;
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
    }

    /* Adjust card body padding on mobile */
    .post-card .card-body {
        border-radius: 0;
    }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #888 transparent;
}

/* Update Notification Badge Positioning */
#notification-dropdown-toggle {
    position: relative !important;
    display: inline-flex !important;
    align-items: center !important;
}

.notification-count {
    position: absolute !important;
    top: 5px !important;
    right: 8px !important;
    transform: translate(50%, -50%) !important;
    display: inline-block;
    z-index: 10;
    min-width: 18px;
    /* Ensure circular shape for single digits */
    height: 18px;
    padding: 0 5px;
    border-radius: 10px;
    line-height: 18px;
    /* Center text vertically */
    font-size: 10px;
    text-align: center;
}

/* Fix pulse animation to include translate */
@keyframes badge-pulse {
    0% {
        transform: translate(50%, -50%) scale(1);
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7);
    }

    70% {
        transform: translate(50%, -50%) scale(1.1);
        box-shadow: 0 0 0 10px rgba(220, 53, 69, 0);
    }

    100% {
        transform: translate(50%, -50%) scale(1);
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
    }
}

.notification-badge-pulse {
    animation: badge-pulse 2s infinite;
}

/* Circular Button Utility */
.btn-circle {
    width: 35px;
    height: 35px;
    border-radius: 50% !important;
    padding: 0 !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.2s ease;
}

.btn-circle i {
    font-size: 0.9rem;
}

.btn-circle.btn-sm {
    width: 30px;
    height: 30px;
}

.btn-circle.btn-sm i {
    font-size: 0.8rem;
}

.btn-circle:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

/* Main header bar + right sidebar: profile avatar white ring + outer glow */
.header img.feed-post-profile-avatar,
#right-sidebar img.feed-post-profile-avatar {
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.95),
        0 0 10px rgba(255, 255, 255, 0.5),
        0 0 16px rgba(255, 255, 255, 0.22);
}