:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --primary-glow: rgba(99, 102, 241, 0.25);
    --secondary: #0ea5e9;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --bg-hover: #475569;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: rgba(71, 85, 105, 0.6);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.35);
    --shadow-glow: 0 0 20px var(--primary-glow);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
    --bg-dark: #f1f5f9;
    --bg-card: #ffffff;
    --bg-input: #f8fafc;
    --bg-hover: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

/* Main Container - Grid Layout Like Surat Penawaran */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 10px;
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 12px;
    min-height: calc(100vh - 20px);
}

/* Form Panel - Left Side */
.form-panel {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 20px);
}

.form-panel form {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

/* Preview Panel - Right Side - Always Visible */
.preview-panel {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.preview-header {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.preview-header h3 {
    font-size: 0.9rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
}

.preview-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-close-preview {
    display: none;
    /* Only show on very small mobile */
}

.preview-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background: linear-gradient(145deg, #475569 0%, #334155 100%);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.preview-invoice {
    width: 210mm;
    max-width: 100%;
    min-height: auto;
    padding: 15mm 20mm;
    margin: 0 auto;
    background: #fff !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    font-size: 10pt;
    line-height: 1.5;
    color: #1a1a1a !important;
    position: relative;
}

.preview-invoice * {
    color: inherit !important;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: linear-gradient(135deg, var(--bg-card) 0%, rgba(30, 41, 59, 0.95) 100%);
    border-radius: var(--radius-lg);
    margin-bottom: 14px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(10px);
}

.header-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-title .icon {
    font-size: 1.5rem;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.header-title .title-main {
    font-size: 1rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-light), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.header-title .title-sub {
    font-size: 0.65rem;
    color: var(--text-muted);
    display: block;
    margin-top: 2px;
}

/* Theme Toggle */
.theme-toggle {
    width: 40px;
    height: 22px;
    background: var(--bg-input);
    border-radius: 100px;
    cursor: pointer;
    position: relative;
    border: 2px solid var(--border-color);
}

.theme-toggle::after {
    content: '🌙';
    position: absolute;
    top: 50%;
    left: 2px;
    transform: translateY(-50%);
    font-size: 9px;
    transition: var(--transition);
}

[data-theme="light"] .theme-toggle::after {
    content: '☀️';
    left: calc(100% - 14px);
}

/* Tabs */
.tabs-nav {
    display: flex;
    gap: 6px;
    margin-bottom: 14px;
    overflow-x: auto;
    padding: 4px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.tabs-nav::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    padding: 10px 14px;
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: var(--transition);
    font-family: inherit;
}

.tab-btn:hover {
    border-color: var(--primary);
    color: var(--text-primary);
    background: rgba(99, 102, 241, 0.1);
    transform: translateY(-1px);
}

.tab-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-color: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Cards */
.card {
    background: linear-gradient(145deg, var(--bg-card) 0%, rgba(30, 41, 59, 0.85) 100%);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
    backdrop-filter: blur(8px);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.card-header .icon {
    font-size: 1rem;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    border-radius: var(--radius-sm);
}

.card-header h2 {
    font-size: 0.8rem;
    font-weight: 700;
    flex: 1;
}

.optional-badge {
    font-size: 0.55rem;
    color: var(--text-muted);
    background: var(--bg-input);
    padding: 2px 5px;
    border-radius: var(--radius-sm);
}

/* Form Elements */
.form-group {
    margin-bottom: 12px;
}

.form-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: 0.01em;
}

.form-label small {
    color: var(--text-muted);
    font-weight: 400;
}

.form-label-inline {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow), var(--shadow-glow);
    background: rgba(51, 65, 85, 0.9);
}

.form-control::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.form-control-small {
    padding: 5px 7px;
    font-size: 0.7rem;
    background: var(--bg-input);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    min-width: 90px;
}

.form-control-mini {
    width: 50px;
    padding: 4px 5px;
    font-size: 0.7rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    text-align: center;
}

.form-control-color {
    width: 36px;
    height: 28px;
    padding: 2px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

textarea.form-control {
    resize: vertical;
    min-height: 46px;
}

input[type="checkbox"] {
    width: 13px;
    height: 13px;
    accent-color: var(--primary);
    cursor: pointer;
    margin-right: 5px;
    vertical-align: middle;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.form-row-3 {
    grid-template-columns: repeat(3, 1fr);
}

.form-row-4 {
    grid-template-columns: repeat(4, 1fr);
}

.mt-4 {
    margin-top: 4px;
}

.mt-6 {
    margin-top: 6px;
}

.mt-10 {
    margin-top: 10px;
}

/* Toggle Label */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    margin-bottom: 6px;
}

.toggle-label input:checked+span {
    color: var(--primary-light);
}

/* Hidden Sections */
.hidden-section {
    display: none;
    margin-top: 8px;
}

.hidden-section.show {
    display: block;
}

.hidden-inline {
    display: none;
}

.hidden-inline.show {
    display: flex;
}

/* Config Box */
.config-box {
    background: var(--bg-input);
    border-radius: var(--radius-md);
    padding: 8px;
    margin-bottom: 10px;
}

.config-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.config-row+.config-row {
    margin-top: 6px;
}

.hint {
    font-size: 0.55rem;
    color: var(--text-muted);
}

/* Logo Upload */
.logo-upload-section {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
    padding: 10px;
    background: var(--bg-input);
    border-radius: var(--radius-md);
}

.logo-preview-container {
    width: 70px;
    height: 35px;
    background: white;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 2px solid var(--border-color);
    flex-shrink: 0;
}

.logo-preview-container img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: none;
}

.logo-preview-container img.show {
    display: block;
}

.logo-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.55rem;
    color: var(--text-muted);
}

.logo-placeholder.hide {
    display: none;
}

.logo-controls {
    display: flex;
    gap: 5px;
    align-items: center;
    flex-wrap: wrap;
}

.logo-controls small {
    font-size: 0.55rem;
    color: var(--text-muted);
    width: 100%;
}

.btn-upload,
.btn-remove {
    padding: 5px 8px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.65rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.btn-upload {
    background: var(--primary);
    color: white;
}

.btn-remove {
    background: var(--danger);
    color: white;
}

/* Upload Zone */
.upload-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--bg-input);
    position: relative;
}

.upload-zone.small {
    padding: 10px;
}

.upload-zone:hover {
    border-color: var(--primary);
}

.upload-zone input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.upload-zone .upload-icon {
    font-size: 1.3rem;
}

.upload-zone .upload-text {
    font-weight: 600;
    font-size: 0.7rem;
}

.upload-preview {
    max-width: 70px;
    max-height: 45px;
    border-radius: var(--radius-sm);
    display: none;
    margin: 5px auto 0;
}

.upload-preview.show {
    display: block;
}

/* Item Cards */
.item-card {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
}

.item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: var(--bg-hover);
    font-weight: 700;
    font-size: 0.75rem;
}

.item-number {
    color: var(--primary-light);
}

.item-body {
    padding: 10px;
}

.item-total-display {
    background: var(--primary);
    color: white;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    text-align: center;
    font-size: 0.75rem;
}

/* Payment Methods */
.payment-method-card {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
}

.payment-method-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: var(--bg-hover);
    font-weight: 600;
    font-size: 0.75rem;
}

.payment-method-body {
    padding: 10px;
}

.payment-options {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 8px;
    background: var(--bg-input);
    border-radius: var(--radius-md);
    margin-top: 8px;
}

.payment-option-btn {
    padding: 5px 8px;
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition);
}

.payment-option-btn:hover {
    border-color: var(--primary);
}

.qris-upload-zone {
    border: 2px dashed var(--success);
    border-radius: var(--radius-md);
    padding: 10px;
    text-align: center;
    cursor: pointer;
    margin-top: 6px;
}

.qris-preview {
    max-width: 90px;
    max-height: 90px;
    display: none;
    margin: 6px auto;
    border-radius: var(--radius-sm);
}

.qris-preview.show {
    display: block;
}

/* Signature */
.signature-tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 8px;
}

.sig-tab {
    padding: 5px 10px;
    background: var(--bg-input);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    color: var(--text-secondary);
    transition: var(--transition);
}

.sig-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.signature-content {
    display: none;
}

.signature-content.active {
    display: block;
}

.signature-canvas-container {
    position: relative;
    margin-bottom: 8px;
}

#signatureCanvas {
    width: 100%;
    height: 90px;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: crosshair;
    touch-action: none;
}

.btn-clear-sig {
    position: absolute;
    top: 5px;
    right: 5px;
    padding: 3px 6px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.6rem;
    cursor: pointer;
}

.text-muted {
    color: var(--text-muted);
    font-size: 0.7rem;
    text-align: center;
}

/* Divider */
.divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 10px 0;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition);
}

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

.btn-success {
    background: var(--success);
    color: white;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-add-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    width: 100%;
    padding: 8px;
    background: transparent;
    border: 2px dashed var(--primary);
    border-radius: var(--radius-md);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
}

.btn-add-item:hover {
    background: rgba(99, 102, 241, 0.1);
}

.btn-add-small,
.btn-remove-small {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    cursor: pointer;
}

.btn-add-small {
    background: var(--primary);
    color: white;
}

.btn-remove-small {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.btn-remove-small:hover {
    background: var(--danger);
    color: white;
}

.btn-delete-item {
    background: transparent;
    border: none;
    font-size: 0.85rem;
    cursor: pointer;
    opacity: 0.6;
}

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

.btn-close-preview {
    display: none;
    width: 26px;
    height: 26px;
    background: var(--bg-input);
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    cursor: pointer;
}

/* Summary */
.summary-card {
    background: linear-gradient(135deg, var(--bg-card), var(--bg-input));
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.78rem;
    flex-wrap: wrap;
    gap: 5px;
}

.summary-row:last-child {
    border-bottom: none;
}

.total-row {
    font-size: 1rem;
    font-weight: 800;
    padding-top: 10px;
    margin-top: 6px;
    border-top: 2px solid var(--primary);
    border-bottom: none !important;
}

.total-amount {
    color: var(--primary-light);
}

.discount-inputs,
.tax-inputs {
    display: flex;
    align-items: center;
    gap: 3px;
}

/* Footer */
.footer {
    text-align: center;
    padding: 10px;
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 12px;
}

.footer a {
    color: var(--primary-light);
    text-decoration: none;
    font-weight: 600;
}

/* Mobile */
.action-buttons {
    display: none;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
}

.mobile-only {
    display: none;
}

/* Loading */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.95);
    display: none;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 12px;
    z-index: 9999;
}

.loading-overlay.show {
    display: flex;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
}

/* ===== PREVIEW STYLES ===== */
.preview-invoice {
    font-family: 'Plus Jakarta Sans', sans-serif;
}

.preview-invoice .inv-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding-bottom: 10pt;
    margin-bottom: 12pt;
    border-bottom: 2pt solid #2563eb;
}

.preview-invoice .inv-logo-container {
    max-width: 100px;
    max-height: 50px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.preview-invoice .inv-logo {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.preview-invoice .inv-company-name {
    font-size: 1.1rem;
    font-weight: 800;
    color: #2563eb;
}

.preview-invoice .inv-company-details {
    font-size: 0.6rem;
    opacity: 0.9;
    line-height: 1.5;
}

.preview-invoice .inv-title {
    text-align: right;
}

.preview-invoice .inv-title h1 {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: 2px;
    color: #2563eb;
}

.preview-invoice .inv-number {
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 4px;
    color: #475569;
    padding: 4px 10px;
    background: #f1f5f9;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
}

.preview-invoice .inv-body {
    flex: 1;
}

.preview-invoice .inv-meta {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.preview-invoice .inv-meta-item {
    flex: 1;
    min-width: 50pt;
    background: #f8fafc;
    padding: 8pt 10pt;
    border-radius: 4pt;
    text-align: center;
    border: 0.5pt solid #e2e8f0;
}

.preview-invoice .inv-meta-label {
    font-size: 7pt;
    color: #64748b;
    text-transform: uppercase;
    font-weight: 700;
}

.preview-invoice .inv-meta-value {
    font-size: 9pt;
    font-weight: 700;
    color: #1e293b;
    margin-top: 2pt;
}

.preview-invoice .inv-info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 14px;
}

.preview-invoice .inv-info-section {
    background: #fafbfc;
    padding: 8pt 10pt;
    border-radius: 4pt;
    border-left: 2pt solid #2563eb;
}

.preview-invoice .inv-info-section h4 {
    color: #2563eb;
    font-size: 7pt;
    text-transform: uppercase;
    letter-spacing: 0.3pt;
    margin-bottom: 4pt;
    font-weight: 700;
}

.preview-invoice .inv-info-section p {
    font-size: 9pt;
    color: #475569;
    margin-bottom: 2pt;
    word-break: break-word;
}

.preview-invoice .inv-info-section .name {
    font-weight: 700;
    color: #1a1a1a;
    font-size: 10pt;
}

.preview-invoice .inv-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 14pt;
    font-size: 9pt;
    table-layout: fixed;
}

.preview-invoice .inv-table th {
    background: #2563eb;
    color: white !important;
    padding: 8pt 12pt;
    text-align: left;
    font-size: 8pt;
    text-transform: uppercase;
    font-weight: 700;
    border: 1pt solid #1d4ed8;
}

.preview-invoice .inv-table th:first-child {
    border-radius: 4px 0 0 0;
    text-align: center;
    width: 35pt;
}

.preview-invoice .inv-table th:last-child {
    border-radius: 0 4px 0 0;
    text-align: right;
}

.preview-invoice .inv-table td {
    padding: 8pt 12pt;
    border: 0.5pt solid #e2e8f0;
    vertical-align: top;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
}

.preview-invoice .inv-table td:first-child {
    text-align: center;
    font-weight: 600;
    color: #475569;
    width: 35pt;
}

.preview-invoice .inv-table td:last-child {
    text-align: right;
    font-weight: 700;
    color: #2563eb !important;
}

.preview-invoice .inv-table .row-num {
    color: #94a3b8 !important;
    font-weight: 600;
    width: 20pt;
    text-align: center;
}

.preview-invoice .inv-item-name {
    font-weight: 600;
    color: #1a1a1a;
    font-size: 9pt;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

.preview-invoice .inv-item-desc {
    font-size: 8pt;
    color: #64748b;
    margin-top: 3pt;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
}

.preview-invoice .inv-summary {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 14px;
}

.preview-invoice .inv-summary-box {
    width: 150pt;
    background: #f8fafc;
    border: 0.5pt solid #e2e8f0;
    border-radius: 4pt;
    padding: 10pt;
    font-size: 9pt;
}

.preview-invoice .inv-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4pt 0;
    border-bottom: 0.5pt solid #e2e8f0;
    gap: 10pt;
}

.preview-invoice .inv-summary-row.total {
    border-bottom: none;
    border-top: 1.5pt solid #2563eb;
    margin-top: 6pt;
    padding-top: 6pt;
    font-size: 11pt;
    font-weight: 800;
    white-space: nowrap;
}

.preview-invoice .inv-summary-row.total span:last-child {
    color: #2563eb !important;
}

.preview-invoice .inv-payment {
    background: linear-gradient(135deg, #eff6ff, #dbeafe);
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 12px;
    border-left: 3px solid #2563eb;
}

.preview-invoice .inv-payment h4 {
    color: #1d4ed8;
    font-size: 0.6rem;
    font-weight: 800;
    margin-bottom: 8px;
}

.preview-invoice .inv-payment-methods {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 8px;
}

.preview-invoice .inv-payment-method {
    background: white;
    padding: 8px;
    border-radius: 4px;
    font-size: 0.55rem;
}

.preview-invoice .inv-payment-method .type {
    color: #059669;
    font-weight: 700;
    font-size: 0.45rem;
    text-transform: uppercase;
    margin-bottom: 3px;
}

.preview-invoice .inv-payment-method .detail strong {
    display: block;
    color: #047857;
    font-size: 0.65rem;
}

.preview-invoice .inv-qris-img {
    max-width: 55px;
    max-height: 55px;
    border-radius: 4px;
    margin-top: 4px;
}

.preview-invoice .inv-notes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 14px;
}

.preview-invoice .inv-note-box h5 {
    color: #64748b;
    font-size: 0.45rem;
    text-transform: uppercase;
    margin-bottom: 4px;
    font-weight: 700;
}

.preview-invoice .inv-note-box p {
    font-size: 0.55rem;
    color: #475569;
    background: #f8fafc;
    padding: 7px;
    border-radius: 4px;
    white-space: pre-line;
}

.preview-invoice .inv-signature {
    display: flex;
    justify-content: flex-end;
    padding-top: 20px;
    margin-top: 15px;
}

.preview-invoice .inv-signature-box {
    text-align: center;
    min-width: 140px;
    padding: 10px;
    background: #fafbfc;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}

.preview-invoice .inv-signature-img {
    max-width: 90px;
    max-height: 45px;
    margin-bottom: 8px;
}

.preview-invoice .inv-signature-line {
    width: 120px;
    height: 2px;
    background: #2563eb;
    margin: 30px auto 8px;
    border-radius: 1px;
}

.preview-invoice .inv-signer-name {
    font-weight: 700;
    color: #1e293b;
    font-size: 0.75rem;
    margin-top: 5px;
}

.preview-invoice .inv-signer-title {
    font-size: 0.6rem;
    color: #64748b;
}

.preview-invoice .inv-watermark {
    position: absolute;
    left: 50%;
    font-weight: 800;
    letter-spacing: 6px;
    pointer-events: none;
    text-transform: uppercase;
    white-space: nowrap;
}

.preview-invoice .inv-watermark-repeat {
    position: absolute;
    inset: 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    place-items: center;
    pointer-events: none;
    z-index: 1;
}

.preview-invoice .inv-watermark-repeat span {
    font-weight: 800;
    letter-spacing: 3px;
    text-transform: uppercase;
}

.preview-invoice .inv-footer {
    background: #f8fafc;
    color: #64748b;
    padding: 12px 30px;
    text-align: center;
    font-size: 0.6rem;
    border-top: 1px solid #e2e8f0;
}

.preview-invoice .pdf-header {
    background: #f8fafc;
    padding: 6px 20px;
    font-size: 0.5rem;
    color: #64748b;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid #e2e8f0;
}

.preview-invoice .pdf-footer-bar {
    background: #f8fafc;
    padding: 5px 20px;
    font-size: 0.45rem;
    color: #64748b;
    display: flex;
    justify-content: space-between;
    border-top: 1px solid #e2e8f0;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
    .app-container {
        grid-template-columns: 360px 1fr;
    }
}

@media (max-width: 992px) {

    /* Stack vertically on tablet/mobile - Like Surat Penawaran */
    .app-container {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .form-panel {
        max-height: none;
    }

    .form-panel form {
        max-height: 60vh;
        overflow-y: auto;
    }

    .preview-panel {
        min-height: 400px;
    }

    /* Hide mobile-only buttons since preview is always visible */
    .mobile-only {
        display: none !important;
    }

    .preview-invoice {
        width: 100%;
        padding: 20px;
        font-size: 10pt;
    }
}

@media (max-width: 768px) {
    .app-container {
        padding: 8px;
    }

    .header {
        flex-direction: column;
        gap: 8px;
        padding: 10px;
    }

    .tabs-nav {
        gap: 4px;
    }

    .tab-btn {
        padding: 8px 10px;
        font-size: 0.7rem;
    }

    .preview-invoice {
        padding: 15px;
        font-size: 9pt;
    }

    .preview-invoice .inv-title {
        font-size: 1.3rem;
    }

    .preview-invoice .inv-table th,
    .preview-invoice .inv-table td {
        padding: 6px 4px;
        font-size: 0.75rem;
    }
}

@media (max-width: 600px) {

    .form-row,
    .form-row-3,
    .form-row-4 {
        grid-template-columns: 1fr;
    }

    .header {
        flex-direction: column;
        gap: 8px;
    }

    .logo-upload-section {
        flex-direction: column;
    }

    .preview-invoice .inv-header {
        flex-direction: column;
        gap: 10px;
    }

    .preview-invoice .inv-title {
        text-align: left;
    }

    .preview-invoice .inv-info-grid,
    .preview-invoice .inv-notes {
        grid-template-columns: 1fr;
    }

    .preview-invoice .inv-meta {
        flex-direction: column;
    }
}

::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

@media print {
    body {
        background: white;
    }

    .form-panel,
    .preview-header,
    .footer {
        display: none !important;
    }

    .preview-panel {
        position: static;
        transform: none;
    }

    .preview-container {
        padding: 0;
    }

    .preview-invoice {
        box-shadow: none;
    }
}

/* ===== Google-Drive-like Preview Scaling ===== */
.preview-container {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.preview-stage {
    transform-origin: top center;
    will-change: transform;
    display: flex;
    justify-content: center;
}

/* Make the invoice look like paper in preview */
.preview-invoice {
    border-radius: 6px;
}

@media (max-width: 992px) {
    .preview-container {
        padding: 12px;
    }
}

@media (max-width: 600px) {
    .preview-container {
        padding: 10px;
    }
}

/* Keep the INVOICE paper layout consistent on small screens.
   We scale the whole paper (like Google Drive), so we DON'T want the invoice
   internal layout to collapse to 1 column in mobile breakpoints. */
@media (max-width: 600px) {
    #previewStage .preview-invoice {
        /* keep A4-like spacing */
        padding: 15mm 20mm !important;
        font-size: 10pt !important;
    }

    #previewStage .preview-invoice .inv-header {
        flex-direction: row !important;
        align-items: flex-start !important;
    }

    #previewStage .preview-invoice .inv-title {
        text-align: right !important;
    }

    #previewStage .preview-invoice .inv-info-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    #previewStage .preview-invoice .inv-meta {
        flex-direction: row !important;
    }
}


/* ===== PDF SAFE ===== */
#pdfRenderHost {
    position: fixed;
    top: 0;
    left: 0;
    width: 210mm;
    background: #ffffff;
    color: #111111;
    z-index: 99999;
    pointer-events: none;
}

#pdfRenderHost .preview-invoice {
    width: 210mm !important;
    max-width: 210mm !important;
    padding: 15mm 20mm !important;
    margin: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
}

/* ===== PDF LAYOUT HARDENING (Word-like) ===== */
#pdfRenderHost,
#pdfRenderHost * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

/* Ensure consistent typography & spacing in PDF */
#pdfRenderHost .preview-invoice.pdf-mode {
    font-family: 'Inter', 'Segoe UI', Arial, sans-serif !important;
    font-size: 10pt !important;
    line-height: 1.45 !important;
    color: #111111 !important;
}

/* Avoid awkward cuts */
#pdfRenderHost .inv-header,
#pdfRenderHost .inv-meta,
#pdfRenderHost .inv-info-grid,
#pdfRenderHost .inv-summary,
#pdfRenderHost .inv-payment,
#pdfRenderHost .inv-signature,
#pdfRenderHost .inv-footer,
#pdfRenderHost .pdf-header,
#pdfRenderHost .pdf-footer-bar {
    break-inside: avoid;
    page-break-inside: avoid;
}

/* Table printing rules */
#pdfRenderHost .inv-table {
    table-layout: fixed;
    width: 100% !important;
    border-collapse: collapse;
}

#pdfRenderHost .inv-table thead {
    display: table-header-group;
}

#pdfRenderHost .inv-table tfoot {
    display: table-footer-group;
}

#pdfRenderHost .inv-table tr {
    break-inside: avoid;
    page-break-inside: avoid;
}

/* Long text should wrap, not overflow */
#pdfRenderHost .inv-item-name,
#pdfRenderHost .inv-item-desc,
#pdfRenderHost .inv-info-section p,
#pdfRenderHost .inv-payment-method .detail {
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* Watermark should never distort layout in PDF */
#pdfRenderHost .inv-watermark,
#pdfRenderHost .inv-watermark-repeat {
    z-index: 0;
}

#pdfRenderHost .inv-body,
#pdfRenderHost .inv-header,
#pdfRenderHost .inv-footer {
    position: relative;
    z-index: 2;
}