:root {
    --primary: #0284c7;
    --primary-hover: #0369a1;
    --success: #10b981;
    --success-hover: #059669;
    --danger: #ef4444;
    --bg-color: #f1f5f9;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --text-main: #0f172a;
    --text-light: #64748b;
}

* { box-sizing: border-box; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; margin: 0; padding: 0; }
body { background-color: var(--bg-color); color: var(--text-main); padding: 30px; }

/* Dashboard Container */
.app-container { max-width: 1100px; margin: 0 auto; background: var(--card-bg); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.08); padding: 30px; }
.header { border-bottom: 2px solid var(--border); padding-bottom: 15px; margin-bottom: 20px; }
.header h2 { color: var(--primary); font-size: 24px; margin-bottom: 5px; }
.header p { color: var(--text-light); font-size: 14px; }

/* REQUISITION DETAILS */
.requisition-details { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; background: #f8fafc; padding: 20px; border-radius: 8px; border: 1px solid var(--border); margin-bottom: 25px; }
.req-input-group { display: flex; flex-direction: column; gap: 8px; }
.req-input-group label { font-size: 13px; font-weight: bold; color: var(--primary); text-transform: uppercase; }
.required-asterisk { color: var(--danger); }
.req-input-group input { width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; outline: none; transition: border 0.2s;}
.req-input-group input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.2); }

.autocomplete-wrapper { position: relative; }
.suggestions-box { position: absolute; top: 100%; left: 0; right: 0; background: white; border: 1px solid var(--border); border-top: none; border-radius: 0 0 6px 6px; z-index: 100; max-height: 200px; overflow-y: auto; box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); }
.suggestions-box:empty { border: none; }
.suggestion-item { padding: 10px 15px; font-size: 14px; border-bottom: 1px solid #f1f5f9; cursor: pointer; }
.suggestion-item:hover { background-color: #f0f9ff; color: var(--primary); }
.selected-display { font-size: 12px; color: var(--text-light); font-style: italic; margin-top: 4px; }

/* Search Area */
.search-section { display: flex; flex-wrap: wrap; gap: 15px; margin-bottom: 5px; align-items: stretch; justify-content: space-between; }
.search-bar { position: relative; flex: 1; min-width: 300px; }
.search-bar .search-icon { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: #94a3b8; }
.search-bar input { width: 100%; height: 100%; padding: 14px 14px 14px 45px; border: 2px solid var(--border); border-radius: 8px; font-size: 16px; outline: none; transition: border 0.2s; }
.search-bar input:focus { border-color: var(--primary); }

.create-new-btn { background-color: var(--success); color: white; border: none; padding: 12px 20px; border-radius: 8px; font-weight: bold; cursor: pointer; transition: background 0.2s; display: flex; align-items: center; gap: 8px; font-size: 15px;}
.create-new-btn:hover { filter: brightness(0.9); }

/* Results Dropdown */
.results-container { background: white; border-radius: 8px; max-height: 250px; overflow-y: auto; margin-bottom: 30px; box-shadow: 0 4px 6px rgba(0,0,0,0.05); border: 1px solid var(--border); }
.results-container:empty { display: none; }
.result-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; border-bottom: 1px solid var(--border); }
.result-item:last-child { border-bottom: none; }
.result-info { font-size: 14px; }
.result-info strong { color: var(--primary); font-size: 15px;}
.add-btn { background: var(--primary); color: white; border: none; padding: 8px 16px; border-radius: 6px; cursor: pointer; font-weight: bold; font-size: 12px;}
.add-btn:hover { background: var(--primary-hover); }
.no-results { padding: 20px; text-align: center; color: var(--text-light); font-weight: bold; font-style: italic;}

/* Cart Area */
.cart-section h3 { color: #334155; margin-bottom: 15px; }
.clear-session-btn { background: #f1f5f9; color: var(--danger); border: 1px solid #cbd5e1; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: bold; transition: background 0.2s;}
.clear-session-btn:hover { background: #fee2e2; border-color: #fca5a5; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid var(--border); font-size: 14px; }
th { background-color: #f8fafc; color: var(--text-light); font-weight: bold; }
.calc-input { width: 80px; padding: 8px; border: 1px solid var(--border); border-radius: 4px; outline: none; }
.calc-input:focus { border-color: var(--primary); }
.row-total { font-weight: bold; color: var(--primary); }
.remove-btn { background: var(--danger); color: white; border: none; padding: 8px 12px; border-radius: 6px; cursor: pointer; }
.empty-row td { text-align: center; color: #94a3b8; font-style: italic; padding: 40px; }

.cart-group-name { font-size: 12px; color: #64748b; display: inline-block; margin-top: 4px; }
.cart-comment-input { width: 100% !important; margin-top: 8px; font-style: italic; font-size: 12px; color: #334155; background-color: #f8fafc; border: 1px dashed var(--border) !important; }
.cart-comment-input:focus { border-color: var(--primary) !important; background-color: #ffffff; }
.unit-input { width: auto; min-width: 80px; }

.cart-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 20px; padding-top: 20px; border-top: 2px solid var(--border); }
.grand-total { font-size: 20px; font-weight: bold; color: var(--text-main); }
.grand-total span { color: var(--primary); }
.footer-actions { display: flex; gap: 15px; }

.preview-btn { background: #64748b; color: white; border: none; padding: 12px 24px; border-radius: 8px; font-weight: bold; cursor: pointer; display: flex; align-items: center; gap: 8px; font-size: 16px; transition: background 0.2s;}
.preview-btn:hover:not(:disabled) { background: #475569; }
.preview-btn:disabled { background: #e2e8f0; color: #94a3b8; cursor: not-allowed; }

.print-btn { background: var(--text-main); color: white; border: none; padding: 12px 24px; border-radius: 8px; font-weight: bold; cursor: pointer; display: flex; align-items: center; gap: 8px; font-size: 16px; transition: background 0.2s;}
.print-btn:hover:not(:disabled) { background: #1e293b; }
.print-btn:disabled { background: #e2e8f0; color: #94a3b8; cursor: not-allowed; }

/* MODAL (POP-UP) STYLES */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(15, 23, 42, 0.7); backdrop-filter: blur(4px); display: flex; justify-content: center; align-items: center; z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.modal-overlay.active { opacity: 1; pointer-events: auto; }

.modal-content { background: white; width: 100%; max-width: 800px; border-radius: 12px; box-shadow: 0 20px 40px rgba(0,0,0,0.2); transform: translateY(-20px); transition: transform 0.3s; overflow: hidden; display: flex; flex-direction: column; max-height: 90vh;}
.modal-overlay.active .modal-content { transform: translateY(0); }

.modal-header { background: var(--primary); padding: 20px; display: flex; justify-content: space-between; align-items: center; color: white; }
.modal-header h2 { font-size: 18px; font-weight: 600; }
.close-btn { background: transparent; border: none; color: white; font-size: 24px; cursor: pointer; transition: transform 0.2s; }
.close-btn:hover { transform: scale(1.1); color: #f1f5f9; }

.modal-body { padding: 25px; overflow-y: auto; }

.section { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin-bottom: 20px; }
.section h3 { font-size: 15px; border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 15px; color: var(--primary); }
.form-group { display: flex; flex-direction: column; margin-bottom: 15px; }
.form-group label { font-size: 12px; font-weight: bold; margin-bottom: 5px; color: var(--text-light); text-transform: uppercase; }
.form-group input, .form-group select { padding: 10px; border: 1px solid var(--border); border-radius: 6px; outline: none; }
.form-group input:focus, .form-group select:focus { border-color: var(--primary); }
.form-group input[readonly] { background-color: #e2e8f0; color: var(--text-light); }

.read-only-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 15px; }
.input-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 15px; }

.preview-section { background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; padding: 20px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.preview-text h3 { color: #166534; margin-bottom: 5px; }
.preview-text p { font-size: 12px; color: #15803d; }
.preview-code { text-align: right; }
#previewPartCode { font-size: 24px; font-weight: bold; font-family: monospace; color: #14532d; letter-spacing: 2px; }
.series-text { font-size: 14px; color: #16a34a; }

.submit-section { display: flex; justify-content: flex-end; }
.save-btn { background-color: var(--success); color: white; border: none; padding: 12px 24px; border-radius: 8px; font-weight: bold; cursor: pointer; transition: background 0.2s; font-size: 16px;}
.save-btn:hover:not(:disabled) { background-color: var(--success-hover); }
.save-btn:disabled { background-color: #cbd5e1; cursor: not-allowed; }

/* ========================================== */
/* ADVANCED PRINT STYLES (Supports two layouts)*/
/* ========================================== */
.print-only { display: none; }
.print-only-new-items { display: none; }

@media print {
    body { background: white; padding: 0; }
    .no-print { display: none !important; }
    .modal-overlay { display: none !important; }

    /* Hide both print areas by default */
    #printArea { display: none !important; }
    #printNewItemsArea { display: none !important; }

    /* LAYOUT 1: TRIGGERED WHEN PRINTING REQUISITIONS */
    body.printing-pr #printArea { display: flex !important; flex-direction: column; min-height: 98vh; width: 100%; }
    
    .print-top-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 25px; }
    .print-logo-container img { max-width: 400px; height: auto; margin-top: 5px; }
    .print-title-container { text-align: right; }
    .pr-title { margin: 0 0 10px 0; font-size: 32px; color: #004b87 !important; font-family: 'Times New Roman', Times, serif; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    
    .pr-meta-table { margin-left: auto; border-collapse: separate; border-spacing: 0 8px; }
    .pr-label { font-size: 15px; font-weight: bold; padding-right: 6px; text-align: right; color: #000000 !important; font-family: 'Times New Roman', Times, serif; border: none !important; }
    .pr-value { border: 1px solid #000000 !important; text-align: center !important; font-size: 10px !important; font-weight: bold; -webkit-print-color-adjust: exact; print-color-adjust: exact; font-family: monospace; padding: 3px 6px; min-width: 85px; }
    
    .print-meta-grid { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
    .print-box { width: 48%; border: 1px solid #000000 !important; border-radius: 4px; padding: 15px 10px 10px 10px; position: relative; margin-top: 10px; }
    .print-box-title { position: absolute; top: -10px; left: 10px; background: white; padding: 0 5px; font-size: 14px; font-weight: bold; color: #000000; font-family: 'Times New Roman', Times, serif; }
    .meta-row { font-size: 12px; margin-bottom: 5px; display: flex; margin-top: 5px; }
    .meta-row span { width: 100px; color: #000000; font-weight: bold; }
    .meta-row strong { color: #000000; flex: 1; }

    .print-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
    .print-table th, .print-table td { border: 1px solid #000000 !important; padding: 8px; text-align: left; font-size: 12px; color: #000000 !important; }
    .print-table th { background-color: #f1f5f9 !important; font-weight: bold; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    
    .print-grand-total { text-align: right; font-size: 16px; font-weight: bold; margin-top: 20px; padding-top: 10px; border-top: 2px solid #000000; }

    .print-footer { margin-top: auto; display: flex; justify-content: flex-end; padding-bottom: 40px; position: relative; }
    .footer-info { position: absolute; bottom: 10px; left: 0; font-size: 8px; font-style: italic; color: #64748b !important; font-family: monospace; }
    .signature-box { width: 280px; text-align: center; }
    .signature-line { border-top: 2px solid #000000 !important; margin-bottom: 8px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .signature-box p { margin: 0; font-size: 14px; font-style: italic; font-weight: bold; color: #004b87 !important; font-family: 'Times New Roman', Times, serif; }

    /* LAYOUT 2: TRIGGERED WHEN PRINTING NEW ITEMS */
    body.printing-new-items #printNewItemsArea { display: block !important; width: 100%; }
}