/* Meta Portal - Dark Theme with Sidebar Layout */

:root {
    --primary-color: #3b82f6;
    --secondary-color: #6c757d;
    --success-color: #22c55e;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --info-color: #06b6d4;
    --dark-color: #343a40;
    --light-color: #f8f9fa;
    --overlay-color: rgba(17, 24, 39, 0.95);
    --card-bg: rgba(17, 24, 39, 0.95);
    --border-color: #333;
    --header-bg: rgba(17, 24, 39, 0.95);
    --table-header-bg: rgba(0, 0, 0, 0.9);
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 64px;
    --body-bg: #111827;
    --text-color: #ffffff;
    --text-muted: #9ca3af;
    --text-muted-light: #6b7280;
    --surface-1: rgba(17, 24, 39, 0.95);
    --surface-2: rgba(0, 0, 0, 0.5);
    --surface-3: rgba(0, 0, 0, 0.3);
    --input-bg: rgba(0, 0, 0, 0.8);
    --input-border: #495057;
}

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

html, body {
    height: 100%;
    width: 100%;
    overflow-x: hidden;
}

body {
    color: white;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    display: flex;
    flex-direction: column;
    position: relative;
    margin: 0;
    background-color: var(--body-bg);
}

/* ============================================================
   APP LAYOUT — Sidebar + Content
   ============================================================ */

.app-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    border-right: 1px solid rgba(255,255,255,0.08);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1040;
    transition: width 0.3s ease, transform 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.2);
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Sidebar Header (brand + toggle on one row) */
.sidebar-header {
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    min-height: 60px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    flex: 1;
    min-width: 0;
    text-decoration: none;
}

.sidebar-brand:hover {
    text-decoration: none;
}

/* White chip keeps the full-color Epic logo readable on the dark sidebar */
.brand-logo {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    background: #ffffff;
    border-radius: 8px;
    padding: 8px 12px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    transition: padding 0.2s ease;
}

.brand-logo img {
    display: block;
    width: 100%;
    height: auto;
    max-height: 38px;
    object-fit: contain;
    object-position: left center;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
}

.sidebar.collapsed .sidebar-brand {
    padding: 12px 8px;
    justify-content: center;
}

/* Collapsed: clip the chip down to the green "e" mark on the left */
.sidebar.collapsed .brand-logo {
    padding: 6px;
}

.sidebar.collapsed .brand-logo img {
    width: auto;
    height: 30px;
    max-height: 30px;
    flex-shrink: 0;
}

/* Login card header: centered white chip with the full logo */
.brand-logo-login {
    width: auto;
    max-width: 220px;
    margin: 4px auto;
    padding: 10px 16px;
    justify-content: center;
}

.brand-logo-login img {
    width: 100%;
    max-height: 56px;
    object-position: center;
}

/* Sidebar Toggle */
.sidebar-toggle {
    background: none;
    border: none;
    border-left: 1px solid rgba(255,255,255,0.08);
    color: #94a3b8;
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color 0.2s ease, opacity 0.2s ease;
}

.sidebar-toggle i {
    transition: transform 0.3s ease;
}

.sidebar.collapsed .sidebar-toggle {
    display: none;
}

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

.sidebar-toggle:hover {
    color: white;
    background-color: rgba(255,255,255,0.05);
}

/* Sidebar Navigation */
.sidebar-section {
    padding: 8px 0;
}

.sidebar-section-title {
    padding: 8px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed .sidebar-section-title {
    padding: 4px 0;
    font-size: 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    margin: 0 10px;
}

.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav-item {
    margin: 1px 8px;
}

.sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    color: #94a3b8;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-nav-link:hover {
    color: white;
    background-color: rgba(255,255,255,0.08);
    text-decoration: none;
}

.sidebar-nav-link.active {
    color: white;
    background-color: var(--primary-color);
}

.sidebar-nav-link i {
    min-width: 20px;
    text-align: center;
    font-size: 0.9rem;
}

.sidebar-nav-link .link-text {
    transition: opacity 0.2s ease;
}

.sidebar.collapsed .link-text,
.sidebar.collapsed .sidebar-user-name,
.sidebar.collapsed .sidebar-user-email {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

.sidebar.collapsed .sidebar-nav-item {
    margin: 1px 8px;
}

.sidebar.collapsed .sidebar-nav-link {
    justify-content: center;
    gap: 0;
    padding: 10px 0;
}

/* Sidebar User Section */
.sidebar-user {
    margin-top: auto;
    padding: 12px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-user-icon {
    min-width: 28px;
    text-align: center;
    color: var(--primary-color);
}

.sidebar-user-info {
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: white;
}

.sidebar-user-email {
    font-size: 0.7rem;
    color: #94a3b8;
}

.sidebar-logout-btn {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px 8px;
    margin-left: auto;
    border-radius: 4px;
    transition: color 0.2s;
}

.sidebar-logout-btn:hover {
    color: var(--danger-color);
}

.sidebar.collapsed .sidebar-user {
    flex-direction: column;
    padding: 8px 6px;
    justify-content: center;
}

.sidebar.collapsed .sidebar-user-info {
    display: none;
}

.sidebar.collapsed .sidebar-logout-btn {
    margin-left: 0;
}

/* Content Area */
.content-area {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
    width: calc(100% - var(--sidebar-width));
}

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

/* Breadcrumb Bar */
.breadcrumb-bar {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 10px 20px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
}

.breadcrumb-bar a {
    color: #94a3b8;
    text-decoration: none;
}

.breadcrumb-bar a:hover {
    color: var(--primary-color);
}

.breadcrumb-list {
    list-style: none;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    margin: 0;
    padding: 0;
}

.breadcrumb-list li {
    display: inline-flex;
    align-items: center;
}

.breadcrumb-bar .separator {
    color: #6b7280;
    margin: 0 8px;
}

.breadcrumb-bar .current {
    color: white;
    font-weight: 500;
}

/* Content Main */
.content-main {
    flex: 1;
    padding: 20px;
    width: 100%;
    max-width: 1470px;
}

/* Mobile Menu Button */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1050;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Sidebar Overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1030;
}

.sidebar-overlay.active {
    display: block;
}

/* ============================================================
   LOADING OVERLAY
   ============================================================ */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ============================================================
   FORM STYLES
   ============================================================ */

.form-control, .form-select {
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    color: white;
    padding: 0.375rem 0.75rem;
    border-radius: 4px;
}

.form-control:focus, .form-select:focus {
    background-color: rgba(0, 0, 0, 0.9);
    border-color: #60a5fa;
    color: white;
    box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.25);
}

.form-control::placeholder {
    color: #6b7280;
    opacity: 1;
}

.form-control[readonly], .form-control:disabled {
    background-color: rgba(0, 0, 0, 0.6);
    color: #adb5bd;
}

.form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
}

.form-label {
    color: white;
    font-weight: 600;
}

.form-text {
    color: #adb5bd;
}

input[type="date"] {
    color-scheme: dark;
}

input[type="date"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 1;
    padding: 2px;
}

/* ============================================================
   MODAL — Dark Theme
   ============================================================ */

.modal {
    z-index: 10050;
}

.modal-backdrop {
    z-index: 10040;
}

.modal-content {
    background-color: #1a1a2e;
    color: white;
    border: 1px solid #495057;
}

.modal-header, .modal-footer {
    border-color: #495057;
}

/* Required field indicator */
.required-field {
    color: var(--danger-color);
    font-weight: bold;
}

.field-validation-error, .text-danger {
    color: var(--danger-color) !important;
    font-size: 0.85rem;
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
    border-radius: 4px;
    padding: 8px 16px;
    font-weight: 500;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-primary:hover {
    background-color: #2563eb;
    border-color: #1d4ed8;
}

.btn-info {
    background-color: var(--info-color);
    border-color: var(--info-color);
    color: white;
}

.btn-info:hover {
    background-color: #0891b2;
    border-color: #0e7490;
    color: white;
}

.btn-danger {
    background-color: var(--danger-color);
    border-color: var(--danger-color);
}

.btn-danger:hover {
    background-color: #dc2626;
    border-color: #b91c1c;
}

.btn-success {
    background-color: var(--success-color);
    border-color: var(--success-color);
}

.btn-success:hover {
    background-color: #16a34a;
    border-color: #15803d;
}

.btn-secondary {
    background-color: var(--secondary-color);
    border-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #5a6268;
    border-color: #545b62;
    color: white;
}

.btn-outline-primary {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-outline-primary:hover {
    background-color: #3b82f6;
    color: white;
}

.btn-outline-secondary {
    color: #adb5bd;
    border-color: #6c757d;
}

.btn-outline-secondary:hover {
    background-color: #6c757d;
    color: white;
}

.btn-outline-danger {
    color: #ef4444;
    border-color: #ef4444;
}

.btn-outline-danger:hover {
    background-color: #ef4444;
    color: white;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
}

/* Custom action buttons */
.btn-action {
    background-color: #3b82f6;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 8px 16px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.btn-action:hover {
    background-color: #2563eb;
    text-decoration: none;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.create-btn, .save-btn {
    background-color: #22c55e;
}

.create-btn:hover, .save-btn:hover {
    background-color: #16a34a;
}

.submit-btn {
    background-color: #3b82f6;
}

.submit-btn:hover {
    background-color: #2563eb;
}

.edit-btn {
    background-color: #22c55e;
}

.edit-btn:hover {
    background-color: #16a34a;
}

.return-btn {
    background-color: #6c757d;
}

.return-btn:hover {
    background-color: #5a6268;
}

.delete-btn {
    background-color: #ef4444;
}

.delete-btn:hover {
    background-color: #dc2626;
}

.download-btn {
    background-color: #06b6d4;
}

.download-btn:hover {
    background-color: #0891b2;
}

/* Action icon buttons (for tables) */
.btn-action-icon {
    width: 30px;
    height: 30px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    text-decoration: none;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-action-icon:hover {
    transform: translateY(-2px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    color: white;
    text-decoration: none;
}

.view-icon { background-color: #06b6d4; }
.edit-icon { background-color: #3b82f6; }
.delete-icon { background-color: #ef4444; }

.view-icon:hover { background-color: #0891b2; }
.edit-icon:hover { background-color: #2563eb; }
.delete-icon:hover { background-color: #dc2626; }

/* Focus-visible styles for accessibility */
.sidebar-nav-link:focus-visible,
.sidebar-toggle:focus-visible,
.sidebar-logout-btn:focus-visible,
.mobile-menu-btn:focus-visible,
.collapse-btn:focus-visible,
.page-nav-btn:focus-visible,
.sort-link:focus-visible {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
}

.btn:focus-visible,
.btn-action:focus-visible,
.btn-action-icon:focus-visible {
    outline: 2px solid #60a5fa;
    outline-offset: 2px;
    box-shadow: none;
}

/* ============================================================
   TABLE STYLES
   ============================================================ */

.table-wrapper {
    overflow-x: auto;
    margin-top: 10px;
    -webkit-overflow-scrolling: touch;
}

/* .card-body.p-0 deliberately does NOT set overflow-x: auto.
   The CSS Overflow spec coerces overflow-y from `visible` to `auto` when overflow-x is
   anything other than visible. That coercion creates a scroll container in BOTH axes,
   so a card-body holding a table that fits its width can still grow a phantom vertical
   scrollbar from sub-pixel height rounding. Pages that truly need horizontal scroll on
   a wide table should wrap that table in <div class="table-responsive"> (Bootstrap's
   scoped scroll wrapper) — keeps the scroll on the table, not the whole card-body. */

/* When .table-responsive IS used, give it a quiet dark-theme scrollbar instead of the
   browser default which looks bright/jarring against the card background. */
.table-responsive {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.12) transparent;
}
.table-responsive::-webkit-scrollbar {
    height: 6px;
}
.table-responsive::-webkit-scrollbar-track {
    background: transparent;
}
.table-responsive::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 3px;
}
.table-responsive::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.22);
}

.table {
    width: 100%;
    margin-bottom: 0;
    color: white;
}

.table th {
    background-color: var(--table-header-bg) !important;
    color: #e0e0e0 !important;
    padding: 12px;
    white-space: nowrap;
    border: none;
    font-weight: 600;
    border-bottom: 1px solid #444;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

.table td {
    padding: 10px;
    background-color: rgba(0, 0, 0, 0.6);
    border-color: var(--border-color);
    vertical-align: middle;
    color: #e2e2e2;
}

.table tbody tr:hover td {
    background-color: rgba(59, 130, 246, 0.05);
}

/* Order-lines tables (Edit + Details). The global .table { padding: 12px/10px; white-space:nowrap }
   on headers is generous and, combined with 9–10 columns, pushes the table just past the card
   width on common desktop viewports — which trips .card-body.p-0's overflow-x:auto and shows a
   scroll bar even with "lots of space" visually. Tighten padding and allow multi-word headers
   ("Receipt ETA", "Unit Price") to wrap so the table fits inside its card. */
#linesTable th,
#detailsLinesTable th {
    padding: 8px 8px;
    white-space: normal;
    line-height: 1.2;
}
#linesTable td,
#detailsLinesTable td {
    padding: 8px;
}

.table-light th, .table-light td, .table-light {
    background-color: rgba(0, 0, 0, 0.5) !important;
    color: white !important;
}

.table > tfoot > tr > td {
    background-color: rgba(0, 0, 0, 0.5) !important;
    color: white !important;
    border-top: 2px solid #444;
}

/* Sortable table headers */
.data-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease;
}

.data-table th.sortable:hover {
    background-color: #111;
}

.sort-icon {
    margin-left: 8px;
    font-size: 12px;
    color: #9ca3af;
    transition: color 0.2s ease;
}

.data-table th.sortable.sort-asc .sort-icon,
.data-table th.sortable.sort-desc .sort-icon {
    color: #3b82f6;
}

/* Sortable column headers (link-based) */
th a.sort-link {
    color: #e0e0e0;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

th a.sort-link:hover {
    color: #3b82f6;
}

th .sort-indicator {
    font-size: 0.75rem;
    color: #3b82f6;
}

/* ============================================================
   CARDS & PANELS
   ============================================================ */

.card {
    background: var(--surface-1);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: white;
}

.card-header {
    background-color: var(--surface-2);
    border-bottom: 1px solid var(--border-color);
    color: white;
    font-weight: 600;
}

.card-body {
    color: white;
}

.card-footer {
    background-color: var(--surface-3);
    border-top: 1px solid var(--border-color);
}

.card-title {
    color: white;
}

.card-text {
    color: #e2e2e2;
}

/* Colored stat cards on dashboard */
.bg-primary.card, .bg-warning.card, .bg-info.card, .bg-success.card {
    border: none;
}

.bg-primary.card {
    background: linear-gradient(135deg, #3b82f6, #1d4ed8) !important;
}

.bg-warning.card {
    background: linear-gradient(135deg, #f59e0b, #d97706) !important;
}

.bg-info.card {
    background: linear-gradient(135deg, #06b6d4, #0e7490) !important;
}

.bg-success.card {
    background: linear-gradient(135deg, #22c55e, #15803d) !important;
}

.bg-primary.card .card-footer,
.bg-warning.card .card-footer,
.bg-info.card .card-footer,
.bg-success.card .card-footer {
    background-color: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

/* Info sections (collapsible) */
.info-section {
    background: var(--surface-1);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    margin-bottom: 1rem;
    overflow: hidden;
}

.main-content-panel {
    background-color: var(--surface-1);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    animation: fadeIn 0.3s ease-in-out;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background-color: var(--surface-2);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    user-select: none;
}

.section-title {
    color: white;
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title i {
    color: #3b82f6;
}

.collapse-btn {
    background: none;
    border: none;
    color: white;
    padding: 5px;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.section-content {
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out;
}

.section-content.collapsed {
    max-height: 0;
    border-top: none;
}

.section-body {
    padding: 20px;
}

/* ============================================================
   HEADER BAR
   ============================================================ */

.header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.page-title {
    color: white;
    font-size: 24px;
    margin-bottom: 0;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
}

h1.page-title {
    font-size: 1.5rem;
    margin-bottom: 0;
}

.order-title {
    display: flex;
    align-items: center;
    gap: 15px;
}

.action-buttons {
    display: flex;
    gap: 10px;
}

/* Search box */
.search-box {
    background-color: rgb(12, 12, 18);
    border: 1px solid var(--border-color);
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    width: 260px;
    height: 38px;
}

.search-box:focus {
    outline: 2px solid #60a5fa;
    outline-offset: -2px;
    border-color: #60a5fa;
}

/* ============================================================
   DETAILS LAYOUT
   ============================================================ */

.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    font-weight: 600;
    color: #9ca3af;
}

.detail-value {
    color: white;
    text-align: right;
}

/* Totals box */
.totals-box {
    margin-top: 10px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.total-row:last-child {
    border-bottom: none;
}

.total-final {
    font-weight: bold;
    font-size: 1.1em;
    border-top: 2px solid #3b82f6;
    margin-top: 10px;
    padding-top: 10px;
}

/* ============================================================
   BADGES
   ============================================================ */

.badge {
    padding: 5px 10px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.85rem;
}

.bg-warning {
    background-color: var(--warning-color) !important;
}

.bg-info {
    background-color: var(--info-color) !important;
}

.bg-success {
    background-color: var(--success-color) !important;
}

.bg-danger {
    background-color: var(--danger-color) !important;
}

.bg-secondary {
    background-color: var(--secondary-color) !important;
}

.bg-primary {
    background-color: var(--primary-color) !important;
}

/* ============================================================
   ALERTS
   ============================================================ */

.alert {
    border-radius: 4px;
    padding: 12px 15px;
    margin-bottom: 15px;
    border: 1px solid transparent;
    display: flex;
    align-items: center;
}

.alert i {
    margin-right: 10px;
    font-size: 1.1em;
}

.alert-success {
    color: #d4edda;
    background-color: rgba(34, 197, 94, 0.2);
    border-color: #22c55e;
}

.alert-danger {
    color: #f8d7da;
    background-color: rgba(239, 68, 68, 0.2);
    border-color: #ef4444;
}

.alert-warning {
    color: #fff3cd;
    background-color: rgba(245, 158, 11, 0.2);
    border-color: #f59e0b;
}

.alert-info {
    color: #d1ecf1;
    background-color: rgba(6, 182, 212, 0.2);
    border-color: #06b6d4;
}

.btn-close {
    filter: invert(1);
}

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #9ca3af;
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state-icon i {
    color: #3b82f6;
}

.empty-state h3 {
    color: white;
    margin-bottom: 10px;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */

.toast-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 9999;
}

.toast {
    background-color: rgba(0, 0, 0, 0.95);
    color: white;
    border-radius: 4px;
    padding: 15px;
    margin-bottom: 10px;
    min-width: 300px;
    display: none;
    animation: slideIn 0.3s ease;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    border-left: 4px solid var(--primary-color);
}

.toast.show {
    display: block;
}

.toast-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.toast-header .close {
    background: none;
    border: none;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
}

.toast.toast-success { border-left-color: #22c55e; }
.toast.toast-error { border-left-color: #ef4444; }
.toast.toast-warning { border-left-color: #f59e0b; }
.toast.toast-info { border-left-color: #06b6d4; }

/* ============================================================
   FOOTER
   ============================================================ */

.site-footer {
    flex-shrink: 0;
    background-color: rgba(0, 0, 0, 0.3);
    padding: 10px 20px;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
    color: #6b7280;
    font-size: 0.8rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.footer-badges {
    display: flex;
    gap: 8px;
    align-items: center;
}

.footer-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
}

.footer-badge.version {
    background-color: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.footer-badge.env-dev {
    background-color: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.3);
}

.footer-badge.env-prod {
    background-color: rgba(34, 197, 94, 0.2);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

/* ============================================================
   PAGINATION
   ============================================================ */

.pagination-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 10px;
}

.records-info {
    color: #e2e2e2;
    font-size: 14px;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.page-dropdown select {
    background-color: #000;
    color: white;
    border: 1px solid var(--border-color);
    padding: 5px 20px 5px 10px;
    border-radius: 4px;
    font-size: 14px;
}

.page-navigator {
    display: flex;
    align-items: center;
    background-color: #000;
    border-radius: 4px;
    padding: 5px 10px;
}

.page-nav-btn {
    color: white;
    text-decoration: none;
    font-weight: bold;
    padding: 0 10px;
    font-size: 16px;
    cursor: pointer;
    background: none;
    border: none;
}

.page-nav-btn:hover {
    color: #3b82f6;
}

.page-nav-btn.disabled {
    color: #4b5563;
    pointer-events: none;
}

.page-info {
    display: flex;
    align-items: center;
    gap: 5px;
    color: #e2e2e2;
    font-size: 14px;
    padding: 0 10px;
}

.page-number {
    background-color: rgba(50, 50, 50, 0.5);
    border: 1px solid var(--border-color);
    color: white;
    width: 40px;
    text-align: center;
    border-radius: 4px;
    height: 25px;
    padding: 0 5px;
}

/* ============================================================
   LOGIN PAGE
   ============================================================ */

.login-container {
    max-width: 450px;
    margin: 0 auto;
    padding: 20px;
    background-color: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* ============================================================
   SPINNER OVERLAY
   ============================================================ */

#spinner-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 9999;
}

#spinner-overlay.show {
    display: block;
}

.spinner-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    width: 90%;
    max-width: 200px;
}

.spinner-message {
    color: white;
    font-size: 16px;
    font-weight: 500;
}

/* ============================================================
   UTILITY OVERRIDES (dark theme)
   ============================================================ */

.text-muted {
    color: #adb5bd !important;
}

a {
    color: #60a5fa;
}

a:hover {
    color: #93bbfd;
}

address {
    color: white;
}

dl dt {
    color: #9ca3af;
}

dl dd {
    color: white;
}

hr {
    border-color: var(--border-color);
}

h1, h2, h3, h4, h5, h6 {
    color: white;
}

h1 i, h2 i, h3 i, h4 i, h5 i, h6 i {
    color: var(--primary-color);
}

/* Skip link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: #000;
    color: white;
    padding: 8px;
    z-index: 100;
    transition: top 0.3s;
}

.skip-link:focus {
    top: 0;
}

/* Container */
.container, .container-fluid {
    max-width: 1470px;
    margin: 0 auto;
}

/* Dropdown menus */
.dropdown-menu {
    background-color: rgba(0, 0, 0, 0.95);
    border: 1px solid var(--border-color);
}

.dropdown-item {
    color: white;
}

.dropdown-item:hover, .dropdown-item:focus {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--primary-color);
}

.dropdown-item-text {
    color: #adb5bd !important;
}

.dropdown-divider {
    border-color: var(--border-color);
}

/* ============================================================
   ITEM-SEARCH DROPDOWN — universal styles
   Used by initItemSearch (item-search.js) on Sales Order line pickers,
   Inventory filter pages, and Inventory.Adjust.
   ============================================================ */

/* Stacking level shared by every item-search rule below. Lives above sticky table chrome
   (~1020) and below modals (Bootstrap 1055 / our overlays 1100). Defined once so the
   desktop, mobile, dropup, and align-right rules can't drift apart. */
:root { --item-search-z: 1080; }

/* The wrapper that establishes the positioning context. The Razor markup uses
   <div class="position-relative"> around the input + dropdown. We make sure
   restrictive ancestors (table cells, especially) don't clip the dropdown. */
.item-search-results,
.item-search-results.dropdown-menu {
    /* Positioning — absolute relative to the .position-relative wrapper. */
    position: absolute;
    top: 100%;
    left: 0;
    right: auto;
    margin: 2px 0 0 0;
    z-index: var(--item-search-z);

    /* Width: at least as wide as the input, capped so it can't overflow the viewport.
       calc(100vw - 32px) leaves 16px of breathing room on each edge so the body never
       grows a horizontal scrollbar from the dropdown alone. */
    min-width: 100%;
    width: max-content;
    max-width: min(540px, calc(100vw - 32px));

    /* Height: bounded vertical scroll inside the dropdown.
       overflow-x:hidden prevents long item descriptions from creating a horizontal
       scroll inside the dropdown itself. */
    max-height: 280px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* When the JS detects no room below the input, flip the dropdown above. */
.item-search-results.dropdown-menu.dropup {
    top: auto;
    bottom: 100%;
    margin-top: 0;
    margin-bottom: 2px;
}

/* When the dropdown would extend past the viewport's right edge, anchor it to the
   right side of the input instead of the left. */
.item-search-results.dropdown-menu.align-right {
    left: auto;
    right: 0;
}

/* Make each result item wrap on long descriptions instead of forcing a horizontal
   overflow on the dropdown. The previous design used white-space:nowrap which made
   long item descriptions push the dropdown wider than the viewport. */
.item-search-results .dropdown-item {
    white-space: normal;
    overflow-wrap: anywhere;
    padding: 6px 12px;
    line-height: 1.4;
}

/* Containers that hold an item-search must not clip absolutely-positioned children.
   Table cells in particular get this treatment. */
.line-cell-item,
#linesTable td.line-cell-item,
#linesTable .position-relative {
    overflow: visible;
}

/* ============================================================
   FIELD-TARGETED SEARCH (Sales Orders / Inventory / Items)
   "Search in: [Field ▾] [Value] [Find]" — BC-style single-filter row.
   ============================================================ */

.field-search-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: end;
}

.field-search-label {
    /* The "Field:" prefix sits on the dark card background. Bootstrap's --bs-secondary-color
       (a mid-gray #6c757d) is too low-contrast here; --text-muted (#9ca3af) is the dark-theme
       muted-text token defined at :root and stays legible. */
    color: var(--text-muted, #9ca3af);
    white-space: nowrap;
}

.field-search-input-group {
    flex-wrap: nowrap;
    width: auto;
    max-width: 100%;
    min-width: 0;
}

.field-search-input-group > .form-select,
.field-search-input-group > .form-control {
    min-width: 130px;
}

@media (max-width: 575.98px) {
    /* On narrow screens stack the inner group so each control is full-width and tappable
       without horizontal scrolling. */
    .field-search-row { gap: 0.25rem; }
    .field-search-label { width: 100%; }
    .field-search-input-group {
        flex-wrap: wrap;
        width: 100%;
    }
    .field-search-input-group > .form-select,
    .field-search-input-group > .form-control,
    .field-search-input-group > .btn {
        flex: 1 1 100%;
        min-width: 0;
        border-radius: var(--bs-border-radius-sm) !important;
        margin-bottom: 0.25rem;
    }
    /* Range fields show two inputs side-by-side on tablets+, stacked on phones. */
    .field-search-range-from,
    .field-search-range-to {
        flex: 1 1 100% !important;
    }
}

/* ============================================================
   MOBILE SAVE BAR (SalesOrder Create/Edit)
   ============================================================ */

.mobile-save-bar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(17, 24, 39, 0.98);
    border-top: 1px solid var(--border-color);
    padding: 10px 16px;
    z-index: 1020;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.3);
}

.mobile-save-total {
    color: white;
    font-size: 0.9rem;
}

/* ============================================================
   CONFIRMATION MODAL
   ============================================================ */

#confirmModal .modal-content {
    background-color: #1e293b;
    border: 1px solid #334155;
}

#confirmModal .modal-header {
    border-bottom-color: #334155;
}

#confirmModal .modal-footer {
    border-top-color: #334155;
}

/* ============================================================
   ANIMATIONS
   ============================================================ */

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ============================================================
   RESPONSIVE — 992px (Tablet)
   ============================================================ */

@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width) !important;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    /* Override collapsed styles when sidebar is open on mobile */
    .sidebar.mobile-open.collapsed {
        width: var(--sidebar-width) !important;
    }
    .sidebar.mobile-open.collapsed .link-text,
    .sidebar.mobile-open.collapsed .sidebar-user-name,
    .sidebar.mobile-open.collapsed .sidebar-user-email {
        opacity: 1;
        width: auto;
        overflow: visible;
    }
    /* Restore the full logo (not just the mark) when open on mobile */
    .sidebar.mobile-open.collapsed .brand-logo {
        padding: 8px 12px;
    }
    .sidebar.mobile-open.collapsed .brand-logo img {
        width: 100%;
        height: auto;
        max-height: 38px;
    }
    .sidebar.mobile-open.collapsed .sidebar-section-title {
        text-align: left;
        padding: 8px 16px;
        font-size: 0.75rem;
    }
    .sidebar.mobile-open.collapsed .sidebar-section-title::after {
        display: none;
    }
    .sidebar.mobile-open.collapsed .sidebar-nav-link {
        justify-content: flex-start;
        padding: 8px 10px;
    }
    .sidebar.mobile-open.collapsed .sidebar-user {
        flex-direction: row;
        padding: 12px 16px;
    }
    .sidebar.mobile-open.collapsed .sidebar-user-info {
        display: block;
    }
    .sidebar.mobile-open.collapsed .sidebar-logout-btn {
        margin-left: auto;
    }

    /* Hide sidebar toggle on mobile (use hamburger menu instead) */
    .sidebar-toggle {
        display: none;
    }

    .mobile-menu-btn {
        display: flex;
    }

    .content-area {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .breadcrumb-bar {
        padding-left: 60px;
    }

    .content-main {
        padding-top: 60px;
    }
}

/* ============================================================
   RESPONSIVE — 768px (Mobile)
   ============================================================ */

@media (max-width: 768px) {
    .container, .container-fluid {
        padding: 0 10px;
    }

    .content-main {
        padding: 60px 12px 12px 12px;
    }

    .header-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .action-buttons {
        width: 100%;
    }

    .btn-action {
        flex: 1;
        justify-content: center;
    }

    .detail-row {
        flex-direction: column;
    }

    .detail-value {
        text-align: left;
    }

    /* Generic form / admin panel: prevent overflow */
    .search-box {
        width: 100%;
    }

    .toast {
        min-width: unset;
        max-width: calc(100vw - 24px);
    }

    .card-body .row > [class*="col-"] {
        overflow-x: hidden;
    }

    .card-body .form-control,
    .card-body .form-select,
    .card-body .input-group {
        max-width: 100%;
    }

    /* Mobile save bar */
    .mobile-save-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(17, 24, 39, 0.98);
        border-top: 2px solid var(--primary-color);
        padding: 10px 16px;
        z-index: 1050;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.4);
    }
    .mobile-save-bar .mobile-save-total {
        font-size: 0.85rem;
        color: #d1d5db;
    }
    .mobile-save-bar .mobile-save-total strong {
        color: white;
        font-size: 1.05rem;
    }
    .mobile-save-bar .btn {
        min-height: 44px;
        padding: 8px 20px;
        white-space: nowrap;
    }

    #orderForm {
        padding-bottom: 70px;
    }

    /* Mobile: keep overflow:visible so the order-lines card layout (which restructures
       rows into vertical cards via the rule below) isn't trapped in a scroll container.
       Wide list-page tables on mobile collapse to card layout via per-page rules, so we
       don't need horizontal scroll here either. */
    .card-body.p-0 {
        -webkit-overflow-scrolling: touch;
    }

    .page-nav-btn {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Responsive table card layout (shared mobile styles) */
    .responsive-table thead { display: none; }
    .responsive-table tbody tr {
        display: block;
        background: var(--surface-1);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        margin-bottom: 8px;
        padding: 12px;
    }
    .responsive-table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 4px 0;
        border: none;
        background: transparent;
    }
    .responsive-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #9ca3af;
        margin-right: 8px;
        white-space: nowrap;
    }
    .responsive-table tbody td:last-child:not([data-label]) {
        justify-content: flex-end;
        border-top: 1px solid var(--border-color);
        margin-top: 4px;
        padding-top: 8px;
    }

    /* Inline form inputs inside responsive-table cards */
    .responsive-table tbody td .form-control,
    .responsive-table tbody td .form-select {
        width: auto;
        flex: 1 1 auto;
        min-width: 0;
    }
    .responsive-table tbody td .form-check-input {
        margin: 0;
    }
    .responsive-table tbody td .btn {
        white-space: nowrap;
    }

    /* Shipments table: collapse row overrides */
    #shipmentsTable > tbody > tr.collapse { display: none; }
    #shipmentsTable > tbody > tr.collapse.show { display: block; }

    /* Shipments table: nested line tables — override inherited responsive-table styles */
    #shipmentsTable .collapse table {
        width: 100% !important;
        margin-left: 0 !important;
    }
    #shipmentsTable .collapse table thead { display: none; }
    #shipmentsTable .collapse table tbody {
        display: block;
        width: 100%;
    }
    #shipmentsTable .collapse table tbody tr {
        display: flex;
        flex-wrap: wrap;
        padding: 6px 8px;
        gap: 2px 8px;
        align-items: center;
        border: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        border-radius: 0;
        margin: 0;
        background: transparent;
    }
    #shipmentsTable .collapse table tbody tr:last-child {
        border-bottom: none;
    }
    #shipmentsTable .collapse table tbody td {
        display: block;
        padding: 0;
        border: none;
        justify-content: normal;
    }
    #shipmentsTable .collapse table tbody td::before {
        display: none;
    }
    /* Hide line number */
    #shipmentsTable .collapse table tbody td:first-child { display: none; }
    /* Item */
    #shipmentsTable .collapse table tbody td:nth-child(2) { flex: 0 0 auto; font-weight: 600; }
    /* Description */
    #shipmentsTable .collapse table tbody td:nth-child(3) { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    /* Qty */
    #shipmentsTable .collapse table tbody td:nth-child(4) { flex: 0 0 auto; }
    #shipmentsTable .collapse table tbody td:nth-child(4)::before {
        content: 'Qty: ';
        font-size: 0.65rem;
        color: #9ca3af;
        text-transform: uppercase;
    }
    /* Tracking */
    #shipmentsTable .collapse table tbody td:nth-child(5) { flex: 0 0 auto; }
    #shipmentsTable .collapse table tbody td:nth-child(5)::before {
        content: 'Track: ';
        font-size: 0.65rem;
        color: #9ca3af;
        text-transform: uppercase;
    }

    /* Ship-to address header stacking on mobile */
    .ship-to-header-controls {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    .ship-to-header-controls select {
        min-width: unset !important;
        max-width: unset !important;
    }

    .pagination-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .pagination-controls {
        justify-content: center;
    }
}

/* ============================================================
   ORDER LINES TABLE — Mobile Card Layout
   ============================================================ */
@media (max-width: 768px) {
    /* --- Order Lines: Table → Card Layout --- */
    #linesTable thead {
        display: none;
    }

    #linesTable,
    #linesTable tbody,
    #linesTable tfoot {
        display: block;
        width: 100%;
    }

    .table-responsive {
        overflow: visible !important;
    }

    /* Primary rows become flex cards */
    #linesTable tr.line-row-primary {
        display: flex;
        flex-wrap: wrap;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        background: var(--card-bg);
        margin-top: 10px;
        padding: 10px 54px 10px 10px;
        gap: 6px;
        align-items: flex-start;
        position: relative;
    }

    /* When secondary row follows, flatten bottom corners */
    #linesTable tr.line-row-primary:has(+ .line-row-secondary) {
        border-radius: 8px 8px 0 0;
        margin-bottom: 0;
    }

    /* Secondary rows continue the card */
    #linesTable tr.line-row-secondary {
        display: block;
        border: 1px solid var(--border-color);
        border-top: 1px dashed rgba(255, 255, 255, 0.1);
        border-radius: 0 0 8px 8px;
        background: var(--card-bg);
        padding: 8px 10px;
    }

    /* Hide line numbers on mobile */
    #linesTable .line-num-cell {
        display: none;
    }

    /* Reset TD styles in card rows */
    #linesTable tr.line-row-primary > td {
        border: none;
        padding: 2px 4px;
    }

    /* Row 1: Item takes full width; delete is absolutely positioned beside it */
    #linesTable .line-cell-item {
        flex: 0 0 100%;
        min-width: 0;
        order: 1;
    }
    #linesTable .line-cell-item .input-group,
    #linesTable .line-cell-item .form-control {
        min-width: 0;
    }

    #linesTable .line-cell-actions {
        position: absolute;
        top: 8px;
        right: 4px;
        width: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Row 2: Qty / UOM / Price / Amount (equal columns with labels above) */
    #linesTable .line-cell-qty {
        flex: 1 1 0;
        order: 3;
    }
    #linesTable .line-cell-uom {
        flex: 1.2 1 0;
        order: 4;
        min-width: 70px;
    }
    #linesTable .line-cell-uom .form-select {
        min-width: 0;
    }
    #linesTable .line-cell-price {
        flex: 1 1 0;
        order: 5;
    }
    #linesTable .line-cell-amount {
        flex: 1 1 0;
        order: 6;
        font-weight: 600;
    }

    /* Mobile field labels via ::before */
    #linesTable .line-cell-qty::before,
    #linesTable .line-cell-uom::before,
    #linesTable .line-cell-price::before,
    #linesTable .line-cell-amount::before {
        display: block;
        font-size: 0.65rem;
        color: #9ca3af;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin-bottom: 2px;
    }

    #linesTable .line-cell-qty::before { content: 'Qty'; }
    #linesTable .line-cell-uom::before { content: 'UOM'; }
    #linesTable .line-cell-price::before { content: 'Price'; }
    #linesTable .line-cell-amount::before { content: 'Amount'; }

    /* Tfoot summary rows */
    #linesTable tfoot tr {
        display: flex;
        justify-content: flex-end;
        align-items: center;
        gap: 8px;
        padding: 4px 10px;
    }
    #linesTable tfoot tr td {
        border: none;
        padding: 2px 0;
    }
    #linesTable tfoot tr td:empty {
        display: none;
    }

    /* Secondary row: compact */
    #linesTable tr.line-row-secondary {
        padding: 6px 10px;
    }
    #linesTable tr.line-row-secondary > td {
        border: none;
        width: 100%;
    }

    /* Outer flex: row wrap so info items stay inline */
    #linesTable .line-row-secondary td > .d-flex {
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 0.2rem 0.5rem !important;
        align-items: center !important;
        font-size: 0.75rem;
    }

    /* Ship / Tracking: own row below info, side by side */
    #linesTable .line-row-secondary td > .d-flex > .d-flex {
        flex: 1 1 calc(50% - 0.25rem);
        min-width: 0;
        flex-direction: row !important;
        align-items: center !important;
        gap: 4px !important;
    }

    /* Labels don't shrink */
    #linesTable .line-row-secondary td > .d-flex > .d-flex > span {
        flex-shrink: 0;
        font-size: 0.7rem;
    }

    /* Inputs fill remaining space */
    #linesTable .line-row-secondary .qty-to-ship,
    #linesTable .line-row-secondary .flex-grow-1 .form-control {
        width: auto !important;
        flex: 1;
        min-width: 0;
    }

    /* Touch targets */
    #linesTable .btn-sm {
        min-height: 44px;
        min-width: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Collapse indicator bigger tap area */
    .collapse-indicator {
        padding: 10px 14px !important;
        margin: -8px -12px;
    }

    /* Mobile item picker: elevated overlay across all consumer pages, not just lines table.
       The base item-search styles already handle width / overflow / position; here we just
       add the shadow + touch-friendly padding. */
    .item-search-results.show {
        border-radius: 12px;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
        border: 1px solid rgba(255, 255, 255, 0.15);
        background: rgba(17, 24, 39, 0.99);
    }

    /* Touch-optimized dropdown items */
    .item-search-results .dropdown-item {
        padding: 12px 16px;
        font-size: 0.95rem;
        line-height: 1.4;
        min-height: 48px;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    }

    .item-search-results .dropdown-item:last-child {
        border-bottom: none;
    }

    .item-search-results .dropdown-item small {
        display: block;
        margin-top: 2px;
    }

    /* Order summary: don't stick on mobile */
    .order-summary-card,
    .position-sticky {
        position: static !important;
    }
}

/* ===== Order Lines: 576px refinements ===== */
@media (max-width: 576px) {
    /* Tighter card padding on smallest screens */
    #linesTable tr.line-row-primary {
        padding: 8px 50px 8px 8px;
        gap: 4px;
    }

    #linesTable tr.line-row-primary > td {
        font-size: 0.8rem;
    }

    /* Ship / Tracking stay side by side */
    #linesTable .line-row-secondary td > .d-flex > .d-flex {
        flex: 1 1 calc(50% - 0.25rem);
        min-width: 0;
    }

    .mobile-save-bar {
        padding: 8px 12px;
    }
    .mobile-save-bar .mobile-save-total {
        font-size: 0.8rem;
    }
    .mobile-save-bar .btn {
        padding: 8px 16px;
    }
}

/* ============================================================
   DETAILS LINES TABLE — Mobile Card Layout
   ============================================================ */
@media (max-width: 768px) {
    #detailsLinesTable thead { display: none; }
    #detailsLinesTable,
    #detailsLinesTable tbody,
    #detailsLinesTable tfoot { display: block; width: 100%; }

    #detailsLinesTable tbody tr {
        display: flex;
        flex-wrap: wrap;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        background: var(--card-bg);
        margin-top: 10px;
        padding: 10px;
        gap: 6px;
        align-items: flex-start;
    }

    #detailsLinesTable tbody tr > td {
        border: none;
        padding: 2px 4px;
    }

    /* Hide line number */
    #detailsLinesTable .dl-num { display: none; }

    /* Row 1: Item + Description (full width) */
    #detailsLinesTable .dl-item {
        flex: 0 0 auto;
        order: 1;
    }
    #detailsLinesTable .dl-desc {
        flex: 1 1 calc(100% - 100px);
        order: 2;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Row 2: Qty + UOM + Price + Amount */
    #detailsLinesTable .dl-qty {
        flex: 1 1 50px;
        order: 3;
    }
    #detailsLinesTable .dl-uom {
        flex: 1 1 40px;
        order: 4;
    }
    #detailsLinesTable .dl-price {
        flex: 1 1 50px;
        order: 5;
    }
    #detailsLinesTable .dl-amount {
        flex: 1 1 50px;
        order: 6;
        font-weight: 600;
    }

    /* Row 3: Shipped */
    #detailsLinesTable .dl-shipped {
        flex: 1 1 100%;
        order: 7;
    }

    /* Mobile field labels */
    #detailsLinesTable .dl-qty::before,
    #detailsLinesTable .dl-uom::before,
    #detailsLinesTable .dl-price::before,
    #detailsLinesTable .dl-amount::before,
    #detailsLinesTable .dl-shipped::before {
        display: block;
        font-size: 0.65rem;
        color: #9ca3af;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin-bottom: 2px;
    }
    #detailsLinesTable .dl-qty::before { content: 'Qty'; }
    #detailsLinesTable .dl-uom::before { content: 'UOM'; }
    #detailsLinesTable .dl-price::before { content: 'Price'; }
    #detailsLinesTable .dl-amount::before { content: 'Amt'; }
    #detailsLinesTable .dl-shipped::before { content: 'Shipped'; }

    /* Tfoot summary */
    #detailsLinesTable tfoot tr {
        display: flex;
        justify-content: flex-end;
        align-items: center;
        gap: 8px;
        padding: 4px 10px;
    }
    #detailsLinesTable tfoot tr td {
        border: none;
        padding: 2px 0;
    }
    #detailsLinesTable tfoot tr td[colspan] {
        flex: 1;
    }
    #detailsLinesTable tfoot tr td:empty {
        display: none;
    }

    /* --- Shipment History nested tables --- */
    [id^="shipment-detail-"] table {
        width: 100% !important;
        margin-left: 0 !important;
    }
    [id^="shipment-detail-"] table thead { display: none; }
    [id^="shipment-detail-"] table,
    [id^="shipment-detail-"] table tbody { display: block; width: 100%; }

    [id^="shipment-detail-"] table tbody tr {
        display: flex;
        flex-wrap: wrap;
        border-bottom: 1px solid rgba(255, 255, 255, 0.06);
        padding: 8px 12px;
        gap: 4px;
        align-items: center;
    }
    [id^="shipment-detail-"] table tbody tr > td {
        border: none;
        padding: 2px 4px;
    }
    /* Hide line number */
    [id^="shipment-detail-"] table tbody tr > td:first-child { display: none; }
    /* Item */
    [id^="shipment-detail-"] table tbody tr > td:nth-child(2) {
        flex: 0 0 auto;
        order: 1;
    }
    /* Description */
    [id^="shipment-detail-"] table tbody tr > td:nth-child(3) {
        flex: 1 1 calc(100% - 100px);
        order: 2;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    /* Qty */
    [id^="shipment-detail-"] table tbody tr > td:nth-child(4) {
        flex: 0 0 auto;
        order: 3;
    }
    [id^="shipment-detail-"] table tbody tr > td:nth-child(4)::before {
        content: 'Qty: ';
        font-size: 0.65rem;
        color: #9ca3af;
        text-transform: uppercase;
    }
    /* Tracking */
    [id^="shipment-detail-"] table tbody tr > td:nth-child(5) {
        flex: 0 0 auto;
        order: 4;
    }
    [id^="shipment-detail-"] table tbody tr > td:nth-child(5)::before {
        content: 'Track: ';
        font-size: 0.65rem;
        color: #9ca3af;
        text-transform: uppercase;
    }

    /* Details page: Order details 2-col → stacked */
    #orderDetailsCollapse .row > .col-md-6:first-child {
        margin-bottom: 0.5rem;
    }

    /* Details page: sticky cards → static on mobile */
    .col-md-4 .card {
        position: static !important;
    }
}

/* ============================================================
   SHIP LINES TABLE — Mobile Card Layout
   ============================================================ */
@media (max-width: 768px) {
    #shipLinesTable thead { display: none; }
    #shipLinesTable,
    #shipLinesTable tbody { display: block; width: 100%; }

    #shipLinesTable tbody tr {
        display: flex;
        flex-wrap: wrap;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        background: var(--card-bg);
        margin-top: 10px;
        padding: 10px;
        gap: 6px;
        align-items: flex-start;
    }

    #shipLinesTable tbody tr > td {
        border: none;
        padding: 2px 4px;
    }

    /* Hide line number */
    #shipLinesTable .sl-num { display: none; }

    /* Row 1: Checkbox + Item + Description */
    #shipLinesTable .sl-check {
        flex: 0 0 32px;
        order: 1;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    #shipLinesTable .sl-check .form-check-input {
        min-width: 28px;
        min-height: 28px;
        padding: 8px;
    }
    #shipLinesTable .sl-item {
        flex: 0 0 auto;
        order: 2;
    }
    #shipLinesTable .sl-desc {
        flex: 1 1 calc(100% - 140px);
        order: 3;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Row 2: Ordered + Shipped + Outstanding (thirds) */
    #shipLinesTable .sl-ordered {
        flex: 1 1 30%;
        order: 4;
    }
    #shipLinesTable .sl-shipped {
        flex: 1 1 30%;
        order: 5;
    }
    #shipLinesTable .sl-outstanding {
        flex: 1 1 30%;
        order: 6;
    }

    /* Row 3: Qty to Ship + Tracking (halves) */
    #shipLinesTable .sl-ship {
        flex: 1 1 calc(50% - 3px);
        order: 7;
    }
    #shipLinesTable .sl-tracking {
        flex: 1 1 calc(50% - 3px);
        order: 8;
    }

    /* Mobile field labels */
    #shipLinesTable .sl-ordered::before,
    #shipLinesTable .sl-shipped::before,
    #shipLinesTable .sl-outstanding::before,
    #shipLinesTable .sl-ship::before,
    #shipLinesTable .sl-tracking::before {
        display: block;
        font-size: 0.65rem;
        color: #9ca3af;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin-bottom: 2px;
    }
    #shipLinesTable .sl-ordered::before { content: 'Ordered'; }
    #shipLinesTable .sl-shipped::before { content: 'Shipped'; }
    #shipLinesTable .sl-outstanding::before { content: 'Outstanding'; }
    #shipLinesTable .sl-ship::before { content: 'Qty to Ship'; }
    #shipLinesTable .sl-tracking::before { content: 'Tracking'; }

    /* Touch-friendly inputs */
    #shipLinesTable .sl-ship .form-control,
    #shipLinesTable .sl-tracking .form-control {
        min-height: 40px;
    }
    #shipLinesTable .sl-check .form-check-input {
        min-width: 28px;
        min-height: 28px;
        padding: 8px;
    }
}

/* ============================================================
   RESPONSIVE — 576px (Small Mobile)
   ============================================================ */

@media (max-width: 576px) {
    .page-title {
        font-size: 20px;
    }

    .action-buttons {
        flex-direction: column;
    }

    .btn-action {
        width: 100%;
    }

    .site-footer {
        flex-direction: column;
        gap: 4px;
        text-align: center;
        padding: 8px;
    }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ============================================================
   PRINT STYLES
   ============================================================ */

@media print {
    body {
        background: white;
        color: black;
    }

    .sidebar, .mobile-menu-btn, .sidebar-overlay,
    .site-footer, .btn, .no-print,
    .loading-overlay, .toast-container,
    .breadcrumb-bar, .mobile-save-bar {
        display: none !important;
    }

    .content-area {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .content-main {
        padding: 0;
    }

    .card {
        background: white;
        border: 1px solid #ddd;
        color: black;
    }

    .table th, .table td {
        background: white !important;
        color: black !important;
        border: 1px solid #ddd !important;
    }

    .form-control, .form-select {
        background-color: white !important;
        color: black !important;
        border: 1px solid #999 !important;
    }

    .badge {
        border: 1px solid #999 !important;
        color: black !important;
        background-color: #eee !important;
    }

    .alert {
        background-color: white !important;
        color: black !important;
        border: 1px solid #999 !important;
    }

    .card-header {
        background-color: #f0f0f0 !important;
        color: black !important;
    }

    a {
        color: black !important;
        text-decoration: underline !important;
    }

    @page {
        margin: 1cm;
    }
}

/* ============================================================
   COLLAPSIBLE CARD HEADERS
   ============================================================ */

.card-header[data-bs-toggle="collapse"] {
    cursor: pointer;
    user-select: none;
}

.card-header[data-bs-toggle="collapse"]:hover {
    filter: brightness(1.1);
}

.collapse-indicator {
    transition: transform 0.2s ease;
    cursor: pointer;
    padding: 2px 4px;
}

.collapse-indicator[aria-expanded="true"] {
    transform: rotate(180deg);
}

.collapse-indicator[aria-expanded="false"] {
    transform: rotate(0deg);
}

/* ============================================================
   TABLE ACTION BUTTON SPACING
   ============================================================ */

.table td .btn-outline-danger {
    margin-left: 4px;
}

/* ============================================================
   ITEM SEARCH COMBOBOX — Keyboard highlight
   ============================================================ */

.item-search-results [role="option"].active,
.dropdown-menu[role="listbox"] [role="option"].active {
    background-color: var(--primary-color);
    color: white;
}
