﻿/* ============================================
   UNIVERSAL SIDEBAR TOGGLE BUTTON
   Premium Redesign — RTL Arabic First
   ============================================ */

/* ============================================
   DESKTOP STYLES (≥ 992px)
   ============================================ */
@media (min-width: 992px) {

    .sidebar-toggle-btn {
        position: absolute;
        top: 50%;
        left: 300px;
        transform: translateY(-50%);
        width: 20px;
        height: 48px;
        border: none;
        border-radius: 0 8px 8px 0;
        background: #ffffff;
        color: #4361ee;
        box-shadow: 2px 0 12px rgba(67, 97, 238, 0.13);
        cursor: pointer;
        z-index: 1050;
        display: flex !important;
        align-items: center;
        justify-content: center;
        padding: 0;
        transition: width 0.22s ease, background 0.22s ease, box-shadow 0.22s ease, color 0.22s ease;
        outline: none;
        border: 1px solid rgba(67, 97, 238, 0.10);
        border-left: none;
        overflow: visible;
        will-change: width, background;
        backface-visibility: hidden;
    }

        .sidebar-toggle-btn:hover {
            width: 28px;
            background: #4361ee;
            color: #ffffff;
            box-shadow: 2px 0 20px rgba(67, 97, 238, 0.28);
            border-color: transparent;
        }

        .sidebar-toggle-btn:active {
            transform: translateY(-50%) scaleY(0.96);
        }

    /* Collapsed state — button sits at left edge */
    .sidebar-hidden .sidebar-toggle-btn {
        left: 0 !important;
        background: #4361ee;
        color: #ffffff;
        border-color: transparent;
        border-radius: 0 8px 8px 0;
        box-shadow: 2px 0 16px rgba(67, 97, 238, 0.22);
        animation: togglePulse 2.8s ease-in-out infinite;
    }

        .sidebar-hidden .sidebar-toggle-btn:hover {
            background: #3451d1;
            width: 28px;
            animation: none;
        }

    @keyframes togglePulse {
        0%, 100% {
            box-shadow: 2px 0 12px rgba(67, 97, 238, 0.18);
        }

        50% {
            box-shadow: 2px 0 24px rgba(67, 97, 238, 0.40);
        }
    }

    /* Icon */
    .sidebar-toggle-btn .toggle-icon {
        font-size: 11px;
        font-weight: 700;
        line-height: 1;
        transition: transform 0.22s ease;
        display: block;
        pointer-events: none;
    }

    /* Hide mobile-only elements */
    .sidebar-toggle-btn .toggle-label,
    .sidebar-toggle-btn .toggle-arrow {
        display: none !important;
    }

    /* Tooltip */
    .sidebar-toggle-btn .toggle-tooltip {
        position: absolute;
        left: calc(100% + 7px);
        top: 50%;
        transform: translateY(-50%);
        background: rgba(15, 15, 35, 0.88);
        color: #fff;
        padding: 3px 8px;
        border-radius: 4px;
        font-size: 10px;
        font-weight: 500;
        white-space: nowrap;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.18s ease, transform 0.18s ease;
        letter-spacing: 0.15px;
        display: block !important;
        z-index: 9999;
    }

        .sidebar-toggle-btn .toggle-tooltip::before {
            content: '';
            position: absolute;
            right: 100%;
            top: 50%;
            transform: translateY(-50%);
            border: 4px solid transparent;
            border-right-color: rgba(15, 15, 35, 0.88);
        }

    .sidebar-toggle-btn:hover .toggle-tooltip {
        opacity: 1;
        transform: translateY(-50%) translateX(3px);
    }

    /* Sidebar dimensions */
    .modal-sidebar {
        flex: 0 0 300px;
        width: 300px;
        transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1), flex-basis 0.28s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.22s ease;
        overflow: hidden;
        position: relative;
        padding: 0 !important;
        will-change: width, flex-basis, opacity;
    }

        .modal-sidebar.sidebar-collapsed {
            flex-basis: 0 !important;
            width: 0 !important;
            min-width: 0 !important;
            max-width: 0 !important;
            opacity: 0;
            padding: 0 !important;
            margin: 0 !important;
            pointer-events: none !important;
        }

    .modal-content-area {
        flex: 1;
        transition: flex 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        will-change: flex;
    }

    /* Ultra-compact sidebar inner spacing */
    .modal-sidebar .premium-customer-list {
        padding: 2px 4px !important;
    }

    .modal-sidebar .list-group-item {
        padding: 5px 8px !important;
        margin-bottom: 1px !important;
        border-radius: 5px !important;
    }

    .modal-sidebar .premium-stats-footer {
        padding: 5px 10px !important;
    }

    .modal-sidebar .px-3.py-3 {
        padding: 5px 10px !important;
    }

    .modal-sidebar .premium-search-box {
        margin-bottom: 2px !important;
    }

    .modal-sidebar .d-flex.align-items-center.justify-content-between.mb-3 {
        margin-bottom: 3px !important;
    }
}

/* ============================================
   RTL DESKTOP — flip button side
   ============================================ */
@media (min-width: 992px) {
    [dir="rtl"] .sidebar-toggle-btn {
        left: auto;
        right: 300px;
        border-radius: 8px 0 0 8px;
        border-left: 1px solid rgba(67, 97, 238, 0.10);
        border-right: none;
        box-shadow: -2px 0 12px rgba(67, 97, 238, 0.13);
    }

        [dir="rtl"] .sidebar-toggle-btn:hover {
            box-shadow: -2px 0 20px rgba(67, 97, 238, 0.28);
        }

    [dir="rtl"] .sidebar-hidden .sidebar-toggle-btn {
        right: 0 !important;
        left: auto !important;
        border-radius: 8px 0 0 8px;
        box-shadow: -2px 0 16px rgba(67, 97, 238, 0.22);
    }

    [dir="rtl"] .sidebar-toggle-btn .toggle-tooltip {
        left: auto;
        right: calc(100% + 7px);
    }

        [dir="rtl"] .sidebar-toggle-btn .toggle-tooltip::before {
            right: auto;
            left: 100%;
            border-right-color: transparent;
            border-left-color: rgba(15, 15, 35, 0.88);
        }
}

/* ============================================
   MOBILE STYLES (< 992px)
   ============================================ */
@media (max-width: 991.98px) {

    .sidebar-toggle-btn {
        display: flex !important;
        align-items: center;
        width: auto;
        margin: 3px 5px;
        padding: 6px 11px;
        border: none;
        border-radius: 7px;
        background: linear-gradient(135deg, #4361ee 0%, #7c3aed 100%);
        color: #ffffff;
        box-shadow: 0 2px 10px rgba(67, 97, 238, 0.22);
        cursor: pointer;
        font-family: inherit;
        font-size: 12px;
        font-weight: 500;
        gap: 5px;
        min-height: 32px;
        letter-spacing: 0.15px;
        transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
        outline: none;
        position: relative;
        z-index: 10;
        will-change: transform;
    }

        .sidebar-toggle-btn:active {
            transform: scale(0.97);
            box-shadow: 0 1px 6px rgba(67, 97, 238, 0.12);
        }

        .sidebar-toggle-btn .toggle-icon {
            font-size: 14px;
            flex-shrink: 0;
            transition: none;
        }

        .sidebar-toggle-btn .toggle-label {
            flex: 1;
            text-align: center;
            display: block !important;
            font-size: 11.5px;
            font-weight: 500;
            letter-spacing: 0.15px;
        }

        .sidebar-toggle-btn .toggle-arrow {
            font-size: 10px;
            display: block !important;
            flex-shrink: 0;
            transition: transform 0.25s ease;
        }

        .sidebar-toggle-btn .toggle-tooltip {
            display: none !important;
        }

    /* Sidebar is hidden (collapsed) → gradient flips */
    .sidebar-hidden .sidebar-toggle-btn {
        background: linear-gradient(135deg, #7c3aed 0%, #4361ee 100%);
        box-shadow: 0 2px 14px rgba(67, 97, 238, 0.28);
    }

    /* Mobile sidebar animation */
    .modal-sidebar {
        display: block !important;
        overflow: hidden;
        transition: max-height 0.28s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.22s ease;
        will-change: max-height, opacity;
        padding: 0 !important;
    }

        .modal-sidebar:not(.sidebar-collapsed) {
            max-height: 2000px !important;
            opacity: 1 !important;
            pointer-events: auto !important;
        }

        .modal-sidebar.sidebar-collapsed {
            max-height: 0 !important;
            opacity: 0 !important;
            pointer-events: none !important;
            border: none !important;
            padding: 0 !important;
            margin: 0 !important;
        }

        /* Prevent Bootstrap collapse fighting us */
        .modal-sidebar.collapse,
        .modal-sidebar.collapse.show {
            display: block !important;
            height: auto !important;
            visibility: visible !important;
        }

    .modal-content-area.sidebar-expanded {
        flex: inherit !important;
        max-width: inherit !important;
    }

    /* Compact mobile spacing */
    .modal-sidebar .premium-customer-list {
        padding: 1px 2px !important;
    }

    .modal-sidebar .list-group-item {
        padding: 4px 6px !important;
        margin-bottom: 1px !important;
        border-radius: 4px !important;
    }

    .modal-sidebar .premium-stats-footer {
        padding: 4px 6px !important;
    }

    .modal-sidebar .px-3.py-3 {
        padding: 4px 8px !important;
    }

    .modal-sidebar .premium-search-box {
        margin-bottom: 2px !important;
    }

    .modal-sidebar .d-flex.align-items-center.justify-content-between.mb-3 {
        margin-bottom: 2px !important;
    }
}

/* ============================================
   COMMON STYLES
   ============================================ */
.sidebar-toggle-btn:focus-visible {
    outline: 2px solid rgba(67, 97, 238, 0.45);
    outline-offset: 2px;
}

/* Smooth inner content fade */
.modal-sidebar .invoice-sidebar-inner-content {
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.modal-sidebar.sidebar-collapsed .invoice-sidebar-inner-content {
    opacity: 0;
    transform: translateX(-5px);
    pointer-events: none;
}

.modal-sidebar:not(.sidebar-collapsed) .invoice-sidebar-inner-content {
    opacity: 1;
    transform: translateX(0);
}

/* ============================================
   DARK THEME
   ============================================ */
@media (min-width: 992px) {
    [data-theme="dark"] .sidebar-toggle-btn {
        background: rgba(22, 22, 44, 0.96);
        color: #7b9fff;
        border-color: rgba(108, 140, 255, 0.10);
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.28);
    }

        [data-theme="dark"] .sidebar-toggle-btn:hover {
            background: #5a7aff;
            color: #ffffff;
            border-color: transparent;
        }

    [data-theme="dark"] .sidebar-hidden .sidebar-toggle-btn {
        background: #5a7aff;
        color: #ffffff;
        border-color: transparent;
    }

    [data-theme="dark"] .sidebar-toggle-btn .toggle-tooltip {
        background: rgba(255, 255, 255, 0.10);
        backdrop-filter: blur(10px);
        color: #e8eeff;
    }

        [data-theme="dark"] .sidebar-toggle-btn .toggle-tooltip::before {
            border-right-color: rgba(255, 255, 255, 0.10);
        }
}

@media (max-width: 991.98px) {
    [data-theme="dark"] .sidebar-toggle-btn {
        background: linear-gradient(135deg, #5a7aff 0%, #a78bfa 100%);
        color: #0f0f23;
        box-shadow: 0 2px 14px rgba(90, 122, 255, 0.25);
    }

    [data-theme="dark"] .sidebar-hidden .sidebar-toggle-btn {
        background: linear-gradient(135deg, #a78bfa 0%, #5a7aff 100%);
    }
}
