/* css/catalog.css - MASTER CATALOG (EXCEL GRID) */
@import url('https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@400;700&display=swap');

/* --- 1. CORE SYSTEM RULES --- */
:root {
    --ledger-font: 'Roboto Mono', monospace;
    --ledger-bg: #f2f2f2;         
    --paper-white: #ffffff;       
    --ink-black: #000000;         
    --border-grey: #333333;       
    --active-blue: #004085;       
    --danger-red: #d32f2f;
    --dirty-yellow: #fff9c4;      /* Highlight for edited rows */
    --font-size-clerical: 11px;
    --row-height-strict: 22px;    
}

* {
    box-sizing: border-box;
    text-transform: uppercase;    
    letter-spacing: 0.5px;
}

body {
    font-family: var(--ledger-font);
    font-size: var(--font-size-clerical);
    background-color: var(--ledger-bg);
    color: var(--ink-black);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Remove Number Input Spinners */
input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
  -webkit-appearance: none; 
  margin: 0; 
}
input[type=number] {
  -moz-appearance: textfield;
}

/* --- 2. HEADER & TOOLBARS --- */
.app-header {
    background-color: #2c3e50;
    color: white;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    border-bottom: 2px solid var(--ink-black);
    position: sticky;
    top: 0;
    z-index: 100;
    flex-shrink: 0;
}

.app-header h1 { font-size: 16px; margin: 0; }
.user-display { font-size: 10px; color: #aeb6bf; margin-left: 15px; }

.header-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.header-button, .header-actions button {
    background: transparent;
    border: 1px solid #ffffff44;
    color: white;
    padding: 2px 8px;
    font-size: 10px;
    cursor: pointer;
    height: 24px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    transition: all 0.2s;
}

.header-button:hover, .header-actions button:hover {
    background-color: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.6);
}

#logoutBtn { border-color: rgba(220, 53, 69, 0.4); color: #ffcccc; }
#logoutBtn:hover { background-color: rgba(220, 53, 69, 0.2); border-color: #dc3545; color: white; }

.po-container {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 0 10px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.ledger-details-panel {
    background: var(--paper-white);
    padding: 10px;
    border: 1px solid var(--ink-black);
    box-shadow: 2px 2px 0px #000;
}

/* Save Button Glow Animation */
@keyframes savePulse {
    0% { box-shadow: 0 0 0 0 rgba(0, 64, 133, 0.7); }
    70% { box-shadow: 0 0 0 6px rgba(0, 64, 133, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 64, 133, 0); }
}
.save-glow:not(:disabled) {
    animation: savePulse 1.5s infinite;
    background-color: #0056b3 !important;
}

/* --- 3. THE EXCEL GRID --- */
.catalog-grid-wrapper {
    background: var(--paper-white);
    border: 2px solid var(--ink-black);
    overflow-y: auto;
    flex-grow: 1;
    margin-bottom: 10px;
    /* Dynamically fill space */
    max-height: calc(100vh - 170px); 
}

.ledger-grid {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed; /* STRICT widths */
}

.ledger-grid th {
    background: #333;
    color: white;
    font-size: 10px;
    height: 24px;
    border: 1px solid var(--border-grey);
    padding: 0 6px;
    text-align: left;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
}

.ledger-grid td {
    border: 1px solid var(--border-grey);
    height: 22px; /* STRICT ROW HEIGHT */
    padding: 0; /* Padding is 0 so inputs can stretch 100% */
    vertical-align: middle;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background: var(--paper-white);
}

/* Read-Only Text Cells get manual padding back */
.ledger-grid td.read-only-cell {
    padding: 2px 6px;
}

/* --- 4. SEAMLESS INLINE INPUTS --- */
.grid-input, .grid-select {
    width: 100%;
    height: 21px; /* Matches td height perfectly minus border */
    border: none;
    background: transparent;
    font-family: var(--ledger-font);
    font-size: 11px;
    padding: 0 6px;
    color: var(--ink-black);
    outline: none;
    text-transform: uppercase;
}

/* Align numbers to right like Excel */
.grid-input[type="number"] {
    text-align: right;
}

/* Focus state makes it look like an active Excel cell */
.grid-input:focus, .grid-select:focus {
    background-color: #fffbe6;
    box-shadow: inset 0 0 0 2px var(--active-blue);
}

/* --- 5. THE DIRTY ROW (Edited State) --- */
.dirty-row td {
    background-color: var(--dirty-yellow) !important;
}

.dirty-row td:first-child {
    border-left: 4px solid var(--danger-red) !important;
}

.dirty-row .grid-input, .dirty-row .grid-select {
    font-weight: bold;
    color: var(--danger-red);
}

/* Row checkbox alignment */
.row-checkbox {
    margin: 0;
    cursor: pointer;
    vertical-align: middle;
}

/* --- 6. UTILITIES & BUTTONS --- */
.action-btn {
    background-color: var(--ledger-bg);
    color: var(--ink-black);
    border: 1px solid var(--border-grey);
    padding: 4px 10px;
    font-family: var(--ledger-font);
    font-size: 10px;
    cursor: pointer;
    font-weight: bold;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.action-btn:hover:not(:disabled) { background-color: #e2e6ea; }

.action-btn.primary {
    background-color: var(--active-blue);
    color: white;
    border-color: var(--ink-black);
}

.action-btn.primary:hover:not(:disabled) { background-color: #002752; }

.action-btn:disabled {
    background-color: #aab7c4 !important;
    color: #666 !important;
    border-color: #888 !important;
    cursor: not-allowed;
}

.deep-edit-btn {
    background: none;
    border: none;
    color: #555;
    cursor: pointer;
    font-size: 12px;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.deep-edit-btn:hover {
    color: var(--active-blue);
    background: #e2e6ea;
}

/* --- 7. MODALS --- */
.modal-backdrop {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    display: none; 
    justify-content: center; align-items: center;
    z-index: 9999;
}

.modal-content, .modal-content-small {
    background: var(--paper-white);
    border: 2px solid var(--ink-black);
    padding: 20px;
    box-shadow: 10px 10px 0px var(--ink-black);
    max-height: 85vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.modal-content { width: 800px; max-width: 95vw; }
.modal-content-small { width: 450px; max-width: 90vw; }

.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 15px; border-bottom: 2px solid var(--border-grey); padding-bottom: 10px;
}
.modal-header h2 { margin: 0; font-size: 14px; color: var(--ink-black); font-weight: bold; }

.modal-close {
    background: none; border: none; font-size: 20px; font-weight: bold;
    cursor: pointer; line-height: 1; color: #555;
}
.modal-close:hover { color: var(--danger-red); }

.modal-body { flex-grow: 1; overflow-y: auto; }
.modal-footer {
    margin-top: 20px; display: flex; justify-content: flex-end;
    border-top: 1px solid var(--border-grey); padding-top: 15px;
}

/* Form Groups inside Modal */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.form-column { display: flex; flex-direction: column; gap: 12px; }
.form-group { display: flex; flex-direction: column; }
.form-group label { font-size: 10px; font-weight: bold; color: var(--ink-black); margin-bottom: 4px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 6px; border: 1px solid var(--border-grey);
    font-family: var(--ledger-font); font-size: 11px; outline: none; background: #fff;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { background-color: #fffbe6; }
.form-group input:disabled, .form-group input[readonly] { background-color: #f8f9fa; color: #555; font-weight: bold; }

/* Loading Overlay */
.loading-overlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(255, 255, 255, 0.85);
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    z-index: 10000;
}
.loading-overlay p { font-family: var(--ledger-font); font-weight: bold; margin-top: 10px; color: var(--ink-black); }
.spinner {
    border: 4px solid rgba(0,0,0,0.1); width: 36px; height: 36px; border-radius: 50%;
    border-left-color: var(--active-blue); animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* ============================================================================
   --- NEW UPGRADES: AUDIT MODAL, ADVANCED FILTERS & DUAL ACTIONS ---
   ============================================================================ */

/* --- 1. DUAL ACTIONS COLUMN (Deep Edit & Delete) --- */
.row-actions-flex {
    display: flex;
    justify-content: center;
    gap: 15px; /* Spacing between gear and trash can */
    align-items: center;
    height: 100%;
}

.deep-edit-btn, .delete-item-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.deep-edit-btn { color: #555; }
.deep-edit-btn:hover { color: var(--active-blue); }

.delete-item-btn { color: var(--danger-red); }
.delete-item-btn:hover { color: #b71c1c; }


/* --- 2. PRE-SAVE AUDIT TABLE HIGHLIGHTS --- */
#summaryTableBody td {
    padding: 6px 8px;
}

.audit-old-value {
    color: #721c24; /* Faint red */
    text-decoration: line-through; /* Strikethrough for old data */
}

.audit-new-value {
    color: #155724; /* Green */
    font-weight: bold;
    background-color: #d4edda; /* Light green background to pop */
}


/* --- 3. ADVANCED FILTER BUILDER UI --- */
.filter-rule-row {
    display: flex;
    gap: 10px;
    align-items: center;
    background: #f8f9fa;
    padding: 8px;
    border: 1px solid var(--border-grey);
}

.filter-rule-row select, .filter-rule-row input {
    flex: 1;
    height: 24px;
    border: 1px solid var(--border-grey);
    font-size: 11px;
    padding: 0 5px;
    font-family: var(--ledger-font);
    outline: none;
}

.filter-rule-row select:focus, .filter-rule-row input:focus {
    background-color: #fffbe6;
    border-color: var(--active-blue);
}

.remove-rule-btn {
    background: none;
    border: none;
    color: var(--danger-red);
    cursor: pointer;
    font-size: 14px;
    padding: 0 5px;
}

.remove-rule-btn:hover {
    color: #b71c1c;
}

/* ============================================================================
   --- SYSTEM MODALS & TOAST NOTIFICATIONS ---
   ============================================================================ */

/* --- 1. TOAST CONTAINER --- */
.toast-container {
    position: fixed;
    bottom: 25px;
    right: 25px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 10005; /* Must be above all modals */
    pointer-events: none; /* Allows clicking through the container itself */
}

/* --- 2. TOAST MESSAGE STYLES --- */
.toast-msg {
    min-width: 250px;
    max-width: 350px;
    padding: 12px 16px;
    color: var(--paper-white);
    font-family: var(--ledger-font);
    font-size: 11px;
    font-weight: bold;
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--ink-black);
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: auto; /* Allows hover/click on the toast itself */
    
    /* 5 second total animation */
    animation: toastSlideFade 5s forwards; 
}

/* Toast Theme Colors */
.toast-success { background-color: #28a745; }
.toast-error { background-color: var(--danger-red); }
.toast-info { background-color: var(--active-blue); }
.toast-warning { background-color: #ff9800; color: var(--ink-black); }

/* Toast Icon Resizing */
.toast-msg i {
    font-size: 14px;
}

/* --- 3. TOAST ANIMATION KEYFRAMES --- */
@keyframes toastSlideFade {
    0% { 
        opacity: 0; 
        transform: translateX(100%); 
    }
    10% { 
        opacity: 1; 
        transform: translateX(0); 
    }
    /* Hold on screen from 10% to 90% (approx 4 seconds) */
    90% { 
        opacity: 1; 
        transform: translateX(0); 
    }
    /* Fade out and slide up gracefully */
    100% { 
        opacity: 0; 
        transform: translateY(-20px); 
    }
}