/* ================== THEME VARIABLES ================== */
:root {
    --primary-color: #1a4d72; /* rgb(26, 77, 114) - Default Blue */
    --primary-color-hover: #0f3a5f;
    --body-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --footer-font: Georgia, 'Times New Roman', Times, serif;
    --border-color: #1a4d72;
}

body.theme-professional {
    --primary-color: #1c4587; /* rgb(28, 69, 135) - Professional Blue */
    --primary-color-hover: #133466;
    --body-font: Georgia, 'Times New Roman', Times, serif;
    --footer-font: 'Helvetica Neue', Arial, sans-serif;
    --border-color: #333;
}

/* ================== LAYOUT & ZOOM STYLES ================== */
html, body {
    margin: 0; padding: 0; height: 100%; overflow: hidden; background-color: #333;
    font-family: var(--body-font);
}
#app-container { display: flex; flex-direction: column; height: 100vh; }
#top-bar {
    flex-shrink: 0; background: #f8f9fa; padding: 8px 15px; border-bottom: 1px solid #dee2e6;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1); z-index: 1002; display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
}
#top-bar .button-group { display: flex; align-items: center; gap: 8px; padding: 0 10px; border-right: 1px solid #ccc; }
#top-bar .button-group:last-child { border-right: none; }
#top-bar button {
    background: var(--primary-color);
    color: white; border: none; padding: 6px 12px; border-radius: 4px;
    cursor: pointer; font-size: 13px; transition: background-color 0.2s; white-space: nowrap;
}
#top-bar button:hover { background: var(--primary-color-hover); }
#top-bar button:disabled { background: #c0c0c0; cursor: not-allowed; }
#top-bar .pdf-btn { background-color: #28a745; }
#top-bar .copy-btn { background-color: #007bff; }
#top-bar .load-btn { background-color: #ffc107; color: #212529; }
#top-bar .submit-btn { background-color: #dc3545; }
#top-bar .msg-btn { background-color: #17a2b8; }
#top-bar .ai-btn { background-color: #6f42c1; }
#top-bar .new-btn { background-color: #6c757d; }
#top-bar .theme-btn { background-color: #fd7e14; }
#top-bar .sheet-btn { background-color: #34A853; }

#zoom-controls { display: flex; align-items: center; gap: 5px; }
#zoom-controls button { padding: 4px 8px; font-size: 16px; width: 32px; }
#zoom-controls span { font-weight: bold; font-size: 14px; margin: 0 5px; }
#pdf-link-container { margin-left: auto; }
#pdf-link-container button { font-size: 13px; padding: 6px 12px; }
#page-nav-controls { display: none; }
#zoom-container { flex-grow: 1; overflow: auto; background: #525659; padding: 30px 10px; text-align: center; }
#invoice-pages-wrapper { display: inline-flex; flex-direction: column; gap: 30px; margin: 0 auto; transform-origin: top center; transition: transform 0.15s ease-out; }

/* --- PAGE AND CONTENT STYLES --- */
* { box-sizing: border-box; }
.page { background: white; width: 210mm; height: 297mm; box-shadow: 0 10px 25px rgba(0,0,0,0.3); display: flex; flex-direction: column; overflow: hidden; text-align: left; }
.page-header { padding: 20px 30px; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.page-content { padding: 0 30px 10px 30px; flex-grow: 1; display: flex; flex-direction: column; overflow: hidden; }
.page-footer { padding: 10px 30px; flex-shrink: 0; }
.company-section { background: var(--primary-color); color: white; padding: 20px 25px; display: flex; align-items: center; gap: 15px; }
.company-info { flex: 1; } .company-name { font-size: 26px; font-weight: bold; } .company-subtitle { font-size: 18px; } .company-tagline { font-size: 11px; opacity: 0.9; font-style: italic; }
.logo-section { display: flex; align-items: center; gap: 20px; } .logo { width: 70px; height: 70px; } .logo img { width: 100%; height: 100%; object-fit: contain; }
.invoice-title { font-size: 42px; font-weight: bold; color: #333; }
.qr-code { width: 90px; height: 90px; background: #f8f9fa; border: 2px solid #ddd; display: flex; align-items: center; justify-content: center; font-size: 9px; text-align: center; border-radius: 4px; padding: 4px; }
.qr-code img { width: 100% !important; height: 100% !important; }
.qr-code a { display: block; }
.invoice-details { display: flex; justify-content: space-between; margin-bottom: 15px; }
.company-address { flex: 1; line-height: 1.4; }
.email-link { color: var(--primary-color); text-decoration: none; font-weight: 500; }
.invoice-meta {
    display: grid;
    grid-template-columns: auto auto;
    justify-content: start;
    gap: 0 10px;
    line-height: 1.4;
    font-size: 14px;
    align-items: center;
    position: relative;
    left: -25px;
}
.invoice-meta > div { grid-column: 1 / -1; display: grid; grid-template-columns: subgrid; }
.invoice-meta > div > strong { text-align: right; padding-right: 5px; }
.invoice-meta > div > span { text-align: left; }
.bill-to-header { background: var(--primary-color); color: white; padding: 8px 25px; font-weight: bold; margin-top: 10px; font-size: 15px; }
.bill-to-content { display: flex; background: #f8f9fa; }
.client-info { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; padding: 8px 10px 8px 25px; flex-grow: 1; }
.client-label { grid-column: 1; text-align: right; font-weight: bold; font-size: 13px; white-space: nowrap; color: #444; }
.client-info .editable { grid-column: 2; width: 100%; }

/* --- MODIFIED: Client Suggestion Styles --- */
.client-name-wrapper {
    position: relative; /* New positioning anchor */
    grid-column: 2;
}
.client-suggestions-popup {
    position: absolute;
    top: 100%;
    left: 0;
    width: 150%;
    max-width: 450px;
    background-color: #fff;
    border: 1px solid #ccc;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    display: none;
    border-radius: 4px;
    text-align: left;
}
.client-suggestions-popup ul {
    list-style: none;
    padding: 0;
    margin: 0;
}
.client-suggestions-popup li {
    padding: 8px 12px;
    border-bottom: 1px solid #eee;
    cursor: default;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
}
.client-suggestions-popup li:last-child {
    border-bottom: none;
}
.client-suggestions-popup li:hover {
    background-color: #f0f0f0;
}
.client-suggestions-popup li small {
    color: #555;
    display: block;
    margin-top: 2px;
}
.load-client-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    white-space: nowrap;
    margin-left: 10px;
    flex-shrink: 0;
}
.load-client-btn:hover {
    background-color: var(--primary-color-hover);
}
/* --- End of Modified Styles --- */

.client-qr { flex-shrink: 0; width: 140px; padding: 10px; display: flex; align-items: center; justify-content: center; }
.client-qrcode-container { width: 110px; height: 110px; background: white; border: 1px dashed #ccc; display: flex; align-items: center; justify-content: center; border-radius: 4px; padding: 5px; font-style: italic; font-size: 11px; color: #888; text-align: center; }
.client-qrcode-container img { width: 100% !important; height: 100% !important; }

.items-table-container { flex-grow: 1; overflow: hidden; border-top: none; border-bottom: 2px solid var(--border-color); }
.items-table { width: 100%; border-collapse: collapse; }
.table-header th { background: var(--primary-color); color: white; font-weight: bold; border-radius: 0; }
.table-header th, .items-table td { padding: 6px 12px; } .items-table td { border-bottom: 1px solid #eee; }
.items-table th:nth-child(1), .items-table td:nth-child(1) { text-align: left; }
.items-table th:nth-child(n+2), .items-table td:nth-child(n+2) { text-align: right; }
.item-row:nth-child(even) { background: rgb(255, 243, 205); }
.summary-section { display: flex; justify-content: space-between; align-items: flex-end; }
.signature-line { flex-grow: 1; text-align: center; font-weight: bold; }
.signature-border { border-bottom: 2px solid #333; margin-bottom: 8px; height: 50px; display: flex; justify-content: center; align-items: center; max-width: 300px; margin-left: auto; margin-right: auto;}
.signature-logo { width: 50px; height: 50px; object-fit: contain; opacity: 0.15; }
.totals { width: 350px; border: none; flex-shrink: 0; }
.total-row { display: flex; justify-content: space-between; padding: 7px 12px; border-bottom: 1px solid #ddd; font-size: 15px; align-items: center; }
.total-row:last-child { border-bottom: none; } .total-row > span:first-child { font-weight: bold; text-align: left; } .totals .numeric { font-weight: bold; }
.total-row.due { color: #d32f2f; background: #ffebee; }
.total-row.paid { color: #2e7d32; background: #e8f5e9; font-weight: bold; }
.total-row.final { background: #eef2f7; color: #333; border-top: 1px solid #ddd; }
/* --- FIXED: Payment BDT alignment --- */
.totals .payment-value.editable {
    padding-right: 0;
}

.footer {
    text-align: center;
    margin-top: 20px;
    font-family: var(--footer-font);
}

.footer .thank-you-footer {
    background: var(--primary-color);
    color: white;
    padding: 8px 30px;
    font-weight: bold;
    font-size: 15px;
    text-align: center;
    border-radius: 0;
    margin: 20px -30px -10px -30px;
}

.editable { outline: none; border: 1px dashed transparent; padding: 2px 4px; border-radius: 3px; }
.editable:focus { border: 1px dashed #007bff; background: #e7f1ff; }
.editable[data-placeholder]:empty:not(:focus)::before { content: attr(data-placeholder); color: #999; pointer-events: none; font-style: italic; }
#notification-bar { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); color: white; padding: 10px 20px; border-radius: 5px; z-index: 1003; opacity: 0; transition: opacity 0.3s ease; pointer-events: none; font-weight: 500;}
#notification-bar.show { opacity: 1; }

/* --- CUSTOM MODAL STYLES --- */
.custom-modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    z-index: 1004;
    display: none;
    align-items: center;
    justify-content: center;
}
.custom-modal-content {
    background: #fff;
    padding: 25px 30px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    width: 90%;
    max-width: 400px;
}
.custom-modal-content h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: var(--primary-color);
}
.custom-modal-content p {
    margin-top: 0;
    margin-bottom: 20px;
    color: #555;
}
.custom-modal-content input {
    width: 100%;
    padding: 10px;
    font-size: 16px;
    border-radius: 4px;
    border: 1px solid #ccc;
    margin-bottom: 20px;
}
.custom-modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* --- AI CHAT & CAMERA STYLES --- */
#ai-chat-modal { position: fixed; bottom: 20px; right: 20px; width: 400px; max-width: 90vw; background: #fff; border-radius: 10px; box-shadow: 0 5px 20px rgba(0,0,0,0.2); z-index: 1001; display: none; flex-direction: column; height: 60vh; }
.ai-chat-header { background: var(--primary-color); color: white; padding: 10px 15px; border-top-left-radius: 10px; border-top-right-radius: 10px; display: flex; justify-content: space-between; align-items: center; }
.ai-chat-header h3 { margin: 0; font-size: 16px; } .ai-chat-header button { background: none; border: none; color: white; font-size: 24px; cursor: pointer; line-height: 1; }
.ai-chat-body { flex-grow: 1; padding: 15px; overflow-y: auto; background: #f4f7f9; }
.chat-message { max-width: 85%; margin-bottom: 12px; padding: 8px 12px; border-radius: 15px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap; }
.chat-message.user { background: #007bff; color: white; margin-left: auto; border-bottom-right-radius: 3px; }
.chat-message.ai { background: #e9ecef; color: #333; margin-right: auto; border-bottom-left-radius: 3px; }
.chat-message.ai.loading span { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background-color: #888; margin: 0 2px; animation: bounce 1.4s infinite ease-in-out both; }
.chat-message.ai.loading span:nth-child(2) { animation-delay: -0.16s; } .chat-message.ai.loading span:nth-child(3) { animation-delay: -0.32s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1.0); } }
.ai-chat-footer { border-top: 1px solid #ddd; padding: 10px; display: flex; flex-direction: column; gap: 5px; }
#image-preview-container { position: relative; display: none; align-self: flex-start; margin-bottom: 5px; }
#image-preview-container img { max-height: 60px; border-radius: 5px; border: 1px solid #ccc; }
#image-preview-container .remove-img-btn { position: absolute; top: -5px; right: -5px; background: #333; color: white; border: none; border-radius: 50%; width: 20px; height: 20px; font-size: 14px; cursor: pointer; line-height: 20px; text-align: center; }
.ai-chat-input-area { display: flex; gap: 10px; align-items: flex-end; width: 100%; }
#ai-chat-input { flex-grow: 1; border: 1px solid #ccc; border-radius: 20px; padding: 10px 15px; font-size: 14px; outline: none; resize: none; overflow-y: auto; max-height: 100px; }
#ai-chat-file-input { display: none; }
.ai-chat-btn { background: var(--primary-color); color: white; border: none; border-radius: 50%; width: 40px; height: 40px; font-size: 18px; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
#camera-modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.6); z-index: 1005; display: none; align-items: center; justify-content: center; }
#camera-modal-content { background: #fff; padding: 20px; border-radius: 8px; text-align: center; max-width: 90vw; }
#camera-view-container { position: relative; margin-bottom: 15px; background: #000; }
#camera-feed, #photo-canvas { max-width: 100%; max-height: 60vh; border-radius: 5px; }
#camera-controls { display: flex; gap: 10px; justify-content: center; }