/* ============================================
   UNIFIED SIDEBAR - WhatsApp Business Dashboard
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --sidebar-width: 260px;
    --sidebar-collapsed: 76px;
    --sidebar-bg: #1a1d21;
    --sidebar-hover: #2a2d32;
    --sidebar-active: rgba(37, 211, 102, 0.12);
    --sidebar-active-border: #25D366;
    --sidebar-text: #b0b7c3;
    --sidebar-text-active: #ffffff;
    --sidebar-heading: #6b7280;
    --sidebar-divider: #2a2d32;
    --accent: #25D366;
    --accent-hover: #20c05c;
    --topbar-height: 0px;
    --content-bg: #f0f2f5;
    --transition-speed: 0.25s;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--content-bg);
    display: flex;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ========== SIDEBAR ========== */
#app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    transition: width var(--transition-speed) ease, transform var(--transition-speed) ease;
    overflow: visible;
    box-shadow: 2px 0 8px rgba(0,0,0,0.15);
}

/* Brand Header */
.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 18px 20px;
    gap: 12px;
    border-bottom: 1px solid var(--sidebar-divider);
    flex-shrink: 0;
    min-height: 64px;
}

.sidebar-brand .brand-icon {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-brand .brand-icon i {
    font-size: 20px;
}

.sidebar-brand .brand-text {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    letter-spacing: -0.3px;
}

.sidebar-brand .brand-sub {
    font-size: 10px;
    color: var(--sidebar-heading);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Toggle Button */
.sidebar-toggle {
    position: absolute;
    top: 20px;
    right: -14px;
    width: 28px;
    height: 28px;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-divider);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--sidebar-text);
    font-size: 12px;
    z-index: 1001;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.sidebar-toggle:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: visible;
    padding: 12px 0;
}

.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--sidebar-divider); border-radius: 3px; }

.nav-section {
    margin-bottom: 8px;
}

.nav-section-label {
    padding: 12px 20px 6px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--sidebar-heading);
    white-space: nowrap;
    overflow: hidden;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    gap: 12px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 450;
    transition: all 0.15s ease;
    cursor: pointer;
    border-left: 3px solid transparent;
    white-space: nowrap;
    position: relative;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
}

.nav-item.active {
    background: var(--sidebar-active);
    color: var(--accent);
    border-left-color: var(--sidebar-active-border);
    font-weight: 600;
}

.nav-item .nav-icon {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.nav-item .nav-icon i {
    font-size: 16px;
    line-height: 1;
}

.nav-item:hover .nav-icon {
    transform: scale(1.1);
}

.nav-item.active .nav-icon {
    color: var(--accent);
}

.nav-item .nav-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Short label: hidden in expanded, shown in collapsed below icon */
.nav-item .nav-short-label {
    display: none;
    font-size: 9px;
    font-weight: 600;
    color: var(--sidebar-text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    line-height: 1;
}

.nav-item.active .nav-short-label {
    color: var(--accent);
}

.nav-item .nav-badge {
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    line-height: 1.4;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--sidebar-divider);
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.15s;
}

.sidebar-user:hover {
    background: var(--sidebar-hover);
}

.sidebar-user .user-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent), #128C7E);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 14px;
    flex-shrink: 0;
}

.sidebar-user .user-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.sidebar-user .user-name {
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user .user-role {
    font-size: 10px;
    color: var(--sidebar-heading);
    text-transform: uppercase;
}

.sidebar-logout {
    background: none;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: all 0.15s;
    font-size: 16px;
    flex-shrink: 0;
}

.sidebar-logout:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

/* ========== MAIN CONTENT ========== */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    transition: margin-left var(--transition-speed) ease;
    padding: 24px;
    width: calc(100% - var(--sidebar-width));
}

/* ========== COLLAPSED STATE ========== */
body.sidebar-collapsed #app-sidebar {
    width: var(--sidebar-collapsed);
}

body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .brand-sub,
body.sidebar-collapsed .nav-section-label,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .nav-badge,
body.sidebar-collapsed .user-info {
    opacity: 0;
    width: 0;
    overflow: hidden;
    transition: opacity 0.15s;
}

body.sidebar-collapsed .sidebar-brand {
    padding: 18px 16px;
    justify-content: center;
}

body.sidebar-collapsed .nav-item {
    padding: 16px 0;
    justify-content: center;
    border-left: 3px solid transparent;
    flex-direction: column;
    gap: 4px;
}

body.sidebar-collapsed .nav-item .nav-icon {
    width: 32px;
    height: 32px;
    font-size: 22px;
}

body.sidebar-collapsed .nav-item .nav-icon i {
    font-size: 22px;
}

body.sidebar-collapsed .nav-item:hover .nav-icon {
    transform: scale(1.1);
    transition: transform 0.2s ease;
}

/* Show short label below icon in collapsed mode */
body.sidebar-collapsed .nav-item .nav-short-label {
    display: block;
}

body.sidebar-collapsed .sidebar-user {
    justify-content: center;
}

body.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed);
    width: calc(100% - var(--sidebar-collapsed));
}

body.sidebar-collapsed .sidebar-toggle {
    transform: rotate(180deg);
}

/* ========== TOOLTIPS FOR COLLAPSED STATE ========== */
body.sidebar-collapsed .nav-item {
    position: relative;
}

body.sidebar-collapsed .nav-item::after {
    content: attr(title);
    position: absolute;
    left: calc(100% + 12px);
    top: 50%;
    transform: translateY(-50%);
    background: #1f2937;
    color: #ffffff;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease 0.3s, left 0.2s ease 0.3s;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    z-index: 99999;
}

body.sidebar-collapsed .nav-item::before {
    content: '';
    position: absolute;
    left: calc(100% + 6px);
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right-color: #1f2937;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease 0.3s, left 0.2s ease 0.3s;
    z-index: 99999;
}

body.sidebar-collapsed .nav-item:hover::after {
    opacity: 1;
    left: calc(100% + 16px);
}

body.sidebar-collapsed .nav-item:hover::before {
    opacity: 1;
    left: calc(100% + 10px);
}

/* ========== MOBILE ========== */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--sidebar-bg);
    z-index: 999;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.mobile-header .mobile-toggle {
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    padding: 6px;
}

.mobile-header .mobile-brand {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 999;
    backdrop-filter: blur(2px);
}

@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }

    /* Always hide sidebar on mobile regardless of collapsed state */
    #app-sidebar,
    body.sidebar-collapsed #app-sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
    }

    body.sidebar-mobile-open #app-sidebar,
    body.sidebar-mobile-open.sidebar-collapsed #app-sidebar {
        transform: translateX(0);
    }

    /* When mobile sidebar is open, show full labels (override collapsed) */
    body.sidebar-mobile-open.sidebar-collapsed .brand-text,
    body.sidebar-mobile-open.sidebar-collapsed .brand-sub,
    body.sidebar-mobile-open.sidebar-collapsed .nav-section-label,
    body.sidebar-mobile-open.sidebar-collapsed .nav-label,
    body.sidebar-mobile-open.sidebar-collapsed .nav-badge,
    body.sidebar-mobile-open.sidebar-collapsed .user-info {
        opacity: 1 !important;
        width: auto !important;
        overflow: visible !important;
    }

    body.sidebar-mobile-open.sidebar-collapsed .sidebar-brand {
        padding: 18px 20px !important;
        justify-content: flex-start !important;
    }

    body.sidebar-mobile-open.sidebar-collapsed .nav-item {
        padding: 10px 20px !important;
        justify-content: flex-start !important;
        flex-direction: row !important;
        gap: 12px !important;
    }

    body.sidebar-mobile-open.sidebar-collapsed .nav-item .nav-icon {
        width: 22px !important;
        height: 22px !important;
        font-size: 16px !important;
    }

    body.sidebar-mobile-open.sidebar-collapsed .nav-item .nav-icon i {
        font-size: 16px !important;
    }

    body.sidebar-mobile-open.sidebar-collapsed .sidebar-user {
        justify-content: flex-start !important;
    }

    body.sidebar-mobile-open.sidebar-collapsed .nav-item .nav-short-label {
        display: none !important;
    }

    body.sidebar-mobile-open .sidebar-overlay {
        display: block;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding-top: 72px;
        padding-left: 12px;
        padding-right: 12px;
    }

    body.sidebar-collapsed .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .sidebar-toggle {
        display: none;
    }

    /* Prevent horizontal overflow on all pages */
    body { overflow-x: hidden; }

    /* Page header: stack on small screens */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .page-header h1 { font-size: 18px; }

    /* Cards: reduce padding */
    .card-body { padding: 12px !important; }

    /* Buttons in page header: full width on mobile */
    .page-header .btn { width: 100%; }
}

/* ========== PAGE HEADER ========== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h1 {
    font-size: 22px;
    font-weight: 700;
    color: #1f2937;
    margin: 0;
}

.page-header .page-subtitle {
    font-size: 13px;
    color: #6b7280;
    margin-top: 2px;
}

/* ========== STATUS DOT ========== */
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

.status-dot.online { background: var(--accent); box-shadow: 0 0 6px rgba(37,211,102,0.4); }
.status-dot.offline { background: #ef4444; }
