/* ============================================================
   RRV3 INVENTORY MODULE — Stylesheet
   VERSION: 2.1 (extracted from rrv3-styles.css section 3)
   DATE: 23-06-2026

   Contains: stock badges, catalog picker, cart rows, manager UI,
             loanable/custom item badges, batch upload, clashes, export

   Loaded AFTER rrv3-styles-core.css so it can use shared CSS
   custom properties (--rr-navy, --rr-blue, --rr-radius-*, etc.)
   and shared utility classes.
   ============================================================ */

/* ============================================================
   INVENTORY: badges, picker, cart rows, manager
   ============================================================ */

.stock-badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 9999px;
    font-size: 10.5px;
    font-weight: 700;
    white-space: nowrap;
}
.stock-badge.stock-in  { background-color: #dcfce7; color: #15803d; }
.stock-badge.stock-low { background-color: #fef9c3; color: #a16207; }
.stock-badge.stock-out { background-color: #fee2e2; color: #b91c1c; }

.loanable-badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 9999px;
    font-size: 10.5px;
    font-weight: 700;
    background-color: var(--rr-blue-soft);
    color: var(--rr-navy);
}

.custom-item-badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 9999px;
    font-size: 10.5px;
    font-weight: 700;
    background-color: #fff7ed;
    color: #c2410c;
    border: 1px dashed #fdba74;
}

/* --- Picker modal --- */
.rrv3-picker-content {
    max-width: 98% !important;
    width: 98% !important;
    height: 94vh !important;
    margin: 3vh auto !important;
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    padding: 24px 26px !important;
}
.rrv3-picker-content h2 {
    margin-top: 0 !important;
    margin-bottom: 15px !important;
}
.rrv3-picker-toolbar input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--rr-border);
    border-radius: var(--rr-radius);
    font-size: 13.5px;
    background-color: var(--rr-white);
    color: var(--rr-text);
    box-sizing: border-box;
    transition: border-color 0.18s, box-shadow 0.18s;
}
.rrv3-picker-toolbar input:focus {
    border-color: var(--rr-blue);
    box-shadow: 0 0 0 3px rgba(0, 136, 255, 0.15);
    outline: none;
}
.rrv3-picker-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 12px 0;
}
.picker-cat-chip {
    padding: 4px 12px;
    border-radius: 9999px;
    border: 1px solid var(--rr-border);
    background: var(--rr-white);
    cursor: pointer;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--rr-text);
    transition: all 0.15s;
}
.picker-cat-chip:hover { border-color: var(--rr-blue); color: var(--rr-blue); }
.picker-cat-chip.active {
    background-color: var(--rr-blue);
    border-color: var(--rr-blue);
    color: var(--rr-white);
}
.rrv3-picker-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)) !important;
    gap: 14px !important;
    flex: 1 !important;
    max-height: 68vh !important;
    overflow-y: auto !important;
    padding: 4px !important;
}
.picker-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--rr-text-muted);
    padding: 18px;
    font-size: 12.5px;
}
/* Specificity & Override Protection for Catalog Picker Cards */
.rrv3-picker-content .rrv3-picker-grid .picker-card {
    border: 1px solid var(--rr-border) !important;
    border-radius: var(--rr-radius-lg) !important;
    overflow: hidden !important;
    background: var(--rr-white) !important;
    display: flex !important;
    flex-direction: column !important;
    min-height: 240px !important;
    transition: box-shadow 0.18s, transform 0.18s, border-color 0.18s !important;
    box-sizing: border-box !important;
}

.rrv3-picker-content .rrv3-picker-grid .picker-card:hover {
    box-shadow: 0 8px 20px -8px rgba(0, 136, 255, 0.25) !important;
    border-color: var(--rr-blue) !important;
    transform: translateY(-2px) !important;
}

.rrv3-picker-content .rrv3-picker-grid .picker-card-img {
    height: 105px !important;
    background: var(--rr-bg) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: hidden !important;
    width: 100% !important;
    box-sizing: border-box !important;
    border-bottom: 1px solid var(--rr-border) !important;
}

.rrv3-picker-content .rrv3-picker-grid .picker-card-img img {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important; /* full image centered, no cropping */
    display: block !important;
}

.rrv3-picker-content .rrv3-picker-grid .picker-card-noimg {
    font-size: 34px !important;
    opacity: 0.35 !important;
    display: block !important;
}

.rrv3-picker-content .rrv3-picker-grid .picker-card-body {
    padding: 10px 12px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 5px !important;
    flex-grow: 1 !important;
    box-sizing: border-box !important;
}

.rrv3-picker-content .rrv3-picker-grid .picker-card-name {
    font-weight: 700 !important;
    font-size: 13px !important;
    color: var(--rr-text) !important;
    line-height: 1.3 !important;
    margin-bottom: 2px !important;
    display: block !important;
}

.rrv3-picker-content .rrv3-picker-grid .picker-card-meta {
    font-size: 11px !important;
    color: var(--rr-text-muted) !important;
    display: block !important;
}

.rrv3-picker-content .rrv3-picker-grid .picker-card-actions {
    display: flex !important;
    gap: 8px !important;
    margin-top: auto !important;
    padding-top: 8px !important;
    align-items: center !important;
    width: 100% !important;
    box-sizing: border-box !important;
}

.rrv3-picker-content .rrv3-picker-grid .picker-card-actions .picker-qty {
    width: 65px !important;
    padding: 6px 8px !important;
    border: 1px solid var(--rr-border) !important;
    border-radius: 6px !important;
    font-size: 12.5px !important;
    box-sizing: border-box !important;
    background-color: var(--rr-white) !important;
    color: var(--rr-text) !important;
    display: block !important;
}

.rrv3-picker-content .rrv3-picker-grid .picker-card-actions .picker-add-btn {
    flex-grow: 1 !important;
    padding: 6px 12px !important;
    font-size: 12.5px !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    box-sizing: border-box !important;
}

.rrv3-picker-content .rrv3-picker-grid .stock-badge {
    padding: 3px 10px !important;
    border-radius: 9999px !important;
    font-size: 10.5px !important;
    font-weight: 700 !important;
    color: var(--rr-text) !important;
    display: inline-block !important;
    margin-top: 2px !important;
}

/* --- Cart rows (New Requisition) --- */
.rrv3-cart-row {
    display: flex;
    align-items: center;
    gap: 14px;
    border: 1px solid var(--rr-border);
    border-left: 3px solid var(--rr-blue);
    border-radius: 9px;
    padding: 9px 14px;
    margin-bottom: 9px;
    background: var(--rr-white);
    transition: box-shadow 0.15s;
}
.rrv3-cart-row:hover { box-shadow: var(--rr-shadow-md); }
.cart-row-img img, .cart-row-noimg {
    width: 46px; height: 46px;
    border-radius: var(--rr-radius);
    object-fit: contain; /* full image centered, no cropping */
    background: var(--rr-bg);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
}
.cart-row-info { display: flex; flex-direction: column; gap: 2px; flex-grow: 1; font-size: 12.5px; color: var(--rr-text); }
.cart-row-info .rrv3-item-no { font-size: 10px; color: var(--rr-text-muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
.cart-row-info strong { color: var(--rr-text); }
.cart-row-controls { display: flex; align-items: center; gap: 12px; }
.cart-row-controls label { font-size: 11.5px; color: var(--rr-text-muted); font-weight: 600; }
.cart-row-controls input[type="number"] {
    width: 80px; padding: 6px 8px; border: 1px solid var(--rr-border); border-radius: 6px; margin-left: 4px; font-size: 12.5px; background-color: var(--rr-white); color: var(--rr-text);
}
.cart-row-controls select { padding: 6px 8px; border: 1px solid var(--rr-border); border-radius: 6px; margin-left: 4px; font-size: 12.5px; background-color: var(--rr-white); color: var(--rr-text); }

/* --- Custom item rows --- */
.rrv3-custom-row {
    border: 1px dashed #fdba74;
    border-radius: 9px;
    padding: 12px 14px;
    margin-bottom: 9px;
    background: #fffbf7;
}
.rrv3-custom-row-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.rrv3-custom-row-header .rrv3-item-no { font-size: 10px; color: var(--rr-text-muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }
.rrv3-custom-row-header .remove-item { margin-left: auto; }

/* --- CATALOG FIELD CHOOSER (column visibility dropdown) --- */
/* Scoped to #catalog-table_wrapper so other DataTables are unaffected. */
#catalog-table_wrapper .dataTables_filter {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative; /* anchor for the absolute dropdown panel */
}
.rrv3-field-chooser-btn {
    flex-shrink: 0;
    white-space: nowrap;
}
.rrv3-field-chooser-panel {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 6px;
    background: var(--rr-white);
    border: 1px solid var(--rr-border);
    border-radius: var(--rr-radius);
    box-shadow: var(--rr-shadow-lg);
    padding: 8px;
    z-index: 1000;
    min-width: 190px;
    max-height: 320px;
    overflow-y: auto;
}
.rrv3-field-chooser-panel.is-open { display: block; }
.rrv3-field-chooser-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12.5px;
    color: var(--rr-text);
    transition: background-color 0.12s;
}
.rrv3-field-chooser-row:hover { background-color: var(--rr-bg); }
.rrv3-field-chooser-row input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
    accent-color: var(--rr-blue);
    width: 15px;
    height: 15px;
}
.rrv3-field-chooser-row span { font-weight: 500; }
.rrv3-field-chooser-reset {
    margin-top: 4px;
    padding-top: 8px;
    border-top: 1px solid var(--rr-border);
    text-align: center;
}
.rrv3-field-chooser-reset-link,
.rrv3-column-width-reset-link {
    color: var(--rr-blue);
    text-decoration: none;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.8;
}
.rrv3-field-chooser-reset-link:hover,
.rrv3-column-width-reset-link:hover { text-decoration: underline; }

/* --- DATABASE MANAGEMENT (danger zone) --- */
.rrv3-danger-zone {
    border: 2px solid #fecaca;
    border-radius: var(--rr-radius-lg);
    background: #fffafa;
    padding: 16px 18px;
    margin-top: 8px;
}
.rrv3-danger-zone-head {
    padding-bottom: 10px;
    margin-bottom: 10px;
    border-bottom: 1px solid #fecaca;
}
.rrv3-wipe-select-all-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--rr-text);
}
.rrv3-wipe-select-all-label input[type="checkbox"],
.wipe-module-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #dc2626;
}
#wipe-modules-table th { background-color: #fee2e2 !important; color: #991b1b !important; }
#wipe-confirm-text {
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
    border-color: #fca5a5 !important;
}
#wipe-confirm-text:focus {
    border-color: #dc2626 !important;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15) !important;
}
#wipe-confirm-btn:disabled { opacity: 0.5; }

/* --- CATALOG EXPORT modal options --- */
.rrv3-export-type-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 6px 16px;
    margin-top: 4px;
}
.rrv3-export-type-options label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border: 1px solid var(--rr-border);
    border-radius: 6px;
    background: var(--rr-white);
    font-size: 12.5px;
    color: var(--rr-text);
    cursor: pointer;
    transition: border-color 0.12s, background-color 0.12s;
}
.rrv3-export-type-options label:hover {
    border-color: var(--rr-blue);
    background: var(--rr-blue-soft);
}
.rrv3-export-type-options input[type="radio"] {
    margin: 0;
    cursor: pointer;
    accent-color: var(--rr-blue);
}

/* --- Catalog manager --- */
.rrv3-inventory-toolbar {
    margin-bottom: 12px;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.catalog-thumb {
    width: 36px; height: 36px;
    object-fit: contain; /* full image centered, no cropping */
    border-radius: 6px;
    background: var(--rr-bg);
    display: block;
}
tr.catalog-discontinued { opacity: 0.45; }
.catalog-image-preview { margin-top: 8px; }
.catalog-image-preview img {
    max-width: 130px; max-height: 130px;
    border-radius: var(--rr-radius);
    border: 1px solid var(--rr-border);
}
.rrv3-field-hint { font-size: 11px; color: var(--rr-text-muted); margin: 5px 0 0; }

/* --- Phase 2: stock actions, history, alerts --- */
.low-stock-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-right: auto;
    padding: 5px 13px;
    border-radius: 9999px;
    background: #fef9c3;
    border: 1px solid #fde047;
    color: #a16207;
    font-size: 11.5px;
    font-weight: 700;
}
tr.catalog-low-stock-row td { background-color: #fffbeb; }
.reserved-note {
    display: inline-block;
    margin-left: 5px;
    font-size: 10.5px;
    color: var(--rr-text-muted);
    white-space: nowrap;
}
.stock-action-current {
    background: var(--rr-bg);
    border-radius: var(--rr-radius);
    padding: 8px 13px;
    font-size: 12.5px;
    color: var(--rr-text);
    margin: 0 0 14px;
}
.stock-action-current strong { color: var(--rr-text); font-size: 14px; }
.movement-qty-in  { color: #15803d; font-weight: 700; }
.movement-qty-out { color: #b91c1c; font-weight: 700; }

/* --- Phase 3: loans & promote panel --- */
.overdue-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 9999px;
    background: #fee2e2;
    color: #b91c1c;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
tr.loan-overdue-row td { background-color: #fff5f5; }

.rrv3-promote-panel {
    margin-top: 22px;
    padding: 16px 18px;
    border: 1px dashed #fdba74;
    border-radius: var(--rr-radius-lg);
    background: #fffbf7;
}
.rrv3-promote-panel h3 { margin: 0 0 4px; color: #c2410c; }
.rrv3-promote-panel .rrv3-table th { background: transparent; }

/* --- Batch upload modal --- */
#batch-paste-area {
    width: 100%;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    white-space: pre;
    overflow-x: auto;
    padding: 10px;
    border: 1px solid var(--rr-border);
    border-radius: var(--rr-radius);
    background-color: var(--rr-white);
    color: var(--rr-text);
    box-sizing: border-box;
}
.batch-preview-scroll {
    max-height: 300px;
    overflow: auto;
    border: 1px solid var(--rr-border);
    border-radius: var(--rr-radius);
}
.batch-preview-scroll .rrv3-table { margin-bottom: 0; }
.batch-preview-scroll th, .batch-preview-scroll td {
    padding: 6px 9px;
    font-size: 11.5px;
    white-space: nowrap;
}
.batch-success {
    background: #dcfce7;
    color: #15803d;
    padding: 10px 14px;
    border-radius: var(--rr-radius);
    font-weight: 600;
    font-size: 12.5px;
}
.batch-errors {
    background: #fef9c3;
    border-radius: var(--rr-radius);
    padding: 10px 14px 10px 28px;
    color: #a16207;
    font-size: 11.5px;
    max-height: 150px;
    overflow-y: auto;
}

/* Batch upload clash row highlighting */
#batch-preview-table tbody tr.clash-sku td,
#batch-preview-table tbody tr.clash-name td,
#batch-preview-table tbody tr.clash-both td {
    background-color: #fff7ed !important;
}
#batch-preview-table tbody tr.clash-both td {
    background-color: #fef2f2 !important;
}
#batch-preview-table tbody tr.clash-name td {
    background-color: #fffbeb !important;
}
.clash-badge {
    display: inline-block;
    margin-left: 8px;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 9.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}
.badge-clash-sku { background: #fee2e2; color: #991b1b; }
.badge-clash-name { background: #fef9c3; color: #a16207; }
.badge-clash-both { background: #fecaca; color: #7f1d1d; }

/* --- Responsive guard for smaller screens --- */
@media (max-width: 900px) {
    .rrv3-dashboard { width: 98%; }
    .rrv3-admin-col-1-3 { max-width: none; }
    .rrv3-items-container { grid-template-columns: 1fr; }
}


/* Catalog table column resizing */
#catalog-table.rrv3-resizable-table {
    table-layout: fixed;
    width: 100% !important;
}
#catalog-table.rrv3-resizable-table th,
#catalog-table.rrv3-resizable-table td {
    position: relative;
    overflow: hidden;
    text-overflow: ellipsis;
}
#catalog-table .rrv3-col-resize-handle {
    position: absolute;
    top: 0;
    right: -4px;
    width: 10px;
    height: 100%;
    cursor: col-resize;
    z-index: 5;
    user-select: none;
}
#catalog-table .rrv3-col-resize-handle::after {
    content: '';
    position: absolute;
    top: 20%;
    right: 3px;
    width: 2px;
    height: 60%;
    border-radius: 999px;
    background: transparent;
    transition: background 0.15s ease;
}
#catalog-table th:hover .rrv3-col-resize-handle::after,
body.rrv3-column-resizing #catalog-table .rrv3-col-resize-handle::after {
    background: var(--rr-blue);
}
body.rrv3-column-resizing {
    cursor: col-resize !important;
    user-select: none !important;
}
body.rrv3-column-resizing * {
    cursor: col-resize !important;
}

/* 1607-14: latest matched supplier/vendor price references in catalog edit */
.catalog-price-ref-card {
    margin: 12px 0 14px;
    padding: 12px 14px;
    border: 1px solid #dbeafe;
    border-radius: 14px;
    background: #f8fbff;
}
.catalog-price-ref-card h3 {
    margin: 0 0 10px;
    color: #0f172a;
}
.catalog-price-ref-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    margin-bottom: 10px;
}
.catalog-price-ref-summary > div {
    padding: 8px 10px;
    border-radius: 10px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
}
.catalog-price-ref-summary label,
.catalog-price-ref-summary strong {
    display: block;
}
.catalog-price-ref-summary label {
    color: #64748b;
    font-size: 10px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.catalog-price-ref-summary strong {
    margin-top: 3px;
    color: #0f172a;
}
.catalog-price-ref-list {
    display: grid;
    gap: 8px;
}
.catalog-price-ref-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #ffffff;
}
.catalog-price-ref-row strong,
.catalog-price-ref-row small,
.catalog-price-ref-amount a {
    display: block;
}
.catalog-price-ref-row small {
    margin-top: 2px;
    color: #64748b;
}
.catalog-price-ref-amount {
    min-width: 105px;
    text-align: right;
}
.catalog-price-ref-amount a {
    margin-top: 3px;
    font-size: 11px;
    font-weight: 800;
    color: #2563eb;
    text-decoration: none;
}
@media (max-width: 640px) {
    .catalog-price-ref-row {
        flex-direction: column;
    }
    .catalog-price-ref-amount {
        text-align: left;
    }
}
html.rrv3-dark-mode .catalog-price-ref-card,
html.rrv3-dark-mode .catalog-price-ref-row {
    background: #0f172a;
    border-color: #334155;
}
html.rrv3-dark-mode .catalog-price-ref-card h3,
html.rrv3-dark-mode .catalog-price-ref-summary strong {
    color: #e2e8f0;
}
html.rrv3-dark-mode .catalog-price-ref-summary > div {
    background: #1e293b;
    border-color: #334155;
}
html.rrv3-dark-mode .catalog-price-ref-summary label,
html.rrv3-dark-mode .catalog-price-ref-row small {
    color: #94a3b8;
}
