/* Clean Orders Page CSS - Inspired by improved_orders_view.html */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --secondary: #64748b;
    --success: #10b981;
    --success-light: #dcfce7;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --info: #3b82f6;
    --info-light: #dbeafe;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius: 12px;
    /* Layout + density tokens */
    --container-max: 100%; /* fill available width by default */
    --ctrl-h: 36px;
    --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
    /* Brand theme colors (progress bars, accents) */
    --brand-start: #e11d2f; /* logo red */
    --brand-end: #1636b3;   /* logo blue */
    --bar-thickness: 6px;   /* unify loader + TC bar thickness */
    --tc-bar-width: 72%;    /* visual width of TC bar inside its cell */
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

body.loading {
    cursor: progress;
}

.loading-screen {
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.loading-screen.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.skeleton-row,
.skeleton-chip {
    position: relative;
}

.skeleton-row {
    pointer-events: none;
}

.skeleton-block {
    display: block;
    width: 100%;
    height: 14px;
    border-radius: 8px;
    background: linear-gradient(90deg, rgba(226,232,240,0.7) 25%, rgba(226,232,240,0.35) 37%, rgba(226,232,240,0.7) 63%);
    background-size: 400% 100%;
    animation: shimmer 1.2s ease-in-out infinite;
}

.skeleton-block.wide {
    height: 18px;
}

.skeleton-chip .skeleton-block {
    height: 16px;
    min-width: 72px;
}

@keyframes shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

body:not(.loading) .skeleton-row,
body:not(.loading) .skeleton-chip {
    display: none;
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--background);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loader-container {
    text-align: center;
    padding: 2rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.spinner {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin: 0 auto 1rem;
    height: 40px;
}

.spinner-dot {
    width: 12px;
    height: 12px;
    background: var(--primary);
    border-radius: 50%;
    animation: pulse 1.4s ease-in-out infinite both;
}

.spinner-dot:nth-child(1) { animation-delay: -0.32s; }
.spinner-dot:nth-child(2) { animation-delay: -0.16s; }
.spinner-dot:nth-child(3) { animation-delay: 0s; }

@keyframes pulse {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.loading-text {
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
}

/* Enhanced, branded loading */
.loader-enhanced { padding: 28px 28px 24px; max-width: 520px; width: calc(100% - 32px); }
.loader-brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 10px; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: #fff; border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow-sm); overflow: hidden; }
.brand-logo { width: 100%; height: 100%; object-fit: contain; }
.brand-name { font-weight: 800; color: var(--text-primary); letter-spacing: .3px; }
.loading-title { font-size: 16px; font-weight: 700; color: var(--text-primary); margin: 6px 0 12px; }
.loading-stages { display: inline-flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 12px; font-weight: 700; margin-bottom: 14px; }
.loading-stages .stage { opacity: .4; position: relative; }
.loading-stages .stage-sep { width: 18px; height: 2px; background: var(--border); border-radius: 2px; opacity: .8; }

/* Stage pulses in sequence during the progress animation */
@keyframes stagePulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; color: var(--brand-end); } }
.stage-1 { animation: stagePulse 3.2s ease-in-out infinite; animation-delay: 0s; }
.stage-2 { animation: stagePulse 3.2s ease-in-out infinite; animation-delay: .9s; }
.stage-3 { animation: stagePulse 3.2s ease-in-out infinite; animation-delay: 1.8s; }

.progress-rail { position: relative; width: 100%; height: var(--bar-thickness); background: var(--background); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; box-shadow: inset 0 1px 2px rgba(0,0,0,.03); }
.progress-fill { position: absolute; left: 0; top: 0; height: 100%; width: 0%; background: linear-gradient(90deg, var(--brand-start) 0%, var(--brand-end) 100%); box-shadow: 0 0 10px rgba(37,99,235,.15); animation: fillBar 3.2s cubic-bezier(0.22,0.61,0.36,1) forwards; }
@keyframes fillBar { from { width: 0%; } to { width: 100%; } }
.loading-subtext { margin-top: 10px; font-size: 12px; color: var(--text-secondary); }

/* Subtle entrance animation for the container */
@keyframes loaderPop { from { transform: translateY(4px) scale(.98); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }
.loader-enhanced { animation: loaderPop .25s ease-out both; }

/* (Reverted) No stage state classes and no skeleton preview */

/* Header */
.header {
    background: var(--background);
    padding: var(--space-2) calc(var(--space-4) + 4px) 0;
    position: relative;
    z-index: 100;
    margin-bottom: 0;
}

/* Compact density mode for small laptops / high zoom */
body.compact .header { padding: 6px 14px; }
body.compact .page-title { font-size: 18px; }
body.compact .filters-bar { gap: 10px; }
body.compact .filter-select { min-width: 160px; padding: 0 28px 0 10px; font-size: 13px; }
body.compact .search-box { min-width: 220px; }
body.compact .search-input { padding: 0 10px 0 34px; font-size: 13px; }
body.compact .toggle-btn { padding: 0 12px; font-size: 13px; }
body.compact .container { padding: 16px 18px; }

/* Compact grid columns */
body.compact .main-list .list-header,
body.compact .main-list .list-row {
  /* Give ITEMS a bit more room so name + brand fit */
  grid-template-columns: 110px 150px 260px 90px 110px 90px 140px 110px;
  gap: 8px;
  padding: 10px 12px;
}
body.compact .list-header { font-size: 11px; }
body.compact .list-cell { font-size: 13px; }
body.compact .chip, body.compact .brand-tag { font-size: 10px; }
body.compact .chip-mini { font-size: 11px; padding: 5px 10px; }
body.compact .more-items-badge { font-size: 10px; padding: 1px 6px; }
body.compact .tc-bar { width: 64%; }

/* Comfortable density for wide screens (≥1920px) */
body.comfortable .header { padding: 12px 24px; }
body.comfortable .page-title { font-size: 28px; }
body.comfortable .filters-bar { gap: 14px; }
body.comfortable .filter-select { min-width: 200px; font-size: 16px; padding: 0 38px 0 16px; }
body.comfortable .search-input { font-size: 16px; padding: 0 16px 0 44px; }
body.comfortable .toggle-btn { padding: 0 18px; font-size: 16px; }
body.comfortable .container { padding: 30px 36px; max-width: 1840px; }
body.comfortable .list-header { font-size: 14px; }
body.comfortable .list-cell { font-size: 16px; }
body.comfortable .main-list .list-header,
body.comfortable .main-list .list-row {
  /* Wider ITEMS column in comfortable density */
  grid-template-columns: 140px 260px 440px 120px 130px 130px 180px 160px;
  gap: 14px;
  padding: 14px 18px;
}
body.comfortable .tc-bar { width: 78%; }

/* Cozy density: mild reduction for 1080p @125% etc. */
body.cozy .header { padding: 8px 18px; }
body.cozy .page-title { font-size: 22px; }
body.cozy .filter-select { min-width: 170px; font-size: 13.5px; padding: 0 32px 0 12px; }
body.cozy .search-input { font-size: 13.5px; padding: 0 12px 0 36px; height: 38px; }
body.cozy .toggle-btn { padding: 0 14px; font-size: 13.5px; }
body.cozy .container { padding: 20px 24px; max-width: 1640px; }
body.cozy .main-list .list-header,
body.cozy .main-list .list-row { grid-template-columns: 120px 200px 340px 100px 115px 105px 150px 120px; gap: 10px; padding: 11px 14px; }
body.cozy .list-header { font-size: 12px; }
body.cozy .list-cell { font-size: 14px; }
body.cozy .tc-bar { width: 68%; }

/* Ultra-compact density for tiny effective viewports (e.g., 1176×738 at 250% scaling) */
body.ultra .header { padding: 4px 12px; }
body.ultra .page-title { font-size: 18px; }
body.ultra .filters-bar { gap: 8px; }
body.ultra .filter-select { min-width: 140px; padding: 0 26px 0 10px; font-size: 12px; }
body.ultra .search-box { min-width: 200px; }
body.ultra .search-input { padding: 0 10px 0 32px; font-size: 12.5px; }
body.ultra .toggle-btn { padding: 0 10px; font-size: 12.5px; border-radius: 6px; }
body.ultra .container { padding: 12px 14px; max-width: 1500px; }

/* Tables: denser cells and columns */
body.ultra .main-list .list-header,
body.ultra .main-list .list-row { grid-template-columns: 100px 140px 220px 80px 90px 80px 130px 110px; gap: 6px; padding: 8px 10px; }
body.ultra .shipments-list .list-header,
body.ultra .shipments-list .list-row { grid-template-columns: 90px 176px minmax(220px, 1fr) 56px 56px 140px 140px 110px; gap: 6px; padding: 8px 10px; }
body.ultra .list-header { font-size: 11px; }
body.ultra .list-cell { font-size: 12.5px; }
body.ultra .chip, body.ultra .brand-tag { font-size: 9.5px; }
body.ultra .chip-mini { font-size: 10px; padding: 4px 8px; }
body.ultra .more-items-badge { font-size: 9.5px; padding: 1px 5px; }
body.ultra .tc-bar { width: 58%; }



.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: var(--space-2);
}

.header-primary {
    flex: 1 1 260px;
    min-width: 220px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.header-title-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.header-insights {
    display: flex;
    justify-content: flex-end;
    flex: 1 1 520px;
    min-width: 320px;
    max-width: 520px;
    align-self: center;
}

.header-insights .view-insights {
    align-items: center;
    width: 100%;
}

.filter-dock {
    position: sticky;
    top: 0;
    z-index: 120;
    background: linear-gradient(135deg, rgba(248, 250, 252, 0.95), rgba(255, 255, 255, 0.98));
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 14px;
    box-shadow: 0 16px 32px -28px rgba(15, 23, 42, 0.35);
    padding: 14px 18px;
    margin-bottom: 24px;
}

@media (max-width: 768px) {
    .filter-dock {
        top: 0;
        padding: 12px 14px;
    }

    .filters-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .filter-group {
        grid-template-columns: 1fr;
        row-gap: 6px;
        min-width: 100%;
    }

    .filter-label {
        min-width: 0;
    }
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
}

.btn {
    padding: 10px 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
}

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

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

.btn-primary:hover {
    background: var(--primary-dark);
}

/* Filters Bar */
.filters-bar {
    display: flex;
    align-items: stretch;
    gap: 12px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.filter-group .select-enhanced,
.filter-group .filter-select {
    flex: 0 1 auto;
    min-width: 0;
}

.filter-group .select-enhanced {
    max-width: 100%;
}

.filter-group .select-enhanced .filter-select-trigger {
    width: auto;
}

.filter-label {
    font-size: 14px;
    color: var(--text-primary);
    font-weight: 600;
    display: flex;
    align-items: center;
    min-width: 60px;
    white-space: nowrap;
}

.status-toggle-group {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: auto;
    flex-wrap: wrap;
}
.status-toggle-group .filter-label {
    min-width: auto;
    margin-right: 4px;
}

.status-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.status-pill {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.18s ease;
}

.status-pill:hover,
.status-pill:focus-visible {
    background: rgba(148, 163, 184, 0.16);
    color: var(--text-primary);
    outline: none;
}

.status-pill.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 6px rgba(37, 99, 235, 0.25);
}
.filter-select {
    height: 40px;
    padding: 0 30px 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    background: var(--surface);
    color: var(--text-primary);
    cursor: pointer;
    min-width: 160px;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2364758b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 10px;
    line-height: 1.3;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
    text-align: left;
}
.filter-select:hover {
    border-color: rgba(15, 23, 42, 0.28);
    box-shadow: 0 3px 6px -3px rgba(15, 23, 42, 0.18);
}
.filter-select:focus,
.filter-select:focus-visible {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
    background: var(--surface);
}
.filter-select:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    color: var(--text-secondary);
    box-shadow: none;
}

.chip-mini {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.chip-mini .k {
    color: var(--text-secondary);
    font-weight: 600;
}

.chip-mini.success {
    background: var(--success-light);
    color: var(--success);
    border-color: transparent;
}

.chip-mini.warn {
    background: var(--warning-light);
    color: var(--warning);
    border-color: transparent;
}

.chip-mini.info {
    background: var(--primary-light);
    color: var(--primary);
    border-color: transparent;
}

.select-enhanced {
    position: relative;
    display: inline-flex;
    min-width: 200px;
}

.filter-select-native {
    display: none !important;
}

.filter-select-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-right: 10px;
    background-color: var(--surface);
    background-image: none;
}

.filter-select-trigger .select-label {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.filter-select-trigger .select-icon {
    pointer-events: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
}

.filter-select-trigger .select-icon svg {
    width: 12px;
    height: 12px;
}

.select-menu {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 100%;
    background: var(--surface);
    border: 1px solid rgba(15, 23, 42, 0.12);
    border-radius: 10px;
    box-shadow: 0 18px 30px -18px rgba(15, 23, 42, 0.35), 0 6px 18px -12px rgba(15, 23, 42, 0.16);
    padding: 6px;
    max-height: 260px;
    overflow-y: auto;
    z-index: 20;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
}

.select-menu.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.select-option {
    width: 100%;
    border: 0;
    background: transparent;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    font-weight: 400;
    color: var(--text-primary);
    transition: background 0.15s ease, color 0.15s ease;
}

.select-option:hover:not([aria-disabled="true"]) {
    background: rgba(37, 99, 235, 0.08) !important;
    color: var(--primary-dark) !important;
}

.select-option[aria-selected="true"] {
    background: rgba(37, 99, 235, 0.12);
    color: var(--primary-dark);
    font-weight: 500;
}

.select-option.is-active {
    background: rgba(37, 99, 235, 0.18);
    color: var(--primary-dark);
    font-weight: 500;
}

.select-option:focus {
    outline: none;
}

.select-option[aria-disabled="true"] {
    cursor: not-allowed;
    color: var(--text-secondary);
    opacity: 0.6;
}

.select-divider {
    height: 1px;
    margin: 4px 0;
    background: rgba(148, 163, 184, 0.18);
}

@media (prefers-reduced-motion: reduce) {
    .select-menu {
        transition: none;
    }
    .filter-select {
        transition: none;
    }
}

/* Additional reduced-motion safeguards for loaders/skeletons */
@media (prefers-reduced-motion: reduce) {
    .skeleton-block { animation: none !important; }
    .stage-1, .stage-2, .stage-3, .progress-fill { animation: none !important; }
}

.search-box { position: relative; flex: 1 1 260px; display: flex; align-items: center; }

.search-input { width: 100%; height: 40px; padding: 0 16px 0 40px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; background: var(--surface); color: var(--text-primary); }

.search-input::placeholder {
    color: var(--text-secondary);
}

.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-secondary); }

/* Container */
.container {
    padding: 0 calc(var(--space-5) + 4px) var(--space-5);
    max-width: var(--container-max);
    width: 100%;
    margin: 0 auto;
}

/* Page title + utility labels */
.page-title { font-size: 22px; line-height: 28px; font-weight: 700; margin: 0; color: var(--text-primary); }
.section-label { font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: .04em; color: var(--text-secondary); }

/* Stats Bar */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-item {
    background: var(--surface);
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    text-align: center;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Search Results Count */
#searchResultsCount {
    padding: 12px 0;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    border-radius: 6px;
    margin-bottom: 20px;
}

/* View insights */
.view-insights {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-left: 0;
    border-left: none;
}

.view-toolbar {
    display: flex;
    align-items: flex-start;
    gap: 24px;
    flex-wrap: wrap;
    margin: 20px 0 24px;
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
    border-top: 1px solid var(--border);
}

.view-toolbar .view-toggle {
    flex: 1 1 520px;
    min-width: 320px;
}

.header-insights .view-insights {
    padding-left: 0;
    border-left: none;
    min-width: 0;
}

.insight-header {
    display: none;
}

.insight-label {
    display: none;
}
.insight-meta {
    display: none;
}

.insight-metrics {
    display: inline-flex;
    align-items: stretch;
    justify-content: center;
    gap: 0;
    padding: 4px 6px;
    background: rgba(241, 245, 249, 0.6);
    border: 1px solid rgba(148, 163, 184, 0.4);
    border-radius: 12px;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.75);
    flex-wrap: nowrap;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.insight-metrics.insight-transitioning {
    opacity: 0;
    transform: translateY(-6px);
}

.insight {
    --insight-accent: var(--text-primary);
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    min-width: auto;
    flex: 0 1 auto;
    background: transparent;
    position: relative;
}

.insight + .insight::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 1px;
    background: rgba(148, 163, 184, 0.4);
}

.insight-name {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-secondary);
    font-weight: 600;
    white-space: nowrap;
}

.insight-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--insight-accent);
    letter-spacing: -0.01em;
    white-space: nowrap;
}

@media (max-width: 1200px) {
    .insight-metrics {
        gap: 0;
        border-radius: 12px;
    }
}

@media (max-width: 680px) {
    .insight-metrics {
        /* Keep horizontal layout even on mobile */
        border-radius: 12px;
    }

    .insight {
        padding: 8px 12px;
    }
}

.insight[data-state="info"] {
    --insight-accent: var(--accent-blue, #2563eb);
}

.insight[data-state="warning"] {
    --insight-accent: var(--warning);
}

.insight[data-state="success"] {
    --insight-accent: var(--success);
}

.insight[data-state="danger"] {
    --insight-accent: var(--danger);
}

.insight[data-state="muted"] {
    --insight-accent: var(--text-secondary);
    opacity: 0.6;
}

@media (max-width: 1024px) {
    .header-row {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }

    .header-title-bar {
        align-items: flex-start;
    }

    .insights-toggle {
        margin-left: 0;
    }

    .header-insights {
        width: 100%;
        justify-content: flex-start;
        max-width: none;
        align-self: auto;
    }

    .header-insights .view-insights {
        align-items: flex-start;
        width: 100%;
    }

    .view-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
        padding: 16px 0;
        border-bottom: 1px solid var(--border);
        border-top: 1px solid var(--border);
    }

    .view-toolbar .view-toggle {
        flex: 1 1 100%;
        min-width: 0;
    }

    .view-toggle {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .view-toggle-buttons {
        justify-content: flex-start;
    }

    .view-toggle-controls {
        width: 100%;
        justify-content: flex-start;
        margin-left: 0;
    }

    .view-insights {
        border-left: none;
        padding-left: 0;
        width: 100%;
        align-items: flex-start;
        margin-top: 12px;
    }

    .insight-metrics {
        width: 100%;
    }
    
    /* Ensure toggle buttons stack properly on small screens */
    .toggle-btn {
        min-width: auto;
        flex: 1 1 auto;
    }
}

/* View Toggle */
.view-toggle {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 0;
}

.view-toggle-buttons {
    display: flex;
    align-items: center;
    gap: 12px;
    row-gap: 10px;
    flex-wrap: wrap;
}

.view-toggle-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    row-gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.view-toggle-controls > * {
    flex: 0 0 auto;
}

/* Hide Card/List view buttons as requested */
#cardViewBtn, #listViewBtn { display: none !important; }

.density-toggle {
    display: none !important;
}

.toggle-btn {
    padding: 10px 16px;
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
    min-height: 40px;
    min-width: 120px;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.toggle-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--primary);
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 0;
}

.toggle-btn:hover::before {
    opacity: 0.1;
}

.toggle-btn span, .toggle-btn svg {
    position: relative;
    z-index: 1;
}

.toggle-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    box-shadow: 0 6px 12px -6px rgba(37, 99, 235, 0.4);
}

.toggle-btn:hover:not(.active) {
    background: var(--primary-light);
    border-color: var(--primary);
    box-shadow: 0 4px 10px -6px rgba(37, 99, 235, 0.45);
}

/* Improve spacing and alignment for better touch targets */
@media (max-width: 768px) {
    .view-toggle {
        gap: 12px;
    }
    
    .view-toggle-buttons {
        gap: 8px;
        width: 100%;
    }
    
    .view-toggle-controls {
        gap: 8px;
        width: 100%;
        justify-content: flex-start;
    }
    
    .toggle-btn {
        padding: 8px 12px;
        min-height: 36px;
        min-width: 100px;
        font-size: 13px;
        flex: 1 1 auto;
    }
}

.shipment-status-filter .filter-select,
.list-status-filter .filter-select {
    min-width: 220px;
}

.shipment-status-filter,
.list-status-filter {
    display: flex;
    align-items: center;
}

/* Hide status filter explicitly */
#statusFilter,
#statusFilter ~ label,
label[for="statusFilter"] {
    display: none !important;
}

/* Density segmented control */
.density-toggle { display: inline-flex; align-items: center; gap: 8px; margin-left: 8px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg-btn { appearance: none; border: 0; background: transparent; padding: 6px 10px; font-size: 12px; font-weight: 600; color: var(--text-secondary); cursor: pointer; line-height: 1; }
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn.active { background: var(--primary); color: #fff; }

/* Card View */
.orders-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.order-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 24px;
    transition: all 0.3s ease;
    cursor: pointer;
    border: 2px solid transparent;
    position: relative;
}

.order-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-4px);
    border-color: var(--primary);
}

.order-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.order-number {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
}

.order-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.order-status {
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    display: inline-block;
    text-align: center;
    min-width: fit-content;
}

.order-status.delivered {
    background: var(--success-light);
    color: var(--success);
}

.order-status.in-transit {
    background: var(--primary-light);
    color: var(--primary);
}

.order-status.partial-transit {
    background: var(--warning-light);
    color: var(--warning);
}

.order-status.receiving {
    background: #f0fdfa;
    color: #0d9488;
}

.order-status.awaiting-shipment {
    background: var(--warning-light);
    color: var(--warning);
}

/* Legacy status support */
.order-status.complete {
    background: var(--success-light);
    color: var(--success);
}

.order-status.partial {
    background: var(--warning-light);
    color: var(--warning);
}

.order-status.pending {
    background: #f8fafc;
    color: #64748b;
}

.order-status.overdue {
    background: #fee2e2;
    color: var(--danger);
}

.order-details {
    margin-bottom: 16px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.detail-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.detail-value {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.progress-section {
    margin: 16px 0;
}

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.progress-text {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.progress-percentage {
    font-size: 12px;
    color: var(--text-secondary);
}

.progress-bar {
    width: 100%;
    height: var(--bar-thickness);
    background: #e7eef6;
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 12px;
    box-shadow: inset 0 1px 2px rgba(0,0,0,.04);
}

.progress-bar-fill {
    height: 100%;
    background: var(--brand-end); /* solid brand blue for consistency */
    border-radius: 999px;
    transition: width 0.3s ease;
}

.order-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.order-stat {
    text-align: center;
    padding: 8px;
    background: var(--background);
    border-radius: 6px;
}

.order-stat-value {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.order-stat-label {
    font-size: 11px;
    color: var(--text-secondary);
}

.order-financial {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.financial-item {
    text-align: center;
}

.financial-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.financial-label {
    font-size: 11px;
    color: var(--text-secondary);
}

.expand-btn {
    padding: 6px 12px;
    font-size: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
}

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

.expanded-details {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Highlight for search */
.highlight {
    background: var(--warning-light);
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 600;
    color: var(--warning);
}

/* List View */
.orders-list, .shipments-list, .main-list {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    /* Allow tooltips to overflow container bounds (prevents clipping at edges) */
    overflow: visible;
    width: 100%;
    display: none;
}

.orders-list.active, .shipments-list.active, .main-list.active {
    display: block;
}

/* Orders List Grid */
.orders-list .list-header {
    display: grid;
    grid-template-columns: 180px 240px 280px 160px 140px 140px;
    padding: 12px 16px;
    background: var(--background);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.orders-list .list-row {
    display: grid;
    grid-template-columns: 180px 240px 280px 160px 140px 140px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
    cursor: pointer;
    align-items: center;
    gap: 12px;
}

/* Density compaction for list views */
body.compact .orders-list .list-header,
body.compact .shipments-list .list-header,
body.compact .main-list .list-header { padding: 8px 12px; }
body.compact .orders-list .list-row,
body.compact .shipments-list .list-row,
body.compact .main-list .list-row { padding: 8px 12px; min-height: 44px; }
body.compact .toggle-btn, body.compact .filter-select, body.compact .search-input { height: 32px; }
body.cozy .toggle-btn, body.cozy .filter-select { height: 38px; }
body.cozy .search-input { height: 38px; }
body.comfortable .toggle-btn, body.comfortable .filter-select, body.comfortable .search-input { height: 52px; }
body.ultra .toggle-btn, body.ultra .filter-select, body.ultra .search-input { height: 30px; }

/* Slightly roomier compact mode for Main View only */
body.compact .main-list .list-header { padding: 10px 14px; }
body.compact .main-list .list-row { padding: 10px 14px; min-height: 50px; }

/* Shipments List Grid */
.shipments-list .list-header {
    display: grid;
    grid-template-columns: 100px 260px minmax(280px, 1fr) 70px 70px 140px 130px 120px;
    padding: 6px 14px;
    background: var(--background);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    gap: 10px;
}

.shipments-list .list-row {
    display: grid;
    grid-template-columns: 100px 260px minmax(280px, 1fr) 70px 70px 140px 130px 120px;
    padding: 6px 14px;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
    min-height: 40px;
    cursor: pointer;
    align-items: flex-start;
    gap: 10px;
}

.shipments-list .list-row:nth-child(even) {
    background: rgba(248, 250, 252, 0.5);
}

.shipments-list .list-row .list-cell {
    align-items: flex-start;
}

/* Main consolidated list */
.main-list .list-header {
    display: grid;
    /* Make ITEMS column flexible to fill remaining space */
    grid-template-columns: 120px 240px minmax(560px, 1fr) 110px 110px 110px 160px 140px;
    padding: 6px 14px;
    background: var(--background);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.main-list .list-row {
    display: grid;
    grid-template-columns: 120px 240px minmax(560px, 1fr) 110px 110px 110px 160px 140px;
    padding: 6px 14px;
    border-bottom: 1px solid var(--border);
    transition: background 0.2s;
    min-height: 40px;
    cursor: pointer;
    align-items: flex-start;
    gap: 12px;
}

.main-list .list-row:nth-child(even) {
    background: rgba(248, 250, 252, 0.5);
}

/* Generic badges (for future use; non-breaking) */
.badge { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1; border: 1px solid transparent; }
.badge.ok { color: var(--success); background: var(--success-light); }
.badge.info { color: var(--primary); background: var(--primary-light); }
.badge.warn { color: var(--warning); background: var(--warning-light); }
.badge.muted { color: var(--text-secondary); background: #f1f5f9; }

/* Two-line clamp utility for dense cells */
.two-line {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.25;
    max-height: calc(1.25em * 2);
}

/* Specific cell tweaks */
.pfi-cell .two-line,
.supplier-cell .two-line,
.items-cell .two-line { word-break: break-word; }

/* Items second-line badge spacing */
.items-cell .more-items-badge { margin-left: 8px; margin-top: 0; display: inline-flex; align-items: center; }

/* Keep +n more at the end (inline) */
.items-cell .items-inline { display: inline-flex; align-items: baseline; gap: 8px; max-width: 100%; }
.items-cell .items-inline .item-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* Doc chips (row) */
.doc-chips { display: flex; gap: 3px; flex-wrap: nowrap; align-items: center; }
.doc-chip { font-size: 10px; font-weight: 700; padding: 2px 5px; border-radius: 999px; border: 1px solid var(--border); }
.doc-chip.status-ok { background: var(--success-light); color: var(--success); border-color: transparent; }
.doc-chip.status-missing { background: #fee2e2; color: var(--danger); border-color: transparent; }
.doc-chip.status-unknown { background: #f1f5f9; color: var(--text-secondary); }

/* Next step cell */
.next-step { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.next-step .due-badge { font-size: 10px; padding: 2px 6px; border-radius: 999px; background: var(--warning-light); color: var(--warning); font-weight: 700; }

/* Shipments cell */
.shipments-cell { position: relative; display: inline-flex; align-items: center; gap: 8px; }
.shipments-cell[role='button'] { cursor: pointer; }
.shipments-badge { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--primary-light); color: var(--primary); }
.shipments-tooltip {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  font-size: 12px;
  color: var(--text-primary);
  width: clamp(260px, 30vw, 360px);
  max-width: 380px;
  z-index: 50;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
  overflow-wrap: anywhere;
}
.shipments-cell.show-tooltip .shipments-tooltip { display: flex; }
.ship-line {
  padding: 6px 0;
  border-bottom: 1px solid rgba(15,23,42,0.06);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ship-line:last-child { border-bottom: none; }
.ship-line-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  line-height: 1.3;
}
.ship-partial {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.ship-os {
  font-weight: 600;
  color: var(--text-primary);
  min-width: 0;
  flex: 1 1 160px;
}
.ship-tc-inline {
  font-weight: 600;
  font-size: 12px;
  color: var(--primary);
  background: rgba(37, 99, 235, 0.12);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.ship-tc-inline.delivered {
  background: rgba(34, 197, 94, 0.16);
  color: var(--success);
}
.ship-meta-inline {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0;
  color: var(--text-secondary);
}
.ship-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.ship-meta-item .k {
  font-weight: 700;
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.eta-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: rgba(148, 163, 184, 0.16);
  color: var(--text-secondary);
}
.eta-chip.eta-in-transit {
  background: rgba(37, 99, 235, 0.12);
  color: var(--primary);
}
.eta-chip.eta-delivered {
  background: rgba(34, 197, 94, 0.16);
  color: var(--success);
}
.eta-chip.eta-pending {
  background: rgba(250, 204, 21, 0.16);
  color: var(--warning);
}
.eta-chip.eta-overdue {
  background: rgba(248, 113, 113, 0.18);
  color: var(--danger);
}
.eta-chip.eta-upcoming {
  background: rgba(148, 163, 184, 0.14);
  color: var(--text-secondary);
}
.eta-chip.eta-soon {
  background: rgba(251, 191, 36, 0.2);
  color: var(--warning);
}
.ship-meta-item + .ship-meta-item::before {
  content: '•';
  color: rgba(148, 163, 184, 0.85);
  margin: 0 6px;
  font-weight: 600;
}
.ship-containers {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding-left: 34px;
  margin-top: 2px;
}
.ship-containers .container-tag-list {
  margin-top: 0;
}

.shipments-list .list-cell {
    font-size: 14px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.shipments-list .list-row .list-cell.bl-cell,
.shipments-list .list-row .list-cell.docs-cell,
.shipments-list .list-row .list-cell.eta-cell {
    white-space: normal;
}

.shipments-list .list-row .list-cell.bl-cell {
    word-break: break-word;
}

.shipments-list .list-row .list-cell.docs-cell {
    line-height: 1.35;
}

/* Removed PFI-specific hover styling to keep Supplier clean */

/* Shipment items cell: allow wrap and brand pill under */
.shipments-list .list-row .list-cell.items-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; white-space: normal; }
.main-list .list-row .list-cell.items-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; white-space: normal; }
.items-cell .item-main { display: flex; align-items: center; gap: 8px; width: 100%; flex-wrap: nowrap; }
.items-cell .item-main .item-text { flex: 0 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.items-cell .item-main .more-items-badge { margin-left: 8px; }
.items-cell .brand-row { margin-top: 2px; }
.brand-pill { display: inline-block; margin-top: 4px; padding: 2px 6px; border-radius: 999px; background: var(--primary-light); color: var(--primary); font-size: 11px; font-weight: 700; }
/* Neutral brand tag (inline, subtle) */
.brand-tag { display: inline-block; padding: 2px 6px; border-radius: 6px; font-size: 10px; font-weight: 600; color: var(--text-secondary); background: var(--background); border: 1px solid var(--border); margin-right: 6px; white-space: nowrap; }

/* ETA cell stacking date and status chip */
.eta-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; }
.eta-line { display: inline-flex; align-items: center; gap: 8px; }
.eta-cell .eta-date { font-weight: 400; }
.eta-dot { display: none; width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; box-shadow: 0 0 0 1px rgba(0,0,0,0.05) inset; }
.eta-dot.in-transit { background: var(--warning); }
.eta-dot.received { background: var(--success); }
.eta-date.eta-overdue { color: var(--danger); font-weight: 700; }
.eta-date.eta-soon { color: var(--warning); font-weight: 700; }
.eta-date.eta-upcoming { color: var(--text-primary); opacity: .95; }
.eta-date.eta-received { color: var(--success); }

/* Align ETA header and values neatly to the right edge */
.shipments-list .list-header > div:last-child { justify-self: start; text-align: left; padding-right: 0; }
.shipments-list .list-row .list-cell:last-child { justify-self: start; }
.shipments-list .list-row .eta-cell { align-items: flex-start; text-align: left; }

/* Orders List - PFI REF column styling */
.orders-list .list-row .list-cell:nth-child(1) {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

/* PFI Reference Text - Modern Inline Hover */
.pfi-ref-text {
    cursor: pointer;
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s ease;
    position: relative;
    font-weight: 500;
}

.pfi-ref-text:hover {
    background: var(--primary-light);
    color: var(--primary);
    text-decoration: underline;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.1);
}

.pfi-ref-text:hover::after {
    content: "📋";
    position: absolute;
    right: -18px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    opacity: 0.8;
}


/* More items badge styling */
.more-items-badge {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 10px;
    font-weight: 500;
    padding: 2px 6px;
    border-radius: 12px;
    margin-left: 6px;
    vertical-align: middle;
    white-space: nowrap;
}

/* Shipment status badges */
.shipment-status {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.shipment-status.in-transit {
    background: var(--warning-light);
    color: var(--warning);
}

.shipment-status.received {
    background: var(--success-light);
    color: var(--success);
}

/* Clickable PFI link in Shipment View */
.pfi-link { color: var(--primary); cursor: pointer; font-weight: 600; }
.pfi-link:hover { text-decoration: underline; }

.list-row:hover {
    background: var(--background);
}

.list-cell {
    font-size: 14px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
}

/* Main View TC Summary */
.tc-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.tc-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px;
    box-shadow: var(--shadow-sm);
    text-align: center;
}

.tc-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.tc-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
}

/* Compact TC cell (clean, professional) */
.tc-cell { display: block; position: relative; }
.tc-line { font-size: 13px; font-weight: 700; color: var(--text-primary); }
.tc-bar { height: var(--bar-thickness); width: var(--tc-bar-width); background: #e7eef6; border-radius: 999px; overflow: hidden; margin-top: 4px; position: relative; box-shadow: inset 0 1px 2px rgba(0,0,0,.04); }
.tc-bar-fill { height: 100%; background: var(--primary); /* match toggle button blue */ border-radius: 999px; transition: width .25s ease; }

/* Hover tooltip with breakdown */
.tc-tooltip { 
  display: none; position: absolute; top: calc(100% + 8px); left: 0; 
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; 
  padding: 8px 10px; box-shadow: var(--shadow); font-size: 12px; color: var(--text-primary);
  white-space: nowrap; z-index: 50; 
  min-width: 180px;
}
.tc-cell:hover .tc-tooltip { display: block; }

/* Fix for tooltip positioning to prevent clipping */
.tc-cell { 
  position: relative; 
  overflow: visible; 
}
.tc-tip-row { display: flex; gap: 8px; align-items: center; }
.tc-tip-row + .tc-tip-row { margin-top: 6px; }
.tc-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.tc-dot.rec { background: var(--success); }
.tc-dot.tran { background: var(--warning); }
.tc-dot.pend { background: #cbd5e1; }

/* Chips row under TC */
.tc-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 999px;
}
.chip.received { background: var(--success-light); color: var(--success); }

.container-tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.container-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
}

.container-tag.more {
    border-style: dashed;
    background: transparent;
    color: var(--text-secondary);
}
.chip.in-transit { background: var(--warning-light); color: var(--warning); }
.chip.notshipped { background: #f1f5f9; color: var(--text-secondary); }

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(3px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, backdrop-filter .2s ease;
    display: flex;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--surface);
    border-radius: 14px;
    width: 92%;
    max-width: 960px;
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: translateY(10px) scale(0.98);
    opacity: 0;
    transition: transform .2s ease, opacity .2s ease;
}

/* Compact modal sizing */
body.compact .modal-content { max-width: 860px; border-radius: 12px; }
body.cozy .modal-content    { max-width: 900px; }
body.ultra .modal-content   { max-width: 720px; border-radius: 10px; }

.modal.active .modal-content {
    transform: translateY(0) scale(1);
    opacity: 1;
}

.modal-header {
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 2;
}

body.compact .modal-header { padding: 14px 16px; }
body.ultra .modal-header   { padding: 10px 12px; }

.modal-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}
body.compact .modal-title { font-size: 18px; }
body.ultra .modal-title   { font-size: 16px; }

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    background: var(--background);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--text-secondary);
    transition: all 0.2s;
}
body.compact .modal-close { width: 28px; height: 28px; font-size: 18px; }
body.ultra .modal-close   { width: 24px; height: 24px; font-size: 16px; }

.modal-close:hover {
    background: var(--danger);
    color: white;
}

.modal-body { padding: 24px; }
body.compact .modal-body { padding: 16px 18px; }
body.ultra .modal-body   { padding: 12px 14px; }

/* Modal Tabs */
.modal-tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.modal-tab { padding: 8px 12px; border-radius: 8px 8px 0 0; cursor: pointer; font-weight: 600; color: var(--text-secondary); }
.modal-tab.active { background: var(--background); color: var(--text-primary); border: 1px solid var(--border); border-bottom-color: transparent; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Chips / Badges */
.chip-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; border: 1px solid var(--border); color: var(--text-primary); background: var(--background); }
.chip-pill.success { background: var(--success-light); color: var(--success); border-color: transparent; }
.chip-pill.info { background: var(--info-light); color: var(--info); border-color: transparent; }
.chip-pill.warning { background: var(--warning-light); color: var(--warning); border-color: transparent; }
.icon-btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; }
.icon-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

/* Stat cards */
.stat-cards { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 12px; margin: 12px 0 20px; }
.stat-card { background: var(--background); border: 1px solid var(--border); border-radius: 10px; padding: 12px; text-align: center; }
.stat-card .label { font-size: 12px; color: var(--text-secondary); font-weight: 700; text-transform: uppercase; letter-spacing: .4px; }
.stat-card .value { font-size: 18px; font-weight: 800; color: var(--text-primary); margin-top: 4px; }
body.compact .stat-cards { gap: 10px; }
body.compact .stat-card { padding: 10px; }
body.compact .stat-card .label { font-size: 11px; }
body.compact .stat-card .value { font-size: 16px; }
body.ultra .stat-cards { gap: 8px; }
body.ultra .stat-card { padding: 8px; border-radius: 8px; }
body.ultra .stat-card .label { font-size: 10px; }
body.ultra .stat-card .value { font-size: 15px; }

/* Info lists */
.info-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.info-row { display: flex; gap: 8px; align-items: baseline; }
.info-row .label { width: 140px; color: var(--text-secondary); font-size: 13px; font-weight: 600; }
.info-row .value { color: var(--text-primary); font-weight: 600; }

@media (max-width: 768px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .info-list { grid-template-columns: 1fr; }
}

/* --- Desktop-focused responsive tweaks (no mobile) --- */
/* Fallback media queries so layouts adapt even if JS density classes don't. */

/* Small desktop/laptop (1024–1199px) */
@media (min-width: 1024px) and (max-width: 1199px) {
  .orders-list .list-header,
  .orders-list .list-row { grid-template-columns: 160px 200px 240px 130px 120px 120px; gap: 10px; }

  .shipments-list .list-header,
  .shipments-list .list-row { grid-template-columns: 90px 186px minmax(220px, 1fr) 56px 56px 150px 150px 130px; gap: 8px; }

  .main-list .list-header,
  .main-list .list-row { grid-template-columns: 110px 200px minmax(320px, 1fr) 95px 110px 90px 150px 120px; gap: 10px; }
}

/* Narrow desktop (1200–1365px) */
@media (min-width: 1200px) and (max-width: 1365px) {
  .orders-list .list-header,
  .orders-list .list-row { grid-template-columns: 170px 220px 260px 140px 130px 130px; gap: 10px; }

  .shipments-list .list-header,
  .shipments-list .list-row { grid-template-columns: 100px 210px minmax(240px, 1fr) 60px 60px 160px 160px 140px; gap: 8px; }

  .main-list .list-header,
  .main-list .list-row { grid-template-columns: 120px 220px minmax(360px, 1fr) 105px 115px 100px 160px 130px; gap: 10px; }
}

/* Large desktop/ultra-wide (≥1920px) */
@media (min-width: 1920px) {
  .container { max-width: 1880px; }
  .main-list .list-header,
  .main-list .list-row { grid-template-columns: 150px 280px minmax(520px, 1fr) 140px 150px 130px 200px 150px; gap: 14px; }
}

/* Lock background scroll when modal open */
body.modal-open {
    overflow: hidden;
}

.detail-section { margin-bottom: 28px; }
body.compact .detail-section { margin-bottom: 20px; }
body.ultra .detail-section   { margin-bottom: 16px; }

.section-title { font-size: 16px; font-weight: 600; color: var(--text-primary); margin-bottom: 16px; padding-bottom: 8px; border-bottom: 2px solid var(--primary); display: flex; align-items: center; gap: 8px; }
body.compact .section-title { font-size: 14px; margin-bottom: 12px; padding-bottom: 6px; }
body.ultra .section-title   { font-size: 13px; margin-bottom: 10px; padding-bottom: 5px; border-bottom-width: 1px; }

.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; }
body.compact .info-grid { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
body.ultra .info-grid   { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.info-grid.info-grid-wide { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.info-grid.info-grid-wide {
    background: none;
    border-radius: 0;
    border: none;
    padding: 0;
    gap: 16px 24px;
}

.info-grid.info-grid-wide .info-item { padding-left: 0; }
.info-grid.info-grid-wide .info-item::before { content: none; }
.info-grid.info-grid-wide .info-value { font-size: 15px; }

.info-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.info-label { font-size: 12px; color: var(--text-secondary); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
body.compact .info-label { font-size: 11px; }
body.ultra .info-label   { font-size: 10.5px; }

.info-value { font-size: 14px; font-weight: 500; color: var(--text-primary); }
body.compact .info-value { font-size: 13px; }
body.ultra .info-value   { font-size: 12.5px; }

.essentials-grid { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.essentials-heading { font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 12px; }
.essentials-info { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.pill-tag { display: inline-flex; align-items: center; padding: 0 8px; height: 22px; border-radius: 999px; background: var(--primary-light); color: var(--primary); font-size: 12px; font-weight: 600; margin-right: 6px; margin-bottom: 4px; }
.essentials-tags { display: flex; flex-wrap: wrap; }

.detail-stack {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

body.compact .detail-stack { gap: 18px; }
body.ultra .detail-stack   { gap: 14px; }

.overview-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

body.compact .overview-card { padding: 18px; border-radius: 12px; }
body.ultra .overview-card   { padding: 14px; border-radius: 10px; }

.overview-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 18px;
}

.overview-title {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 4px;
}

body.compact .overview-title { font-size: 20px; }
body.ultra .overview-title   { font-size: 18px; }

.overview-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    color: var(--text-secondary);
    font-size: 13px;
}

.overview-meta span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.overview-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.pill-action {
    border: 1px solid var(--border);
    background: #f8fafc;
    color: var(--text-secondary);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pill-action:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.stage-tracker {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.stage-node {
    display: flex;
    align-items: center;
    gap: 12px;
}

.stage-marker {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--surface);
}

.stage-node.state-done .stage-marker {
    background: var(--success-light);
    border-color: transparent;
    color: var(--success);
}

.stage-node.state-current .stage-marker {
    background: var(--primary-light);
    border-color: transparent;
    color: var(--primary);
}

.stage-node.state-next .stage-marker {
    opacity: 0.8;
}

.stage-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stage-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.stage-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.stage-connector {
    flex: 1;
    height: 2px;
    background: rgba(148, 163, 184, 0.4);
}

.stage-node.state-done + .stage-connector {
    background: linear-gradient(90deg, var(--success) 0%, var(--success-light) 100%);
}

.stage-node.state-current + .stage-connector {
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary-light) 100%);
}

.stage-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    border-radius: 999px;
    padding: 6px 12px;
    background: var(--background);
    color: var(--text-secondary);
}

.stage-chip.stage-ordered   { background: #f1f5f9; color: var(--text-secondary); }
.stage-chip.stage-shipped   { background: var(--info-light); color: var(--info); }
.stage-chip.stage-validation { background: #fef3c7; color: var(--warning); }
.stage-chip.stage-livraison { background: var(--success-light); color: var(--success); }

.overview-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

.metric-card {
    padding: 12px 14px;
    border: 1px solid rgba(148, 163, 184, 0.25);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.metric-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.metric-value {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
}

.metric-meta {
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}

.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 12px;
}

.section-subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.table-scroll {
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.detail-table {
    width: 100%;
    border-collapse: collapse;
}

.detail-table th,
.detail-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 13px;
    vertical-align: top;
}

.detail-table th {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    color: var(--text-secondary);
    background: #f8fafc;
}

.detail-table tbody tr:last-child td {
    border-bottom: none;
}

.table-strong {
    font-weight: 600;
    color: var(--text-primary);
}

.muted {
    color: var(--text-secondary);
    font-size: 12px;
    margin-top: 2px;
}

.doc-stack {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.doc-stack-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-secondary);
}

.container-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
    padding: 0;
    background: transparent;
    border-radius: 0;
}

.container-pill {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 999px;
    background: #f1f5f9;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
}

.empty-state {
    padding: 16px;
    border: 1px dashed var(--border);
    border-radius: 12px;
    background: #f8fafc;
    color: var(--text-secondary);
    font-size: 13px;
}

@media (max-width: 768px) {
    .stage-tracker {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .stage-connector {
        display: none;
    }

    .overview-metrics {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
}

.items-table th, .items-table td { padding: 12px; text-align: left; border-bottom: 1px solid var(--border); }
body.compact .items-table th, body.compact .items-table td { padding: 10px; }
body.ultra .items-table th, body.ultra .items-table td { padding: 8px; }

.items-table th {
    background: var(--background);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.items-table td {
    font-size: 14px;
    color: var(--text-primary);
}

.item-status {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.item-status.complete {
    background: var(--success-light);
    color: var(--success);
}

.item-status.partial {
    background: var(--warning-light);
    color: var(--warning);
}

.item-status.pending {
    background: var(--primary-light);
    color: var(--primary);
}

/* Empty State */
.orders-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.orders-empty svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.orders-empty h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.orders-empty p {
    font-size: 14px;
}

/* Toast Notifications */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--success);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 10000;
    opacity: 0;
    transform: translateX(100px);
    transition: all 0.3s ease;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast::before {
    content: "✓";
    margin-right: 8px;
    font-weight: bold;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .header {
        padding: 16px;
    }

    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .search-box {
        max-width: 100%;
    }
    
    .container {
        padding: 16px;
    }
    
    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .orders-grid {
        grid-template-columns: 1fr;
    }
    
    .list-header,
    .list-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .list-cell::before {
        content: attr(data-label);
        font-weight: 600;
        display: inline-block;
        width: 120px;
        color: var(--text-secondary);
        margin-right: 8px;
    }
    
    .list-header {
        display: none;
    }
    
    .view-toggle {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .page-title {
        font-size: 20px;
    }
    
    .stats-bar {
        grid-template-columns: 1fr;
    }
    
    .order-stats,
    .order-financial {
        grid-template-columns: repeat(2, 1fr);
    }
}
/* Allow supplier to wrap to two lines with ellipsis */
.shipments-list .list-row .list-cell.supplier-cell {
    white-space: normal;
}
.shipments-list .list-row .list-cell.supplier-cell .two-line {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
