:root {
    --bg-color: #050510;
    --panel-bg: rgba(13, 16, 33, 0.65);
    --border-color: rgba(255,255,255,0.06);
    --primary-color: #9333ea;
    --primary-hover: #a855f7;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #06b6d4;
    --paper-bg: #ffffff;
    --paper-text: #1e293b;
    --paper-border: #e2e8f0;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(147, 51, 234, 0.3);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(168, 85, 247, 0.6);
}

body {
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(circle at 15% 25%, rgba(147, 51, 234, 0.15) 0%, transparent 35%),
        radial-gradient(circle at 85% 75%, rgba(6, 182, 212, 0.1) 0%, transparent 40%),
        radial-gradient(circle at 50% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
}

#splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--bg-color);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.8s ease;
}

#splash-screen img {
    height: 120px;
    background-color: #ffffff;
    padding: 15px 30px;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
    animation: zoomIntro 2.5s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes zoomIntro {
    0% { transform: scale(0.5); opacity: 0; }
    40% { transform: scale(1.1); opacity: 1; }
    70% { transform: scale(1); opacity: 1; }
    100% { transform: scale(3); opacity: 0; }
}

.splash-hidden {
    opacity: 0;
    pointer-events: none;
}

input, select, textarea, button {
    font-family: inherit;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Editor Panel (Left) */
.editor-panel {
    width: 450px;
    background-color: var(--panel-bg);
    border-right: 1px solid var(--border-color);
    box-shadow: inset -1px 0 0 rgba(255,255,255,0.02), 10px 0 30px rgba(0,0,0,0.5);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.editor-header h1 {
    font-size: 1.5rem;
    background: linear-gradient(135deg, #a855f7, #06b6d4);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.25rem;
    text-shadow: 0 0 20px rgba(168, 85, 247, 0.2);
}

.editor-header p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.form-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: rgba(255, 255, 255, 0.02);
    padding: 1.5rem;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease, border-color 0.3s ease;
}

.form-section:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3), 0 0 15px rgba(147, 51, 234, 0.15);
    border-color: rgba(147, 51, 234, 0.3);
}

.form-section h3 {
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.row {
    display: flex;
    gap: 1rem;
}

.half {
    flex: 1;
    min-width: 0;
}

input, select, textarea {
    width: 100%;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: 10px;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    appearance: none;
    resize: vertical;
}

input[type="file"] {
    padding: 0.5rem;
    background: transparent;
    border: 1px dashed var(--border-color);
    cursor: pointer;
}
input[type="file"]::file-selector-button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    margin-right: 1rem;
}
select option {
    background: var(--panel-bg);
    color: var(--text-primary);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(147, 51, 234, 0.3), 0 0 15px rgba(147, 51, 234, 0.2), inset 0 2px 4px rgba(0,0,0,0.2);
    background: rgba(0, 0, 0, 0.4);
}

/* Dynamic Item Row */
.item-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    align-items: center;
}
.item-row input[type="text"] { flex: 2; }
.item-row input[type="number"] { flex: 1; }
.remove-btn {
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0.5rem;
    transition: transform 0.2s ease;
}
.remove-btn:hover { transform: scale(1.1); }

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    width: 100%;
}

.btn.primary {
    background: linear-gradient(135deg, #a855f7, #6366f1);
    color: white;
    font-size: 1rem;
    box-shadow: 0 4px 15px rgba(147, 51, 234, 0.4), inset 0 1px 0 rgba(255,255,255,0.2);
    border-radius: 12px;
}

.btn.primary:hover {
    background: linear-gradient(135deg, #c084fc, #818cf8);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(147, 51, 234, 0.6), inset 0 1px 0 rgba(255,255,255,0.3);
}

.btn.secondary {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.btn.secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255,255,255,0.2);
    box-shadow: 0 6px 15px rgba(0,0,0,0.3), 0 0 10px rgba(255,255,255,0.05);
}

/* Preview Panel (Right) */
.preview-panel {
    flex: 1;
    background: radial-gradient(circle at center, #1e2235 0%, #0d0f1a 100%);
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
}

.preview-wrapper {
    background: var(--paper-bg);
    padding: 40px;
    width: 100%;
    max-width: 800px;
    min-height: 1100px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.5);
    border-radius: 4px;
    color: var(--paper-text);
}

/* Invoice Design */
.invoice-container {
    padding: 20px;
    min-height: 1131px; /* Mathematically exactly A4 vertical scaling at 800px */
    position: relative;
    background-color: var(--paper-bg);
}

/* Premium Gold Edges */
#invoice-preview.gold-edges {
    border: 12px solid transparent;
    border-image: linear-gradient(135deg, #bf953f, #fcf6ba, #b38728, #fbf5b7, #aa771c) 1;
}
#invoice-preview.gold-edges::before {
    content: '';
    position: absolute;
    top: 6px; left: 6px; right: 6px; bottom: 6px;
    border: 1px solid rgba(191, 149, 63, 0.4);
    pointer-events: none;
}
#invoice-preview.dark-mode.gold-edges::before,
#invoice-preview.blue-mode.gold-edges::before {
    border-color: rgba(252, 246, 186, 0.2);
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid var(--paper-border);
    padding-bottom: 2rem;
    margin-bottom: 2rem;
}

.brand h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-color);
}

.brand p {
    color: #475569;
    font-size: 14px;
    margin-top: 4px;
}

.invoice-meta {
    text-align: right;
}

.invoice-meta .title {
    font-size: 32px;
    font-weight: 800;
    letter-spacing: 2px;
    color: var(--paper-border);
    margin-bottom: 12px;
}

.invoice-meta p {
    font-size: 14px;
    color: #475569;
    margin-bottom: 4px;
}

.invoice-body {
    margin-bottom: 2rem;
}

.bill-to {
    margin-bottom: 2rem;
}

.bill-to h3 {
    font-size: 14px;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.bill-to .highlight {
    font-weight: 700;
    font-size: 18px;
    color: var(--paper-text);
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.invoice-table th {
    background: #f8fafc;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 600;
    color: #475569;
    border-bottom: 2px solid var(--paper-border);
}
.invoice-table th:nth-child(1) { width: 50%; }
.invoice-table th:nth-child(2) { width: 10%; }
.invoice-table th:nth-child(3) { width: 20%; }
.invoice-table th:nth-child(4) { width: 20%; }

.invoice-table td {
    padding: 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--paper-border);
    color: #000000 !important;
    word-break: break-word;
}

.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

.invoice-footer {
    display: flex;
    justify-content: flex-end;
}

.totals-section {
    width: 300px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 14px;
    color: #475569;
}

.total-row.grand-total {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-color);
    border-top: 2px solid var(--paper-border);
    padding-top: 16px;
    margin-top: 8px;
}

.invoice-footer-note {
    margin-top: 4rem;
    text-align: center;
    font-size: 13px;
    color: #94a3b8;
}

/* Payment Info Baseline Colors */
#invoice-preview .payment-info-title {
    color: #334155 !important;
}
#invoice-preview .payment-info-text {
    color: #475569 !important;
}

/* Pro Badge */
.pro-badge {
    font-size: 0.6rem;
    background: var(--border-color);
    color: var(--text-secondary);
    padding: 3px 6px;
    border-radius: 4px;
    vertical-align: middle;
    margin-left: 8px;
    letter-spacing: 1px;
}
.pro-badge.active {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
}

/* Watermark */
.watermark {
    text-align: center;
    font-size: 11px;
    color: #94a3b8;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--paper-border);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.8);
    justify-content: center;
    align-items: center;
}
.modal-content {
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 2.5rem;
    width: 400px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}
.close-modal {
    color: var(--text-secondary);
    float: right;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}
.price-tag {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary-color);
    margin: 1.5rem 0;
}

/* Deep Blue & Dark Mode Shared Texts */
#invoice-preview.dark-mode { background-color: #121212 !important; color: #f8fafc !important; }
#invoice-preview.blue-mode { background-color: #0a1326 !important; color: #f8fafc !important; }

#invoice-preview.dark-mode *, #invoice-preview.blue-mode * { color: inherit; }

#invoice-preview.dark-mode .brand h2, 
#invoice-preview.dark-mode .total-row.grand-total span,
#invoice-preview.blue-mode .brand h2, 
#invoice-preview.blue-mode .total-row.grand-total span {
    color: var(--primary-color) !important;
}

#invoice-preview.dark-mode .invoice-table th,
#invoice-preview.blue-mode .invoice-table th {
    background-color: rgba(255,255,255,0.03) !important;
    border-bottom: 2px solid rgba(255,255,255,0.08);
    color: #94a3b8;
}

#invoice-preview.dark-mode .invoice-table td,
#invoice-preview.blue-mode .invoice-table td {
    border-bottom: 1px solid rgba(255,255,255,0.08);
    color: #f8fafc !important;
    word-break: break-word;
}

#invoice-preview.dark-mode .invoice-header,
#invoice-preview.dark-mode .total-row.grand-total,
#invoice-preview.dark-mode .watermark,
#invoice-preview.blue-mode .invoice-header,
#invoice-preview.blue-mode .total-row.grand-total,
#invoice-preview.blue-mode .watermark {
    border-color: rgba(255,255,255,0.08);
}

#invoice-preview.dark-mode .invoice-meta p,
#invoice-preview.dark-mode .bill-to h3,
#invoice-preview.dark-mode .total-row,
#invoice-preview.dark-mode .invoice-footer-note,
#invoice-preview.dark-mode .payment-info-title,
#invoice-preview.blue-mode .invoice-meta p,
#invoice-preview.blue-mode .bill-to h3,
#invoice-preview.blue-mode .total-row,
#invoice-preview.blue-mode .invoice-footer-note,
#invoice-preview.blue-mode .payment-info-title {
    color: #94a3b8 !important;
}

#invoice-preview.dark-mode .payment-info-text,
#invoice-preview.blue-mode .payment-info-text {
    color: #f8fafc !important;
}

/* Golden Mode Layer */
#invoice-preview.gold-mode { background: linear-gradient(135deg, #fcd34d 0%, #fbbf24 50%, #f59e0b 100%) !important; color: #1e293b !important; }
#invoice-preview.gold-mode * { color: inherit; }

#invoice-preview.gold-mode .brand h2, 
#invoice-preview.gold-mode .total-row.grand-total span { color: #451a03 !important; }

#invoice-preview.gold-mode .invoice-table th { background-color: rgba(255,255,255,0.4) !important; border-bottom: 2px solid rgba(69, 26, 3, 0.2); color: #451a03; }
#invoice-preview.gold-mode .invoice-table td { border-bottom: 1px solid rgba(69, 26, 3, 0.1); color: #1e293b !important; word-break: break-word; }

#invoice-preview.gold-mode .invoice-header,
#invoice-preview.gold-mode .total-row.grand-total,
#invoice-preview.gold-mode .watermark { border-color: rgba(69, 26, 3, 0.2); }

#invoice-preview.gold-mode .invoice-meta p,
#invoice-preview.gold-mode .bill-to h3,
#invoice-preview.gold-mode .total-row,
#invoice-preview.gold-mode .invoice-footer-note,
#invoice-preview.gold-mode .payment-info-title { color: #451a03 !important; }

#invoice-preview.gold-mode .payment-info-text { color: #1e293b !important; }

/* TEMPLATE ENGINES */
#invoice-preview.minimal-template .invoice-header { border-bottom: 1px solid var(--paper-border); padding-bottom: 1rem; }
#invoice-preview.minimal-template .invoice-table th { background: transparent; border-bottom: 2px solid rgba(0,0,0,0.5); }
#invoice-preview.minimal-template.dark-mode .invoice-table th { border-bottom: 2px solid rgba(255,255,255,0.5); }

#invoice-preview.corporate-template .invoice-header { background-color: var(--paper-border); padding: 2rem; margin: -40px -40px 2rem -40px; border-bottom: none; }
#invoice-preview.corporate-template.dark-mode .invoice-header, #invoice-preview.corporate-template.blue-mode .invoice-header { background-color: rgba(255,255,255,0.05); }

#invoice-preview.creative-template .invoice-header { flex-direction: row-reverse; border-bottom: 4px solid var(--primary-color); }
#invoice-preview.creative-template .invoice-meta { text-align: left; }
#invoice-preview.creative-template .brand { text-align: right; }
#invoice-preview.creative-template .brand img { margin-left: auto; margin-right: 0; }

#invoice-preview.executive-template .invoice-header { flex-direction: column; align-items: center; text-align: center; border-bottom: 1px solid var(--paper-border); }
#invoice-preview.executive-template .brand img { margin: 0 auto 10px auto; }
#invoice-preview.executive-template .invoice-meta { text-align: center; margin-top: 15px; display: flex; justify-content: center; gap: 20px; }
#invoice-preview.executive-template .invoice-meta p { margin: 0; }

#invoice-preview.bold-template .title { font-size: 50px; color: var(--primary-color); }
#invoice-preview.bold-template .invoice-table th { background: var(--primary-color) !important; color: #fff !important; border: none; }

/* AI Dictation Button */
.ai-dictate-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(99, 102, 241, 0.4);
    cursor: pointer;
    z-index: 100;
    transition: transform 0.2s, box-shadow 0.2s;
}
.ai-dictate-btn:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 15px 35px rgba(168, 85, 247, 0.6);
}
.ai-dictate-btn.listening {
    animation: pulse-mic 1.5s infinite;
    background: linear-gradient(135deg, #ef4444, #f97316);
}
@keyframes pulse-mic {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    70% { box-shadow: 0 0 0 20px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Sponsored Adverts */
#sponsored-ad-container {
    position: fixed;
    bottom: 30px;
    left: 480px;
    width: 320px;
    background: var(--panel-bg);
    border: 1px solid rgba(99, 102, 241, 0.4);
    border-radius: 12px;
    box-shadow: 0 15px 40px rgba(0,0,0,0.6);
    padding: 15px;
    z-index: 95;
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.5s ease;
}

#sponsored-ad-container.ad-slide-out {
    transform: translateY(150%) scale(0.9);
    opacity: 0;
    pointer-events: none;
}

#close-ad-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

#close-ad-btn:hover {
    transform: scale(1.1);
}

#ad-content-wrapper {
    width: 100%;
    min-height: 150px;
    background: #1e2235;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ad-placeholder {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ad-disclaimer {
    font-size: 9px;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 10px;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    body {
        overflow-y: auto;
        overflow-x: hidden;
        height: auto;
    }
    .app-container {
        flex-direction: column;
        height: auto;
        overflow-x: hidden;
    }
    .editor-panel {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 1.5rem 1rem;
        overflow: visible;
    }
    .preview-panel {
        padding: 1rem;
        width: 100%;
        display: block;
        overflow-x: auto;
        overflow-y: visible;
        -webkit-overflow-scrolling: touch;
    }
    .mobile-swipe-hint {
        display: block !important;
    }
    .preview-wrapper {
        padding: 10px;
        min-height: auto;
        width: 820px; /* 800px invoice + 20px pad */
        margin: 0 auto;
        display: block;
        transform-origin: top left;
    }
    #invoice-preview {
        width: 800px !important;
        min-width: 800px !important;
        max-width: 800px !important;
    }
    .row {
        flex-direction: column;
    }
    #sponsored-ad-container {
        left: 50%;
        transform: translateX(-50%);
        bottom: 80px;
        width: 90%;
        max-width: 320px;
    }
    #sponsored-ad-container.ad-slide-out {
        transform: translate(-50%, 150%) scale(0.9);
    }
    .modal-content {
        width: 90%;
        padding: 1.5rem;
    }
    .actions {
        padding-bottom: 1rem;
    }
}

/* Premium Gold Diamond Custom Color Filter */
.gold-diamond {
    display: inline-block;
    filter: sepia(1) saturate(5) hue-rotate(-10deg) brightness(1.1) drop-shadow(0 0 2px rgba(245, 158, 11, 0.4));
}
.pro-option {
    color: #f59e0b; /* Makes the option text goldish */
}

/* Native Vector PDF Print Engine Support */
@media print {
    body {
        margin: 0 !important;
        padding: 0 !important;
        background: transparent !important;
    }
    
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    .editor-panel, #download-btn, #sponsored-ad-container, .mobile-swipe-hint, #ai-dictate-btn, .pro-badge {
        display: none !important;
    }

    .preview-panel {
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        background: transparent !important;
        overflow: visible !important;
        height: auto !important;
        display: block !important;
    }

    .preview-wrapper {
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        height: auto !important;
        display: block !important;
        transform: none !important;
    }

    #invoice-preview {
        box-shadow: none !important;
        border: none !important;
        width: 100% !important;
        max-width: none !important;
        min-width: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
    }
}
