/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

:root {
    /* Color Palette */
    --primary: #4F46E5;
    /* Indigo 600 */
    --primary-hover: #4338CA;
    --secondary: #10B981;
    /* Emerald 500 */
    --background: #F3F4F6;
    /* Gray 100 */
    --panel-bg: #FFFFFF;
    --text-main: #111827;
    /* Gray 900 */
    --text-muted: #6B7280;
    /* Gray 500 */
    --border: #E5E7EB;
    /* Gray 200 */
    --danger: #EF4444;
    /* Red 500 */
    --danger-hover: #DC2626;

    /* Shadow and Radii */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px 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 {
    background-color: var(--background);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 2rem;
}

/* App Container Layout */
.app-container {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
    width: 100%;
    max-width: 1400px;
}

/* --- Sidebar Controls --- */
.controls-panel {
    background: var(--panel-bg);
    border-radius: var(--radius-lg);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    height: fit-content;
}

.brand {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.brand-logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.brand h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.brand p {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Form Styles */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
}

input,
select,
textarea {
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    transition: all 0.2s ease;
    background-color: #F9FAFB;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2);
    background-color: #FFFFFF;
}

/* Items Section */
.items-section {
    background: #F9FAFB;
    padding: 1rem;
    border-radius: var(--radius-md);
    border: 1px dashed var(--border);
}

.items-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.items-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--primary);
    transition: transform 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    color: var(--primary-hover);
    transform: scale(1.1);
}

.btn-icon.danger {
    color: var(--danger);
}

.btn-icon.danger:hover {
    color: var(--danger-hover);
}

.item-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr auto;
    gap: 0.5rem;
    margin-bottom: 0.8rem;
    align-items: flex-start;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.item-row input {
    width: 100%;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 1rem;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    margin-top: 1rem;
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* --- Preview Panel --- */
.preview-panel {
    flex: 1;
    min-width: 600px;
    display: flex;
    flex-direction: column;
}

.preview-wrapper {
    background: var(--panel-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: fit-content;
}

.preview-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border);
    background: #F9FAFB;
}

.preview-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-main);
}

/* Invoice Paper specific styles for PDF generation */
.invoice-paper-container {
    padding: 2rem;
    background: #E5E7EB;
    /* Background around the paper */
    display: flex;
    justify-content: center;
    overflow-x: auto;
}

.invoice-document {
    background: white;
    width: 210mm;
    /* A4 width */
    min-height: 296mm;
    /* A4 height, dikurangi sedikit menghindari halaman ekstra */
    padding: 20mm;
    /* Standard margins */
    box-shadow: var(--shadow-md);
    position: relative;
    /* Print scaling handled by html2pdf */
}

.invoice-document * {
    color: var(--text-main);
}

/* Document Header */
.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 2rem;
    margin-bottom: 2rem;
}

.company-details {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.invoice-logo {
    width: 80px;
    height: 80px;
    object-fit: contain;
}

.company-name {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 0.2rem;
    letter-spacing: -0.5px;
}

.company-tagline {
    font-weight: 600;
    color: var(--secondary);
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.company-address,
.company-web {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.4;
}

.invoice-title {
    text-align: right;
}

.invoice-title h2 {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: 2px;
    margin-bottom: 0.5rem;
}

.invoice-number {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* Document Meta */
.invoice-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 3rem;
}

.bill-to h4 {
    color: var(--text-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
}

.strong-text {
    font-weight: 700;
    font-size: 1.2rem;
    margin-bottom: 0.2rem;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    gap: 2rem;
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

/* Table */
.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2rem;
}

.invoice-table th {
    background-color: var(--background);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    padding: 1rem;
    border-bottom: 2px solid var(--border);
    text-align: left;
}

.invoice-table td {
    padding: 1.2rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: 1rem;
}

.text-center {
    text-align: center !important;
}

.text-right {
    text-align: right !important;
}

/* Summary Area */
.invoice-summary {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-top: 2rem;
}

.summary-notes {
    width: 50%;
}

.summary-notes h4 {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.summary-notes p {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-main);
}

.summary-totals {
    width: 40%;
    background-color: #F9FAFB;
    padding: 1.5rem;
    border-radius: var(--radius-md);
}

.total-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
    font-size: 1rem;
}

.grand-total {
    border-top: 2px solid var(--border);
    padding-top: 1rem;
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 0;
}

/* Due Date highlight */
.due-date-text {
    color: #DC2626 !important;
}

/* Payment Section */
.payment-section {
    display: flex;
    gap: 2rem;
    margin-top: 2.5rem;
    padding-top: 2rem;
    border-top: 2px solid var(--border);
    align-items: flex-start;
}

.payment-banks {
    flex: 1;
}

.payment-qris {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.payment-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.payment-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.8rem;
}

.bank-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.bank-item {
    background: #F9FAFB;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.9rem;
}

.bank-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.bank-account {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: 1px;
}

.bank-holder {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.qris-img {
    width: 130px;
    height: 130px;
    object-fit: contain;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px;
}

/* Footer */
.invoice-footer {
    margin-top: 2rem;
    text-align: center;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--secondary);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-weight: 600;
    transform: translateY(150%);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
}

.toast.show {
    transform: translateY(0);
}

/* Responsive */
@media (max-width: 1024px) {
    .preview-panel {
        min-width: 100%;
    }

    .controls-panel {
        max-width: 100%;
    }

    .invoice-document {
        /* Scale down for preview on smaller screens */
        transform: scale(0.8);
        transform-origin: top center;
        margin-bottom: -20%;
    }
}

@media (max-width: 600px) {
    .invoice-document {
        transform: scale(0.5);
        margin-bottom: -50%;
    }
}