:root {
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --input-bg: #ffffff;
    --primary-color: #0f172a;
    --accent-color: #10b981; /* Green */
    --font-family: 'Inter', sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    padding-bottom: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Website Header */
.site-header {
    background-color: #ffffff;
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.site-logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary-color);
}

.header-logo {
    height: 45px;
    width: auto;
    object-fit: contain;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Website Footer */
.site-footer {
    background-color: #ffffff;
    border-top: 1px solid var(--border-color);
    padding: 1rem 2rem;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 100;
}

.footer-simple-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.footer-stats {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid var(--border-color);
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    background-color: var(--card-bg);
}

.footer-stats span {
    font-weight: 600;
    color: var(--primary-color);
}

.footer-copyright p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.footer-links {
    display: flex;
    gap: 1.5rem;
}

.footer-links a {
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--primary-color);
}

.btn {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.btn-secondary {
    background-color: #ffffff;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: #f8fafc;
    border-color: #cbd5e1;
}

.btn-primary {
    background-color: var(--primary-color);
    color: #ffffff;
}

.btn-primary:hover {
    background-color: #000000;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.currency-selector select {
    padding: 0.5rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background-color: #ffffff;
    font-size: 0.875rem;
    cursor: pointer;
    outline: none;
}

/* Main Invoice Card */
.invoice-container {
    padding: 0 1rem;
    display: flex;
    justify-content: center;
    margin-top: 4rem;
    margin-bottom: 6rem;
}

.invoice-card {
    background-color: var(--card-bg);
    width: 100%;
    max-width: 1000px;
    padding: 3rem;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Common Form Elements */
.form-input {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: #3b82f6;
}

.form-input::placeholder {
    color: #94a3b8;
}

textarea.form-input {
    resize: none;
}

.section-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.35rem;
}

/* Header Section */
.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.logo-box {
    width: 200px;
    height: 120px;
    border: 1px dashed #cbd5e1;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background-color: #f8fafc;
    transition: all 0.2s;
    overflow: hidden;
}

.logo-box:hover {
    background-color: #f1f5f9;
    border-color: #94a3b8;
}

.logo-placeholder {
    color: var(--text-secondary);
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

#logo-preview {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 0.5rem;
}

.header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
}

.invoice-type-title {
    font-size: 2.5rem;
    font-weight: 400;
    text-align: right;
    border: 1px solid transparent; /* Placeholder for border to prevent shift */
    border-radius: 4px;
    outline: none;
    color: var(--text-primary);
    text-transform: uppercase;
    width: 100%;
    letter-spacing: 0.02em;
    padding: 0 0.5rem;
    transition: all 0.2s;
    background-color: transparent;
}

.invoice-type-title:hover {
    border-color: var(--border-color);
    background-color: #f8fafc;
}

.invoice-type-title:focus {
    border-color: #3b82f6;
    background-color: #ffffff;
}

.invoice-number-box {
    display: flex;
    align-items: center;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    width: 150px;
}

.invoice-number-box .prefix {
    padding: 0.5rem 0.75rem;
    background-color: #f8fafc;
    color: var(--text-secondary);
    border-right: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.invoice-number-box input {
    border: none;
    outline: none;
    padding: 0.5rem;
    width: 100%;
    font-size: 0.9rem;
    color: var(--text-primary);
    text-align: right;
}

/* From Section */
.section-row {
    display: flex;
    gap: 3rem;
    margin-bottom: 1rem;
}

.from-row .col-left {
    flex: 1.5;
}

.from-row .col-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.large-area {
    min-height: 5rem;
}

.meta-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.meta-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1rem;
}

.meta-row label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: right;
    min-width: 100px;
}

.meta-row input {
    width: 180px;
    text-align: right;
}

/* To Section */
.to-row {
    margin-top: 1rem;
}

.col-half {
    flex: 1;
}

.medium-area {
    min-height: 5rem;
}

/* Items Section */
.items-section {
    margin-top: 2rem;
    margin-bottom: 2rem;
}

.items-header {
    display: flex;
    background-color: var(--primary-color);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.col-item { flex: 4; }
.col-qty { flex: 1; }
.col-rate { flex: 1.5; }
.col-amount { flex: 1; text-align: right; }
.col-action { width: 40px; }

.item-row {
    display: flex;
    align-items: flex-start;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
    gap: 0;
}

.item-row > div {
    padding: 0 0.5rem;
}

.item-row .col-item { flex: 4; }
.item-row .col-qty { flex: 1; }
.item-row .col-rate { flex: 1.5; }
.item-row .col-amount { flex: 1; text-align: right; padding-top: 0.6rem; font-weight: 500; }
.item-row .col-action { width: 40px; text-align: center; padding-top: 0.4rem; }

.delete-btn {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1.2rem;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.delete-btn:hover {
    opacity: 1;
}

.btn-add-line {
    margin-top: 1rem;
    background: white;
    border: 1px solid var(--accent-color);
    color: var(--accent-color);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s;
}

.btn-add-line:hover {
    background-color: #ecfdf5;
}

.btn-add-line .plus {
    font-size: 1.2rem;
    line-height: 1;
}

/* Footer Section */
.footer-section {
    display: flex;
    gap: 4rem;
    margin-top: 1rem;
}

.footer-left {
    flex: 1.5;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.footer-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-top: 1rem;
}

.totals-row {
    display: flex;
    align-items: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.totals-row .label {
    width: 80px; /* Fixed width for alignment */
    flex-shrink: 0;
}

.totals-row .value {
    margin-left: auto;
    text-align: right;
}

.totals-row.total-final {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
    margin-top: 0.5rem;
}

.tax-input-group {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.6rem;
    width: 80px;
}

.tax-input-group input {
    border: none;
    outline: none;
    width: 100%;
    text-align: right;
    font-size: 0.9rem;
}

.tax-input-group .percent {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.currency-symbol {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

/* Print and PDF Mode Styles (Legacy - for reference or if we revert) */
@media print {
    body {
        background-color: white;
    }
    .site-header, .site-footer, .btn-add-line, .delete-btn, .col-action, .logo-placeholder {
        display: none !important;
    }
    .invoice-container {
        margin: 0;
        padding: 0;
        box-shadow: none;
    }
    .invoice-card {
        border: none;
        padding: 0;
    }
}

.pdf-mode .items-header {
    background-color: var(--primary-color) !important;
    color: white !important;
    -webkit-print-color-adjust: exact;
}

/* New PDF Template Styles */
.pdf-container {
    font-family: 'Inter', sans-serif;
    color: #0f172a;
    background: #ffffff;
    padding: 50px 30px 30px 30px;
    width: 780px; /* Tuned for A4 (approx 210mm @ 96DPI) to prevent right-side cutoff */
    box-sizing: border-box;
}

.pdf-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4rem;
}

.pdf-sender {
    font-weight: 700;
    font-size: 0.9rem; /* Reduced by ~3px (from 1.1rem) */
    color: #0f172a;
    white-space: pre-wrap;
    max-width: 100%; /* Increased from 45% to use full available space */
    padding-top: 20px;
}

.pdf-title-section {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.pdf-title {
    font-size: 3rem;
    font-weight: 400;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #0f172a;
    line-height: 1;
    margin-bottom: 0.5rem;
}

.pdf-number {
    font-size: 1.2rem;
    color: #64748b;
    margin-bottom: 1.5rem;
}

.pdf-meta-row {
    display: flex;
    justify-content: flex-end;
    gap: 2rem;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
}

.pdf-meta-label {
    color: #64748b;
}

.pdf-meta-value {
    font-weight: 500;
    min-width: 100px;
    text-align: right;
}

.pdf-balance-bar {
    background-color: #f3f4f6;
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 3rem;
    margin-top: 0.5rem;
    font-weight: 700;
    min-width: 300px;
}

.pdf-balance-label {
    color: #0f172a;
}

.pdf-client-section {
    display: flex;
    gap: 2rem;
    margin-bottom: 3rem;
}

.pdf-client-col {
    flex: 1;
}

.pdf-client-label {
    font-size: 0.9rem;
    color: #64748b;
    margin-bottom: 0.5rem;
}

.pdf-client-value {
    font-weight: 700;
    font-size: 0.9rem;
    color: #0f172a;
    white-space: pre-wrap;
}

.pdf-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2rem;
}

.pdf-table th {
    background-color: #1e293b;
    color: #ffffff;
    padding: 0.75rem 1rem;
    font-weight: 500;
    font-size: 0.9rem;
    text-align: left;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

.pdf-table th.right {
    text-align: right;
}

.pdf-table td {
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
    color: #334155;
    font-size: 0.95rem;
}

.pdf-table td.right {
    text-align: right;
}

.pdf-table tr:last-child td {
    border-bottom: none;
}

.pdf-brand-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 65%; /* Increased from 50% to allow more space */
}

.pdf-logo {
    max-width: 150px;
    max-height: 80px;
    object-fit: contain;
}

.pdf-footer-grid {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-top: 0; /* Removed margin to sit flush with table */
    gap: 0; /* Remove gap to handle spacing via padding */
}

.pdf-notes-section {
    flex: 1;
    padding-left: 1rem; /* Align with table "Item" column text (which has 1rem padding) */
    padding-top: 1.5rem; /* Add spacing from table bottom */
    padding-right: 2rem;
}

.pdf-section-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: #0f172a;
    margin-bottom: 0.25rem;
}

.pdf-text {
    font-size: 0.85rem;
    color: #64748b;
    line-height: 1.4;
    white-space: pre-wrap;
}

.pdf-totals-section {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.75rem;
    min-width: 300px;
    padding-right: 1rem; /* Align with table "Amount" column text */
    padding-top: 1.5rem; /* Add spacing from table bottom */
}

.pdf-total-row {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    font-size: 0.8rem; /* Reduced by ~3px (from 0.95rem) */
    color: #64748b;
    width: 100%;
}

.pdf-total-row.final {
    font-size: 0.95rem; /* Reduced by ~3px (from 1.1rem) */
    font-weight: 700;
    color: #0f172a;
    margin-top: 0.5rem;
}

.pdf-total-label {
    text-align: right;
    width: 120px; /* Fixed width for alignment */
}

.pdf-total-value {
    min-width: 100px;
    text-align: right;
}

@media (max-width: 900px) {
    .invoice-card {
        padding: 2rem;
        gap: 1.5rem;
    }

    .section-row {
        gap: 2rem;
    }

    .invoice-header {
        gap: 1.5rem;
    }

    .items-header {
        font-size: 0.8rem;
    }
}

@media (max-width: 720px) {
    .site-header {
        padding: 0.75rem 1rem;
        position: static;
    }

    .header-container {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .header-actions {
        width: 100%;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .site-footer {
        position: static;
        padding: 1rem;
    }

    .footer-simple-container {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .footer-links {
        flex-wrap: wrap;
        gap: 0.75rem 1rem;
    }

    .invoice-container {
        margin-top: 2rem;
        margin-bottom: 2rem;
    }

    .invoice-card {
        padding: 1.5rem;
        gap: 1.25rem;
    }

    .invoice-header {
        flex-direction: column;
        align-items: stretch;
    }

    .logo-box {
        width: 100%;
        height: 110px;
    }

    .header-right {
        align-items: flex-start;
        width: 100%;
    }

    .invoice-type-title {
        font-size: 2rem;
        text-align: left;
        padding: 0.25rem 0.5rem;
    }

    .invoice-number-box {
        width: 100%;
    }

    .section-row {
        flex-direction: column;
        gap: 1.25rem;
    }

    .meta-row {
        justify-content: flex-start;
        gap: 0.75rem;
    }

    .meta-row label {
        min-width: 0;
        text-align: left;
    }

    .meta-row input {
        width: 100%;
        text-align: left;
    }

    .items-header {
        display: none;
    }

    .item-row {
        flex-wrap: wrap;
        gap: 0.75rem 0.5rem;
    }

    .item-row .col-item {
        flex: 1 1 100%;
        padding: 0;
    }

    .item-row .col-qty,
    .item-row .col-rate,
    .item-row .col-amount {
        flex: 1 1 30%;
        padding: 0;
    }

    .item-row .col-amount {
        text-align: left;
        padding-top: 0;
    }

    .item-row .col-action {
        width: auto;
        padding: 0;
    }

    .footer-section {
        flex-direction: column;
        gap: 1.5rem;
    }

    .footer-left,
    .footer-right {
        flex: 1 1 100%;
    }

    .totals-row .label {
        width: auto;
    }

    .tax-input-group {
        width: 100px;
    }
}

@media (max-width: 480px) {
    .invoice-card {
        padding: 1.25rem;
    }

    .invoice-type-title {
        font-size: 1.6rem;
    }

    .btn {
        width: 100%;
        text-align: center;
    }

    .header-actions .btn,
    .header-actions select {
        width: 100%;
    }

    .item-row .col-qty,
    .item-row .col-rate,
    .item-row .col-amount {
        flex: 1 1 100%;
    }
}
