* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    background: var(--surface);
    padding: 20px 30px;
    border-radius: 8px;
    margin-bottom: 30px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 28px;
    color: var(--primary-color);
}

.header-actions {
    display: flex;
    gap: 10px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: #1d4ed8;
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background-color: #475569;
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-success:hover {
    background-color: #059669;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background-color: #dc2626;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

.invoice-form {
    background: var(--surface);
    padding: 30px;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.form-section {
    margin-bottom: 30px;
    padding-bottom: 30px;
    border-bottom: 1px solid var(--border-color);
}

.form-section:last-of-type {
    border-bottom: none;
}

.form-section h2 {
    font-size: 20px;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.template-actions {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 15px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.form-group input,
.form-group textarea,
.form-group select {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-group input[type="file"] {
    padding: 8px;
    cursor: pointer;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.logo-preview {
    margin-top: 10px;
    min-height: 60px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-preview img {
    max-width: 200px;
    max-height: 80px;
    object-fit: contain;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 5px;
    background: white;
}

.logo-preview button {
    padding: 5px 10px;
    font-size: 12px;
}

.items-container {
    margin-bottom: 15px;
}

.item-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 60px;
    gap: 10px;
    align-items: start;
    margin-bottom: 10px;
}

.item-header {
    font-weight: 600;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
}

.item-row input,
.item-row textarea {
    padding: 8px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}

.item-row textarea {
    resize: vertical;
    min-height: 40px;
    line-height: 1.4;
}

.item-row input:focus,
.item-row textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.item-amount {
    text-align: right;
    font-weight: 500;
    padding-top: 8px;
}

.item-actions {
    text-align: center;
    padding-top: 4px;
}

.totals-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
}

.totals-display {
    background: var(--background);
    padding: 20px;
    border-radius: 6px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 16px;
}

.total-final {
    border-top: 2px solid var(--border-color);
    margin-top: 10px;
    padding-top: 15px;
    font-size: 20px;
    font-weight: 700;
    color: var(--primary-color);
}

.form-actions {
    display: flex;
    gap: 15px;
    justify-content: flex-end;
    margin-top: 30px;
}

.hidden {
    display: none !important;
}

.template-manager,
.saved-invoices {
    background: var(--surface);
    padding: 30px;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.templates-list,
.invoices-list {
    margin: 20px 0;
}

.template-card,
.invoice-card {
    background: var(--background);
    padding: 20px;
    border-radius: 6px;
    margin-bottom: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.template-info,
.invoice-info {
    flex: 1;
}

.template-info h3,
.invoice-info h3 {
    font-size: 18px;
    margin-bottom: 5px;
}

.template-info p,
.invoice-info p {
    color: var(--text-secondary);
    font-size: 14px;
}

.template-actions-card,
.invoice-actions-card {
    display: flex;
    gap: 10px;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--surface);
    padding: 30px;
    border-radius: 8px;
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: auto;
    position: relative;
    box-shadow: var(--shadow-lg);
}

.close {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 28px;
    font-weight: bold;
    color: var(--text-secondary);
    cursor: pointer;
}

.close:hover {
    color: var(--text-primary);
}

.invoice-preview {
    background: white;
    border: 1px solid var(--border-color);
    box-sizing: border-box;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

/* Wrapper for Style A elements */
.invoice-preview:not(:has(.invoice-preview-styleb)) {
    padding: 40px;
    width: 210mm;
    display: block;
}

.invoice-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}

.invoice-preview-left {
    flex: 1;
}

.invoice-preview-logo {
    margin-bottom: 20px;
}

.invoice-preview-logo img {
    max-width: 200px;
    max-height: 80px;
    object-fit: contain;
}

.invoice-preview-from {
    line-height: 1.6;
}

.invoice-preview-from h4 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 5px;
    color: #000;
}

.invoice-preview-from p {
    margin: 2px 0;
    color: #333;
    font-size: 11px;
}

.invoice-preview-right {
    text-align: right;
}

.invoice-preview-title {
    font-size: 28px;
    font-weight: 700;
    color: #000;
    margin-bottom: 5px;
}

.invoice-preview-number {
    font-size: 14px;
    color: #666;
}

.invoice-preview-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 40px;
    margin-bottom: 20px;
    padding: 15px 0;
    border-top: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
}

.invoice-preview-billto h3 {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 10px;
    color: #000;
}

.invoice-preview-billto h4 {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 5px;
    color: #000;
}

.invoice-preview-billto p {
    margin: 2px 0;
    color: #333;
    font-size: 11px;
}

.invoice-preview-info {
    text-align: right;
}

.invoice-info-table {
    width: 100%;
    border-collapse: collapse;
    margin-left: auto;
}

.invoice-info-table td {
    padding: 6px 0;
    font-size: 12px;
}

.invoice-info-table .info-label {
    font-weight: 600;
    color: #000;
    text-align: right;
    padding-right: 10px;
    white-space: nowrap;
}

.invoice-info-table .info-value {
    text-align: right;
    color: #333;
}

.invoice-info-table .balance-due-row {
    border-top: 1px solid #ddd;
}

.invoice-info-table .balance-due-row td {
    padding-top: 12px;
    margin-top: 8px;
    font-size: 14px;
    font-weight: 700;
    color: #000;
}

.invoice-preview-items {
    margin-bottom: 20px;
}

.preview-items-table {
    width: 100%;
    border-collapse: collapse;
}

.preview-items-table thead {
    background: var(--background);
}

.preview-items-table th {
    padding: 10px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    border-bottom: 2px solid var(--border-color);
}

.preview-items-table td {
    padding: 10px;
    font-size: 12px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
    line-height: 1.5;
}

.preview-items-table .text-right {
    text-align: right;
}

.invoice-preview-totals {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 20px;
}

.totals-table {
    width: 300px;
}

.totals-table tr {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 12px;
}

.totals-table .total-final-row {
    border-top: 2px solid var(--border-color);
    margin-top: 10px;
    padding-top: 15px;
    font-size: 16px;
    font-weight: 700;
}

.invoice-preview-notes {
    background: var(--background);
    padding: 15px;
    border-radius: 6px;
}

.invoice-preview-notes h3 {
    font-size: 13px;
    margin-bottom: 10px;
}

.invoice-preview-notes p {
    color: var(--text-secondary);
    font-size: 11px;
    white-space: pre-wrap;
}

@media (max-width: 768px) {
    header {
        flex-direction: column;
        gap: 15px;
    }

    .header-actions {
        width: 100%;
        flex-direction: column;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .item-row {
        grid-template-columns: 1fr;
    }

    .item-header {
        display: none;
    }

    .totals-section {
        grid-template-columns: 1fr;
    }

    .invoice-preview-parties {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column;
    }

    .modal-content {
        margin: 20px;
        max-width: calc(100% - 40px);
    }
}

/* Server Invoice Cards */
.invoice-card {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 15px;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
}

.invoice-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.invoice-header h3 {
    margin: 0;
    color: var(--primary-color);
    font-size: 18px;
}

.invoice-date {
    color: var(--text-secondary);
    font-size: 14px;
}

.invoice-details {
    margin-bottom: 15px;
}

.invoice-details p {
    margin: 5px 0;
    color: var(--text-primary);
    font-size: 14px;
}

.invoice-details strong {
    color: var(--text-secondary);
    font-weight: 500;
}

.invoice-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn-download,
.btn-delete {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: background-color 0.3s, transform 0.1s;
}

.btn-download {
    background: var(--success-color);
    color: white;
}

.btn-download:hover {
    background: #27ae60;
    transform: translateY(-1px);
}

.btn-delete {
    background: var(--danger-color);
    color: white;
}

.btn-delete:hover {
    background: #c0392b;
    transform: translateY(-1px);
}

/* Style B - Clean Minimal Invoice */
.invoice-preview-styleb {
    padding: 50px 70px;
    background: white;
    width: 210mm;
    min-height: 297mm;
    max-width: 210mm;
    box-sizing: border-box;
    margin: 0 auto;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    color: #000;
    line-height: 1.5;
}

.styleb-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
}

.styleb-title {
    font-size: 32px;
    font-weight: 600;
    color: #000;
}

.styleb-logo img {
    max-width: 100px;
    max-height: 50px;
    object-fit: contain;
}

.styleb-details {
    margin-bottom: 40px;
}

.styleb-detail-row {
    display: flex;
    margin-bottom: 8px;
    font-size: 14px;
}

.styleb-label {
    width: 150px;
    color: #000;
}

.styleb-value {
    color: #000;
}

.styleb-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 60px;
    margin-bottom: 40px;
}

.styleb-party h3 {
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: #000;
}

.styleb-party h4 {
    font-size: 14px;
    font-weight: 600;
    margin: 0 0 8px 0;
    color: #000;
}

.styleb-party p {
    margin: 4px 0;
    font-size: 14px;
    color: #000;
    line-height: 1.6;
}

.styleb-amount-due {
    margin-bottom: 30px;
    padding: 20px 0;
}

.styleb-amount-due h2 {
    font-size: 24px;
    font-weight: 600;
    margin: 0;
    color: #000;
}

.styleb-notes {
    margin-bottom: 30px;
    font-size: 13px;
    line-height: 1.7;
}

.styleb-notes p {
    margin: 0;
    white-space: pre-wrap;
}

.styleb-items {
    margin-bottom: 40px;
}

.styleb-table {
    width: 100%;
    border-collapse: collapse;
}

.styleb-table thead {
    border-bottom: 2px solid #000;
}

.styleb-table th {
    padding: 12px 8px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    color: #000;
}

.styleb-table tbody tr {
    border-bottom: 1px solid #e0e0e0;
}

.styleb-table td {
    padding: 16px 8px;
    font-size: 14px;
    color: #000;
    vertical-align: top;
}

.styleb-table .text-right {
    text-align: right;
}

.styleb-totals {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.styleb-total-row {
    display: flex;
    justify-content: space-between;
    width: 300px;
    font-size: 14px;
    padding: 8px 0;
}

.styleb-total-row.styleb-final {
    border-top: 2px solid #000;
    margin-top: 8px;
    padding-top: 16px;
    font-size: 16px;
}
