:root {
    --sip-primary: #4f46e5;
    --sip-primary-dark: #3730a3;
    --sip-primary-soft: #eef2ff;
    --sip-ink: #111827;
    --sip-muted: #64748b;
    --sip-line: #e2e8f0;
    --sip-surface: #ffffff;
    --sip-bg: #f1f5f9;
    --sip-success: #15803d;
    --sip-success-soft: #dcfce7;
    --sip-danger: #b91c1c;
    --sip-danger-soft: #fee2e2;
    --sip-warning: #b45309;
    --sip-warning-soft: #fef3c7;
    --sip-info: #0369a1;
    --sip-info-soft: #e0f2fe;
    --sip-radius: 18px;
    --sip-shadow: 0 24px 70px rgba(15, 23, 42, .12);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--sip-bg); }
body.sip-body {
    min-height: 100vh;
    margin: 0;
    color: var(--sip-ink);
    background:
        radial-gradient(circle at 10% 10%, rgba(79, 70, 229, .11), transparent 28rem),
        radial-gradient(circle at 90% 85%, rgba(14, 165, 233, .09), transparent 26rem),
        var(--sip-bg);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.55;
}

a { color: var(--sip-primary); text-decoration: none; }
a:hover { color: var(--sip-primary-dark); text-decoration: none; }

.sip-page-shell { width: 100%; padding: 42px 20px 28px; }
.sip-invoice {
    position: relative;
    width: min(1120px, 100%);
    margin: 0 auto;
    overflow: hidden;
    background: var(--sip-surface);
    border: 1px solid rgba(226, 232, 240, .9);
    border-radius: 24px;
    box-shadow: var(--sip-shadow);
}
.sip-accent-line { height: 7px; background: linear-gradient(90deg, var(--sip-primary), #7c3aed 55%, #0ea5e9); }
.sip-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 32px;
    padding: 38px 44px 30px;
    border-bottom: 1px solid var(--sip-line);
}
.sip-brand { min-width: 0; }
.sip-brand-link { display: inline-flex; align-items: center; max-width: 280px; }
.sip-logo { display: block; max-width: 240px; max-height: 78px; width: auto; height: auto; object-fit: contain; }
.sip-brand-name { color: var(--sip-ink); font-size: 30px; font-weight: 800; letter-spacing: -.04em; }
.sip-brand-subtitle { margin-top: 10px; color: var(--sip-muted); font-size: 13px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.sip-title-area { max-width: 480px; text-align: right; }
.sip-eyebrow { color: var(--sip-muted); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.sip-title-area h1 { margin: 5px 0 14px; color: var(--sip-ink); font-size: clamp(28px, 4vw, 44px); font-weight: 850; line-height: 1.08; letter-spacing: -.045em; }
.sip-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 104px;
    padding: 8px 14px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 850;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.sip-status-paid { color: var(--sip-success); background: var(--sip-success-soft); }
.sip-status-unpaid, .sip-status-collections { color: var(--sip-danger); background: var(--sip-danger-soft); }
.sip-status-pending, .sip-status-draft { color: var(--sip-warning); background: var(--sip-warning-soft); }
.sip-status-refunded { color: var(--sip-info); background: var(--sip-info-soft); }
.sip-status-cancelled { color: #475569; background: #e2e8f0; }

.sip-alert { display: grid; gap: 3px; margin: 24px 44px 0; padding: 14px 18px; border: 1px solid transparent; border-radius: 12px; }
.sip-alert strong { font-size: 13px; }
.sip-alert span { font-size: 14px; }
.sip-alert-success { color: #14532d; background: #f0fdf4; border-color: #bbf7d0; }
.sip-alert-danger, .sip-alert-error { color: #7f1d1d; background: #fef2f2; border-color: #fecaca; }
.sip-alert-info { color: #0c4a6e; background: #f0f9ff; border-color: #bae6fd; }
.sip-alert-warning { color: #78350f; background: #fffbeb; border-color: #fde68a; }

.sip-summary-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    padding: 30px 44px;
}
.sip-info-card, .sip-balance-card, .sip-notes, .sip-qr-section {
    border: 1px solid var(--sip-line);
    border-radius: var(--sip-radius);
    background: #fff;
}
.sip-info-card { min-height: 180px; padding: 22px; }
.sip-card-label { display: flex; align-items: center; gap: 9px; margin-bottom: 15px; color: var(--sip-primary); font-size: 12px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.sip-address { color: #334155; font-size: 14px; line-height: 1.75; }
.sip-muted { color: var(--sip-muted); }
.sip-custom-fields { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--sip-line); }
.sip-custom-fields div { margin-top: 4px; }
.sip-custom-fields span { color: var(--sip-muted); }
.sip-meta-card { display: grid; align-content: center; gap: 0; }
.sip-meta-row { display: flex; justify-content: space-between; gap: 18px; padding: 13px 0; border-bottom: 1px solid var(--sip-line); color: var(--sip-muted); font-size: 13px; }
.sip-meta-row:last-child { border-bottom: 0; }
.sip-meta-row strong { color: var(--sip-ink); text-align: right; }
.sip-payment-method { max-width: 64%; text-align: right; }
.sip-gateway-form { margin: 0; }
.sip-select, .sip-input {
    width: 100%;
    min-height: 42px;
    padding: 9px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    color: var(--sip-ink);
    background: #fff;
    font: inherit;
}
.sip-select:focus, .sip-input:focus { outline: 3px solid rgba(79, 70, 229, .14); border-color: var(--sip-primary); }
.sip-balance-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 180px;
    padding: 26px;
    color: #fff;
    background: linear-gradient(135deg, #111827, #312e81 62%, #4338ca);
    border: 0;
}
.sip-balance-card span { color: #c7d2fe; font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.sip-balance-card strong { margin: 8px 0 5px; font-size: clamp(30px, 4vw, 46px); line-height: 1.1; letter-spacing: -.04em; }
.sip-balance-card small { color: #e0e7ff; }

.sip-payment-panel, .sip-credit-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin: 0 44px 30px;
    padding: 22px 24px;
    border: 1px solid #c7d2fe;
    border-radius: var(--sip-radius);
    background: linear-gradient(135deg, #eef2ff, #f8fafc);
}
.sip-payment-copy { display: flex; align-items: center; gap: 16px; }
.sip-payment-icon { display: grid; place-items: center; flex: 0 0 46px; width: 46px; height: 46px; color: #fff; background: var(--sip-primary); border-radius: 14px; box-shadow: 0 9px 22px rgba(79, 70, 229, .24); }
.sip-payment-panel h2, .sip-credit-panel h2 { margin: 0 0 3px; font-size: 18px; font-weight: 800; }
.sip-payment-panel p, .sip-credit-panel p { margin: 0; color: var(--sip-muted); font-size: 13px; }
.sip-payment-button { min-width: 190px; text-align: right; }
.sip-payment-button form { margin: 0; }
.sip-payment-button .btn, .sip-payment-button button, .sip-payment-button input[type="submit"], .sip-payment-button a {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 11px 20px !important;
    border: 0 !important;
    border-radius: 12px !important;
    color: #fff !important;
    background: var(--sip-primary) !important;
    box-shadow: 0 10px 24px rgba(79, 70, 229, .2);
    font-weight: 800 !important;
    text-decoration: none !important;
}
.sip-payment-button .btn:hover, .sip-payment-button button:hover, .sip-payment-button input[type="submit"]:hover, .sip-payment-button a:hover { background: var(--sip-primary-dark) !important; transform: translateY(-1px); }
.sip-credit-panel { align-items: flex-end; background: #f0fdf4; border-color: #bbf7d0; }
.sip-credit-form { width: min(420px, 100%); }
.sip-credit-form label { display: block; margin-bottom: 6px; color: #166534; font-size: 12px; font-weight: 800; }
.sip-input-group { display: flex; gap: 8px; }

.sip-notes { margin: 0 44px 30px; padding: 20px 22px; background: #fffbeb; border-color: #fde68a; color: #78350f; }
.sip-notes .sip-card-label { color: #b45309; }
.sip-section { padding: 6px 44px 32px; }
.sip-section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.sip-section-kicker { color: var(--sip-primary); font-size: 11px; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; }
.sip-section-heading h2 { margin: 3px 0 0; font-size: 24px; font-weight: 850; letter-spacing: -.03em; }
.sip-section-count, .sip-balance-pill { padding: 7px 11px; border-radius: 999px; color: var(--sip-muted); background: #f8fafc; border: 1px solid var(--sip-line); font-size: 11px; font-weight: 800; }
.sip-balance-pill { color: var(--sip-primary-dark); background: var(--sip-primary-soft); border-color: #c7d2fe; }
.sip-table-wrap { overflow-x: auto; border: 1px solid var(--sip-line); border-radius: 15px; }
.sip-table { width: 100%; margin: 0; border-collapse: collapse; font-size: 13px; }
.sip-table th, .sip-table td { padding: 15px 16px; vertical-align: top; border-bottom: 1px solid var(--sip-line); text-align: left; }
.sip-table th { color: #475569; background: #f8fafc; font-size: 11px; font-weight: 850; letter-spacing: .07em; text-transform: uppercase; }
.sip-table tbody tr:last-child td { border-bottom: 1px solid var(--sip-line); }
.sip-table tbody tr:hover td { background: #fafbff; }
.sip-table tfoot td { padding-top: 12px; padding-bottom: 12px; background: #fbfdff; font-weight: 700; }
.sip-table tfoot tr:last-child td { border-bottom: 0; }
.sip-table .sip-total-row td { color: var(--sip-primary-dark); background: var(--sip-primary-soft); font-size: 15px; font-weight: 850; }
.sip-amount-col { width: 22%; text-align: right !important; white-space: nowrap; }
.sip-tax-star { color: var(--sip-danger); font-weight: 900; }
.sip-tax-note { margin: 8px 0 0; color: var(--sip-muted); font-size: 11px; }
.sip-empty-row { padding: 28px !important; color: var(--sip-muted); text-align: center !important; }
.sip-qr-section { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 0 44px 32px; padding: 20px 22px; background: #f8fafc; }
.sip-qr-section .sip-card-label { margin: 0; }
.sip-qr-wrapper img, .sip-qr-wrapper svg { display: block; max-width: 120px; height: auto; }

.sip-footer { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 26px 44px; border-top: 1px solid var(--sip-line); background: #f8fafc; }
.sip-footer > div:first-child { display: grid; gap: 2px; }
.sip-footer strong { font-size: 14px; }
.sip-footer span { color: var(--sip-muted); font-size: 12px; }
.sip-footer-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.sip-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 9px 15px;
    border: 1px solid transparent;
    border-radius: 11px;
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    font-weight: 800;
    transition: transform .18s ease, box-shadow .18s ease, background-color .18s ease;
}
.sip-btn:hover { transform: translateY(-1px); }
.sip-btn-primary { color: #fff !important; background: var(--sip-primary); box-shadow: 0 8px 18px rgba(79, 70, 229, .18); }
.sip-btn-primary:hover { background: var(--sip-primary-dark); }
.sip-btn-light { color: #334155 !important; background: #fff; border-color: var(--sip-line); }
.sip-btn-light:hover { background: #f1f5f9; }
.sip-btn-success { color: #fff; background: var(--sip-success); }
.sip-back-link { margin: 20px auto 0; text-align: center; }
.sip-back-link a { color: #475569; font-size: 13px; font-weight: 700; }

.sip-error-card { width: min(620px, 100%); margin: 10vh auto 0; padding: 44px; text-align: center; background: #fff; border: 1px solid var(--sip-line); border-radius: 22px; box-shadow: var(--sip-shadow); }
.sip-error-icon { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto 18px; color: var(--sip-danger); background: var(--sip-danger-soft); border-radius: 18px; font-size: 26px; }
.sip-error-card h1 { margin: 0 0 8px; }
.sip-error-card p { margin: 0 0 24px; color: var(--sip-muted); }

#fullpage-overlay { z-index: 99999; }

@media (max-width: 760px) {
    .sip-page-shell { padding: 14px 10px 22px; }
    .sip-invoice { border-radius: 18px; }
    .sip-header { flex-direction: column; padding: 26px 22px 22px; }
    .sip-title-area { max-width: none; text-align: left; }
    .sip-summary-grid { grid-template-columns: 1fr; padding: 22px; }
    .sip-info-card, .sip-balance-card { min-height: auto; }
    .sip-payment-panel, .sip-credit-panel, .sip-footer { flex-direction: column; align-items: stretch; margin-left: 22px; margin-right: 22px; }
    .sip-payment-button { min-width: 0; text-align: left; }
    .sip-credit-form { width: 100%; }
    .sip-input-group { flex-direction: column; }
    .sip-notes, .sip-qr-section { margin-left: 22px; margin-right: 22px; }
    .sip-section { padding-left: 22px; padding-right: 22px; }
    .sip-section-heading { align-items: flex-start; flex-direction: column; }
    .sip-footer { margin: 0; padding: 24px 22px; }
    .sip-footer-actions { justify-content: flex-start; }
    .sip-transactions-table { min-width: 720px; }
}

@media print {
    @page { size: A4; margin: 10mm; }
    html, body.sip-body { background: #fff !important; }
    body.sip-body { color: #000; }
    .sip-page-shell { padding: 0; }
    .sip-invoice { width: 100%; border: 0; border-radius: 0; box-shadow: none; }
    .sip-header { padding: 22px 0; }
    .sip-summary-grid { padding: 20px 0; }
    .sip-payment-panel, .sip-credit-panel, .sip-notes, .sip-qr-section { margin-left: 0; margin-right: 0; }
    .sip-section { padding-left: 0; padding-right: 0; }
    .sip-footer { padding-left: 0; padding-right: 0; background: #fff; }
    .sip-table-wrap { overflow: visible; }
    .sip-table th { color: #000; }
    .sip-balance-card { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .d-print-none, .sip-back-link, #fullpage-overlay { display: none !important; }
    a { color: inherit !important; text-decoration: none !important; }
}
