:root {
    --primary-color: #b65a29; /* brownish orange */
    --text-main: #333;
    --text-muted: #666;
    --bg-paper: #fff;
    --bg-app: #f4f7f6;
    --border-color: #dee2e6;
    --table-header-bg: #faeedf; /* light beige */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-app);
    color: var(--text-main);
}

.login-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #f4f7f6;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.login-box {
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    text-align: center;
    width: 350px;
}

.login-box h2 {
    margin-bottom: 20px;
    font-size: 1.5rem;
    color: #333;
}

.login-box input[type="password"] {
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
}

.login-box button {
    width: 100%;
}

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

/* Sidebar Styles */
.sidebar {
    width: 350px;
    background: #fff;
    border-right: 1px solid var(--border-color);
    padding: 20px;
    overflow-y: auto;
    box-shadow: 2px 0 5px rgba(0,0,0,0.05);
}

.sidebar h2 {
    font-size: 1.2rem;
    margin-bottom: 20px;
    color: #444;
}

.control-group {
    background: #f9f9f9;
    border: 1px solid #eee;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.control-group h3 {
    font-size: 0.95rem;
    margin-bottom: 10px;
    color: #555;
    border-bottom: 1px solid #ddd;
    padding-bottom: 5px;
}

.control-group label {
    display: block;
    margin-top: 10px;
    font-size: 0.85rem;
    color: #555;
}

.control-group input[type="text"],
.control-group input[type="number"],
.control-group input[type="date"],
.control-group input[type="color"],
.control-group textarea {
    width: 100%;
    padding: 8px;
    margin-top: 5px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9rem;
}

.control-group input[type="color"] {
    height: 40px;
    padding: 2px 5px;
    cursor: pointer;
}

.control-group input[type="file"] {
    width: 100%;
    margin-top: 5px;
    font-size: 0.8rem;
}

.control-group input[type="range"] {
    width: 100%;
    margin-top: 5px;
}

.actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.btn {
    padding: 10px 15px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    text-align: center;
    transition: background 0.2s;
}

.btn-primary {
    background: #007bff;
    color: white;
}
.btn-primary:hover { background: #0056b3; }

.btn-secondary {
    background: #6c757d;
    color: white;
}
.btn-secondary:hover { background: #5a6268; }

.btn-success {
    background: #28a745;
    color: white;
}
.btn-success:hover { background: #218838; }

.mt-2 { margin-top: 10px; }
.mt-4 { margin-top: 20px; }
.text-right { text-align: right !important; }

/* Preview Area */
.preview-area {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 40px;
    overflow-y: auto;
    background: #e9ecef;
}

.invoice-paper {
    background: var(--bg-paper);
    width: 210mm; /* A4 width */
    min-height: 297mm; /* A4 height */
    padding: 40px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    position: relative;
    color: #000;
}

#watermark-layer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 0;
    width: 80%;
    height: 80%;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.1;
    display: none;
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    position: relative;
    z-index: 1;
    margin-bottom: 20px;
}

.company-section {
    max-width: 50%;
}

.logo-preview-container {
    max-width: 150px;
    max-height: 100px;
    margin-bottom: 10px;
}
.logo-preview-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.brand-title {
    color: var(--primary-color);
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin: 0 0 5px 0;
}

.brand-tagline {
    color: var(--primary-color);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    margin: 0 0 10px 0;
}

.header-text {
    font-size: 11px;
    color: #333;
    line-height: 1.5;
    margin: 0;
}

.client-section {
    max-width: 45%;
}

.client-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid #ccc;
    padding-bottom: 5px;
}

.client-details-table {
    width: 100%;
    border-collapse: collapse;
}

.client-details-table td {
    font-size: 11px;
    padding: 3px 0;
    vertical-align: top;
}

.client-details-table td:first-child {
    white-space: nowrap;
    width: 80px;
    color: #555;
}

.divider {
    border: none;
    border-top: 1px dotted #aaa;
    margin: 20px 0;
}

.divider-dashed {
    border: none;
    border-top: 1px dashed #aaa;
    margin: 15px 0;
}

.invoice-meta {
    display: flex;
    justify-content: space-between;
    background: #fdfdfd;
    padding: 10px 15px;
    border-radius: 4px;
    font-size: 12px;
    margin-bottom: 20px;
    border: 1px solid #eee;
}

.table-container {
    margin-bottom: 10px;
    position: relative;
    z-index: 1;
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    border: 1px solid var(--border-color);
}

.items-table th,
.items-table td {
    border: 1px solid var(--border-color);
    padding: 10px;
    text-align: center;
}

.items-table th {
    background-color: var(--table-header-bg);
    font-weight: 700;
}

.items-table tbody td {
    color: #222;
}

.items-table tfoot .highlight-row {
    background-color: var(--table-header-bg);
}

.items-table tfoot td {
    border: 1px solid var(--border-color);
    padding: 10px;
}

.bold-row strong {
    font-weight: 700;
    font-size: 13px;
}
.bold-row td {
    font-weight: 700;
    font-size: 13px;
}


.amount-in-words {
    font-size: 13px;
    font-weight: 500;
    text-align: right;
    margin-top: 10px;
    margin-bottom: 15px;
}

.invoice-footer {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: #444;
    position: relative;
    z-index: 1;
}

.footer-left {
    width: 65%;
}

.terms-title {
    font-weight: 600;
    margin-bottom: 5px;
}

.terms-list {
    list-style-type: none;
    padding-left: 0;
}

.terms-list li::before {
    content: "- ";
}

.footer-right {
    width: 30%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-end;
}

.signature-block {
    text-align: center;
}

.signature-line {
    border-top: 1px solid #000;
    width: 150px;
    margin: 30px auto 5px auto;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 8px;
    width: 600px;
    max-width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.item-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
}
.item-row input {
    padding: 5px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.btn-remove {
    background: #dc3545;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}
.btn-remove:hover {
    background: #c82333;
}

/* --- Theme Designs --- */

/* Design 2: Modern Minimal */
.design-2 {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    color: #444;
}
.design-2 .invoice-header {
    flex-direction: row-reverse;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 20px;
}
.design-2 .client-section {
    border-right: 1px solid #eee;
    padding-right: 20px;
}
.design-2 .client-title {
    border-bottom: none;
    font-size: 14px;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.design-2 .items-table th, .design-2 .items-table td {
    border: none;
    border-bottom: 1px solid #eee;
    padding: 12px 10px;
}
.design-2 .items-table {
    border: none;
}
.design-2 .items-table th {
    background-color: transparent;
    border-bottom: 2px solid #ddd;
    text-transform: uppercase;
}
.design-2 .items-table tfoot td {
    border: none;
}
.design-2 .items-table tfoot .highlight-row {
    background-color: transparent;
}
.design-2 .invoice-meta {
    background: transparent;
    border: none;
    border-bottom: 1px dashed #ccc;
    box-shadow: none;
}
.design-2 .divider, .design-2 .divider-dashed {
    display: none;
}

/* Design 3: Elegant Boxed */
.design-3 {
    border: 8px solid var(--primary-color);
    padding: 30px;
    border-radius: 4px;
}
.design-3 .invoice-header {
    background: var(--table-header-bg);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 30px;
}
.design-3 .brand-title {
    color: #333;
}
.design-3 .client-title {
    color: var(--primary-color);
}
.design-3 .items-table {
    border: 2px solid var(--primary-color);
}
.design-3 .items-table th {
    background-color: var(--primary-color);
    color: white;
}
.design-3 .invoice-meta {
    background: var(--table-header-bg);
    border: 1px solid var(--primary-color);
    border-radius: 6px;
}

/* Print Settings */
@media print {
    body {
        background: white;
    }
    .no-print {
        display: none !important;
    }
    .preview-area {
        padding: 0;
        background: transparent;
    }
    .invoice-paper {
        box-shadow: none;
        width: 100%;
        min-height: auto;
        padding: 0;
    }
}
