/* ================================================================
   Logistics Admin Dashboard - Custom Styles
   ================================================================ */

/* ----------------------------------------------------------------
   Logo Customization
   ---------------------------------------------------------------- */
.header-logo img {
    height: 50px !important;
    width: auto;
    max-height: 50px;
}

/* Make sure the header accommodates the larger logo */
.header {
    min-height: 70px;
}

.header .header-logo {
    display: flex;
    align-items: center;
}

/* Create banner background for header through metrics cards only */
.wrapper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 450px;
    /* Covers header + page title + breadcrumb + metric cards */
    background-image: url('../media/patterns/header-bg.jpg') !important;
    background-size: cover !important;
    background-position: center top !important;
    background-repeat: no-repeat !important;
    z-index: 0;
}

/* Ensure all content is above the background */
.wrapper>* {
    position: relative;
    z-index: 1;
}

/* Header must stack above page content so dropdowns render on top */
#kt_header {
    z-index: 100;
}

/* Remove stacking context from content so Bootstrap modals (z-index: 1055)
   and their backdrop (z-index: 1050) operate at the root level correctly.
   Without this, modals are trapped inside the z-index:1 stacking context and
   the backdrop blocks all interaction with the modal. */
#kt_content {
    z-index: auto !important;
}

/* Make sure the rest of the page has white/normal background */
.content {
    background: transparent;
}

/* ----------------------------------------------------------------
   Status Badge Colors
   ---------------------------------------------------------------- */
.badge-shipment-pending {
    background-color: #f1f1f4;
    color: #7e8299;
}

.badge-shipment-paid {
    background-color: #e8e9f5;
    color: #2E3192;
}

.badge-shipment-in-transit {
    background-color: #fff8dd;
    color: #f1bc00;
}

.badge-shipment-out-for-delivery {
    background-color: #f1e9ff;
    color: #7239ea;
}

.badge-shipment-delivered {
    background-color: #e8fff3;
    color: #50cd89;
}

.badge-shipment-cancelled {
    background-color: #fce8e9;
    color: #C1272D;
}

.badge-shipment-failed {
    background-color: #C1272D;
    color: #ffffff;
}

/* Payment Status Badges */
.badge-payment-success {
    background-color: #e8fff3;
    color: #50cd89;
}

.badge-payment-pending {
    background-color: #fff8dd;
    color: #f1bc00;
}

.badge-payment-failed {
    background-color: #fce8e9;
    color: #C1272D;
}

/* ----------------------------------------------------------------
   Metric Cards
   ---------------------------------------------------------------- */
.metric-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

.metric-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 0.5rem 1.5rem 0.5rem rgba(0, 0, 0, 0.075);
}

.metric-card .metric-icon {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.75rem;
    font-size: 1.75rem;
}

.metric-card .metric-value {
    font-size: 2rem;
    font-weight: 700;
    color: #181c32;
    line-height: 1.2;
}

.metric-card .metric-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: #7e8299;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-card .metric-trend {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.875rem;
    font-weight: 600;
}

.metric-trend.trend-up {
    color: #50cd89;
}

.metric-trend.trend-down {
    color: #C1272D;
}

/* ----------------------------------------------------------------
   Alerts Panel
   ---------------------------------------------------------------- */
.alerts-panel {
    background: #fff;
    border-radius: 0.75rem;
    padding: 1.5rem;
}

.alert-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    margin-bottom: 0.75rem;
    border-radius: 0.5rem;
    border-left: 4px solid;
    transition: background-color 0.2s ease;
}

.alert-item:hover {
    background-color: #f9f9f9;
}

.alert-item.alert-critical {
    background-color: #fce8e9;
    border-left-color: #C1272D;
}

.alert-item.alert-warning {
    background-color: #fff8dd;
    border-left-color: #f1bc00;
}

.alert-item.alert-info {
    background-color: #e8e9f5;
    border-left-color: #2E3192;
}

.alert-item .alert-content {
    flex: 1;
}

.alert-item .alert-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: #181c32;
    margin-bottom: 0.25rem;
}

.alert-item .alert-description {
    font-size: 0.85rem;
    color: #7e8299;
}

.alert-item .alert-badge {
    font-size: 1.25rem;
    font-weight: 700;
    margin-right: 1rem;
}

/* ----------------------------------------------------------------
   Data Tables
   ---------------------------------------------------------------- */
.shipments-table thead th {
    background-color: #f9f9f9;
    font-weight: 600;
    color: #181c32;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    padding: 1rem 0.75rem;
    border-bottom: 2px solid #eff2f5;
}

.shipments-table tbody tr {
    transition: background-color 0.15s ease;
}

.shipments-table tbody tr:hover {
    background-color: #f9f9f9;
    cursor: pointer;
}

.shipments-table tbody td {
    padding: 1rem 0.75rem;
    vertical-align: middle;
    color: #5e6278;
    font-size: 0.925rem;
}

.shipments-table .tracking-number {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    color: #2E3192;
    text-decoration: none;
}

.shipments-table .tracking-number:hover {
    text-decoration: underline;
}

.shipments-table .route-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.shipments-table .route-arrow {
    color: #b5b5c3;
}

/* Table Row Selection */
.shipments-table tbody tr.selected {
    background-color: #e8e9f5;
}

/* ----------------------------------------------------------------
   Timeline (Shipment Tracking)
   ---------------------------------------------------------------- */
.tracking-timeline {
    position: relative;
    padding-left: 2.5rem;
}

.tracking-timeline::before {
    content: '';
    position: absolute;
    left: 0.875rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background-color: #e4e6ef;
}

.timeline-item {
    position: relative;
    padding-bottom: 2rem;
}

.timeline-item:last-child {
    padding-bottom: 0;
}

.timeline-item .timeline-icon {
    position: absolute;
    left: -2.5rem;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #fff;
    border: 2px solid #e4e6ef;
    z-index: 1;
}

.timeline-item.completed .timeline-icon {
    background-color: #50cd89;
    border-color: #50cd89;
    color: #fff;
}

.timeline-item.active .timeline-icon {
    background-color: #2E3192;
    border-color: #2E3192;
    color: #fff;
}

.timeline-item.pending .timeline-icon {
    background-color: #f9f9f9;
    border-color: #e4e6ef;
    color: #b5b5c3;
}

.timeline-item .timeline-content {
    padding-left: 0;
}

.timeline-item .timeline-title {
    font-size: 1rem;
    font-weight: 600;
    color: #181c32;
    margin-bottom: 0.25rem;
}

.timeline-item .timeline-meta {
    font-size: 0.875rem;
    color: #7e8299;
    margin-bottom: 0.5rem;
}

.timeline-item .timeline-description {
    font-size: 0.875rem;
    color: #5e6278;
}

/* ----------------------------------------------------------------
   Agent Cards & Avatars
   ---------------------------------------------------------------- */
.agent-avatar {
    width: 35px;
    height: 35px;
    border-radius: 0.475rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
}

.agent-avatar.agent-online {
    border: 2px solid #50cd89;
}

.agent-avatar-lg {
    width: 80px;
    height: 80px;
    font-size: 1.5rem;
}

.agent-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 0.475rem;
    font-size: 0.875rem;
    font-weight: 600;
}

.agent-status-badge.status-active {
    background-color: #e8fff3;
    color: #50cd89;
}

.agent-status-badge.status-inactive {
    background-color: #f1f1f4;
    color: #7e8299;
}

.agent-status-badge .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: currentColor;
}

/* ----------------------------------------------------------------
   Quick Actions & Buttons
   ---------------------------------------------------------------- */
.bulk-actions-bar {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: #181c32;
    color: #fff;
    padding: 1rem 2rem;
    border-radius: 0.75rem;
    box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 1.5rem;
    z-index: 100;
}

.bulk-actions-bar .selected-count {
    font-weight: 600;
    font-size: 1rem;
}

.quick-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 0.475rem;
    transition: all 0.2s ease;
}

/* ----------------------------------------------------------------
   Search & Filter Bar
   ---------------------------------------------------------------- */
.filter-bar {
    background: #fff;
    padding: 1.5rem;
    border-radius: 0.75rem;
    margin-bottom: 1.5rem;
}

.filter-bar .search-box {
    position: relative;
}

.filter-bar .search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: #b5b5c3;
}

.filter-bar input[type="search"] {
    padding-left: 3rem;
}

.quick-filter-tabs {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.quick-filter-tab {
    padding: 0.5rem 1.25rem;
    border: 1px solid #e4e6ef;
    border-radius: 0.475rem;
    background: #fff;
    color: #5e6278;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quick-filter-tab:hover {
    background: #f9f9f9;
}

.quick-filter-tab.active {
    background: #2E3192;
    color: #fff;
    border-color: #2E3192;
}

/* ----------------------------------------------------------------
   Charts & Analytics
   ---------------------------------------------------------------- */
.chart-container {
    background: #fff;
    border-radius: 0.75rem;
    padding: 1.5rem;
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.chart-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #181c32;
}

/* ----------------------------------------------------------------
   Mobile Responsive Adjustments
   ---------------------------------------------------------------- */
@media (max-width: 991px) {
    .metric-card .metric-value {
        font-size: 1.5rem;
    }

    .metric-card .metric-icon {
        width: 50px;
        height: 50px;
        font-size: 1.5rem;
    }

    .tracking-timeline {
        padding-left: 2rem;
    }

    /* Filter Bar Mobile */
    .filter-bar {
        padding: 1rem;
    }

    .filter-bar .col-lg-6 {
        margin-bottom: 1rem;
    }

    .filter-bar .text-end {
        text-align: left !important;
    }

    .filter-bar .btn {
        margin-bottom: 0.5rem;
        width: 100%;
    }

    /* Bulk Actions Bar Mobile */
    .bulk-actions-bar {
        bottom: 1rem;
        width: calc(100% - 2rem);
        padding: 0.75rem 1rem;
        flex-direction: column;
        gap: 0.75rem;
    }

    .bulk-actions-bar .quick-action-btn {
        width: 100%;
        justify-content: center;
    }
}

/* Fix: action dropdowns in tables get clipped by .table-responsive overflow.
   Popper.js detects overflow:auto containers and traps the dropdown inside them.
   Setting visible on desktop allows dropdowns to extend beyond the table boundary.
   The mobile media query below re-applies overflow-x:auto for horizontal scroll. */
.table-responsive {
    overflow: visible;
}

/* Mobile-specific table responsiveness */
@media (max-width: 767px) {

    /* Make tables horizontally scrollable */
    .card-body {
        padding: 0.5rem !important;
    }

    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Wrap shipments table in a scrollable container */
    .shipments-table {
        font-size: 0.75rem;
        min-width: 800px;
        /* Minimum width to maintain readability */
    }

    .shipments-table thead th {
        padding: 0.75rem 0.5rem;
        font-size: 0.75rem;
        white-space: nowrap;
    }

    .shipments-table tbody td {
        padding: 0.75rem 0.5rem;
        font-size: 0.75rem;
    }

    /* Reduce column widths on mobile */
    .shipments-table th.min-w-125px,
    .shipments-table th.min-w-150px,
    .shipments-table th.min-w-120px,
    .shipments-table th.min-w-100px,
    .shipments-table th.min-w-80px {
        min-width: auto !important;
    }

    /* Make route cell more compact */
    .shipments-table .route-cell {
        flex-direction: row;
        gap: 0.25rem;
        font-size: 0.7rem;
    }

    .shipments-table .route-arrow {
        font-size: 0.75rem;
    }

    /* Agent avatar smaller */
    .agent-avatar {
        width: 25px;
        height: 25px;
        font-size: 0.7rem;
    }

    /* Page title adjustments */
    .page-heading {
        font-size: 1.5rem !important;
    }

    /* Filter tabs wrap better */
    .quick-filter-tabs {
        gap: 0.35rem;
    }

    .quick-filter-tab {
        padding: 0.4rem 0.75rem;
        font-size: 0.75rem;
    }

    /* Header adjustments */
    .header-logo img {
        height: 35px !important;
        max-height: 35px;
    }

    /* Background banner height adjustment for mobile */
    .wrapper::before {
        height: 350px;
    }

    /* Metric cards on mobile */
    .metric-card {
        margin-bottom: 1rem;
    }

    .metric-card .card-body {
        padding: 1rem !important;
    }

    /* Alerts panel on mobile */
    .alert-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .alert-item .alert-badge {
        margin-right: 0;
    }

    /* Dropdown actions in table */
    .shipments-table .dropdown-toggle {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
}

/* Extra small devices */
@media (max-width: 575px) {
    .container-xxl {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Stack filter buttons vertically */
    .filter-bar .btn {
        display: block;
        width: 100%;
        margin-bottom: 0.5rem;
    }

    /* Make search input full width */
    .search-box input {
        width: 100%;
    }

    /* Page title smaller */
    .page-heading {
        font-size: 1.25rem !important;
    }

    /* Ensure table scrolls properly */
    .shipments-table {
        display: block;
        width: 100%;
        overflow-x: auto;
    }

    .shipments-table thead,
    .shipments-table tbody,
    .shipments-table tr {
        display: table;
        width: 100%;
        table-layout: auto;
    }
}

/* ----------------------------------------------------------------
   Print Styles (for shipping labels)
   ---------------------------------------------------------------- */
@media print {
    body * {
        visibility: hidden;
    }

    .printable-area,
    .printable-area * {
        visibility: visible;
    }

    .printable-area {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }

    .no-print {
        display: none !important;
    }
}

/* ----------------------------------------------------------------
   Utility Classes
   ---------------------------------------------------------------- */
.copyable {
    cursor: pointer;
    position: relative;
}

.copyable:hover {
    text-decoration: underline;
}

.text-monospace {
    font-family: 'Courier New', monospace;
}

.overdue {
    color: #C1272D;
    font-weight: 600;
}

.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(46, 49, 146, 0.2);
    border-top-color: #2E3192;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ----------------------------------------------------------------
   Dark Mode Support (if Metronic dark mode is enabled)
   ---------------------------------------------------------------- */
[data-bs-theme="dark"] .metric-card .metric-value {
    color: #f9f9f9;
}

[data-bs-theme="dark"] .alerts-panel,
[data-bs-theme="dark"] .filter-bar,
[data-bs-theme="dark"] .chart-container {
    background: #1e1e2d;
}

[data-bs-theme="dark"] .shipments-table tbody tr:hover {
    background-color: #2b2b40;
}

[data-bs-theme="dark"] .timeline-item .timeline-title {
    color: #f9f9f9;
}

/* ----------------------------------------------------------------
   User Dropdown Menu Positioning Fix
   ---------------------------------------------------------------- */
#kt_header_user_menu_toggle {
    position: relative;
}

#kt_header_user_menu_toggle .menu-sub-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    left: auto;
    z-index: 9999;
    margin-top: 0.5rem;
    box-shadow: 0 0.5rem 1.5rem 0.5rem rgba(0, 0, 0, 0.075);
    background: #fff;
}

/* Ensure dropdown is hidden by default */
#kt_header_user_menu_toggle .menu-sub-dropdown:not(.show) {
    display: none;
}