/**
 * Core Layout Styles
 * Extracted from app.php - Main layout structure including sidebar, navbar, and responsive design
 */

:root {
    --sidebar-width: 250px;
    --topnav-height: calc(56px + env(safe-area-inset-top, 0px));
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--theme-bg-primary);
    color: var(--theme-text-primary);
    overflow-x: hidden;
}

/* Wrapper */
.wrapper {
    position: relative;
    width: 100%;
    min-height: calc(100vh - var(--topnav-height));
    margin-top: var(--topnav-height);
    display: flex;
}

/* Top Navigation */
.navbar {
    box-shadow: 0 2px 4px var(--theme-shadow-color);
    z-index: 1030;
    padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
}

.navbar-brand {
    font-weight: 600;
    font-size: 1.25rem;
}

.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-align: center;
    font-weight: 600;
    font-size: 0.875rem;
    overflow: visible;
    flex-shrink: 0;
    position: relative;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* Online status indicator */
.online-indicator {
    display: inline-block;
    position: relative;
    width: 12px;
    height: 12px;
}

.online-indicator .indicator-dot {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: #9e9e9e;
    transition: background-color 0.3s ease;
}

.online-indicator.online .indicator-dot {
    background-color: #4CAF50;
    animation: pulse-online 2s infinite;
}

.online-indicator.offline .indicator-dot {
    background-color: #9e9e9e;
}

@keyframes pulse-online {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(76, 175, 80, 0);
    }
}

/* Online indicator on avatar */
.position-relative .online-indicator {
    position: absolute;
    bottom: 0;
    right: 0;
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: var(--topnav-height);
    bottom: env(safe-area-inset-bottom, 0px);
    left: 0;
    width: var(--sidebar-width);
    background-color: var(--theme-sidebar-bg);
    border-right: 1px solid var(--theme-border-color);
    overflow-y: auto;
    box-shadow: 2px 0 4px var(--theme-shadow-sidebar);
    z-index: 1020;
    padding-left: env(safe-area-inset-left, 0px);
}

.sidebar .nav-link {
    color: var(--theme-sidebar-text);
    padding: 0.75rem 1rem;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
}

.sidebar .nav-link:hover {
    background-color: var(--theme-sidebar-hover-bg);
    color: var(--theme-sidebar-hover-text);
}

.sidebar .nav-link.active {
    background-color: var(--theme-sidebar-active-bg);
    color: var(--theme-sidebar-active-text);
    border-left-color: var(--theme-sidebar-active-border);
    font-weight: 600;
}

.sidebar .nav-link i {
    width: 20px;
    margin-right: 8px;
}

/* Kill Bootstrap's default blue link colour on ALL sidebar anchors */
.sidebar a {
    color: inherit;
    text-decoration: none;
}

/* Sidebar section headers - direct navigation links */
.sidebar .section-header {
    padding: 0 !important;
    margin: 0 !important;
    list-style: none !important;
    border: none !important;
}

.sidebar .section-header a {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    padding: 0.75rem 1rem !important;
    color: var(--theme-sidebar-text, #495057) !important;
    font-weight: 600 !important;
    font-size: 0.8rem !important;
    text-transform: uppercase !important;
    letter-spacing: 0.06em !important;
    transition: all 0.2s ease !important;
    text-decoration: none !important;
    width: 100% !important;
    background-color: transparent !important;
    border: none !important;
    border-left: 3px solid transparent !important;
}

.sidebar .section-header a:hover {
    background-color: var(--theme-sidebar-hover-bg, #f8f9fa) !important;
    color: var(--theme-sidebar-hover-text, #4f46e5) !important;
}

.sidebar .section-header a i.bi-chevron-right {
    font-size: 0.875rem !important;
    opacity: 0.5 !important;
    transition: opacity 0.2s ease !important;
}

.sidebar .section-header a:hover i.bi-chevron-right {
    opacity: 1 !important;
}

/* Sidebar logo container - positioned below menu items */
.sidebar-logo-container {
    margin-top: 0;
    padding: 8px 16px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.sidebar-logo {
    width: 100%;
    max-width: 180px;
    min-width: 40px;
    height: auto;
    object-fit: contain;
    opacity: 0.7;
    transition: opacity 0.3s ease;
}

.sidebar-logo:hover {
    opacity: 1;
}

/* Ensure sidebar uses flexbox for proper bottom positioning */
.sidebar .position-sticky {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 56px);
    min-height: calc(100dvh - 56px);
}

.sidebar .nav.flex-column {
    flex: 0 0 auto;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2rem;
    margin-left: var(--sidebar-width);
    overflow-x: hidden;
    min-height: 100vh;
    min-height: 100dvh;
    background-color: var(--theme-bg-primary, #f8f9fa) !important;
}

.main-content.no-sidebar {
    margin-left: 0;
}

/* Footer */
footer {
    margin-left: var(--sidebar-width);
    margin-top: 3rem;
    padding: 2rem 0;
    border-top: 1px solid var(--theme-footer-border);
    background-color: var(--theme-footer-bg);
    color: var(--theme-text-secondary);
}

footer.no-sidebar {
    margin-left: 0;
}

.footer-links a {
    font-size: 0.9rem;
    transition: color 0.2s ease;
}

.footer-links a:hover {
    color: #0d6efd !important;
    text-decoration: underline !important;
}

.footer-links .text-muted {
    font-size: 0.9rem;
}

/* Responsive — tablet and below (matches navbar-expand-lg breakpoint) */
@media (max-width: 992px) {
    .sidebar {
        margin-left: calc(-1 * var(--sidebar-width));
        transition: margin-left 0.3s ease;
        padding-top: 1rem;
    }

    .sidebar.show {
        margin-left: 0;
        box-shadow: 2px 0 20px rgba(0,0,0,0.3);
    }

    .main-content {
        margin-left: 0;
        padding: 0;
    }

    footer {
        margin-left: 0;
    }

    /* Fix dropdown menus on mobile - prevent overflow */
    .dropdown-menu {
        position: absolute !important;
        max-width: calc(100vw - 20px);
        left: auto !important;
        right: 0 !important;
    }

    /* Ensure navbar dropdowns don't overflow screen */
    .navbar .dropdown-menu-end {
        right: 10px !important;
        left: auto !important;
    }

    /* User dropdown adjustments for mobile */
    #userDropdownMenu,
    #notificationDropdownMenu {
        min-width: 300px;
        max-width: calc(100vw - 20px);
    }

    /* Better navbar spacing on mobile */
    .navbar-brand {
        font-size: 1.1rem;
    }

    .navbar-brand img {
        height: 24px !important;
    }

    /* Navbar toggler adjustments */
    .navbar-toggler {
        padding: 0.25rem 0.5rem;
        font-size: 1rem;
    }
}

/* Extra small screens - phones in portrait */
@media (max-width: 576px) {
    .main-content {
        padding: 0;
    }

    /* Make dropdowns full width on very small screens for better usability */
    .navbar .dropdown-menu {
        width: calc(100vw - 30px);
        max-width: 320px;
    }

    /* Reduce navbar height slightly on very small screens */
    .navbar-brand {
        font-size: 1rem;
    }

    /* Smaller user avatar on mobile */
    .user-avatar {
        width: 28px;
        height: 28px;
        font-size: 0.75rem;
    }

    /* Better notification badge positioning */
    .position-absolute.badge {
        font-size: 0.65rem;
        padding: 0.2em 0.4em;
    }

    /* Notification bell icon on mobile */
    .notification-icon-wrapper {
        width: 28px;
        height: 28px;
    }

    .notification-icon-wrapper .bi-bell {
        font-size: 1rem;
    }

    .notification-count {
        min-width: 14px;
        height: 14px;
        font-size: 0.55rem;
    }
}

/* User dropdown with notifications */
#userDropdownMenu {
    min-width: 320px;
    max-height: 80vh;
    overflow-y: auto;
}

/* Notification dropdown menu */
#notificationDropdownMenu {
    min-width: 320px;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
}

/* Notification section in dropdown */
#notificationDropdownMenu #notificationList,
#userDropdownMenu #notificationList {
    max-height: 300px;
    overflow-y: auto;
}

#notificationDropdownMenu #notificationList .dropdown-item,
#userDropdownMenu #notificationList .dropdown-item {
    white-space: normal;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--theme-border-light);
}

#notificationDropdownMenu #notificationList .dropdown-item:last-child,
#userDropdownMenu #notificationList .dropdown-item:last-child {
    border-bottom: none;
}

/* Badge on user avatar */
.user-avatar .badge {
    font-size: 0.625rem;
    min-width: 18px;
    height: 18px;
    padding: 0.25em 0.4em;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1050 !important;
    position: absolute !important;
}

/* Notification bell icon */
.notification-icon-wrapper {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    position: relative;
    transition: background 0.2s ease;
}

.notification-icon-wrapper:hover {
    background: rgba(255, 255, 255, 0.2);
}

.notification-icon-wrapper .bi-bell {
    font-size: 1.125rem;
    color: rgba(255, 255, 255, 0.85);
    transition: color 0.2s ease;
}

.notification-icon-wrapper:hover .bi-bell {
    color: rgba(255, 255, 255, 1);
}

.notification-count {
    position: absolute;
    top: -2px;
    right: -2px;
    background-color: #dc3545;
    color: white;
    border-radius: 50%;
    min-width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.625rem;
    font-weight: 600;
    padding: 0 4px;
}

#notificationDropdown {
    color: rgba(255, 255, 255, 0.85);
    transition: color 0.2s ease;
    padding: 0.5rem 0.75rem;
}

#notificationDropdown:hover {
    color: rgba(255, 255, 255, 1);
}

#notificationDropdown .badge {
    font-size: 0.625rem;
    min-width: 18px;
    height: 18px;
    padding: 0.25em 0.4em;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Sidebar overlay for mobile */
@media (max-width: 992px) {
    /* Add dark overlay when sidebar is open */
    body.sidebar-open::before {
        content: '';
        position: fixed;
        top: var(--topnav-height);
        left: 0;
        right: 0;
        bottom: 0;
        background: var(--theme-overlay-bg);
        z-index: 1010;
        animation: fadeIn 0.3s ease;
    }

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

    /* Prevent body scroll when sidebar is open */
    body.sidebar-open {
        overflow: hidden;
    }
}

/* Footer Styles */
.footer {
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
}

.footer-links a {
    font-size: 0.9rem;
    transition: color 0.2s ease;
}

.footer-links a:hover {
    color: #0d6efd !important;
    text-decoration: underline !important;
}

.footer-links .text-muted {
    font-size: 0.9rem;
}
