/* Global Styles & Mobile App Shell */
:root {
    color-scheme: light;
    --top-nav-height: 54px;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color-scheme: light;
}

.app-wrapper {
    display: flex;
    flex: 1;
    position: relative;
    min-height: 100vh;
    width: 100%;
}

/* Sticky Top Navigation Bar (Tier 1) */
.top-nav-bar {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid #dee2e6;
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: var(--top-nav-height, 54px);
    min-height: var(--top-nav-height, 54px);
}

/* Ensure Dropdown Menus render above sticky bars */
.dropdown-menu {
    z-index: 1040 !important;
}

/* Tier 2: Sticky Table Headers inside Scroll Containers */
.table-responsive thead th,
.table-responsive thead.sticky-top th,
thead.sticky-top th {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: #212529 !important;
    color: #ffffff !important;
    box-shadow: inset 0 -1px 0 #495057;
}

.main-content {
    flex: 1;
    padding: 20px;
    background-color: #f8f9fa;
    min-width: 0;
}

/* Sidebar Desktop & Mobile Off-canvas Drawer */
.sidebar {
    width: 280px;
    min-width: 280px;
    min-height: 100vh;
    background-color: #212529;
    z-index: 1045;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-logo {
    max-width: 200px;
    height: auto;
}

.sidebar-close-btn {
    display: none;
}

/* Sidebar Backdrop for Mobile */
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.sidebar-backdrop.show {
    opacity: 1;
    visibility: visible;
}

/* Desktop Sidebar collapse */
@media (min-width: 992px) {
    .sidebar.sidebar-collapsed,
    .sidebar.d-none {
        display: none !important;
    }
}

/* Mobile & Tablet Drawer (< 992px) */
@media (max-width: 991.98px) {
    .sidebar {
        display: flex !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        height: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        overflow-y: auto !important;
        overscroll-behavior-y: contain !important;
        -webkit-overflow-scrolling: touch !important;
        transform: translateX(-100%) !important;
        box-shadow: none !important;
        z-index: 1050 !important;
        padding-bottom: calc(90px + env(safe-area-inset-bottom, 20px)) !important;
    }

    .sidebar.show {
        transform: translateX(0) !important;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35) !important;
    }

    .sidebar-close-btn {
        display: inline-flex !important;
        align-items: center;
        justify-content: center;
    }

    .main-content {
        padding: 12px 8px !important;
    }
    
    .main-content > .container-fluid {
        padding-left: 4px !important;
        padding-right: 4px !important;
    }
}

/* Touch targets & Form Zoom Prevention for Mobile */
@media (max-width: 767.98px) {
    input[type="text"],
    input[type="date"],
    input[type="time"],
    input[type="number"],
    input[type="email"],
    input[type="tel"],
    input[type="password"],
    select.form-select,
    .ts-control input {
        font-size: 16px !important; /* Prevents auto-zoom on iOS */
    }

    .btn,
    .form-check-label,
    .nav-link {
        min-height: 38px;
    }
}

/* =========================================================
   GLOBAL MOBILE MODAL ARCHITECTURE (95% Screen Width & Scroll)
   ========================================================= */
@media (max-width: 767.98px) {
    .modal-dialog,
    .modal-dialog.modal-sm,
    .modal-dialog.modal-lg,
    .modal-dialog.modal-xl {
        width: 95vw !important;
        max-width: 95vw !important;
        margin: 10px auto !important;
    }

    .modal-content {
        border-radius: 12px !important;
        overflow: hidden !important;
        max-height: calc(100vh - 20px) !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .modal-header {
        position: sticky;
        top: 0;
        z-index: 1055;
        padding: 0.75rem 1rem !important;
    }

    .modal-body {
        padding: 0.85rem !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        max-height: calc(100vh - 140px) !important;
    }

    .modal-footer {
        position: sticky;
        bottom: 0;
        z-index: 1055;
        padding: 0.65rem 1rem !important;
        background-color: #fff;
        border-top: 1px solid #dee2e6;
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    /* Modal Close Button Size */
    .modal-header .btn-close {
        min-width: 36px;
        min-height: 36px;
        padding: 0.5rem;
    }
}

.text-pink-bright {
    color: #E040FB !important;
}

/* TomSelect dropdown layering & high z-index fix */
.ts-dropdown {
    z-index: 1085 !important;
}
.ts-wrapper.focus {
    z-index: 1075 !important;
}
.modal .ts-dropdown,
body > .ts-dropdown {
    z-index: 1095 !important;
}

/* =========================================================
   OPERATIONS (LOGISTICA) STYLES
   ========================================================= */
.pulse-red {
    animation: ops-pulse 2s infinite;
}

@keyframes ops-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(220, 53, 69, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
    }
}

.pulse-red-light {
    animation: ops-pulse-light 2s infinite;
}

@keyframes ops-pulse-light {
    0% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4);
    }
    70% {
        box-shadow: 0 0 0 8px rgba(220, 53, 69, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
    }
}

.card-overdue {
    border: 2px solid #dc3545 !important;
    background-color: rgba(220, 53, 69, 0.04);
}

.card-confirmed {
    border: 2.5px solid #198754 !important;
}

.return-note-callout {
    padding: 0.75rem;
    border-left: 4px solid #fd7e14;
    border-radius: 0.5rem;
    background: rgba(255, 243, 205, 0.7);
}

.return-note-label {
    margin-bottom: 0.35rem;
    color: #b35a00;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.return-note-text {
    color: #5c3b12;
    font-size: 0.9rem;
    font-style: italic;
    line-height: 1.4;
    word-break: break-word;
}

.card-swap {
    border: 2.5px solid #ffc107 !important;
    background-color: rgba(255, 193, 7, 0.04) !important;
}

.highlight-swap {
    animation: ops-highlight-pulse 2s ease-in-out;
}

@keyframes ops-highlight-pulse {
    0%, 100% {
        box-shadow: none;
    }
    50% {
        box-shadow: 0 0 20px #ffc107;
        background-color: rgba(255, 193, 7, 0.2) !important;
    }
}

/* Operations Top Header */
.ops-top-header {
    position: relative;
    z-index: 1025;
    background: #ffffff;
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 1rem;
    border: 1px solid #e9ecef;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* Operations Sticky Search & Filter Bar */
.ops-sticky-bar {
    position: sticky;
    top: var(--top-nav-height, 54px);
    z-index: 1020;
    background: rgba(248, 249, 250, 0.96);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid #dee2e6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    padding: 10px 14px;
    margin-bottom: 1rem;
    border-radius: 12px;
}

.ops-status-strip {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 4px 2px 6px 2px;
    scrollbar-width: thin;
}

.ops-status-strip::-webkit-scrollbar {
    height: 4px;
}

.ops-status-strip::-webkit-scrollbar-thumb {
    background-color: #ced4da;
    border-radius: 4px;
}

.ops-status-btn {
    white-space: nowrap;
    border-radius: 20px !important;
    font-size: 0.84rem;
    padding: 6px 14px !important;
    font-weight: 600;
    border: 1px solid #dee2e6 !important;
    background-color: #ffffff !important;
    color: #495057 !important;
    transition: all 0.15s ease;
    text-decoration: none !important;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 36px;
}

.ops-status-btn:hover {
    background-color: #f1f3f5 !important;
    color: #212529 !important;
}

.ops-status-btn.active {
    background-color: #0d6efd !important;
    color: #ffffff !important;
    border-color: #0d6efd !important;
    box-shadow: 0 2px 6px rgba(13, 110, 253, 0.25);
}

.ops-status-btn.btn-outline-danger.active {
    background-color: #dc3545 !important;
    border-color: #dc3545 !important;
    color: #fff !important;
}

.ops-status-btn.btn-outline-warning.active {
    background-color: #ffc107 !important;
    border-color: #ffc107 !important;
    color: #000 !important;
}

.ops-status-btn.btn-outline-success.active {
    background-color: #198754 !important;
    border-color: #198754 !important;
    color: #fff !important;
}

/* Mobile Segmented Switcher (Livrari ⟷ Retururi) */
.ops-segmented-tabs {
    display: none;
    background-color: #e9ecef;
    padding: 4px;
    border-radius: 12px;
    margin-bottom: 1rem;
    gap: 4px;
}

.ops-tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 12px !important;
    border-radius: 9px !important;
    font-size: 0.95rem;
    font-weight: 700;
    border: none !important;
    background: transparent !important;
    color: #6c757d !important;
    transition: all 0.2s ease;
    cursor: pointer;
    min-height: 44px;
}

.ops-tab-btn.active.tab-deliveries {
    background-color: #0d6efd !important;
    color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(13, 110, 253, 0.3);
}

.ops-tab-btn.active.tab-returns {
    background-color: #dc3545 !important;
    color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(220, 53, 69, 0.3);
}

.ops-tab-btn .badge {
    font-size: 0.8rem;
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: 700;
    transition: all 0.2s ease;
}

/* High contrast badges in unselected tabs */
.ops-tab-btn.tab-deliveries:not(.active) .badge {
    background-color: #ffffff !important;
    color: #0d6efd !important;
    border: 1px solid #ced4da;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.ops-tab-btn.tab-returns:not(.active) .badge {
    background-color: #ffffff !important;
    color: #dc3545 !important;
    border: 1px solid #ced4da;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* High contrast badges in active tabs */
.ops-tab-btn.active.tab-deliveries .badge {
    background-color: #ffffff !important;
    color: #0d6efd !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.ops-tab-btn.active.tab-returns .badge {
    background-color: #ffffff !important;
    color: #dc3545 !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Mobile Section Stacking Logic */
@media (max-width: 991.98px) {
    .ops-segmented-tabs {
        display: flex !important;
    }

    .ops-section-col {
        display: none !important;
    }

    .ops-section-col.active-tab-section {
        display: block !important;
    }
}

@media (min-width: 992px) {
    .ops-section-col {
        display: block !important;
    }
}

/* Operational Touch Cards */
.ops-card-item {
    border-radius: 12px !important;
    margin-bottom: 12px;
    border: 1px solid #e9ecef !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
    background-color: #ffffff !important;
}

.ops-contact-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 6px;
    margin-top: 8px;
}

.ops-contact-btn {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-weight: 600;
    font-size: 0.86rem;
    border-radius: 8px !important;
    padding: 8px 4px !important;
    text-decoration: none !important;
    text-align: center;
}

@media (max-width: 575.98px) {
    .ops-contact-grid {
        grid-template-columns: 1.4fr 1.2fr 0.9fr;
    }
    .ops-contact-btn {
        font-size: 0.8rem;
        padding: 6px 2px !important;
    }
}

.ops-hero-cta {
    min-height: 46px;
    font-size: 1rem;
    font-weight: 700;
    border-radius: 10px !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.ops-action-toolbar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    margin-top: 8px;
}

.ops-action-btn {
    min-height: 38px;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 6px 4px !important;
    border-radius: 8px !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-align: center;
    white-space: nowrap;
}

@media (max-width: 480px) {
    .ops-action-toolbar {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    .ops-action-btn {
        min-height: 40px;
        font-size: 0.85rem;
    }
}

.ops-floating-filter-btn {
    position: fixed;
    bottom: 24px;
    right: 18px;
    z-index: 1025;
    display: none;
    padding: 10px 18px !important;
    font-weight: 700;
    font-size: 0.92rem;
    border-radius: 50px !important;
    box-shadow: 0 4px 16px rgba(13, 110, 253, 0.45) !important;
}

@media (max-width: 991.98px) {
    .ops-floating-filter-btn {
        display: inline-flex !important;
        align-items: center;
        gap: 8px;
    }

    .ops-content-container {
        padding-bottom: 75px !important;
    }
}

/* =========================================================
   STANDARDIZED CRM INDEX & LISTING STYLES (crm-index-standard)
   ========================================================= */

/* Floating Mobile Filter Button */
.floating-filter-btn {
    position: fixed;
    bottom: 20px;
    right: 16px;
    z-index: 1025;
    display: none;
    padding: 10px 18px;
    font-weight: 700;
    font-size: 0.9rem;
    border-radius: 50px !important;
    box-shadow: 0 4px 16px rgba(13, 110, 253, 0.4) !important;
    background-color: #0d6efd;
    border: none;
    color: #ffffff;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.floating-filter-btn:hover,
.floating-filter-btn:focus {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(13, 110, 253, 0.5) !important;
    color: #ffffff;
}

@media (max-width: 991.98px) {
    .floating-filter-btn {
        display: inline-flex;
        align-items: center;
        gap: 6px;
    }
}

/* Collapse Icon rotation */
[data-bs-toggle="collapse"][aria-expanded="true"] .collapse-icon {
    transform: rotate(180deg);
}
.collapse-icon {
    transition: transform 0.2s ease-in-out;
}

/* Active Filter Chips Bar */
.active-filters-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 8px 12px;
    margin-bottom: 1rem;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background-color: #ffffff;
    color: #1e293b;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 3px 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}