/* ==========================================
           BASE STYLES & LAYOUT (Eye-Friendly Slate Theme)
           ========================================== */
        * { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
        body { display: flex; background-color: #f8fafc; color: #334155; height: 100vh; overflow: hidden; }
        
        /* Sidebar Styling */
        .sidebar { 
            width: 260px; 
            background: #1e293b; 
            color: white; 
            display: flex; 
            flex-direction: column; 
            height: 100vh; 
            overflow: hidden; 
            position: sticky; 
            top: 0; 
            transition: margin-left 0.3s ease-in-out, transform 0.3s ease-in-out; 
            z-index: 100; 
        }
        .sidebar.collapsed { margin-left: -260px; }
        
        .sidebar-header { 
            padding: 15px; 
            text-align: center; 
            background: #0f172a; 
            border-bottom: 1px solid #334155; 
            cursor: pointer; 
            transition: background 0.2s; 
        }
        .sidebar-header:hover { background: #1e293b; }
        .logo-container { background: white; padding: 8px; border-radius: 8px; display: inline-block; margin-bottom: 5px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
        .logo-container img { width: 90px; height: auto; display: block; margin: 0 auto; }
        .nav-menu { 
            flex: 1; 
            display: flex; 
            flex-direction: column; 
            overflow-y: auto; 
            padding: 5px 0; 
        }
        .nav-link { 
            padding: 12px 20px; 
            color: #cbd5e1; 
            text-decoration: none; 
            display: flex; 
            align-items: center; 
            gap: 10px;
            border-bottom: 1px solid rgba(51, 65, 85, 0.5); 
            transition: all 0.2s; 
            cursor: pointer; 
            font-weight: 500;
            font-size: 14px;
        }
        .nav-link:hover { background: #334155; color: white; padding-left: 24px; }
        .nav-link.active { background: #0f172a; color: white; border-left: 4px solid #3b82f6; }
        
        .main-content { flex: 1; display: flex; flex-direction: column; overflow-y: auto; position: relative; }
        .header { background: white; padding: 15px 20px; display: flex; align-items: center; box-shadow: 0 2px 5px rgba(0,0,0,0.05); gap: 15px; border-bottom: 1px solid #e2e8f0; }
        .menu-btn { background: none; border: none; font-size: 24px; cursor: pointer; color: #1e293b; display: inline-block; transition: 0.2s;}
        .menu-btn:hover { color: #3b82f6; }
        
        .app-page { display: none; padding: 20px; animation: fadeIn 0.3s; }
        .app-page.active { display: block; }
        @keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

        /* ==========================================
           UI COMPONENTS
           ========================================== */
        .summary-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; margin-bottom: 20px; }
        .card { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); border-top: 4px solid #1e293b; }
        .card h3 { color: #64748b; font-size: 14px; text-transform: uppercase; margin-bottom: 10px; }
        .card .value { font-size: 28px; font-weight: bold; color: #1e293b; }
        .split-layout { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
        .data-section, .content-card { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); flex: 2; min-width: 300px; }
        .form-card { background: white; padding: 25px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); flex: 1; min-width: 300px; border-top: 4px solid #1e293b; }

        table { width: 100%; border-collapse: collapse; text-align: left; }
        th, td { padding: 12px; border-bottom: 1px solid #e2e8f0; font-size: 14px; vertical-align: middle;}
        th { color: #64748b; font-weight: 600; font-size: 14px; background: #f8fafc;}
        
        .status-badge { padding: 4px 8px; border-radius: 4px; font-size: 12px; font-weight: bold; }
        .badge-active { background: #dcfce7; color: #166534; }
        .badge-hold { background: #fef3c7; color: #b45309; }
        .badge-completed { background: #dbeafe; color: #1e40af; }
        .badge-pending { background: #fef08a; color: #854d0e; }
        .badge-client { background: #f3e8ff; color: #6b21a8; }
        .badge-sale { background: #fef08a; color: #854d0e; border: 1px solid #fde047; }
        .badge-rent { background: #e0e7ff; color: #1e40af; border: 1px solid #bfdbfe; }
        
        .text-inward { color: #16a34a; font-weight: bold; }
        .text-outward { color: #ef4444; font-weight: bold; }

        input[type="text"], input[type="number"], input[type="date"], select, textarea, .search-bar { width: 100%; padding: 10px; border: 1px solid #cbd5e1; border-radius: 4px; font-size: 14px; background: #fff;}
        input:focus, select:focus, textarea:focus { border-color: #3b82f6; outline: none; box-shadow: 0 0 0 2px rgba(59,130,246,0.1); }
        
        .form-group { margin-bottom: 15px; }
        label { display: block; font-size: 14px; font-weight: 600; color: #64748b; margin-bottom: 5px; }
        
        .btn, .btn-main, button[type="submit"] { padding: 8px 15px; border: none; border-radius: 4px; cursor: pointer; font-weight: bold; background: #3b82f6; color: white; transition: 0.2s; }
        .btn-success { background: #10b981; color: white; }
        .btn-primary { background: #3b82f6; color: white; }
        .btn-secondary { background: #64748b; color: white; }
        .btn-remove { background: #ef4444; color: white; }
        .btn:hover, .btn-main:hover { opacity: 0.9; }
        
        .action-btn { background: #e2e8f0; color: #333; border: none; padding: 6px 12px; border-radius: 4px; cursor: pointer; font-size: 12px; font-weight: bold; margin-right: 5px; transition: 0.2s; display: inline-flex; align-items: center; justify-content: center; gap: 4px;}
        .action-btn:hover { background: #cbd5e1; }
        .delete-btn { background: #fee2e2; color: #ef4444; }

        /* ==========================================
           PROJECT & REAL ESTATE GRIDS
           ========================================== */
        .project-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
        .project-card, .re-card { background: white; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.05); border: 1px solid #e2e8f0; overflow:hidden; }
        .project-card-header { padding: 15px; background: #f8fafc; border-bottom: 1px solid #e2e8f0; display: flex; justify-content: space-between; align-items: center; }
        .project-card-body { padding: 15px; }
        .project-info { font-size: 14px; color: #64748b; margin-bottom: 5px; display: flex; justify-content: space-between;}
        .project-info strong { color: #1e293b; text-align: right; }
        
        .re-img-container { width: 100%; height: 160px; background: #e2e8f0; position: relative; }
        .re-img-container img { width: 100%; height: 100%; object-fit: cover; }
        .re-badges { position: absolute; top: 10px; left: 10px; display: flex; gap: 5px; }
        
        .update-toggle-btn { background: #f1f5f9; border: 1px solid #cbd5e1; color: #475569; padding: 8px; width: 100%; text-align: center; border-radius: 4px; cursor: pointer; font-weight: bold; margin-top: 15px; transition: 0.2s; }
        .update-toggle-btn:hover { background: #e2e8f0; color: #1e293b; }

        /* ==========================================
           GALLERY & MEDIA STYLES
           ========================================== */
        .photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 15px; margin-top: 15px; }
        .photo-card { background: white; padding: 8px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); cursor: pointer; transition: transform 0.2s; border: 1px solid #e2e8f0; position: relative;}
        .photo-card:hover { transform: scale(1.02); }
        .photo-thumb { width: 100%; height: 100px; object-fit: cover; border-radius: 4px; }
        .photo-name { font-size: 11px; color: #64748b; margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; font-weight: bold; }
        .video-indicator { position: absolute; top: 12px; right: 12px; background: rgba(0,0,0,0.7); color: white; border-radius: 4px; padding: 2px 6px; font-size: 10px; font-weight: bold;}
        
        .mini-gallery { display: flex; gap: 10px; flex-wrap: wrap; padding-bottom: 10px; }
        .mini-thumb { width: 70px; height: 70px; object-fit: cover; border-radius: 4px; cursor: pointer; border: 1px solid #e2e8f0; transition: 0.2s; }
        .mini-thumb:hover { opacity: 0.8; }

        .lightbox-content { max-width: 90vw; max-height: 80vh; object-fit: contain; border-radius: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }

.admin-tabs .tab-btn {
    padding: 10px 20px;
    background: #f1f5f9;
    border: none;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    font-weight: bold;
    color: #64748b;
    transition: all 0.2s;
}

.admin-tabs .tab-btn.active {
    background: #fff;
    color: #3b82f6;
    border-bottom: 2px solid #3b82f6;
}

.admin-tabs .tab-btn:hover {
    background: #e2e8f0;
}

        /* ==========================================
           BUILDER MODULE (Quote & Invoice)
           ========================================== */
        .quote-sub-nav { display: flex; gap: 10px; margin-bottom: 20px; border-bottom: 2px solid #e2e8f0; padding-bottom: 10px; overflow-x: auto;}
        .quote-tab-btn { background: none; border: none; font-size: 15px; font-weight: bold; color: #64748b; padding: 8px 15px; cursor: pointer; border-radius: 4px; transition: 0.2s;}
        .quote-tab-btn.active { background: #eff6ff; color: #3b82f6; border: 1px solid #bfdbfe; }
        .quote-view { display: none; animation: fadeIn 0.3s; }
        .quote-view.active { display: block; }
        
        .container { max-width: 1000px; margin: 0 auto; background: white; padding: 40px; box-shadow: 0 4px 15px rgba(0,0,0,0.05); border-radius: 8px; }
        .clean-input { border: 1px dashed transparent; padding: 6px; border-radius: 4px; transition: border-color 0.2s; min-height: 28px; width: 100%; font-family: inherit; white-space: pre-wrap;}
        .clean-input:hover, .clean-input:focus { border-color: #cbd5e1; outline: none; background: #f8fafc; }
        .resizable-box {
            display: block;
            resize: both;
            overflow: auto;
            min-width: 220px;
            min-height: 38px;
        }

        /* Contenteditable Placeholder */
        [contenteditable="true"]:empty:before {
            content: attr(placeholder);
            color: #94a3b8;
            pointer-events: none;
            display: block;
        }
        
        /* Table Responsive Enhancements */
        .payment-table { 
            width: 65% !important; 
            margin: 20px 0;
            border-collapse: collapse; 
            table-layout: fixed; 
            font-size: 14px;
            color: #1e293b;
        }
        .payment-table th { 
            background: #f1f5f9; 
            color: #475569; 
            font-weight: 700; 
            text-transform: uppercase; 
            letter-spacing: 0.05em;
            padding: 12px 10px;
            border-bottom: 2px solid #e2e8f0;
        }
        .payment-table td { 
            padding: 12px 10px;
            border-bottom: 1px solid #f1f5f9;
            vertical-align: top;
            word-wrap: break-word; 
            overflow-wrap: break-word; 
        }
        
        /* Column Widths & Alignments */
        .col-sno { width: 10%; text-align: center; }
        .col-desc { width: 45%; text-align: left; }
        .col-pct { width: 15%; text-align: center; }
        .col-amt { width: 30%; text-align: right; }
        
        #paymentBody { counter-reset: rowNumber; }
        #paymentBody tr { counter-increment: rowNumber; }
        #paymentBody tr td.col-sno:before { content: counter(rowNumber); font-weight: 600; color: #64748b; }

        .payment-table .pay-desc { 
            white-space: pre-wrap; 
            text-align: left; 
            line-height: 1.5; 
            font-size: 14px;
            border: 1px dashed transparent;
            padding: 4px;
            border-radius: 4px;
            background: transparent;
            min-height: 24px;
            display: block;
            width: 100%;
            box-sizing: border-box;
            transition: 0.2s;
        }
        .payment-table .pay-desc:hover, .payment-table .pay-desc:focus {
            border-color: #cbd5e1;
            background: #f8fafc;
            outline: none;
        }
        .payment-table .pay-pct-input, .payment-table .pay-amt-input {
            width: 100%;
            border: none;
            background: transparent;
            text-align: center;
            font-weight: 600;
            color: #1e293b;
            font-size: 14px;
        }
        .payment-table .pay-amt-input {
            text-align: right;
            color: #0f172a;
        }
        .payment-table .pay-amt-val {
            font-weight: 700;
            color: #0f172a;
        }
        
        .quote-header-grid {
            display: grid;
            grid-template-columns: 1fr 320px;
            align-items: flex-start;
            gap: 32px;
            width: 100%;
            margin-bottom: 30px;
        }
        .quote-header-left {
            min-width: 0;
            display: flex;
            flex-direction: column;
            gap: 10px;
            order: 1;
            justify-self: start;
            align-items: flex-start;
            width: min(100%, 360px);
        }
        .quote-header-right {
            display: flex;
            flex-direction: column;
            justify-content: flex-start;
            min-width: 0;
            order: 2;
            align-items: flex-end;
            width: 320px;
        }
        .document-info-section {
            width: 100%;
            text-align: right;
            display: flex;
            flex-direction: column;
            align-items: flex-end;
        }
        .quote-meta-row {
            display: flex;
            width: 100%;
            justify-content: flex-end;
            margin-bottom: 15px;
        }
        .quote-meta-stack {
            width: 100%;
            max-width: 360px;
            display: flex;
            flex-direction: column;
            gap: 8px;
        }
        .quote-meta-item {
            display: grid;
            grid-template-columns: 42px 1fr;
            gap: 10px;
            align-items: center;
            width: 100%;
            text-align: left;
        }
        .quote-meta-item label { margin: 0; }
        .quote-meta-item input {
            width: 100%;
            box-sizing: border-box;
        }
        .customer-details-section {
            width: 100%;
            display: flex;
            flex-direction: column;
            align-items: flex-end;
        }
        .customer-card {
            width: 100%;
            max-width: 360px;
            display: flex;
            flex-direction: column;
            gap: 5px;
            text-align: left;
            align-self: flex-end;
        }
        .company-details-section {
            width: 100%;
            display: flex;
            flex-direction: column;
            gap: 6px;
            align-items: flex-start;
            border-bottom: none;
            padding-bottom: 0;
        }
        .company-logo-group {
            width: auto;
            display: flex;
            flex-direction: column;
            align-items: flex-start;
        }
        .company-details-section .clean-input { text-align: left; }
        .quote-info-box { background: #f8fafc; padding: 12px 15px; border-radius: 6px; border: 1px solid #e2e8f0; margin-bottom: 15px; }
        .detail-row { display: flex; gap: 10px; margin-bottom: 8px; align-items: center; }
        .detail-row label { width: 125px; text-align: left; font-weight: bold; color: #475569; font-size: 13px; margin: 0; flex-shrink: 0;}
        
        #itemsTable th:nth-child(1), #itemsTable td:nth-child(1), #constructionTable th:nth-child(1), #constructionTable td:nth-child(1) { width: 8%; text-align: center; } 
        #itemsTable th:nth-child(2), #itemsTable td:nth-child(2), #constructionTable th:nth-child(2), #constructionTable td:nth-child(2) { width: 39%; } 
        #itemsTable th:nth-child(3), #itemsTable td:nth-child(3), #constructionTable th:nth-child(3), #constructionTable td:nth-child(3) { width: 8%; text-align: center;} 
        #itemsTable th:nth-child(4), #itemsTable td:nth-child(4), #constructionTable th:nth-child(4), #constructionTable td:nth-child(4) { width: 8%; text-align: center;}
        #itemsTable th:nth-child(5), #itemsTable td:nth-child(5), #constructionTable th:nth-child(5), #constructionTable td:nth-child(5) { width: 18%; text-align: right;}
        #itemsTable th:nth-child(6), #itemsTable td:nth-child(6), #constructionTable th:nth-child(6), #constructionTable td:nth-child(6) { width: 19%; text-align: right;}

        .library-section { background: #f8fafc; padding: 15px; border-radius: 8px; border: 1px solid #e2e8f0; margin-bottom: 20px; }
        .library-controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 15px; }
        .library-controls select { padding: 8px; border: 1px solid #cbd5e1; border-radius: 4px; flex-grow: 1; }
        
        .totals-wrapper { display: flex; justify-content: space-between; align-items: flex-start; margin-top: 15px; padding-top: 15px;}
        .amount-in-words { width: 60%; padding-right: 20px; font-weight: bold; color: #333; }
        .amount-in-words label { display: block; font-size: 0.85em; color: #64748b; margin-bottom: 5px; text-transform: uppercase; }
        .totals-box { width: 40%; border-collapse: collapse; }
        .totals-box table { width: 100%; border: 2px solid #cbd5e1; border-radius: 4px; overflow: hidden; border-collapse: collapse;}
        .totals-box td { padding: 6px 12px; border-bottom: 1px solid #e2e8f0; vertical-align: middle; }
        .grand-total-row { background: #f1f5f9; font-weight: 800; font-size: 1.15em; color: #1e293b; }
        .tax-input { width: 32px !important; min-width: 32px !important; padding: 2px; text-align: center; border: 1px solid #cbd5e1; border-radius: 4px; font-weight: bold; font-size: 13px; display: inline-block; margin: 0 4px;}
        
        .drag-row.over { border-top: 3px solid #3b82f6; }
        .drag-handle { cursor: grab; color: #94a3b8; font-size: 16px; margin-right: 5px; user-select: none; }
        .drag-handle:active { cursor: grabbing; }
        .inline-cat { font-size: 11px; padding: 2px 6px; border-radius: 4px; background: #e0f2fe; color: #3b82f6; border: 1px solid #bae6fd; margin-bottom: 4px; display: inline-block; font-weight: bold; width: auto; max-width: 100%;}
        .category-subtotal-row td { background: #f8fafc !important; }
        .sub-item-row td { background: #fafafa; border-bottom: 1px dotted #e2e8f0;}

        .construction-spec-ul { padding-left: 0; margin-bottom: 10px; list-style: none;}
        .construction-spec-ul li { margin-bottom: 8px; display: flex; align-items: flex-start; gap: 10px;}
        
        .bottom-toolbar { 
            position: sticky; 
            bottom: 0; 
            z-index: 10;
            margin-top: 40px; 
            display: flex; 
            justify-content: space-between; 
            align-items: center; 
            border-top: 1px solid #e2e8f0; 
            padding: 15px 20px; 
            border-radius: 8px; 
            background: #f8fafc; 
            box-shadow: 0 -4px 10px rgba(0,0,0,0.05);
        }

        .modal-overlay { display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.85); z-index: 1000; justify-content: center; align-items: center; flex-direction: column; padding: 20px;}
        .modal-overlay.active { display: flex; animation: fadeIn 0.2s; }

        /* ==========================================
           RICH TEXT TOOLBAR
           ========================================== */
        .rich-text-toolbar {
            position: fixed;
            background: #ffffff;
            border: 1px solid #cbd5e1;
            border-radius: 6px;
            padding: 8px 12px;
            display: flex;
            align-items: center;
            gap: 8px;
            z-index: 9999;
            box-shadow: 0 10px 25px -5px rgba(0,0,0,0.2), 0 8px 10px -6px rgba(0,0,0,0.1);
            opacity: 0;
            pointer-events: none;
            transition: opacity 0.2s ease, transform 0.2s ease;
            transform: translateY(10px);
        }
        .rich-text-toolbar.active {
            opacity: 1;
            pointer-events: auto;
            transform: translateY(0);
        }
        .rt-btn {
            background: #f1f5f9;
            border: 1px solid #cbd5e1;
            border-radius: 4px;
            padding: 4px 10px;
            cursor: pointer;
            color: #334155;
            font-size: 14px;
            font-weight: bold;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: all 0.2s;
            height: 32px;
        }
        .rt-btn:hover { background: #e2e8f0; color: #0f172a; }
        .rt-select {
            padding: 4px 8px;
            border: 1px solid #cbd5e1;
            border-radius: 4px;
            font-size: 13px;
            color: #334155;
            height: 32px;
            width: 130px;
        }
        .rt-color {
            width: 32px;
            height: 32px;
            padding: 0;
            border: 1px solid #cbd5e1;
            border-radius: 4px;
            cursor: pointer;
        }
        .rt-separator {
            width: 1px;
            height: 24px;
            background: #cbd5e1;
            margin: 0 4px;
        }

        /* ==========================================
           DPR (DAILY PROGRESS REPORT)
           ========================================== */
        .dpr-card {
            background: #ffffff;
            border: 1px solid #cbd5e1;
            border-radius: 8px;
            padding: 15px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.02);
            border-left: 4px solid #3b82f6;
        }
        .dpr-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 12px;
            padding-bottom: 8px;
            border-bottom: 1px solid #e2e8f0;
        }
        .dpr-date {
            font-weight: bold;
            color: #0f172a;
            font-size: 16px;
        }
        .dpr-notes-section {
            font-size: 14px;
            color: #334155;
            white-space: pre-wrap;
            margin-bottom: 15px;
            padding: 10px;
            background: #f8fafc;
            border-radius: 6px;
        }
        .dpr-materials-section {
            margin-bottom: 15px;
        }
        .dpr-materials-section table {
            font-size: 13px;
        }
        .dpr-materials-section th, .dpr-materials-section td {
            padding: 6px;
        }
        .whatsapp-share-btn {
            background: #25D366;
            color: white;
            border: none;
            padding: 6px 12px;
            border-radius: 4px;
            font-weight: bold;
            cursor: pointer;
            display: inline-flex;
            align-items: center;
            gap: 6px;
            font-size: 13px;
            text-decoration: none;
        }
        .whatsapp-share-btn:hover { background: #128C7E; }

        /* =========================================================
           PRINT CSS
           ========================================================= */
        @media print {
            body { background: white; color: black; font-size: 11pt; padding: 0; margin: 0; height: auto !important; overflow: visible !important; display: block !important; }
            .main-content { height: auto !important; overflow: visible !important; display: block !important; }
            .app-page { display: none !important; }
            .app-page.active { height: auto !important; overflow: visible !important; display: block !important; padding: 0 !important; }
            .container { width: 100% !important; box-shadow: none !important; padding: 0 !important; border: none !important; margin: 0 !important; height: auto !important; overflow: visible !important; }
            .payment-table { width: 65% !important; margin: 20px auto !important; border-collapse: collapse; border: 1px solid #000; }
            .no-print, .sidebar, .header, .calc-widget, .calc-launcher, .bottom-toolbar, .overlay { display: none !important; }
            #generatorView, #invGeneratorView { position: static !important; width: 100% !important; padding: 0 !important; margin: 0 !important; }
            .quote-header-grid {
                display: grid !important;
                grid-template-columns: 1fr 320px !important;
                align-items: flex-start !important;
                gap: 28px !important;
            }
            .quote-header-left {
                order: 1 !important;
                justify-self: start !important;
                align-items: flex-start !important;
                width: 360px !important;
                max-width: 360px !important;
            }
            .quote-header-right { 
                order: 2 !important; 
                justify-content: flex-start !important; 
                align-items: flex-end !important;
                width: 320px !important;
            }
            .document-info-section { text-align: right !important; align-items: flex-end !important; }
            .quote-meta-row {
                width: 100% !important;
                max-width: 100% !important;
                justify-content: flex-end !important;
                align-self: auto !important;
                margin-left: 0 !important;
            }
            .quote-meta-stack { width: 100% !important; }
            .quote-meta-item { grid-template-columns: 42px 1fr !important; gap: 10px !important; }
            .customer-details-section {
                width: 100% !important;
                max-width: 100% !important;
                align-items: flex-end !important;
                align-self: auto !important;
                margin-left: 0 !important;
            }
            .client-select-box {
                width: 100% !important;
                max-width: 360px !important;
                margin-left: auto !important;
                margin-right: 0 !important;
            }
            .customer-card {
                width: 100% !important;
                max-width: 360px !important;
                margin-left: auto !important;
                margin-right: 0 !important;
                align-self: flex-end !important;
            }
            .company-details-section, .company-logo-group { align-items: flex-start !important; text-align: left !important; }
            .company-details-section .clean-input { text-align: left !important; }
            .no-print, .sidebar, .header { display: none !important; }
            .clean-input { border: none !important; background: transparent !important; resize: none; overflow: visible; -webkit-appearance: none; padding: 1px !important; min-height: 0 !important; margin: 0 !important; white-space: pre-wrap;}
            #itemsTable, #constructionTable, #invItemsTable { border: 1px solid #000; border-collapse: collapse; }
            #itemsTable th, #itemsTable td, #constructionTable th, #constructionTable td, #invItemsTable th, #invItemsTable td { border: 1px solid #000; color: black; padding: 3px 5px !important; font-size: 12px !important;}
            #itemsTable th, #constructionTable th, #invItemsTable th { background: #f0f0f0 !important; color: black !important; -webkit-print-color-adjust: exact; print-color-adjust: exact;}
            #itemsTable th:nth-child(7), #itemsTable td:nth-child(7), #invItemsTable th:nth-child(7), #invItemsTable td:nth-child(7) { display: none !important; } 
            .totals-box { width: 35% !important; } 
            .amount-in-words { width: 60% !important; } 
            .totals-box table { border: 1px solid #000; }
            .totals-box td { border-bottom: 1px solid #000; padding: 4px 6px; font-size: 12px;}
            .grand-total-row td { background: #f1f5f9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
            .payment-table th, .payment-table td, .payment-table tfoot td { border: 1px solid #000; padding: 4px 8px !important; font-size: 11px !important; line-height: 1.4;}
            .payment-table th, .payment-table tfoot td { background: #f0f0f0 !important; font-weight: bold; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
            .inline-cat { display: none !important; } 
            .drag-handle { display: none !important; }
            .print-keep-together { page-break-inside: avoid; }
            
            /* Print Modal Fixes */
            body.printing-modal .app-page.active { display: none !important; }
            body.printing-modal .modal-overlay:not(#doc-modal) { display: none !important; }
            body.printing-modal #doc-modal { position: static !important; background: white !important; padding: 0 !important; display: block !important; }
            body.printing-modal #doc-modal > div { box-shadow: none !important; width: 100% !important; max-width: 100% !important; height: auto !important; max-height: none !important; overflow: visible !important; border: none !important; }
            body.printing-modal #doc-modal-content { padding: 0 !important; max-width: 100% !important; overflow: visible !important; }
            body.printing-modal .doc-modal-header,
            body.printing-modal .doc-modal-footer { display: none !important; }
        }

        /* Responsive Fixes */
        @media (max-width: 1100px) {
            .project-grid { grid-template-columns: repeat(2, 1fr); }
            .split-layout { flex-direction: column; }
            .data-section, .form-card, .content-card { width: 100%; flex: none; }
        }
        @media (max-width: 920px) {
            .quote-header-grid { grid-template-columns: 1fr; gap: 18px; }
            .quote-header-left { width: 100%; }
            .quote-header-right { justify-content: flex-start; }
            .customer-card { max-width: 100%; }
            #documentMainTitle { font-size: 1.8em !important; text-align: right !important; }
            .company-logo-group img { max-width: 120px !important; }
            .company-logo-group div { font-size: 0.92em !important; }
            .company-details-section .clean-input { font-size: 0.9em; line-height: 1.35; }
        }

        @media (max-width: 560px) {
            .sidebar { position: absolute; height: 100%; transform: translateX(-100%); margin-left: 0 !important; }
            .sidebar.collapsed { transform: translateX(-100%); }
            .sidebar.open { transform: translateX(0); }
            .overlay { display: none; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 90; }
            .overlay.active { display: block; }
            .project-grid { grid-template-columns: 1fr; }
            .quote-header-grid { grid-template-columns: 1fr; gap: 20px;}
            .quote-header-grid > div { width: 100% !important; text-align: left !important; }
            .quote-header-left, .quote-header-right { order: initial; }
            .quote-header-left { justify-self: stretch; align-items: flex-start; width: 100%; margin-left: 0; }
            .quote-header-right { justify-content: flex-start; }
            .document-info-section { text-align: left; align-items: flex-start; }
            .quote-meta-row { justify-content: flex-start; }
            .customer-details-section { align-items: flex-start; }
            .company-logo-group { align-items: flex-start; }
            .company-details-section { align-items: flex-start; text-align: left; }
            .company-details-section .clean-input { text-align: left; }
            .totals-wrapper { flex-direction: column; gap: 20px;}
            .amount-in-words, .totals-box { width: 100% !important; }
        }

        /* DPR Selection Styles */
        .dpr-media-select {
            width: 20px !important;
            height: 20px !important;
            cursor: pointer;
            accent-color: #2563eb;
            margin: 0 8px 0 0 !important;
            vertical-align: middle;
            display: inline-block !important;
            visibility: visible !important;
            opacity: 1 !important;
        }
        .dpr-label {
            display: flex !important;
            align-items: center;
            justify-content: center;
            background: #eff6ff !important;
            padding: 6px 12px !important;
            border-radius: 4px;
            border: 1px solid #bfdbfe;
            color: #1e3a8a !important;
            font-weight: bold;
            font-size: 13px !important;
            cursor: pointer;
            margin-top: 8px !important;
            user-select: none;
            width: 100%;
        }
        .dpr-label:hover { background: #dbeafe !important; }
        
        /* .no-print is handled in @media print block below */

        /* DPR Media Preview in Form */
        .dpr-preview-container {
            display: flex;
            gap: 8px;
            flex-wrap: wrap;
            margin-bottom: 15px;
            padding: 10px;
            background: #f1f5f9;
            border-radius: 6px;
            border: 1px dashed #cbd5e1;
            min-height: 40px;
        }
        .dpr-preview-item {
            width: 50px;
            height: 50px;
            object-fit: cover;
            border-radius: 4px;
            border: 2px solid #3b82f6;
        }

        /* Media Selection Styles */
        .selected-media-card {
            border: 3px solid #3b82f6 !important;
            background: #eff6ff !important;
            box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2) !important;
            transform: translateY(-2px);
            position: relative;
        }
        .selected-media-card::after {
            content: '✓';
            position: absolute;
            top: -10px;
            right: -10px;
            background: #3b82f6;
            color: white;
            width: 24px;
            height: 24px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 14px;
            font-weight: bold;
            border: 2px solid white;
            z-index: 5;
        }

/* ==========================================
   LOGIN SCREEN & AUTH PROTECTION
   ========================================== */
.login-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease, visibility 0.5s;
}

.login-card {
    background: rgba(255, 255, 255, 0.98);
    padding: 40px;
    border-radius: 20px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.login-header {
    text-align: center;
    margin-bottom: 35px;
}

.login-logo {
    width: 160px;
    height: auto;
    margin-bottom: 20px;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.1));
}

.login-header h2 {
    color: #0f172a;
    font-size: 26px;
    font-weight: 800;
    margin-bottom: 10px;
    letter-spacing: -0.5px;
}

.login-header p {
    color: #64748b;
    font-size: 14px;
    line-height: 1.5;
}

.login-card .form-group label {
    color: #1e293b;
    font-size: 13px;
    margin-bottom: 8px;
}

/* ==========================================
   FLOATING CALCULATOR WIDGET
   ========================================== */
.calc-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 320px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    z-index: 10000;
    font-family: 'Inter', system-ui, sans-serif;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    user-select: none;
    transform: translate3d(0,0,0);
    transition: opacity 0.3s;
}

.calc-header {
    background: #1e293b;
    color: white;
    padding: 10px 15px;
    cursor: move;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
}

.calc-header .actions { display: flex; gap: 10px; }
.calc-header .btn-icon { cursor: pointer; opacity: 0.8; transition: 0.2s; }
.calc-header .btn-icon:hover { opacity: 1; }

.calc-display {
    padding: 20px;
    background: #f8fafc;
    text-align: right;
    border-bottom: 1px solid #e2e8f0;
}

.calc-expression { font-size: 12px; color: #64748b; min-height: 18px; margin-bottom: 4px; }
.calc-result { font-size: 28px; font-weight: 700; color: #0f172a; word-break: break-all; }

.calc-sync-panel {
    background: #eff6ff;
    padding: 8px 15px;
    font-size: 11px;
    color: #1e40af;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #dbeafe;
}

.calc-body { padding: 15px; }

.calc-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.calc-btn {
    padding: 12px;
    border: 1px solid #e2e8f0;
    background: white;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.1s;
    text-align: center;
}

.calc-btn:hover { background: #f1f5f9; border-color: #cbd5e1; }
.calc-btn:active { transform: scale(0.95); background: #e2e8f0; }
.calc-btn.op { background: #f1f5f9; color: #3b82f6; }
.calc-btn.eq { background: #3b82f6; color: white; grid-column: span 2; }
.calc-btn.clear { color: #ef4444; }

.calc-history {
    display: none;
    max-height: 200px;
    overflow-y: auto;
    background: white;
    border-top: 1px solid #e2e8f0;
    padding: 10px;
    font-size: 12px;
}

.calc-history.active { display: block; }
.history-item { 
    padding: 6px 0; 
    border-bottom: 1px solid #f1f5f9; 
    display: flex; 
    justify-content: space-between;
}
.history-item:last-child { border-bottom: none; }

body.is-authenticated .calc-widget { display: none; flex-direction: column; }
body.is-authenticated .calc-launcher { display: flex; }
body:not(.is-authenticated) .calc-widget, body:not(.is-authenticated) .calc-launcher { display: none; }

.calc-launcher {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: #1e293b;
    color: white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    z-index: 9999;
    transition: transform 0.2s;
}
.calc-launcher:hover { transform: scale(1.1); background: #334155; }

.login-card input {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    padding: 12px 15px;
    font-size: 15px;
    color: #0f172a;
    transition: all 0.2s;
}

.login-card input:focus {
    background: #fff;
    border-color: #3b82f6;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.btn-login {
    width: 100%;
    padding: 14px;
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 15px;
    box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.3);
}

.btn-login:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: 0 10px 15px -3px rgba(59, 130, 246, 0.4);
}

.btn-login:active {
    transform: translateY(0);
}

.login-error {
    color: #ef4444;
    background: #fee2e2;
    padding: 12px;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
    margin-bottom: 20px;
    font-weight: 600;
    border: 1px solid #fecaca;
}

.login-footer {
    margin-top: 35px;
    text-align: center;
    font-size: 12px;
    color: #94a3b8;
    border-top: 1px solid #f1f5f9;
    padding-top: 20px;
}

/* Hide restricted UI when not authenticated */
body:not(.is-authenticated) .sidebar,
body:not(.is-authenticated) .main-content,
body:not(.is-authenticated) .overlay,
body:not(.is-authenticated) .modal-overlay {
    display: none !important;
}

/* Hide login screen when authenticated */
body.is-authenticated .login-screen {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}


#libraryTableDash thead th, #packagesTable thead th { position: sticky; top: 0; background-color: #f8fafc; z-index: 5; box-shadow: 0 1px 2px rgba(0,0,0,0.1); }
