:root { 
    --primary-color: #2c3e50; 
    --accent-color: #27ae60; 
    --danger-color: #e74c3c; 
}

body { 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    background: #f0f2f5; 
    display: flex; 
    margin: 0; 
    position: relative;
}

/* --- Sidebar (Old Style) --- */
.sidebar { 
    width: 300px; 
    background: var(--primary-color); 
    color: white; 
    padding: 20px; 
    height: 100vh; 
    position: fixed; 
    overflow-y: auto; 
    z-index: 1000; 
    box-sizing: border-box;
}
.sidebar h2 { 
    border-bottom: 1px solid #555; 
    padding-bottom: 10px; 
    margin-top: 0; 
}

.control-group { 
    margin-bottom: 15px; 
}
.control-group label { 
    display: block; 
    margin-bottom: 5px; 
    font-size: 0.9rem; 
    color: #bdc3c7; 
}
input[type="number"], 
input[type="file"], 
select { 
    width: 100%; 
    padding: 8px; 
    border-radius: 4px; 
    border: none; 
}

.btn { 
    width: 100%; 
    padding: 10px; 
    border: none; 
    cursor: pointer; 
    font-weight: bold; 
    border-radius: 4px; 
    margin-bottom: 10px; 
    color: white; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    gap: 8px; 
}
.btn-print { 
    background: var(--accent-color); 
}
.btn-csv { 
    background: #2980b9; 
}
.btn-reset { 
    background: var(--danger-color); 
    margin-top: 20px; 
}

.save-msg { 
    color: #2ecc71; 
    font-size: 0.8rem; 
    text-align: center; 
    display: none; 
    margin-bottom: 10px; 
}

/* Toggle Switch */
.switch { 
    position: relative; 
    display: inline-block; 
    width: 50px; 
    height: 24px; 
}
.switch input { 
    opacity: 0; 
    width: 0; 
    height: 0; 
}
.slider { 
    position: absolute; 
    cursor: pointer; 
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0; 
    background-color: #ccc; 
    transition: .4s; 
    border-radius: 24px; 
}
.slider:before { 
    position: absolute; 
    content: ""; 
    height: 16px; 
    width: 16px; 
    left: 4px; 
    bottom: 4px; 
    background-color: white; 
    transition: .4s; 
    border-radius: 50%; 
}
input:checked + .slider { 
    background-color: var(--accent-color); 
}
input:checked + .slider:before { 
    transform: translateX(26px); 
}

/* --- TTS Logo Header with Line --- */
.header-container {
    position: fixed;
    top: 0;
    left: 300px; /* Sidebar width */
    right: 0;
    height: 80px;
    background: transparent;
    z-index: 999;
    display: flex;
    align-items: center;
    padding: 0 20px;
}

.header-line {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #ff6b00, #ffa500, #ff4500);
    z-index: 1;
}

.tts-logo {
    position: relative;
    z-index: 2;
    margin-left: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo-circle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(45deg, #ff6b00, #ffa500, #ff4500, #ff8c00);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 20px rgba(255, 69, 0, 0.6), 0 0 40px rgba(255, 107, 0, 0.4);
    animation: flame 3s infinite alternate;
}

@keyframes flame {
    0% { 
        box-shadow: 0 0 15px rgba(255, 69, 0, 0.4), 0 0 30px rgba(255, 165, 0, 0.3); 
    }
    100% { 
        box-shadow: 0 0 25px rgba(255, 107, 0, 0.6), 0 0 50px rgba(255, 69, 0, 0.4); 
    }
}

.logo-text {
    color: #fff;
    font-size: 24px;
    font-weight: bold;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
}

.logo-name {
    font-size: 22px;
    font-weight: bold;
    color: #ff4500;
    letter-spacing: 1px;
    text-shadow: 0 0 10px rgba(255, 69, 0, 0.3);
}

.logo-flame {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 15px;
    background: linear-gradient(to top, transparent, #ff4500);
    border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
    filter: blur(4px);
    animation: flicker 1.5s infinite alternate;
}

@keyframes flicker {
    0% { 
        opacity: 0.7; 
        height: 12px; 
    }
    100% { 
        opacity: 1; 
        height: 18px; 
    }
}

.thank-you-text {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
    color: #666;
    font-style: italic;
    z-index: 2;
}

/* --- Invoice Container --- */
.invoice-container { 
    margin-left: 320px; 
    padding: 40px; 
    width: calc(100% - 320px); 
    display: flex; 
    justify-content: center;
    margin-top: 100px; /* Header ke niche se start */
}

.paper { 
    width: 210mm; 
    min-height: 297mm; 
    background: white; 
    padding: 15mm 20mm; /* Standard Margins */
    box-shadow: 0 0 15px rgba(0,0,0,0.1); 
    display: flex; 
    flex-direction: column; 
    position: relative;
    box-sizing: border-box;
}

/* Watermark for Locked Form */
.watermark {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-45deg);
    font-size: 60px;
    color: rgba(255, 0, 0, 0.1);
    font-weight: bold;
    pointer-events: none;
    z-index: 100;
}

.doc-title { 
    text-align: center; 
    font-size: 2rem; 
    font-weight: bold; 
    text-decoration: underline; 
    margin-bottom: 15px; 
    margin-top: 10px;
}

.ref-date-row { 
    display: flex; 
    justify-content: space-between; 
    border-bottom: 2px solid #333; 
    padding-bottom: 5px; 
    margin-bottom: 20px; 
    padding-top: 10px;
}

/* Tables */
table { 
    width: 100%; 
    border-collapse: collapse; 
}
th, td { 
    border: 1px solid #000; 
    padding: 6px; 
    vertical-align: top; 
}

.clean-input { 
    width: 100%; 
    border: none; 
    text-align: right; 
    outline: none; 
    font-family: inherit; 
    font-size: inherit; 
    background: transparent; 
}
.address-table td { 
    width: 50%; 
    height: 90px; 
}
.item-table th { 
    background: #f8f9fa; 
}

.add-row-btn { 
    background: #eee; 
    border: 1px dashed #999; 
    text-align: center; 
    padding: 5px; 
    cursor: pointer; 
    margin-top: 10px; 
}
.del-btn { 
    color: red; 
    cursor: pointer; 
    margin-left: 5px; 
    opacity: 0.5; 
}
.del-btn:hover { 
    opacity: 1; 
}

/* Footer - Signature RIGHT SIDE FIXED with touching line */
.footer-section { 
    margin-top: auto; 
    padding-top: 20px; 
    display: flex; 
    justify-content: space-between; 
    align-items: flex-end; 
}
.footer-left { 
    width: 60%; 
} 
.footer-right { 
    width: 38%; 
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}
.bank-box, 
.terms-box { 
    border: 1px solid #eee; 
    padding: 8px; 
    margin-bottom: 8px; 
    font-size: 0.85rem; 
}

/* Signature Area - RIGHT SIDE FIXED with touching line */
.signature-box {
    text-align: right;
    width: 100%;
}

.signature-upload { 
    cursor: pointer; 
    margin-bottom: 0; /* REMOVED margin so line touches */
    text-align: right;
    display: inline-block;
    position: relative;
}
.signature-img { 
    max-height: 70px; 
    max-width: 200px; 
    object-fit: contain; 
    display: none;
    margin-bottom: 0; /* REMOVED margin */
}
#sigUploadText { 
    color: #aaa; 
    font-size: 0.85rem; 
    white-space: nowrap; 
    border: 1px dashed #ccc;
    padding: 5px;
    display: inline-block;
    text-align: right;
    margin-bottom: 0; /* REMOVED margin */
}

.sign-text {
    font-weight: bold;
    margin-bottom: 8px;
    text-align: right;
    width: 100%;
}

.authorised-line {
    border-top: 1px solid #000; 
    width: 100%; 
    margin-top: 0; /* CHANGED from 5px to 0 to touch signature */
    padding-top: 3px;
    text-align: center;
}

/* Totals Section */
.totals-section {
    margin-top: 20px;
    width: 100%;
}

.totals-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

.totals-table td {
    border: 1px solid #000;
    padding: 10px;
    text-align: right;
    font-size: 1rem;
}

.totals-table tr:last-child {
    background: #f9f9f9;
    font-weight: bold;
}

/* Editable Fields Styling */
.editable-field {
    min-width: 150px;
    display: inline-block;
    border-bottom: 1px dashed #ccc;
    padding: 2px 4px;
    cursor: text;
}

/* Logo Upload Area - Fixed for PDF generation */
.logo-upload-area {
    text-align: center;
    margin-bottom: 15px;
    padding: 0 10px; /* Added padding to prevent shrinking */
}
.logo-upload-img {
    max-height: 100px;
    max-width: 100%;
    object-fit: contain;
    display: none;
}

/* --- CRITICAL PRINT FIXES - FORM LOGO SHRINKING FIXED --- */
@media print {
    @page { 
        margin: 0; 
        size: A4 portrait; /* Fixed A4 Size */
    }
    
    body { 
        display: block; /* Reset Flexbox */
        background: white; 
        margin: 0; 
        padding: 0;
        width: 210mm;
        height: 297mm;
    }

    /* Hide Sidebar, Header & Buttons */
    .sidebar, 
    .add-row-btn, 
    .del-btn, 
    .save-msg, 
    #sigUploadText, 
    .watermark, 
    .home-btn, 
    .header-container, 
    .thank-you-text { 
        display: none !important; 
    }

    /* Reset Container to 0 margin */
    .invoice-container { 
        margin: 0 !important; 
        padding: 0 !important; 
        width: 100% !important; 
        display: block !important;
        margin-top: 0 !important;
    }

    /* Force Paper to fit exactly A4 width - FIXED LOGO SHRINKING */
    .paper {
        width: 210mm !important;
        height: 297mm !important;
        margin: 0 !important;
        padding: 15mm 20mm !important; /* Fixed margins */
        box-shadow: none !important;
        border: none !important;
        overflow: hidden !important;
        page-break-inside: avoid;
        page-break-after: avoid;
    }

    /* Prevent Table Overflow */
    table { 
        width: 100% !important; 
        table-layout: fixed; 
    } 
    td { 
        word-wrap: break-word; 
    } /* Break long words if needed */
    
    /* Clean up Inputs */
    input { 
        border: none !important; 
        background: transparent !important; 
        padding: 0 !important; 
    }
    .clean-input { 
        text-align: right; 
    }
    
    /* Ensure footer doesn't break weirdly */
    .footer-section { 
        page-break-inside: avoid; 
    }
    
    /* Show signature image in print */
    .signature-img { 
        display: block !important; 
        max-height: 60px !important;
    }
    
    /* Show uploaded logo in print if exists - FIXED SHRINKING */
    .logo-upload-img {
        display: block !important;
        max-height: 80px !important;
        margin: 0 auto !important;
        width: auto !important;
        min-width: 150px !important; /* Prevent shrinking */
    }
    
    /* Hide upload text in print */
    #uploadText {
        display: none !important;
    }
    
    /* Ensure proper alignment */
    .footer-right {
        text-align: right !important;
        align-items: flex-end !important;
    }
    
    /* Prevent logo area shrinking in PDF */
    .logo-upload-area {
        padding: 0 !important;
        margin: 0 auto 15px !important;
        width: 100% !important;
        min-height: 80px !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
    }
    
    /* Ensure no overflow */
    * {
        overflow: visible !important;
        box-sizing: border-box;
    }
    
    /* Fix for logo positioning */
    .logo-upload-area img {
        position: relative !important;
        left: auto !important;
        right: auto !important;
    }
}

/* ===== DONATION MODAL ===== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1002;
}
.modal-box {
    background: #fff;
    width: 400px;
    padding: 20px;
    margin: 10% auto;
    text-align: center;
    border-radius: 8px;
}

.donate-qr {
    width: 220px;
    height: 220px;
    margin: 10px auto;
    display: block;
    border: 1px solid #eee;
    border-radius: 8px;
}

/* SLOT TOOLS */
.slot-tools input {
    width: 100%;
    margin-bottom: 6px;
}

/* Hide file inputs properly */
#signInput, #logoInput {
    display: none;
}

/* Make signature upload area more visible */
.signature-upload:hover #sigUploadText {
    border-color: #27ae60;
}

/* Home Button */
.home-btn {
    background: #3498db;
    color: white;
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 20px;
    text-decoration: none;
    font-size: 0.9rem;
}
.home-btn:hover {
    background: #2980b9;
}