:root {
    --bg-color: #f8fafc;
    --panel-bg: #000000; /* Brand Black */
    --border-color: rgba(255,255,255,0.1);
    --primary-color: #D4AF37; /* Elite Gold */
    --primary-hover: #B8860B; /* Deep Gold */
    --text-primary: #ffffff; /* White text on black panels */
    --text-secondary: #94a3b8;
    --accent: #D4AF37;
    --paper-bg: #ffffff;
    --paper-text: #1e293b;
    --paper-border: #e2e8f0;
    --gold-glow: rgba(212, 175, 55, 0.2);
}

body.dark-mode {
    --bg-color: #000000;
    --panel-bg: #000000;
    --border-color: rgba(212, 175, 55, 0.2);
    --text-primary: #ffffff;
    --text-secondary: #cbd5e1;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(212, 175, 55, 0.4);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(212, 175, 55, 0.7);
}

body {
    background-color: var(--bg-color);
    background-image: 
        radial-gradient(circle at 15% 25%, rgba(212, 175, 55, 0.08) 0%, transparent 35%),
        radial-gradient(circle at 85% 75%, rgba(184, 134, 11, 0.05) 0%, transparent 40%);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    font-family: 'Inter', sans-serif;
    transition: background-color 0.3s, color 0.3s;
}

body.dark-mode {
    background-image: 
        radial-gradient(circle at 15% 25%, rgba(212, 175, 55, 0.12) 0%, transparent 35%),
        radial-gradient(circle at 85% 75%, rgba(184, 134, 11, 0.08) 0%, transparent 40%);
}

/* Premium Watermark Positioning - Ash Color */
#invoice-watermark {
    position: absolute;
    bottom: 20px;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 10px;
    color: #94a3b8;
    opacity: 0.8;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 1px;
    pointer-events: none;
}

.invoice-container {
    position: relative;
    padding-bottom: 80px !important;
}

/* AI Wave Pulse Animation */
.ai-wave-container {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 15px;
}
.ai-wave-bar {
    width: 3px;
    height: 100%;
    background: #d4af37;
    border-radius: 2px;
    animation: ai-wave 1s ease-in-out infinite;
}
.ai-wave-bar:nth-child(2) { animation-delay: 0.1s; }
.ai-wave-bar:nth-child(3) { animation-delay: 0.2s; }
.ai-wave-bar:nth-child(4) { animation-delay: 0.3s; }

@keyframes ai-wave {
    0%, 100% { height: 5px; }
    50% { height: 15px; }
}

@media print {
    #invoice-watermark {
        position: absolute;
        bottom: 20px;
        left: 0;
    }
}

#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: none;
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    padding: 2rem;
    overflow-y: auto;
    position: relative;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.editor-header h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.6rem;
    font-weight: 800;
    background: linear-gradient(135deg, #D4AF37, #B8860B);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.25rem;
}

.editor-header p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.form-section {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    background: #000000;
    padding: 1.5rem;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: none;
    transition: 0.3s ease;
}

.form-section:hover {
    transform: none;
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: none;
}

.form-section h3 {
    font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    font-weight: 800;
}

.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: var(--bg-color);
    border: 1px solid var(--border-color);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.05);
    color: var(--text-primary);
    padding: 0.75rem 1rem;
    border-radius: 10px;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    appearance: none;
    resize: vertical;
}

body.dark-mode input, body.dark-mode select, body.dark-mode textarea {
    background: rgba(0, 0, 0, 0.25);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

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 4px var(--gold-glow);
    background: #000000;
}

body.dark-mode input:focus, body.dark-mode select:focus, body.dark-mode textarea:focus {
    background: rgba(0, 0, 0, 0.4);
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.3), 0 0 15px rgba(212, 175, 55, 0.2), inset 0 2px 4px rgba(0,0,0,0.2);
}

.pricing-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

@media (max-width: 600px) {
    .pricing-grid {
        grid-template-columns: 1fr;
    }
}

/* 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.8rem 1.5rem;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 0.95rem;
}

.btn.primary {
    background: linear-gradient(135deg, #D4AF37, #B8860B);
    color: white;
    font-size: 1rem;
    box-shadow: 0 4px 15px rgba(212, 175, 55, 0.4), inset 0 1px 0 rgba(255,255,255,0.2);
    border-radius: 12px;
}

.btn.primary:hover {
    background: linear-gradient(135deg, #B8860B, #966e09);
    transform: translateY(-2px);
    box-shadow: none;
}

.btn.secondary {
    background: var(--bg-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn.secondary:hover {
    background: var(--border-color);
    border-color: var(--text-secondary);
}

body.dark-mode .btn.secondary {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255,255,255,0.1);
}

body.dark-mode .btn.secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255,255,255,0.2);
}

/* Preview Panel (Right) */
.preview-panel {
    flex: 1;
    background: #000000;
    padding: 2rem;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
    transition: background-color 0.3s;
}

body.dark-mode .preview-panel {
    background: #000000;
}

.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: 40px 60px;
    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 {
    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, #d4af37, #b8860b);
    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;
}

/* Light/Dark Mode True Enforcement */
#invoice-preview {
    background-color: #ffffff !important;
    color: #1e293b !important;
}

#invoice-preview * {
    color: inherit; /* Ensure children don't accidentally inherit body colors */
}

#invoice-preview .brand h2, 
#invoice-preview .total-row.grand-total span {
    color: var(--primary-color) !important;
}

#invoice-preview .invoice-table th {
    background-color: rgba(0,0,0,0.03) !important;
    border-bottom: 2px solid rgba(0,0,0,0.08);
    color: #475569;
}

#invoice-preview .invoice-table td {
    border-bottom: 1px solid rgba(0,0,0,0.08);
    color: #1e293b !important;
    word-break: break-word;
}

#invoice-preview .invoice-header,
#invoice-preview .total-row.grand-total,
#invoice-preview .watermark {
    border-color: rgba(0,0,0,0.08);
}

#invoice-preview .invoice-meta p,
#invoice-preview .bill-to h3,
#invoice-preview .total-row,
#invoice-preview .invoice-footer-note,
#invoice-preview .payment-info-title {
    color: #475569 !important;
}

#invoice-preview .payment-info-text {
    color: #1e293b !important;
}

/* Dark Mode Shared Texts */
#invoice-preview.dark-mode { 
    background-color: #000000 !important; 
    color: #ffffff !important; 
}

#invoice-preview.dark-mode * { 
    color: inherit; 
}

#invoice-preview.dark-mode .brand h2, 
#invoice-preview.dark-mode .total-row.grand-total span {
    color: var(--primary-color) !important;
}

#invoice-preview.dark-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 !important;
}

#invoice-preview.dark-mode .invoice-table td {
    border-bottom: 1px solid rgba(255,255,255,0.08);
    color: #ffffff !important;
    word-break: break-word;
}

#invoice-preview.dark-mode .invoice-header,
#invoice-preview.dark-mode .total-row.grand-total,
#invoice-preview.dark-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 {
    color: #94a3b8 !important;
}

#invoice-preview.dark-mode .payment-info-text {
    color: #ffffff !important;
}

/* Golden Mode Layer */
#invoice-preview.gold-mode { background: linear-gradient(135deg, #fcd34d 0%, #fbbf24 50%, #d4af37 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 { 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: 2rem;
    right: 2rem;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: #000000;
    border: 2px solid var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(212, 175, 55, 0.2);
    cursor: pointer;
    z-index: 1000;
    transition: 0.3s;
}
.ai-dictate-btn:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 15px 35px rgba(212, 175, 55, 0.4);
}
.ai-dictate-btn.listening {
    animation: pulse-gold 1.5s infinite;
    background: linear-gradient(135deg, #d4af37, #b8860b);
}
/* --- FINGER-ZOOM GESTURE ENGINE --- */
#invoice-preview {
    /* Zoom enabled via Viewport Meta */
}

.zoom-status-pill {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(212, 175, 55, 0.9);
    color: #000;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    z-index: 1000;
    display: none;
    pointer-events: none;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}
@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 & Tablet Optimization (Expanded to 1024px) */
@media (max-width: 1024px) {
    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;
    }
    
    /* Make inputs and buttons exceptionally full-width tap-friendly */
    .editor-panel .grid-2 {
        grid-template-columns: 1fr; /* Stacks all 2-columns naturally */
        gap: 15px;
    }
    .editor-panel input, .editor-panel select, .editor-panel button {
        width: 100%;
        margin-bottom: 5px;
    }
    
    .preview-panel {
        padding: 1.5rem 0.5rem;
        width: 100%;
        display: flex;
        justify-content: flex-start; /* Align left to ensure left side is visible */
        align-items: flex-start;
        overflow-x: auto !important; /* Enable horizontal scrolling */
        -webkit-overflow-scrolling: touch;
        background: var(--bg-color);
        min-height: 50vh;
    }
    
    .preview-wrapper {
        padding: 0;
        min-height: auto;
        width: fit-content; /* Allow wrapper to expand based on content */
        display: block;
        margin: 0 auto;
        /* Dynamic scaling for initial fit, but allowing overflow for zoom/scroll */
        transform-origin: top center;
        zoom: calc(100vw / 840); 
    }
    
    #invoice-preview {
        width: 800px !important;
        min-width: 800px !important;
        max-width: 800px !important;
        margin: 0 auto;
        box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    }
    
    .row {
        flex-direction: column;
    }
    .editor-header { padding-right: 1.5rem !important; }
    .editor-header h1 { font-size: 1.25rem !important; }
    .editor-header p { font-size: 0.75rem !important; }
    
    .actions {
        padding: 1rem 0 2rem;
        display: flex;
        flex-direction: column;
        gap: 15px;
        width: 100%;
    }
    .actions .btn { 
        margin: 0 !important; 
        height: 54px !important; 
        font-size: 1rem !important;
        border-radius: 16px !important;
    }
    
    #sponsored-ad-container {
        display: none !important; /* Hide ads temporarily on tiny screens to maximize workflow */
    }
    .modal-content {
        width: 90%;
        padding: 1.5rem;
    }
}

/* 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(212, 175, 55, 0.4));
}
.pro-option {
    color: #d4af37; /* Makes the option text goldish */
}

/* Native Vector PDF Print Engine Support */
@media print {
    body { background: white !important; overflow: visible !important; height: auto !important; margin: 0 !important; padding: 0 !important; }
    
    .editor-panel, #download-btn, #sponsored-ad-container, .mobile-swipe-hint, #ai-magic-btn-circle, .pro-badge, #upgrade-modal, #copy-email-btn, .mobile-tab-bar, .navbar, .chat-nav, .floating-ai-agent, #ai-dictate-btn, .auth-btn-container, #upgrade-btn, .sign-out-btn, .language-float { 
        display: none !important; 
    }

    .preview-panel, .preview-wrapper { 
        padding: 0 !important; 
        margin: 0 !important; 
        display: block !important; 
        overflow: visible !important;
        background: white !important;
        width: 100% !important;
        height: auto !important;
        transform: none !important;
    }

    #invoice-preview { 
        box-shadow: none !important; 
        border: none !important; 
        width: 210mm !important; 
        max-width: none !important;
        min-width: 0 !important;
        padding: 0 !important;
        margin: 0 !important;
        background: white !important;
    }
    .app-container { display: block !important; height: auto !important; }
    @page { margin: 10mm; size: auto; }
}

/* SYNERGY PRO - Golden Status Aura */
.pro-glow {
    position: relative;
    border: 2.5px solid #bf953f !important;
    box-shadow: 0 0 15px rgba(191, 149, 63, 0.6), 0 0 5px rgba(252, 246, 186, 0.4);
    animation: pro-glow-pulse 2s infinite alternate !important;
}

.pro-badge-mini {
    position: absolute;
    bottom: -6px;
    right: -6px;
    background: linear-gradient(135deg, #bf953f, #fcf6ba, #b38728, #fbf5b7, #aa771c);
    color: #1e293b;
    font-size: 0.55rem;
    font-weight: 950;
    padding: 1.5px 4px;
    border-radius: 4px;
    border: 1px solid rgba(0,0,0,0.15);
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    z-index: 10;
}

@keyframes pro-glow-pulse {
    0% { filter: brightness(1) scale(1); }
    100% { filter: brightness(1.2) scale(1.05); }
}

/* === iOS & ANDROID NATIVE COMPLIANCE & ANTI-ZOOM === */
@media screen and (max-width: 1024px) {
    input, textarea, select { 
        font-size: 16px !important; /* Prevents auto-zoom on iOS Safari */
        -webkit-appearance: none; /* Removes native iOS default shadow/border */
        appearance: none; /* Modern standard */
        border-radius: 8px;
    }
    
    /* Fix hover stickiness on iOS */
    .btn:active, .tool-card:active {
        transform: scale(0.98);
        opacity: 0.8;
    }
}

/* === STRICT MOBILE-FIRST OPTIMIZATION === */
@media screen and (max-width: 600px) {
    /* Stack Line Items Cleanly */
    .item-row {
        flex-direction: column !important;
        align-items: stretch !important;
        background: rgba(0, 0, 0, 0.15) !important;
        padding: 15px !important;
        border-radius: 12px !important;
        margin-bottom: 20px !important;
        position: relative;
    }
    .item-row input[type="text"], .item-row input[type="number"] {
        flex: none !important;
        width: 100% !important;
        margin-bottom: 8px !important;
    }
    .remove-btn {
        position: absolute;
        top: 10px;
        right: 10px;
        background: rgba(239, 68, 68, 0.2);
        border-radius: 50%;
        width: 35px;
        height: 35px;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    
    /* Document Live Preview Horizontal Swipe & Fit */
    .preview-panel {
        max-width: 100vw !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 10px !important;
        border-radius: 12px !important;
    }
    #invoice-preview {
        min-width: 800px; /* Preserve physical A4 document ratio */
        margin: 0 auto;
    }
    
    /* Touch Targets Expansion */
    .btn, input, select, textarea, .remove-btn {
        min-height: 52px !important; /* Minimum Apple iOS recommended hit size */
        padding: 12px 16px !important;
    }
    
    .template-thumb {
        min-width: 100px !important;
        min-height: 140px !important;
        margin-right: 15px; /* thumb spacing */
    }
    
    /* Grid spacing fix */
    .app-container {
        padding: 5px !important;
        gap: 20px !important;
        overflow-x: hidden;
    }
}

/* === MOBILE DOCUMENT TAB SYSTEM === */
@media screen and (max-width: 768px) {
    .mobile-tab-bar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(20px);
        box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
        z-index: 9999;
        border-top: 1px solid var(--border-color);
    }
    
    .mobile-tab-btn {
        flex: 1;
        text-align: center;
        padding: 18px 0;
        font-weight: 800;
        font-size: 1rem;
        color: var(--text-muted);
        transition: 0.3s;
        border-bottom: 4px solid transparent;
        cursor: pointer;
    }
    
    .mobile-tab-btn.active {
        color: var(--primary-color);
        border-bottom-color: var(--primary-color);
        background: rgba(99,102,241,0.05);
    }

    /* Padding for the body to not hide behind sticky bar */
    body { padding-bottom: 90px; }

    /* Fix for "Add Item" button being hidden by mobile bar */
    .editor-panel { padding-bottom: 150px !important; }

    /* Hide States Refactored for PDF Generation Compatibility */
    body.show-edit .preview-panel {
        position: fixed;
        top: 0;
        left: -9999px;
        opacity: 0;
        pointer-events: none;
        z-index: -1;
    }
    body.show-preview .editor-panel {
        display: none !important;
    }
    body.show-preview .preview-panel {
        position: relative;
        left: 0;
        opacity: 1;
        pointer-events: auto;
        z-index: 100 !important;
        display: flex !important;
    }
}
@media screen and (min-width: 769px) {
    .mobile-tab-bar { display: none !important; }
}



#user-avatar { cursor: pointer; transition: opacity 0.3s ease; display: block !important; }
#user-avatar:hover { opacity: 0.8; }
#avatar-upload-label { cursor: pointer; }

/* GLOBAL AUTH MODAL */
.auth-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4); backdrop-filter: blur(20px);
    z-index: 10000; display: none !important; align-items: center; justify-content: center;
}
.auth-modal.active { display: flex !important; }
.auth-card {
    background: white; width: 400px; padding: 2.5rem; border-radius: 32px;
    box-shadow: 0 40px 100px rgba(0,0,0,0.1); border: 1px solid var(--border);
    text-align: center; position: relative;
    color: var(--text-main);
}
.auth-card h2 { font-weight: 800; font-family: 'Outfit', sans-serif; margin-bottom: 1rem; }
.google-auth-btn {
    width: 100%; padding: 12px; border: 1px solid var(--border); border-radius: 12px;
    background: white; color: var(--text-main); font-weight: 700;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    cursor: pointer; margin: 1.5rem 0; transition: 0.3s;
}
.google-auth-btn:hover { background: var(--surface); transform: translateY(-3px); }
.auth-divider { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: 0.8rem; margin: 1.5rem 0; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.auth-form input {
    width: 100%; padding: 12px 16px; border-radius: 12px; border: 1px solid var(--border);
    margin-bottom: 12px; font-size: 0.95rem; font-family: inherit;
    background: #fff; color: #000;
}
.auth-form .btn-submit {
    width: 100%; padding: 12px; border-radius: 12px; border: none;
    background: var(--primary); color: white; font-weight: 700; cursor: pointer; transition: 0.3s;
}
.auth-form .btn-submit:hover { background: var(--secondary); transform: scale(1.02); }

/* --- PREMIUM PROFILE POPUP SYSTEM --- */
.profile-click-zone {
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    user-select: none;
}

.profile-click-zone:active {
    transform: scale(0.92);
}

.profile-dropdown-card {
    position: absolute;
    top: calc(100% + 15px);
    right: 0;
    width: 260px;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    padding: 24px;
    z-index: 1000;
    display: none; /* Controlled by JS */
    animation: slideDownFade 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transform-origin: top right;
}

.profile-dropdown-card.active {
    display: block;
}

@keyframes slideDownFade {
    from { opacity: 0; transform: translateY(-10px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.profile-info-header {
    text-align: center;
    margin-bottom: 20px;
}

.profile-name {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.profile-email {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.tier-badge {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.tier-badge.pro {
    background: linear-gradient(135deg, #d4af37, #ca8a04);
    color: white;
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3);
}

.tier-badge.free {
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-secondary);
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 15px 0;
}

.dropdown-action-btn {
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
    gap: 12px;
}

.dropdown-action-btn:hover {
    background: rgba(212, 175, 55, 0.05);
    color: var(--primary-color);
}

.dropdown-action-btn.sign-out {
    color: #ef4444;
}

.dropdown-action-btn.sign-out:hover {
    background: rgba(239, 68, 68, 0.05);
    color: #ef4444;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .profile-dropdown-card {
        right: -10px;
        width: 240px;
    }
}

/* --- PREMIUM PROFILE POPUP SYSTEM --- */
.profile-click-zone {
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    user-select: none;
}
.profile-click-zone:active { transform: scale(0.92); }
.profile-dropdown-card {
    position: absolute;
    top: calc(100% + 15px);
    right: 0;
    width: 260px;
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    padding: 24px;
    z-index: 1000;
    display: none;
    animation: slideDownFade 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transform-origin: top right;
}
.profile-dropdown-card.active { display: block; }
@keyframes slideDownFade {
    from { opacity: 0; transform: translateY(-10px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.profile-info-header { text-align: center; margin-bottom: 20px; }
.profile-name { font-weight: 800; font-size: 1.1rem; color: var(--text-primary); margin-bottom: 4px; }
.profile-email { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 12px; }
.tier-badge { display: inline-block; padding: 6px 14px; border-radius: 50px; font-size: 0.75rem; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; }
.tier-badge.pro { background: linear-gradient(135deg, #d4af37, #ca8a04); color: white; box-shadow: 0 4px 12px rgba(212, 175, 55, 0.3); }
.tier-badge.free { background: rgba(148, 163, 184, 0.1); color: var(--text-secondary); border: 1px solid rgba(148, 163, 184, 0.2); }
.dropdown-divider { height: 1px; background: var(--border-color); margin: 15px 0; }
.dropdown-action-btn { width: 100%; padding: 12px; border-radius: 12px; border: none; background: transparent; color: var(--text-primary); font-weight: 600; text-align: left; cursor: pointer; transition: 0.2s; display: flex; align-items: center; gap: 12px; }
.dropdown-action-btn:hover { background: rgba(212, 175, 55, 0.05); color: var(--primary-color); }
.dropdown-action-btn.sign-out { color: #ef4444; }
.dropdown-action-btn.sign-out:hover { background: rgba(239, 68, 68, 0.05); color: #ef4444; }

/* Suite Dropdown System */
.show { display: block !important; }
.dropdown-content.show {
    display: block !important;
}

.dropdown-content a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    transition: 0.2s;
    border-bottom: 1px solid var(--border-color);
}

.dropdown-content a:last-child {
    border-bottom: none;
}

.dropdown-content a:hover {
    background: rgba(212, 175, 55, 0.08);
    color: var(--primary-color) !important;
    padding-left: 25px;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Button Pro States */
.btn.pro-active {
    background: linear-gradient(135deg, #bf953f, #fcf6ba, #b38728, #fbf5b7, #aa771c);
    color: #000 !important;
    border: none !important;
    box-shadow: 0 4px 15px rgba(184, 134, 11, 0.3);
}

/* AI Recording Overlay Animation */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.recording-pulse {
    animation: pulse-gold 1.5s infinite;
}

@keyframes pulse-gold {
    0% { box-shadow: 0 0 0 0 rgba(212, 175, 55, 0.7); }
    70% { box-shadow: 0 0 0 20px rgba(212, 175, 55, 0); }
    100% { box-shadow: 0 0 0 0 rgba(212, 175, 55, 0); }
}

