/* CRM System - Admin Layout Styles */

/* 
 * Layout Structure:
 * - Sidebar: Fixed left sidebar
 * - Main Content: Right side content area
 * - Navbar (Topbar): Fixed at top of main content
 * - Footer: At bottom of main content
 */

/* Reset body padding */
body {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

/* Sidebar Styles */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 260px;
    background: #2c3e50;
    color: #ecf0f1;
    z-index: 1000;
    transition: all 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-header {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-brand {
    font-size: 1.25rem;
    font-weight: 600;
    color: #fff;
    text-decoration: none;
    display: flex;
    align-items: center;
}

.sidebar-brand:hover {
    color: #3498db;
}

.sidebar-toggle {
    background: none;
    border: none;
    color: #ecf0f1;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    display: none;
}

.sidebar-nav {
    padding: 1rem 0;
}

.sidebar-nav .nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav .nav-item {
    margin: 0;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: #bdc3c7;
    text-decoration: none;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.sidebar-nav .nav-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    border-left-color: #3498db;
}

.sidebar-nav .nav-link.active {
    background: rgba(52, 152, 219, 0.2);
    color: #fff;
    border-left-color: #3498db;
}

.sidebar-nav .nav-link i {
    width: 20px;
    margin-right: 0.75rem;
    font-size: 1rem;
}

.sidebar-nav .nav-text {
    font-size: 0.95rem;
}

/* Badge (counter) for nav items: align to the right of the link */
.sidebar-nav .nav-link {
    position: relative;
    display: flex;
    align-items: center;
}

/* Allow the nav text to take available space so the badge can be pinned to the right */
.sidebar-nav .nav-text {
    flex: 1 1 auto;
}

.sidebar-nav .nav-badge {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.75rem;
    padding: 0.18rem 0.45rem;
    line-height: 1;
    display: inline-block;
}

/* When sidebar is collapsed, hide the numeric badges to avoid overflow */
.sidebar.collapsed .nav-badge {
    display: none;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    margin-top: auto;
}

.sidebar-user {
    display: flex;
    align-items: center;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0.5rem;
}

.sidebar-user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    margin-right: 0.75rem;
}

.sidebar-user-info {
    flex: 1;
}

.sidebar-user-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
    margin: 0;
}

.sidebar-user-role {
    font-size: 0.75rem;
    color: #95a5a6;
    margin: 0;
}

/* Main Content Area */
.main-content {
    margin-left: 260px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: #f4f6f9;
    transition: margin-left 0.3s ease;
}

/* Topbar (Navbar) */
.topbar {
    position: sticky;
    top: 0;
    z-index: 11050; /* elevated to sit above overlays/backdrops */
    background: #fff;
    border-bottom: 1px solid #e3e6f0;
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar-left .sidebar-toggle {
    background: none;
    border: none;
    color: #5a5c69;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    display: none;
}

.topbar-left h1 {
    margin: 0;
    font-size: 1.25rem;
    color: #5a5c69;
    font-weight: 600;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Uniform notification and cart button appearance across pages */
.topbar-right .notifications-toggle,
.topbar-right #notificationsToggle,
.topbar-right #cartButton,
.topbar .notifications .btn,
.topbar #cartButton {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: #0d6efd; /* Bootstrap primary */
    color: #fff;
    border-radius: 8px;
    border: none;
    padding: 0;
    box-shadow: 0 2px 6px rgba(13,110,253,0.12);
}

.topbar-right .notifications-toggle i,
.topbar-right #cartButton i {
    font-size: 1.05rem;
}

/* Badge positioning for both badge ids used across layouts */
#notificationsBadge, #notificationCount, #notificationsBadge.small, #cartBadge {
    position: absolute;
    top: -6px;
    right: -6px;
    display: inline-block;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    padding: 0 5px;
    font-size: 0.675rem;
    border-radius: 9px;
    background: #dc3545; /* danger */
    color: #fff;
    text-align: center;
}

/* Ensure notification/cart button keeps consistent spacing */
.topbar-right .notifications,
.topbar-right #cartButton {
    margin-right: 0.25rem;
}

/* Ensure the user dropdown menu floats above modal/backdrop overlays */
.user-menu .dropdown-menu {
    z-index: 11060;
}

.theme-toggle {
    background: none;
    border: none;
    color: #5a5c69;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    background: #f8f9fc;
}

.user-menu .dropdown-toggle {
    background: none;
    border: none;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.2s ease;
}

/* Ensure Bootstrap modals and Google Places suggestions float above the topbar/header */
.modal-backdrop { z-index: 11120 !important; }
.modal { z-index: 11130 !important; }
.pac-container { z-index: 11140 !important; pointer-events: auto; }
.user-avatar:hover {
    transform: scale(1.05);
}

/* Content Wrapper */
.content-wrapper {
    flex: 1;
    padding: 1.5rem;
}

/* Breadcrumb */
.breadcrumb-wrapper {
    margin-bottom: 1.5rem;
}

.breadcrumb {
    background: transparent;
    padding: 0;
    margin: 0;
}

.breadcrumb-item {
    font-size: 0.875rem;
}

.breadcrumb-item a {
    color: #858796;
    text-decoration: none;
}

.breadcrumb-item a:hover {
    color: #4e73df;
}

.breadcrumb-item.active {
    color: #5a5c69;
}

/* Footer */
.footer {
    background: #fff;
    border-top: 1px solid #e3e6f0;
    padding: 1.5rem;
    margin-top: auto;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.footer-left {
    color: #858796;
    font-size: 0.875rem;
}

.footer-right {
    display: flex;
    gap: 1.5rem;
}

.footer-link {
    color: #858796;
    text-decoration: none;
    font-size: 0.875rem;
    transition: color 0.2s ease;
}

.footer-link:hover {
    color: #4e73df;
}

/* Sidebar Collapsed State (Desktop) */
.sidebar.collapsed {
    width: 70px;
}

.sidebar.collapsed .sidebar-brand {
    justify-content: center;
}

.sidebar.collapsed .sidebar-brand i {
    margin-right: 0;
}

.sidebar.collapsed .sidebar-brand span {
    display: none;
}

/* Show/hide logo vs favicon when sidebar is collapsed */
.sidebar-brand img.app-logo {
    max-height: 70px;
    max-width: 200px;
    object-fit: contain;
    display: inline-block;
}
.sidebar-brand img.favicon-small {
    display: none;
    max-height: 28px;
    width: auto;
}
.sidebar.collapsed .sidebar-brand img.app-logo {
    display: none;
}
.sidebar.collapsed .sidebar-brand img.favicon-small {
    display: inline-block;
}

.sidebar.collapsed .nav-text {
    display: none;
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding-left: 0;
    padding-right: 0;
}

.sidebar.collapsed .nav-link i {
    margin-right: 0;
}

.sidebar.collapsed .sidebar-footer {
    padding: 0.5rem;
}

.sidebar.collapsed .sidebar-user {
    flex-direction: column;
    padding: 0.5rem;
}

.sidebar.collapsed .sidebar-user-avatar {
    margin-right: 0;
    margin-bottom: 0.5rem;
}

.sidebar.collapsed .sidebar-user-info {
    display: none;
}

.main-content.sidebar-collapsed {
    margin-left: 70px;
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

/* Responsive Design */
@media (max-width: 991.98px) {
    .sidebar {
        left: -260px;
    }

    .sidebar.show {
        left: 0;
        box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
    }

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

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

    .topbar-left .sidebar-toggle {
        display: block;
    }

    .sidebar-header .sidebar-toggle {
        display: block;
    }
}

@media (max-width: 767.98px) {
    .topbar {
        padding: 0.75rem 1rem;
    }

    .topbar-left h1 {
        font-size: 1rem;
    }

    .content-wrapper {
        padding: 1rem;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
    }

    .footer-right {
        justify-content: center;
    }
}

/* Dark Theme Support */
[data-bs-theme="dark"] .sidebar {
    background: #1a252f;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}

[data-bs-theme="dark"] .main-content {
    background: #151d26;
}

[data-bs-theme="dark"] .topbar {
    background: #1e2a35;
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

[data-bs-theme="dark"] .topbar-left h1 {
    color: #e3e6f0;
}

[data-bs-theme="dark"] .topbar-left .sidebar-toggle,
[data-bs-theme="dark"] .theme-toggle {
    color: #e3e6f0;
}

[data-bs-theme="dark"] .theme-toggle:hover {
    background: rgba(255, 255, 255, 0.05);
}

[data-bs-theme="dark"] .footer {
    background: #1e2a35;
    border-top-color: rgba(255, 255, 255, 0.1);
}

[data-bs-theme="dark"] .footer-left,
[data-bs-theme="dark"] .footer-link {
    color: #adb5bd;
}

[data-bs-theme="dark"] .footer-link:hover {
    color: #3498db;
}

[data-bs-theme="dark"] .breadcrumb-item a {
    color: #adb5bd;
}

[data-bs-theme="dark"] .breadcrumb-item a:hover {
    color: #3498db;
}

[data-bs-theme="dark"] .breadcrumb-item.active {
    color: #e3e6f0;
}

/* Toast Container */
#toastContainer {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
}

/* Scrollbar Styling */
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}
