/* Products Sheet — shared between admin wizard products page and PSC popup
 * Lifted verbatim from templates/admin/purchasing/purchaseorder/wizard_products.html
 * (the inline <style> block, lines 4-155 + the product picker styles lines 985-1063).
 * See docs/po-wizard/03_POW_IMPLEMENTATION_GUIDE.md for context.
 */

/* ============ Sheet (table) ============ */
.sheet-wrap { overflow: auto; border: 1px solid #ddd; border-radius: 4px; }
.sheet {
    border-collapse: separate !important;
    border-spacing: 0;
    width: 100%;
    font-size: 0.82rem;
}
.sheet th {
    background: #417690;
    color: #fff;
    padding: 0.4rem 0.35rem;
    text-align: center;
    font-weight: 600;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
}
.sheet td {
    padding: 2px 3px;
    border: 1px solid #ddd;
    vertical-align: middle;
}
.sheet tr:hover td { background: #f0f4ff; }
.sheet .row-num {
    background: #f5f5f5;
    text-align: center;
    color: #999;
    font-size: 0.75rem;
    width: 30px;
    font-weight: 600;
}
.sheet .del-cell { text-align: center; width: 30px; }

.cell-select, .cell-input {
    border: none;
    background: transparent;
    padding: 0.3rem 0.25rem;
    font-size: 0.82rem;
    width: 100%;
    margin: 0;
    box-sizing: border-box;
}
.cell-select:focus, .cell-input:focus {
    outline: 2px solid #417690;
    outline-offset: -1px;
    background: #fff;
}
.cell-input::placeholder { color: #ccc; }

.del-btn {
    background: none; border: none; color: #ccc;
    cursor: pointer; font-size: 1rem; padding: 0.2rem;
}
.del-btn:hover { color: #d32f2f; }

.set-all-row td {
    background: #eef3ff;
    border-bottom: 2px solid #417690;
    padding: 4px 3px;
}
.set-all-row .sa-label {
    font-size: 0.7rem; font-weight: 700; color: #417690;
    text-transform: uppercase; text-align: center;
}
.set-all-row select, .set-all-row input {
    background: #fff; border: 1px solid #b8cff0; border-radius: 3px;
    padding: 0.25rem; font-size: 0.8rem; width: 100%;
}

.readonly-cell {
    background: #f9f9f9;
    color: #666;
    font-size: 0.8rem;
    padding: 0.3rem 0.25rem;
}

.sheet-actions {
    display: flex; justify-content: space-between; align-items: center; margin-top: 0.5rem;
}
.add-rows-btn {
    background: none; border: 1px dashed #999; color: #666;
    padding: 0.3rem 1.2rem; border-radius: 4px; cursor: pointer;
    font-size: 0.82rem;
}
.add-rows-btn:hover { border-color: #417690; color: #417690; }
.img-preview {
    max-width: 48px; max-height: 48px; border-radius: 3px;
    object-fit: cover; cursor: pointer;
}
.visual-cell { min-width: 60px; }
.img-lightbox {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,0.7); z-index: 1100;
    justify-content: center; align-items: center; cursor: zoom-out;
}
.img-lightbox.open { display: flex; }
.img-lightbox img {
    max-width: 90vw; max-height: 90vh; border-radius: 6px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.4); object-fit: contain;
}

/* ============ Toolbar (search + bulk actions) ============ */
.wz-toolbar {
    display: flex; gap: 0.75rem; align-items: center;
    margin-bottom: 0.5rem; flex-wrap: wrap;
}
.wz-search-input {
    padding: 0.35rem 0.6rem; border: 1px solid #ccc; border-radius: 4px;
    font-size: 0.85rem; width: 240px;
}
.wz-search-input:focus { outline: 2px solid #417690; border-color: #417690; }
.wz-search-count { font-size: 0.8rem; color: #666; }
.wz-action-select {
    padding: 0.35rem 0.5rem; border: 1px solid #ccc; border-radius: 4px;
    font-size: 0.85rem; background: #fff;
}
.wz-action-go {
    padding: 0.35rem 0.75rem; border: 1px solid #417690; border-radius: 4px;
    font-size: 0.85rem; background: #417690; color: #fff; cursor: pointer;
}
.wz-action-go:hover { background: #205067; }
.wz-action-go:disabled { opacity: 0.5; cursor: not-allowed; }
.sheet .chk-cell { width: 30px; text-align: center; }
.sheet .chk-cell input[type="checkbox"] { cursor: pointer; }

/* ============ Formula bar + indicator ============ */
.has-formula { position: relative; }
.has-formula::after {
    content: '';
    position: absolute;
    top: 2px; left: 2px;
    width: 0; height: 0;
    border-left: 6px solid #4caf50;
    border-bottom: 6px solid transparent;
}
.formula-bar {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.4rem 0.6rem; background: #f5f5f5;
    border: 1px solid #ddd; border-radius: 4px;
    margin-bottom: 0.5rem; font-size: 0.85rem;
}
.formula-bar label { font-weight: 700; color: #417690; min-width: 20px; }
.formula-bar input {
    flex: 1; border: 1px solid #ccc; border-radius: 3px;
    padding: 0.3rem 0.5rem; font-family: monospace; font-size: 0.85rem;
}
.formula-bar input:focus { outline: 2px solid #417690; border-color: #417690; }
.formula-bar .fx-hint { font-size: 0.75rem; color: #999; }

/* ============ Product Picker Modal ============ */
.pp-overlay {
    display: none; position: fixed; inset: 0; z-index: 10001;
    background: rgba(0,0,0,0.5); justify-content: center; align-items: center;
}
.pp-overlay.open { display: flex; }
.pp-modal {
    background: #fff; border-radius: 8px; width: 90vw; max-width: 900px;
    max-height: 85vh; display: flex; flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.pp-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.75rem 1rem; background: #417690; color: #fff;
    border-radius: 8px 8px 0 0; flex-shrink: 0;
}
.pp-header h3 { margin: 0; font-size: 1rem; }
.pp-close {
    background: none; border: none; color: #fff; font-size: 1.4rem;
    cursor: pointer; padding: 0 0.3rem; line-height: 1;
}
.pp-close:hover { opacity: 0.7; }
.pp-toolbar {
    display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 1rem;
    border-bottom: 1px solid #ddd; flex-shrink: 0; flex-wrap: wrap;
}
.pp-search {
    padding: 0.35rem 0.6rem; border: 1px solid #ccc; border-radius: 4px;
    font-size: 0.85rem; width: 220px;
}
.pp-search:focus { outline: 2px solid #417690; border-color: #417690; }
.pp-toolbar-btn {
    padding: 0.3rem 0.7rem; border: 1px solid #ccc; border-radius: 4px;
    background: #fff; font-size: 0.8rem; cursor: pointer;
}
.pp-toolbar-btn:hover { border-color: #417690; color: #417690; }
.pp-tabs {
    display: flex; gap: 0; border-bottom: 2px solid #ddd;
    padding: 0 1rem; flex-shrink: 0; overflow-x: auto;
}
.pp-tab {
    padding: 0.45rem 0.9rem; border: none; background: none;
    font-size: 0.82rem; cursor: pointer; color: #666;
    border-bottom: 2px solid transparent; margin-bottom: -2px;
    white-space: nowrap;
}
.pp-tab:hover { color: #417690; }
.pp-tab.active { color: #417690; font-weight: 600; border-bottom-color: #417690; }
.pp-body {
    flex: 1; overflow-y: auto; padding: 0.75rem 1rem;
}
.pp-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem;
}
.pp-item {
    display: flex; align-items: center; gap: 0.4rem;
    padding: 0.4rem 0.5rem; border: 1px solid #e0e0e0; border-radius: 4px;
    cursor: pointer; font-size: 0.82rem; transition: background 0.15s;
}
.pp-item:hover { background: #f0f4ff; border-color: #417690; }
.pp-item.selected { background: #e3f0ff; border-color: #417690; }
.pp-item input[type="checkbox"] { margin: 0; cursor: pointer; flex-shrink: 0; }
.pp-item-name { flex: 1; }
.pp-item-code { color: #999; font-size: 0.75rem; }
.pp-footer {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.6rem 1rem; border-top: 1px solid #ddd;
    background: #f9f9f9; border-radius: 0 0 8px 8px; flex-shrink: 0;
}
.pp-footer-count { font-size: 0.85rem; color: #666; }
.pp-add-btn {
    padding: 0.4rem 1.2rem; background: #417690; color: #fff;
    border: none; border-radius: 4px; font-size: 0.85rem;
    cursor: pointer; font-weight: 600;
}
.pp-add-btn:hover { background: #205067; }
.pp-add-btn:disabled { opacity: 0.5; cursor: not-allowed; }
