:root {
    --primary: #0a2540; --primary-hover: #1e3a5a; --secondary: #00d2ff; --accent: #00b4d8; 
    --bg-dark: #f8fafc; --bg-card: #ffffff; --text-main: #0f172a; --text-muted: #64748b; 
    --border: #e2e8f0; --glass-bg: rgba(255, 255, 255, 0.8); --glass-border: rgba(10, 37, 64, 0.1);
    --shadow: 0 4px 6px -1px rgba(10, 37, 64, 0.1), 0 2px 4px -1px rgba(10, 37, 64, 0.06); 
    --font-main: 'Inter', sans-serif; --font-display: 'Outfit', sans-serif;
    --report-header-bg: #f8fafc;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: var(--font-main); background-color: var(--bg-dark); color: var(--text-main); min-height: 100vh; overflow-x: hidden; }
.layout-container { display: flex; height: 100vh; width: 100vw; overflow: hidden; }
.sidebar { width: 260px; height: 100%; background: #ffffff; border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 20px 15px; flex-shrink: 0; transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s cubic-bezier(0.4, 0, 0.2, 1); position: relative; }
.sidebar.collapsed { width: 70px; padding: 20px 8px; }
.sidebar-logo { font-family: var(--font-display); font-size: 1.3rem; font-weight: 700; margin-bottom: 24px; color: var(--primary); display: flex; align-items: center; gap: 8px; cursor: pointer; justify-content: center; overflow: hidden; white-space: nowrap; transition: 0.2s; }

.nav-link { display: flex; align-items: center; gap: 12px; padding: 12px 14px; color: #64748b; border-radius: 10px; margin-bottom: 4px; font-weight: 600; font-size: 0.95rem; letter-spacing: -0.3px; transition: all 0.2s ease-in-out; background: none; border: none; width: 100%; text-align: left; cursor: pointer; justify-content: flex-start; overflow: hidden; white-space: nowrap; position: relative; }
.nav-link .menu-label { transition: opacity 0.2s; }
.sidebar.collapsed .nav-link { padding: 14px 0; justify-content: center; border-radius: 12px; }
.sidebar.collapsed .nav-link .menu-label { opacity: 0; width: 0; display: none; }
.sidebar.collapsed .nav-link svg { margin: 0 auto; }
.nav-link:hover, .nav-link.active { background: rgba(10, 37, 64, 0.05); color: var(--primary); }

.sidebar-toggle-btn { margin-top: auto; display: flex; align-items: center; justify-content: center; padding: 12px; cursor: pointer; color: var(--text-muted); background: none; border: none; border-radius: 8px; transition: 0.2s; width: 100%; }
.sidebar-toggle-btn:hover { background: rgba(10, 37, 64, 0.05); color: var(--primary); }

.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; position: relative; }
.top-bar { height: 60px; padding: 0 32px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); background: #ffffff; flex-shrink: 0; }
.glass-card { background: var(--bg-card); backdrop-filter: blur(8px); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
.btn-primary { background: var(--primary); color: white; border: none; padding: 10px 20px; border-radius: 4px; font-weight: 600; cursor: pointer; transition: 0.2s; display: flex; align-items: center; gap: 8px; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }

/* Pane Layout */
.pane-left { width: 320px; border-right: 1px solid var(--border); background: #ffffff; display: flex; flex-direction: column; padding: 20px; flex-shrink: 0; height: 100%; overflow-y: auto; }
.pane-right { flex: 1; background: #f1f5f9; overflow-y: auto; display: flex; flex-direction: column; align-items: center; padding: 40px 0; }

/* Doc List Items */
.doc-list-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 8px; margin-bottom: 4px; cursor: pointer; transition: 0.2s; border: 1px solid transparent; }
.doc-list-item:hover { background: #f8fafc; border-color: var(--border); }
.doc-list-item.active { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.month-header { padding: 10px 12px; font-weight: 800; color: var(--primary); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; display: flex; align-items: center; justify-content: space-between; cursor: pointer; margin-top: 10px; }

/* Report PDF High-Fidelity Styles */
.report-container { background: white; color: #1e293b; padding: 50px 40px; width: 1060px; height: 1499px; box-sizing: border-box; display: flex; flex-direction: column; overflow: hidden; position: relative; box-shadow: 0 10px 25px rgba(0,0,0,0.1); border-radius: 4px; }
.paper-inner { flex: 1; display: flex; flex-direction: column; }
.report-title-box { text-align: center; margin-bottom: 25px; position: relative; }
.report-title-box h1 { font-family: var(--font-display); font-size: 2.5rem; font-weight: 900; color: var(--primary); text-transform: uppercase; letter-spacing: 0.05em; }
.report-title-box .page-tag { font-size: 0.9rem; color: var(--accent); margin-top: 8px; font-weight: 700; }
.report-title-box::after { content: ''; display: block; width: 80px; height: 4px; background: var(--accent); margin: 10px auto 0; }

.report-section { margin-bottom: 25px; }
.report-section-title { font-size: 0.95rem; font-weight: 800; color: var(--primary); margin-bottom: 12px; text-transform: uppercase; border-bottom: 2px solid var(--primary); padding-bottom: 4px; }

.info-grid { border: 1px solid #cbd5e1; border-radius: 4px; overflow: hidden; display: flex; flex-direction: column; }
.info-row { display: flex; border-bottom: 1px solid #e2e8f0; }
.info-row:last-child { border-bottom: none; }
.info-cell { display: flex; flex: 1; border-right: 1px solid #e2e8f0; }
.info-cell:last-child { border-right: none; }
.info-label { width: 130px; background: #f8fafc; padding: 10px 15px; font-size: 0.8rem; font-weight: 700; color: var(--primary); border-right: 1px solid #e2e8f0; display: flex; align-items: center; }
.info-value { flex: 1; padding: 10px 15px; font-size: 0.85rem; display: flex; align-items: center; }

.inspection-table { width: 100%; border-collapse: collapse; border: 1px solid #cbd5e1; }
.inspection-table th { background: #f8fafc; padding: 10px; font-size: 0.85rem; font-weight: 700; color: var(--primary); border: 1px solid #cbd5e1; text-align: center; }
.inspection-table td { padding: 8px 12px; font-size: 0.85rem; border: 1px solid #cbd5e1; height: 36px; position: relative; }
.status-pill { padding: 4px 10px; border-radius: 4px; font-weight: 800; font-size: 0.75rem; display: inline-flex; align-items: center; gap: 4px; }
.status-normal { color: #059669; }
.status-abnormal { color: #ef4444; }

/* Merge cell style */
.merged-cell { border-top: 1px solid transparent !important; color: transparent !important; }
.merged-cell::before { content: ''; }

.remarks-box { border: 1px solid #cbd5e1; border-radius: 4px; flex: 1; min-height: 100px; padding: 15px; font-size: 0.85rem; color: #334155; line-height: 1.6; }

.footer-area { margin-top: auto; padding-top: 20px; border-top: 1px solid #e2e8f0; display: flex; justify-content: space-between; align-items: flex-end; }
.footer-logo { display: flex; align-items: center; gap: 10px; font-weight: 900; color: var(--primary); opacity: 0.8; }
.footer-text { font-size: 0.75rem; color: var(--text-muted); line-height: 1.4; }

/* Account Management */
.status-badge { padding: 4px 8px; border-radius: 99px; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; }
.status-badge.success { background: #d1fae5; color: #065f46; }
.status-badge.failure { background: #fee2e2; color: #991b1b; }

/* Utilities */
.form-input { width: 100%; padding: 10px 12px; background: #ffffff; border: 1px solid var(--border); border-radius: 6px; color: var(--text-main); outline: none; margin-bottom: 12px; font-size: 0.9rem; transition: 0.2s; }
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0, 210, 255, 0.1); }
.btn-icon { background: none; border: none; padding: 6px; cursor: pointer; color: var(--text-muted); transition: 0.2s; border-radius: 4px; }
.btn-icon:hover { background: #f1f5f9; color: var(--primary); }

.tab-btn { padding: 10px 20px; border: none; background: none; font-weight: 700; color: var(--text-muted); cursor: pointer; border-bottom: 3px solid transparent; transition: 0.2s; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

@page {
    size: A4 portrait;
    margin: 0mm !important;
}

@media print {
    /* ===== 1. Global Reset ===== */
    body, html {
        margin: 0 !important;
        padding: 0 !important;
        width: 210mm !important;
        height: 297mm !important;
        min-height: 0 !important;
        background: white !important;
        overflow: hidden !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body * {
        visibility: hidden;
    }

    /* ===== 2. Hide ALL UI chrome ===== */
    .sidebar, .top-bar, .pane-left, .doc-toolbar, .report-toolbar,
    .btn-primary, [role="button"], #sidebar, .modal-overlay,
    .hide-on-print, button, .bulk-action-bar {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        overflow: hidden !important;
    }

    /* ===== 3. Flatten every layout wrapper to static ===== */
    .layout-container, .main-content, .pane-right, .report-pane-right, 
    .report-content-scroll, .report-scroll-inner, .troubleshoot-module-root,
    .trade-module-root,
    #root, [data-reactroot], #quote-pdf-wrapper {
        position: static !important;
        display: block !important;
        width: 210mm !important;
        height: auto !important;
        max-height: none !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        border: none !important;
        box-shadow: none !important;
        background: transparent !important;
    }

    /* ===== 4. The actual printable document — visibility ===== */
    .print-surface, .print-surface *,
    .report-container, .report-container *,
    #contract-container, #contract-container *,
    .pdf-page-capture, .pdf-page-capture * {
        visibility: visible !important;
    }
    
    /* ===== 5. Force print-surface to fill exactly 1 A4 page ===== */
    .print-surface, .report-container, #contract-container, .pdf-page-capture {
        position: relative !important;
        width: 210mm !important;
        height: 297mm !important;
        min-height: 297mm !important;
        max-height: 297mm !important;
        margin: 0 !important;
        padding: 5mm 8mm !important;
        background: white !important;
        box-shadow: none !important;
        border: none !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        page-break-inside: avoid;
        display: flex !important;
        flex-direction: column !important;
    }

    /* ===== 6. Stretch inner table area to fill remaining height ===== */
    .print-surface table {
        flex: 1;
    }
    .print-surface table tbody {
        display: table-row-group;
    }
    /* Empty rows stretch to fill space */
    .print-surface table tr {
        height: auto !important;
    }
    .print-surface table tbody tr:empty,
    .print-surface table tbody tr td:empty {
        height: auto !important;
    }

    /* ===== 7. Compress padding for density ===== */
    .print-surface table th, .print-surface table td {
        padding-top: 1px !important;
        padding-bottom: 1px !important;
    }
    .remarks-box {
        min-height: 30px !important;
        padding: 4px 8px !important;
    }
    .report-title-box {
        margin-bottom: 3px !important;
    }
    .report-section {
        margin-bottom: 3px !important;
    }
    .info-label {
        padding: 6px 10px !important;
    }
    .info-value {
        padding: 6px 10px !important;
    }

    /* ===== 8. Quote-specific: make items table fill remaining page ===== */
    .quote-pdf-page {
        height: 297mm !important;
        min-height: 297mm !important;
        max-height: 297mm !important;
        display: flex !important;
        flex-direction: column !important;
        padding: 5mm 8mm !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }
    .quote-pdf-page table {
        flex: 1 1 auto !important;
    }
    .quote-pdf-page table tbody tr {
        height: 1fr !important;
    }

    /* ===== 9. Multi-page support ===== */
    .pdf-page-capture {
        page-break-after: always;
        break-after: page;
    }
    .pdf-page-capture:last-child {
        page-break-after: auto;
        break-after: auto;
    }
    .quote-pdf-page {
        page-break-after: always !important;
        break-after: page !important;
    }
    .quote-pdf-page:last-child {
        page-break-after: auto !important;
        break-after: auto !important;
    }

    /* ===== 10. Report container inner layout fix ===== */
    .report-container .paper-inner {
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
    }
}

/* WBS Edit Mode Stage Input Placeholder */
.wbs-stage-input::placeholder { color: rgba(15, 23, 42, 0.4); font-weight: 500; font-size: 0.8rem; }

.rich-editor:empty:before { content: attr(data-placeholder); color: #94a3b8; pointer-events: none; display: block; }
