/* ─────────────────────────────────────────────────────────────────────────────
   Price Comparison Laboratory — price-lab.css
   Scoped to: #priceLabView, .price-lab-*, .plab-*
   Design language: matches existing ERP dark-panel + card aesthetics
───────────────────────────────────────────────────────────────────────────── */

/* ── View Layout ─────────────────────────────────────────────────────────── */
#priceLabView {
    animation: fadeInUp 0.22s ease;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

.price-lab-subtitle {
    font-size: 13px;
    color: #6366f1;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.price-lab-body {
    padding: 0 0 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ── Selector Card ───────────────────────────────────────────────────────── */
.price-lab-selector-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 20px 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

.price-lab-selector-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 14px;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.price-lab-selector-header svg {
    color: #6366f1;
    flex-shrink: 0;
}

/* ── Search Input ────────────────────────────────────────────────────────── */
.price-lab-search-wrapper {
    position: relative;
    margin-bottom: 12px;
}

.price-lab-search-input {
    width: 100%;
    padding: 10px 16px 10px 42px;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    font-size: 14px;
    color: #1e293b;
    background: #f8fafc url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") no-repeat 14px center;
    transition: border-color .18s, box-shadow .18s;
    box-sizing: border-box;
}

.price-lab-search-input:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,.12);
    background-color: #fff;
}

/* ── Search Dropdown ─────────────────────────────────────────────────────── */
.price-lab-search-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0; right: 0;
    background: #fff;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,.1);
    max-height: 280px;
    overflow-y: auto;
    z-index: 200;
    animation: dropDown .15s ease;
}

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

.plab-drop-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    transition: background .12s;
}

.plab-drop-item:last-child { border-bottom: none; }

.plab-drop-item:hover {
    background: #f5f3ff;
}

.plab-drop-item--selected {
    background: #ede9fe;
    pointer-events: none;
    opacity: 0.7;
}

.plab-drop-icon {
    width: 30px; height: 30px;
    background: #f1f5f9;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    color: #6366f1;
}

.plab-drop-meta {
    flex: 1;
    min-width: 0;
}

.plab-drop-name {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.plab-drop-desc {
    display: block;
    font-size: 11px;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.plab-drop-check {
    color: #6366f1;
    font-size: 14px;
    font-weight: 700;
}

.plab-drop-empty {
    padding: 16px;
    text-align: center;
    color: #94a3b8;
    font-size: 13px;
}

/* ── Selected Product Chips ──────────────────────────────────────────────── */
.price-lab-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 0;
    margin-bottom: 4px;
}

.plab-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #ede9fe;
    color: #4f46e5;
    border: 1px solid #c4b5fd;
    border-radius: 20px;
    padding: 4px 10px 4px 12px;
    font-size: 12px;
    font-weight: 600;
    animation: chipIn .15s ease;
}

@keyframes chipIn {
    from { opacity: 0; transform: scale(.85); }
    to   { opacity: 1; transform: scale(1); }
}

.plab-chip-name {
    white-space: nowrap;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.plab-chip-remove {
    background: none;
    border: none;
    color: #7c3aed;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
    border-radius: 50%;
    transition: background .12s;
}

.plab-chip-remove:hover {
    background: rgba(124,58,237,.15);
}

/* ── Selector Footer ─────────────────────────────────────────────────────── */
.price-lab-selector-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid #f1f5f9;
}

.price-lab-count-label {
    font-size: 12px;
    color: #94a3b8;
    font-weight: 500;
}

/* ── Results Summary Bar ─────────────────────────────────────────────────── */
.plab-results-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 4px;
}

.plab-results-tag {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #f1f5f9;
    color: #475569;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.plab-results-tag--note {
    background: #fef3c7;
    color: #92400e;
}

/* ── Results Grid ────────────────────────────────────────────────────────── */
.plab-results-grid {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* ── Product Card ────────────────────────────────────────────────────────── */
.plab-product-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,.04);
    transition: box-shadow .2s;
}

.plab-product-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,.08);
}

.plab-product-card-header {
    padding: 18px 20px 14px;
    background: linear-gradient(135deg, #f8f9fe 0%, #f5f3ff 100%);
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.plab-product-title-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.plab-product-icon {
    width: 36px; height: 36px;
    background: rgba(99,102,241,.12);
    color: #6366f1;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.plab-product-name {
    margin: 0 0 5px;
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
}

.plab-product-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.plab-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.plab-tag--cat {
    background: #e0e7ff;
    color: #3730a3;
}

.plab-tag--unit {
    background: #f0fdf4;
    color: #166534;
}

.plab-product-desc {
    padding: 10px 20px;
    font-size: 12px;
    color: #64748b;
    border-bottom: 1px solid #f1f5f9;
    font-style: italic;
}

/* ── Summary Stats Row ───────────────────────────────────────────────────── */
.plab-product-summary {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
}

.plab-summary-item {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 64px;
}

.plab-summary-label {
    font-size: 10px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
}

.plab-summary-value {
    font-size: 14px;
    font-weight: 700;
    color: #1e293b;
}

.plab-best-price {
    color: #059669;
    font-size: 18px;
}

/* ── Vendor List Header ──────────────────────────────────────────────────── */
.plab-vendor-list-header {
    display: grid;
    grid-template-columns: 1.8fr 1.2fr 1.2fr 1fr auto;
    gap: 8px;
    padding: 8px 20px;
    background: #f8fafc;
    border-bottom: 1px solid #e5e7eb;
    font-size: 11px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: .04em;
}

/* ── Vendor Rows ─────────────────────────────────────────────────────────── */
.plab-vendor-list {
    divide: y 1 solid #f1f5f9;
}

.plab-vendor-row {
    border-top: 1px solid #f1f5f9;
    transition: background .12s;
}

.plab-vendor-row:first-child {
    border-top: none;
}

.plab-vendor-row:hover {
    background: #fafafa;
}

.plab-vendor-row--best {
    background: linear-gradient(90deg, #f0fdf4 0%, #fff 100%);
}

.plab-vendor-row--best:hover {
    background: linear-gradient(90deg, #dcfce7 0%, #f8fffe 100%);
}

.plab-vendor-row-main {
    display: grid;
    grid-template-columns: 1.8fr 1.2fr 1.2fr 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 12px 20px;
}

/* Vendor Name Cell */
.plab-vendor-name-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.plab-best-tag {
    display: inline-block;
    background: #dcfce7;
    color: #15803d;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    white-space: nowrap;
    flex-shrink: 0;
}

.plab-vendor-name {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Price Cell */
.plab-price-cell {
    display: flex;
    align-items: baseline;
    gap: 4px;
    flex-wrap: wrap;
}

.plab-price {
    font-size: 14px;
    font-weight: 700;
    color: #1e293b;
}

.plab-price--best {
    color: #059669;
    font-size: 16px;
}

.plab-price-unit {
    font-size: 11px;
    color: #94a3b8;
}

.plab-variance {
    font-size: 10px;
    font-weight: 700;
    color: #ef4444;
    background: #fef2f2;
    padding: 1px 5px;
    border-radius: 6px;
    white-space: nowrap;
}

/* Reference Cell */
.plab-ref-cell {
    min-width: 0;
}

.plab-ref-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.plab-ref-no {
    font-size: 12px;
    color: #475569;
    font-family: monospace;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}

/* Source Badges */
.plab-source-badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .04em;
    white-space: nowrap;
    flex-shrink: 0;
}

.plab-source-badge--rfq {
    background: #e0e7ff;
    color: #3730a3;
    border: 1px solid #c7d2fe;
}

.plab-source-badge--po {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

/* Date Cell */
.plab-date-cell {
    display: flex;
    flex-direction: column;
    line-height: 1;
}

.plab-date {
    font-size: 12px;
    color: #475569;
}

.plab-age {
    font-size: 10px;
    color: #94a3b8;
    margin-top: 2px;
}

/* Actions Cell */
.plab-actions-cell {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.plab-history-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: #6366f1;
    border-color: #c7d2fe !important;
    background: #f5f3ff !important;
    white-space: nowrap;
}

.plab-history-toggle:hover {
    background: #ede9fe !important;
}

.plab-single-entry {
    font-size: 11px;
    color: #94a3b8;
}

/* ── Price History Panel ─────────────────────────────────────────────────── */
.plab-history-panel {
    background: #f8fafc;
    border-top: 1px dashed #e2e8f0;
    padding: 12px 20px 14px;
    animation: expandDown .18s ease;
}

@keyframes expandDown {
    from { opacity: 0; transform: scaleY(0.9); transform-origin: top; }
    to   { opacity: 1; transform: scaleY(1); }
}

.plab-history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.plab-history-table thead th {
    padding: 5px 10px;
    text-align: left;
    color: #94a3b8;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 700;
    border-bottom: 1px solid #e5e7eb;
}

.plab-history-row td {
    padding: 7px 10px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
    color: #475569;
}

.plab-history-row:last-child td {
    border-bottom: none;
}

.plab-history-row--latest {
    background: #f0fdf4;
}

.plab-history-price {
    font-weight: 700;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: 5px;
}

.plab-latest-dot {
    color: #22c55e;
    font-size: 9px;
}

.plab-history-ref {
    font-family: monospace;
    font-size: 11px;
    max-width: 120px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.plab-history-date {
    white-space: nowrap;
}

/* ── Empty / Error States ────────────────────────────────────────────────── */
.plab-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 24px;
    text-align: center;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    color: #94a3b8;
}

.plab-empty-state h3 {
    margin: 16px 0 8px;
    font-size: 18px;
    color: #1e293b;
    font-weight: 700;
}

.plab-empty-state p {
    font-size: 14px;
    max-width: 360px;
    margin: 0;
    line-height: 1.6;
}

.plab-empty-state small {
    display: block;
    margin-top: 8px;
    font-size: 12px;
    color: #cbd5e1;
}

.plab-error-state svg {
    color: #f87171;
}

.plab-error-state h3 {
    color: #ef4444;
}

.plab-no-vendors {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 28px 16px;
    text-align: center;
    color: #94a3b8;
}

.plab-no-vendors svg {
    color: #cbd5e1;
    margin-bottom: 10px;
}

.plab-no-vendors p {
    font-size: 13px;
    margin: 0 0 4px;
}

.plab-no-vendors small {
    font-size: 11px;
    color: #cbd5e1;
}

/* ── Skeleton Loading ────────────────────────────────────────────────────── */
.plab-skeleton {
    pointer-events: none;
}

.plab-skel-line {
    background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    border-radius: 6px;
    animation: shimmer 1.4s infinite;
}

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

.plab-skel-title  { height: 18px; width: 55%; margin-bottom: 8px; }
.plab-skel-sub    { height: 12px; width: 30%; }
.plab-skel-row    { padding: 12px 20px; display: flex; gap: 16px; align-items: center; }
.plab-skel-vendor { height: 12px; flex: 1.5; }
.plab-skel-price  { height: 12px; flex: 0.8; }

/* ── Button Spinner ──────────────────────────────────────────────────────── */
.plab-btn-spinner {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

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

/* ── Responsiveness ──────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .plab-vendor-row-main,
    .plab-vendor-list-header {
        grid-template-columns: 1fr 1fr;
        row-gap: 4px;
    }

    .plab-product-card-header {
        flex-direction: column;
    }

    .plab-product-summary {
        justify-content: flex-start;
    }

    .plab-ref-cell,
    .plab-date-cell,
    .plab-actions-cell {
        display: none;
    }

    .plab-vendor-list-header span:nth-child(3),
    .plab-vendor-list-header span:nth-child(4),
    .plab-vendor-list-header span:nth-child(5) {
        display: none;
    }
}

/* ── View Toggle Buttons ─────────────────────────────────────────────────── */
.plab-view-toggle {
    display: flex;
    background: #f1f5f9;
    border-radius: 8px;
    padding: 3px;
    gap: 2px;
}

.plab-toggle-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: #64748b;
    font-size: 12px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: all .2s;
}

.plab-toggle-btn:hover {
    color: #1e293b;
}

.plab-toggle-btn.active {
    background: #fff;
    color: #6366f1;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
}

.plab-summary-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.plab-results-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

/* ── Matrix Table View ───────────────────────────────────────────────────── */
.plab-matrix-wrapper {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    overflow-x: auto;
    box-shadow: 0 1px 4px rgba(0,0,0,.04);
}

.plab-matrix-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 600px;
}

.plab-matrix-table th,
.plab-matrix-table td {
    padding: 14px 20px;
    vertical-align: middle;
    border-bottom: 1px solid #e5e7eb;
    border-right: 1px solid #f1f5f9;
}

.plab-matrix-table th:last-child,
.plab-matrix-table td:last-child {
    border-right: none;
}

.plab-matrix-table thead th {
    background: #f8fafc;
    font-size: 11px;
    text-transform: uppercase;
    font-weight: 700;
    color: #64748b;
    letter-spacing: .04em;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 10;
}

.plab-matrix-table thead th.plab-sticky-col {
    text-align: left;
    left: 0;
    z-index: 20;
}

.plab-sticky-col {
    position: sticky;
    left: 0;
    background: #fff;
    z-index: 10;
    width: 250px;
    min-width: 200px;
    box-shadow: 2px 0 5px rgba(0,0,0,.03);
}

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

.plab-matrix-table tbody tr:hover td {
    background: #fafafa;
}

.plab-matrix-table tbody tr:hover td.plab-sticky-col {
    background: #fff;
}

.plab-matrix-prod strong {
    display: block;
    font-size: 14px;
    color: #1e293b;
    margin-bottom: 4px;
}

.plab-m-unit {
    font-size: 12px;
    color: #64748b;
}

.plab-matrix-best-cell {
    background: #f0fdf4 !important;
    text-align: center;
    position: relative;
    border-bottom-color: #dcfce7 !important;
}

.plab-matrix-norm-cell {
    text-align: center;
}

.plab-matrix-empty-cell {
    text-align: center;
    color: #cbd5e1;
    font-style: italic;
    background: #f8fafc !important;
}

.plab-matrix-price {
    font-size: 16px;
    font-weight: 700;
    color: #1e293b;
}

.plab-matrix-best-cell .plab-matrix-price {
    color: #059669;
}

.plab-matrix-best-badge {
    display: inline-block;
    background: #dcfce7;
    color: #15803d;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    margin-bottom: 6px;
}

.plab-export-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: #0f172a;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .02em;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(15,23,42,.15);
    transition: background .2s, transform .1s;
}

.plab-export-btn:hover {
    background: #1e293b;
}

.plab-export-btn:active {
    transform: scale(0.97);
}

.plab-exclude-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 2px;
    border-radius: 50%;
    transition: color .2s, background .2s;
}

.plab-exclude-btn:hover {
    color: #ef4444;
    background: #fee2e2;
}

/* ── Print / PDF Download Styles ─────────────────────────────────────────── */
@media print {
    /* Hide the global layout elements */
    body.plab-printing .sidebar,
    body.plab-printing .top-bar,
    body.plab-printing .price-lab-selector-card,
    body.plab-printing .plab-view-toggle,
    body.plab-printing .plab-export-btn,
    body.plab-printing .plab-chip-remove {
        display: none !important;
    }
    
    /* Reset main content boundaries to prevent clipping */
    body.plab-printing .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
        background: #fff;
    }
    
    /* Reset matrix wrapper so tables aren't constrained or scrollable */
    body.plab-printing .plab-matrix-wrapper {
        border: none;
        box-shadow: none;
        overflow: visible !important;
        margin-top: 10px;
    }

    body.plab-printing .plab-matrix-table {
        min-width: 0;
        width: 100%;
    }

    body.plab-printing .plab-matrix-table th,
    body.plab-printing .plab-matrix-table td {
        border-color: #000;
        padding: 8px 10px;
        color: #000 !important;
    }

    /* Keep the sticky column static for printing */
    body.plab-printing .plab-sticky-col {
        position: static !important;
        box-shadow: none;
        width: auto;
        min-width: 0;
    }

    /* Retain essential colors for the badge and best cell */
    body.plab-printing .plab-matrix-best-cell {
        background-color: #f0fdf4 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    body.plab-printing .plab-matrix-best-badge {
         background-color: #dcfce7 !important;
         -webkit-print-color-adjust: exact;
         print-color-adjust: exact;
    }
    
    body.plab-printing .plab-matrix-best-cell .plab-matrix-price {
        color: #059669 !important;
    }
}
