/* Global Styles & Variables */
:root {
    --primary-color: #4361ee; /* More modern blue */
    --primary-hover: #3a56d4;
    --secondary-color: #858796;
    --success-color: #2ec4b6; /* Teal-ish success */
    --info-color: #3f37c9;
    --warning-color: #f72585; /* Pinkish warning for contrast or #f6c23e */
    --warning-actual: #ff9f1c; /* Orange */
    --danger-color: #e63946;
    --light-color: #f8f9fa;
    --dark-color: #2b2d42;
    --sidebar-bg: #4361ee;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 80px;
    --header-height: 64px;
    --transition-speed: 0.3s;
    --card-radius: 1rem;
    --btn-radius: 0.5rem;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
    --shadow-md: 0 5px 15px rgba(0,0,0,0.08);
}

html, body {
    overflow-x: hidden;
    max-width: 100%;
}

body {
    min-height: 100vh;
    background-color: #f0f2f5; /* Clean light gray */
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #495057;
    -webkit-font-smoothing: antialiased;
}

a {
    text-decoration: none;
    color: var(--primary-color);
    transition: color 0.2s;
}

a:hover {
    color: var(--primary-hover);
}

/* ------------------------------------------------------------------
   Sidebar Structure & Logic
   ------------------------------------------------------------------ */
.sidebar {
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    background: linear-gradient(135deg, #4361ee 0%, #3f37c9 100%);
    padding-top: 0;
    z-index: 1040;
    transition: all var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 25px rgba(0,0,0,0.05);
}

/* Collapsed State */
body.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .sidebar .sidebar-header span,
body.sidebar-collapsed .sidebar .nav-link span,
body.sidebar-collapsed .sidebar .btn-toggle span,
body.sidebar-collapsed .sidebar .dropdown span,
body.sidebar-collapsed .sidebar .dropdown strong,
body.sidebar-collapsed .sidebar .btn-toggle::after {
    display: none;
}

body.sidebar-collapsed .sidebar .nav-link,
body.sidebar-collapsed .sidebar .btn-toggle {
    justify-content: center;
    padding: 1rem 0;
}

body.sidebar-collapsed .sidebar .nav-link i,
body.sidebar-collapsed .sidebar .btn-toggle i {
    margin-right: 0 !important;
    font-size: 1.5rem;
}

body.sidebar-collapsed .sidebar .btn-toggle-nav,
body.sidebar-collapsed .sidebar .collapse.show {
    display: none !important;
}

body.sidebar-collapsed .sidebar-header {
    padding: 0;
    justify-content: center;
    flex-direction: column;
    height: auto;
    padding: 1rem 0;
}

body.sidebar-collapsed .sidebar-header a {
    margin-right: 0 !important;
    display: flex;
    justify-content: center;
    width: 100%;
}

body.sidebar-collapsed .sidebar-header a i {
    margin-right: 0 !important;
    font-size: 2rem;
}

body.sidebar-collapsed .sidebar-header .sidebar-toggle-btn {
    width: 100%;
    padding: 0.5rem 0;
    text-align: center;
}

/* Sidebar Header */
.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background-color: rgba(255,255,255,0.05);
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-toggle-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle-btn:hover {
    color: #fff;
    background-color: rgba(255,255,255,0.1);
}

/* Sidebar Nav */
.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1.5rem 1rem;
}

/* Custom Scrollbar for sidebar */
.sidebar-scroll::-webkit-scrollbar {
    width: 5px;
}
.sidebar-scroll::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar-scroll::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
}
.sidebar-scroll::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.4);
}

.sidebar .nav-item {
    margin-bottom: 0.5rem;
}

.sidebar .nav-link {
    color: rgba(255, 255, 255, 0.85);
    padding: 0.8rem 1.2rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.sidebar .nav-link:hover {
    color: #fff;
    background-color: rgba(255,255,255,0.1);
    transform: translateX(3px);
}

.sidebar .nav-link.active {
    color: var(--primary-color);
    background-color: #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    font-weight: 700;
}

.sidebar .nav-link i,
.sidebar .btn-toggle i {
    font-size: 1.2rem;
    margin-right: 0.8rem;
    width: 1.5rem;
    text-align: center;
    flex-shrink: 0;
}

/* Toggle Buttons (Submenu) */
.sidebar .btn-toggle {
    color: rgba(255, 255, 255, 0.85);
    padding: 0.8rem 1.2rem;
    margin-bottom: 0.5rem;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    white-space: nowrap;
    transition: all 0.2s;
    border-radius: 0.75rem;
}

.sidebar .btn-toggle:hover, .sidebar .btn-toggle[aria-expanded="true"] {
    color: #fff;
    background-color: rgba(255,255,255,0.1);
}

.sidebar .btn-toggle::after {
    content: "\f282"; /* bi-chevron-down */
    font-family: bootstrap-icons;
    transition: transform 0.2s;
    font-size: 0.8em;
    margin-left: auto;
    opacity: 0.7;
}

.sidebar .btn-toggle[aria-expanded="true"]::after {
    transform: rotate(180deg);
    opacity: 1;
}

.sidebar .btn-toggle-nav {
    padding-left: 0.5rem;
    background: rgba(0,0,0,0.05);
    border-radius: 0.75rem;
    margin-top: 0.25rem;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.sidebar .btn-toggle-nav .nav-link {
    padding-left: 2.5rem;
    font-size: 0.95em;
    font-weight: 400;
    color: rgba(255,255,255,0.7);
}
.sidebar .btn-toggle-nav .nav-link:hover {
    background: transparent;
    color: #fff;
}
.sidebar .btn-toggle-nav .nav-link.active {
    background: transparent;
    color: #fff;
    font-weight: 700;
    box-shadow: none;
}
.sidebar .btn-toggle-nav .nav-link.active::before {
    content: "•";
    position: absolute;
    left: 1.5rem;
    font-size: 1.5em;
}

/* ------------------------------------------------------------------
   Main Content Area
   ------------------------------------------------------------------ */
.main-content {
    margin-left: var(--sidebar-width);
    padding: calc(var(--header-height) + 1.5rem) 1.5rem 1.5rem 1.5rem;
    transition: margin-left var(--transition-speed) ease-in-out;
    min-height: 100vh;
}

body.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

/* Topbar */
.topbar {
    position: fixed;
    top: 0;
    right: 0;
    left: var(--sidebar-width);
    height: var(--header-height);
    background-color: #fff;
    /* backdrop-filter: blur(10px); */
    z-index: 1020;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: left var(--transition-speed) ease-in-out;
    border-bottom: 1px solid #e3e6f0;
}

body.sidebar-collapsed .topbar {
    left: var(--sidebar-collapsed-width);
}

.main-content > .topbar {
    display: none !important;
}

/* Mobile Header */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background-color: var(--primary-color);
    color: white;
    z-index: 1030;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    align-items: center;
    padding: 0 1rem;
    justify-content: space-between;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1035;
    backdrop-filter: blur(2px);
    transition: opacity 0.3s;
    opacity: 0;
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

/* Mobile Media Query */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
        box-shadow: 5px 0 15px rgba(0,0,0,0.1);
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0 !important;
        padding: calc(var(--header-height) + 1rem) 1rem 1rem 1rem;
    }
    .mobile-header {
        display: flex;
    }
    
    .sidebar span, .sidebar .btn-toggle::after, .sidebar strong {
        display: inline-block !important;
    }
    .sidebar .nav-link, .sidebar .btn-toggle {
        justify-content: flex-start !important;
        padding: 0.8rem 1.2rem !important;
    }
    .sidebar .nav-link i, .sidebar .btn-toggle i {
        margin-right: 0.8rem !important;
        width: 1.5rem !important;
        font-size: 1.2rem !important;
    }
    .sidebar-toggle-btn.desktop-only {
        display: none;
    }
    
    /* Mobile Table Fix */
    .table-responsive {
        border: 0;
        box-shadow: none;
        margin-bottom: 1rem;
        border-radius: 0.5rem;
    }

    /* Mobile Table Card View */
    .table-mobile-card {
        background: transparent;
    }
    
    .table-mobile-card thead {
        display: none;
    }
    
    .table-mobile-card tbody tr {
        display: block;
        margin-bottom: 1rem;
        background: #fff;
        border-radius: 0.75rem;
        box-shadow: 0 2px 8px rgba(0,0,0,0.05);
        border: 1px solid rgba(0,0,0,0.05);
        padding: 0.5rem 1rem;
        position: relative;
    }
    
    .table-mobile-card tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem 0;
        border: none;
        border-bottom: 1px solid #f0f2f5;
        text-align: right;
    }
    
    .table-mobile-card tbody td:last-child {
        border-bottom: none;
        justify-content: flex-end;
        padding-top: 1rem;
        gap: 0.5rem;
    }

    /* Special handling for checkbox column */
    .table-mobile-card tbody td:first-child {
        justify-content: flex-start;
        border-bottom: 1px solid #f0f2f5;
        background: #fafafa;
        margin: -0.5rem -1rem 0.5rem -1rem;
        padding: 0.75rem 1rem;
        border-radius: 0.75rem 0.75rem 0 0;
    }
    
    .table-mobile-card tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--secondary-color);
        margin-right: 1rem;
        text-align: left;
        font-size: 0.9rem;
        flex-shrink: 0;
    }

    /* Empty data label (like checkbox or actions) */
    .table-mobile-card tbody td[data-label=""]::before {
        display: none;
    }
    
    /* Enhance mobile touch targets */
    .btn {
        padding: 0.5rem 1rem;
    }
    
    /* Mobile Toolbar Stack */
    .btn-toolbar {
        width: 100%;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .btn-toolbar .btn, .btn-toolbar .btn-group {
        width: 100%;
        margin-right: 0 !important;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    .btn-toolbar .btn-group .btn {
        flex: 1;
    }

    /* Filter form stacking */
    .card-body form.row > div {
        margin-bottom: 0.5rem;
    }
    
    .card-body form.row .btn {
        width: 100%;
        margin-bottom: 0.5rem;
        margin-left: 0 !important;
    }
}

/* ------------------------------------------------------------------
   Components & Beautification
   ------------------------------------------------------------------ */
   
/* Cards */
.card {
    border: none;
    border-radius: var(--card-radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    transition: box-shadow 0.2s ease;
    background: #fff;
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.05);
}

.card:hover {
    /* transform: translateY(-3px); */
    box-shadow: var(--shadow-md);
}

.card-header {
    background-color: #fff;
    border-bottom: 1px solid #f0f2f5;
    font-weight: 600;
    color: var(--dark-color);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Colored Border Cards (Bootstrap style) */
.border-left-primary { border-left: 4px solid var(--primary-color) !important; }
.border-left-success { border-left: 4px solid var(--success-color) !important; }
.border-left-info { border-left: 4px solid var(--info-color) !important; }
.border-left-warning { border-left: 4px solid var(--warning-actual) !important; }
.border-left-danger { border-left: 4px solid var(--danger-color) !important; }

/* Buttons */
.btn {
    border-radius: var(--btn-radius);
    font-weight: 500;
    box-shadow: none;
    transition: all 0.2s;
    letter-spacing: normal;
    padding: 0.375rem 0.75rem;
}
.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    border-radius: 0.25rem;
}
.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}
.btn-primary:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
}
.btn-outline-primary {
    color: var(--primary-color);
    border-color: var(--primary-color);
}
.btn-outline-primary:hover {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

/* Tables */
.table {
    margin-bottom: 0;
    color: var(--text-color);
}
.table thead th {
    font-weight: 600;
    text-transform: none;
    font-size: 0.85rem;
    letter-spacing: normal;
    background-color: #f8f9fa;
    color: var(--secondary-color);
    border-bottom: 2px solid #e3e6f0;
    padding: 0.75rem;
    white-space: nowrap;
}
.table td {
    vertical-align: middle;
    padding: 0.75rem;
    border-top: 1px solid #e3e6f0;
}
.table-hover tbody tr:hover {
    background-color: rgba(0,0,0,0.02);
}

.table tbody tr.selected,
.table tbody tr.table-row-selected {
    background-color: rgba(67, 97, 238, 0.08) !important;
}

/* DataTables Custom Styles */
.dataTables_wrapper .row {
    margin-bottom: 0.5rem;
    align-items: center;
}

.dataTables_info {
    padding-top: 0.5rem !important;
    font-size: 0.85rem;
    color: var(--secondary-color);
}

.dataTables_paginate {
    padding-top: 0.5rem !important;
}

.dataTables_paginate .pagination {
    margin-bottom: 0;
    justify-content: flex-end;
}

.dataTables_length label, .dataTables_filter label {
    font-size: 0.85rem;
    color: var(--secondary-color);
    font-weight: 500;
}

.dataTables_filter input {
    margin-left: 0.5rem !important;
}

.dataTables_length select {
    padding-right: 2rem !important;
    min-width: 4rem !important;
}

@media (max-width: 768px) {
    .dataTables_info, .dataTables_paginate {
        text-align: center !important;
        display: block !important;
        width: 100% !important;
        margin: 0.25rem 0 !important;
    }
    
    .dataTables_paginate .pagination {
        justify-content: center !important;
    }
    
    .dataTables_length, .dataTables_filter {
        text-align: center !important;
    }
}

/* Breadcrumbs */
.breadcrumb-wrapper {
    background-color: transparent;
    padding: 0;
    border-radius: 0;
    box-shadow: none;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
}
.breadcrumb {
    margin-bottom: 0;
    background-color: transparent;
    padding: 0;
}
.breadcrumb-item {
    display: flex;
    align-items: center;
    font-size: 0.85rem;
}
.breadcrumb-item + .breadcrumb-item::before {
    content: "/";
    font-family: inherit;
    font-size: 0.85rem;
    color: #b7b9cc;
    padding: 0 0.5rem;
}
.breadcrumb-item a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 400;
}
.breadcrumb-item a:hover {
    text-decoration: underline;
}
.breadcrumb-item.active {
    color: var(--secondary-color);
    font-weight: 400;
}

/* Form Controls */
.form-control, .form-select {
    border-radius: var(--btn-radius);
    border: 1px solid #ced4da;
    padding: 0.375rem 0.75rem;
    font-size: 0.9rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
.form-control:focus, .form-select:focus {
    border-color: #86b7fe;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Badges */
.badge {
    padding: 0.4em 0.65em;
    font-weight: 600;
    border-radius: 0.25rem;
    font-size: 0.75em;
}

/* Custom Utilities */
.text-gray-800 { color: #343a40 !important; }
.text-gray-600 { color: #6c757d !important; }

/* Dashboard Specific */
.dashboard-stat-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}
.dashboard-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #333;
    line-height: 1.2;
}

/* EPC 标签样式 - 确保长 EPC 完整显示 */
.epc-tag {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
    background-color: #f8f9fa;
    border: 1px solid #e3e6f0;
    padding: 2px 8px;
    margin: 2px;
    border-radius: 4px;
    color: #4e73df;
    font-size: 0.85em;
    letter-spacing: 0.5px;
    font-weight: 600;
    display: inline-block;
    vertical-align: middle;
    word-break: break-all;
    white-space: nowrap; /* 内部不换行 */
    max-width: 100%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}