:root {
    color-scheme: light;
    --bg: #eef3f9;
    --surface: #ffffff;
    --surface-muted: #f7f9fc;
    --text: #142033;
    --text-soft: #66758a;
    --line: #dfe6ef;
    --line-strong: #cbd6e3;
    --primary: #155eef;
    --primary-hover: #0d4fd4;
    --primary-soft: #eaf1ff;
    --success: #07875f;
    --success-soft: #e8f8f2;
    --warning: #ad6800;
    --warning-soft: #fff6df;
    --danger: #c93434;
    --danger-soft: #fff0f0;
    --shadow: 0 24px 72px rgba(25, 43, 73, .14), 0 4px 18px rgba(25, 43, 73, .07);
    --radius: 24px;
    --transition: 170ms ease;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
    min-height: 100svh;
    color: var(--text);
    background:
        radial-gradient(circle at 15% 15%, rgba(21, 94, 239, .10), transparent 30%),
        radial-gradient(circle at 90% 90%, rgba(40, 181, 145, .09), transparent 32%),
        var(--bg);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
button, input, select { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
button { border: 0; }
svg { display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

.viewport-shell {
    display: grid;
    width: 100%;
    height: 100dvh;
    min-height: 100svh;
    padding: clamp(10px, 2.5vh, 24px);
    place-items: center;
}

.payment-card {
    position: relative;
    width: min(548px, 100%);
    max-height: calc(100dvh - clamp(20px, 5vh, 48px));
    min-height: 0;
    padding: clamp(20px, 3.5vh, 32px);
    overflow: hidden;
    border: 1px solid rgba(203, 214, 227, .86);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, .97);
    box-shadow: var(--shadow);
    isolation: isolate;
}
.payment-card::before {
    position: absolute;
    z-index: -1;
    top: 0;
    right: 0;
    left: 0;
    height: 4px;
    content: "";
    background: linear-gradient(90deg, var(--primary), #3f8cff 58%, #28b591);
}

.panel { min-width: 0; }
.panel.is-active { animation: panel-in 180ms ease both; }
@keyframes panel-in {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

.form-heading {
    display: flex;
    align-items: center;
    gap: 13px;
    margin-bottom: clamp(15px, 2.5vh, 22px);
}
.form-mark {
    display: grid;
    flex: 0 0 45px;
    width: 45px;
    height: 45px;
    color: var(--primary);
    border: 1px solid #d9e5fb;
    border-radius: 15px;
    background: var(--primary-soft);
    place-items: center;
}
.form-mark svg { width: 24px; height: 24px; stroke-width: 1.9; }
h1, h2, p { margin: 0; }
.form-heading h1 { font-size: clamp(1.35rem, 3vw, 1.6rem); line-height: 1.1; letter-spacing: -.025em; }
.form-heading p { margin-top: 5px; color: var(--text-soft); font-size: .77rem; font-weight: 600; }

#payment-form { display: grid; gap: clamp(11px, 1.8vh, 15px); }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.field-group { min-width: 0; }
.field-group > label {
    display: block;
    margin: 0 0 6px 2px;
    color: #35455c;
    font-size: .75rem;
    font-weight: 750;
}
.input-control {
    position: relative;
    display: flex;
    min-width: 0;
    height: 48px;
    align-items: center;
    border: 1px solid var(--line-strong);
    border-radius: 13px;
    background: #fff;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.input-control:focus-within {
    border-color: #6d9cf7;
    box-shadow: 0 0 0 4px rgba(21, 94, 239, .10);
}
.input-control.is-invalid { border-color: #e67474; box-shadow: 0 0 0 4px rgba(201, 52, 52, .08); }
.input-control input,
.input-control select {
    width: 100%;
    min-width: 0;
    height: 100%;
    border: 0;
    outline: 0;
    color: var(--text);
    background: transparent;
    font-size: .88rem;
    font-weight: 650;
}
.input-control input { padding: 0 14px; }
.input-control input::placeholder { color: #9aa7b7; font-weight: 500; }
.input-control select {
    padding: 0 42px 0 43px;
    appearance: none;
    cursor: pointer;
}
.input-control input:disabled,
.input-control select:disabled { cursor: not-allowed; color: #9aa7b7; }
.input-control:has(input:disabled),
.input-control:has(select:disabled) { background: #f5f7fa; }
.control-icon {
    position: absolute;
    left: 14px;
    width: 18px;
    height: 18px;
    color: #77869a;
    pointer-events: none;
}
.control-icon svg { width: 18px; height: 18px; }
.input-control .control-icon + input { padding-left: 43px; }
.select-arrow {
    position: absolute;
    right: 16px;
    width: 8px;
    height: 8px;
    border-right: 2px solid #7d8da1;
    border-bottom: 2px solid #7d8da1;
    transform: translateY(-2px) rotate(45deg);
    pointer-events: none;
}
.amount-control input { padding-left: 50px; font-size: 1.06rem; font-weight: 800; letter-spacing: .01em; }
.currency-prefix {
    position: absolute;
    left: 14px;
    color: #51647e;
    font-size: .82rem;
    font-weight: 800;
    pointer-events: none;
}
.field-meta { display: flex; min-height: 15px; justify-content: space-between; gap: 8px; padding: 4px 2px 0; }
.field-meta small, .field-error { color: #8996a7; font-size: .62rem; line-height: 1.35; }
.field-error { display: block; min-height: 14px; padding: 3px 2px 0; color: var(--danger); font-weight: 650; }
.field-meta .field-error { margin-left: auto; padding: 0; text-align: right; }

.invoice-description {
    display: flex;
    min-width: 0;
    min-height: 46px;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface-muted);
}
.invoice-description span { flex: 0 0 auto; color: var(--text-soft); font-size: .68rem; font-weight: 650; }
.invoice-description strong { min-width: 0; overflow: hidden; color: #304159; font-size: .72rem; text-align: right; text-overflow: ellipsis; white-space: nowrap; }

.button {
    display: inline-flex;
    min-height: 49px;
    align-items: center;
    justify-content: center;
    gap: 9px;
    padding: 0 17px;
    border: 1px solid transparent;
    border-radius: 13px;
    cursor: pointer;
    transition: transform var(--transition), background var(--transition), border-color var(--transition), opacity var(--transition), box-shadow var(--transition);
    font-size: .79rem;
    font-weight: 800;
}
.button svg { width: 18px; height: 18px; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(0); }
.button:focus-visible, .icon-button:focus-visible, .text-button:focus-visible, .method-option:focus-visible { outline: 3px solid rgba(21, 94, 239, .24); outline-offset: 2px; }
.button:disabled { cursor: not-allowed; opacity: .48; }
.button-full { width: 100%; }
.button-primary { color: #fff; background: var(--primary); box-shadow: 0 9px 20px rgba(21, 94, 239, .20); }
.button-primary:hover:not(:disabled) { background: var(--primary-hover); box-shadow: 0 11px 24px rgba(21, 94, 239, .25); }
.button-secondary { color: #29415f; border-color: var(--line-strong); background: #fff; }
.button-secondary:hover:not(:disabled) { border-color: #9fb2ca; background: #f7f9fc; }

.alert {
    margin-bottom: 14px;
    padding: 11px 13px;
    border: 1px solid #efb8b8;
    border-radius: 12px;
    color: #8d2929;
    background: var(--danger-soft);
    font-size: .72rem;
    font-weight: 650;
    line-height: 1.45;
}
.setup-notice {
    display: grid;
    gap: 3px;
    padding: 10px 12px;
    border: 1px solid #eed59b;
    border-radius: 12px;
    background: var(--warning-soft);
}
.setup-notice strong { color: #7a4c00; font-size: .75rem; }
.setup-notice span, .setup-notice small { color: #8d6a2c; font-size: .65rem; line-height: 1.35; }
.setup-notice code { font-size: .62rem; }

.panel-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.panel-topbar h2, .invoice-status-row h2 { font-size: 1.08rem; line-height: 1.2; letter-spacing: -.015em; }
.panel-topbar p { margin-top: 4px; color: var(--text-soft); font-size: .7rem; font-weight: 600; }
.icon-button {
    display: grid;
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    color: #425671;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    place-items: center;
}
.icon-button:hover { background: var(--surface-muted); }
.icon-button svg { width: 20px; height: 20px; }

#methods-panel {
    display: flex;
    max-height: calc(100dvh - clamp(60px, 10vh, 96px));
    min-height: 0;
    flex-direction: column;
}
.methods-list {
    display: grid;
    min-height: 120px;
    max-height: min(54vh, 430px);
    padding: 2px 5px 2px 2px;
    overflow: auto;
    gap: 9px;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}
.method-option {
    position: relative;
    display: grid;
    width: 100%;
    min-height: 62px;
    grid-template-columns: 46px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    color: var(--text);
    background: #fff;
    cursor: pointer;
    text-align: left;
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}
.method-option:hover { border-color: #b6c7dc; background: #fbfcfe; }
.method-option.is-selected { border-color: #6d9cf7; background: #f5f8ff; box-shadow: 0 0 0 3px rgba(21, 94, 239, .09); }
.method-logo {
    display: grid;
    width: 46px;
    height: 42px;
    overflow: hidden;
    border: 1px solid #e4eaf2;
    border-radius: 10px;
    background: #fff;
    place-items: center;
}
.method-logo img { display: block; max-width: 38px; max-height: 29px; object-fit: contain; }
.method-logo span { color: var(--primary); font-size: .68rem; font-weight: 900; }
.method-copy { min-width: 0; }
.method-copy strong { display: block; overflow: hidden; font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.method-copy small { display: block; margin-top: 4px; color: var(--text-soft); font-size: .63rem; }
.method-check {
    display: grid;
    width: 20px;
    height: 20px;
    color: transparent;
    border: 1.5px solid #bac6d5;
    border-radius: 50%;
    place-items: center;
}
.method-check svg { width: 13px; height: 13px; stroke-width: 2.4; }
.method-option.is-selected .method-check { color: #fff; border-color: var(--primary); background: var(--primary); }
.panel-actions { padding-top: 14px; }

.invoice-panel { display: flex; max-height: calc(100dvh - clamp(60px, 10vh, 96px)); min-height: 0; flex-direction: column; }
.invoice-status-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.invoice-kicker { display: block; margin-bottom: 4px; color: var(--primary); font-size: .61rem; font-weight: 850; letter-spacing: .09em; text-transform: uppercase; }
.status-badge {
    display: inline-flex;
    min-width: 76px;
    height: 29px;
    align-items: center;
    justify-content: center;
    padding: 0 11px;
    border-radius: 999px;
    font-size: .64rem;
    font-weight: 900;
    letter-spacing: .045em;
}
.status-unpaid { color: var(--warning); background: var(--warning-soft); }
.status-paid { color: var(--success); background: var(--success-soft); }
.invoice-scroll { min-height: 0; overflow: auto; padding-right: 3px; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }
.invoice-total {
    display: grid;
    padding: 17px;
    border-radius: 16px;
    color: #fff;
    background: linear-gradient(135deg, #164fcb, #176df1 65%, #3484ff);
    box-shadow: 0 13px 28px rgba(21, 94, 239, .20);
}
.invoice-total span { color: rgba(255,255,255,.76); font-size: .67rem; font-weight: 650; }
.invoice-total strong { margin-top: 5px; font-size: clamp(1.42rem, 5vw, 1.85rem); letter-spacing: -.025em; }
.invoice-total small { margin-top: 8px; color: rgba(255,255,255,.82); font-size: .65rem; line-height: 1.4; }
.hosted-link-box {
    position: relative;
    display: grid;
    gap: 5px;
    margin-top: 12px;
    padding: 11px 78px 11px 12px;
    border: 1px solid #cddcf5;
    border-radius: 13px;
    background: #f5f8ff;
}
.hosted-link-box > span { color: #62738a; font-size: .61rem; font-weight: 700; }
.hosted-link-box a { overflow: hidden; color: var(--primary); font-size: .68rem; font-weight: 750; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
.hosted-link-box a:hover { text-decoration: underline; }
.hosted-link-box .text-button { position: absolute; top: 50%; right: 11px; transform: translateY(-50%); }
.invoice-details { margin: 12px 0 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.invoice-details > div { display: grid; grid-template-columns: 38% minmax(0, 62%); gap: 10px; padding: 9px 11px; border-bottom: 1px solid var(--line); background: #fff; }
.invoice-details > div:last-child { border-bottom: 0; }
.invoice-details dt { color: var(--text-soft); font-size: .64rem; font-weight: 650; }
.invoice-details dd { min-width: 0; margin: 0; color: #2e4058; font-size: .67rem; font-weight: 750; text-align: right; overflow-wrap: anywhere; }
.invoice-actions { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, .85fr); gap: 9px; padding-top: 14px; }
.invoice-actions .button { min-width: 0; padding: 0 12px; }
.invoice-new { grid-column: 1 / -1; justify-self: center; margin-top: 1px; }
.text-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 5px;
    color: var(--primary);
    background: transparent;
    cursor: pointer;
    font-size: .65rem;
    font-weight: 800;
    text-decoration: none;
}
.text-button:hover { color: var(--primary-hover); text-decoration: underline; }

.loading-overlay {
    position: fixed;
    z-index: 9999;
    inset: 0;
    display: grid;
    padding: 20px;
    background: rgba(13, 25, 43, .56);
    backdrop-filter: blur(6px);
    place-items: center;
}
.loading-card {
    display: grid;
    width: min(310px, 90vw);
    padding: 24px;
    border: 1px solid rgba(255,255,255,.7);
    border-radius: 18px;
    background: #fff;
    box-shadow: var(--shadow);
    place-items: center;
    text-align: center;
}
.loading-card strong { margin-top: 13px; font-size: .88rem; }
.loading-card small { margin-top: 5px; color: var(--text-soft); font-size: .68rem; }
.spinner { width: 28px; height: 28px; border: 3px solid rgba(21, 94, 239, .16); border-top-color: var(--primary); border-radius: 50%; animation: spin .78s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
    position: fixed;
    z-index: 10000;
    right: 18px;
    bottom: 18px;
    max-width: min(370px, calc(100vw - 36px));
    padding: 11px 14px;
    border-radius: 11px;
    color: #fff;
    background: #16263d;
    box-shadow: 0 16px 36px rgba(15, 30, 53, .24);
    opacity: 0;
    pointer-events: none;
    transform: translateY(9px);
    transition: opacity var(--transition), transform var(--transition);
    font-size: .7rem;
    font-weight: 700;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }

.return-page { display: grid; width: 100%; height: 100dvh; min-height: 100svh; padding: 18px; overflow: hidden; place-items: center; background: var(--bg); }
.return-card { width: min(410px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 20px; background: #fff; box-shadow: var(--shadow); text-align: center; }
.return-card .spinner { display: inline-block; }
.return-card h1 { margin-top: 16px; font-size: 1.18rem; }
.return-card p { margin-top: 8px; color: var(--text-soft); font-size: .74rem; line-height: 1.55; }
.return-card a { display: inline-block; margin-top: 17px; color: var(--primary); font-size: .73rem; font-weight: 800; }

@media (max-width: 560px) {
    .viewport-shell { padding: 10px; }
    .payment-card { max-height: calc(100dvh - 20px); padding: 20px 17px; border-radius: 20px; }
    .field-row { gap: 8px; }
    .field-group > label { font-size: .7rem; }
    .input-control { height: 46px; border-radius: 12px; }
    .input-control input, .input-control select { font-size: .8rem; }
    .input-control select { padding-left: 39px; }
    .control-icon { left: 12px; }
    .input-control .control-icon + input { padding-left: 39px; }
    .invoice-description { gap: 9px; padding-right: 10px; padding-left: 10px; }
    .invoice-description strong { font-size: .66rem; }
    .button { min-height: 47px; }
    .invoice-actions { grid-template-columns: 1fr 1fr; }
    .invoice-actions .button { font-size: .69rem; }
}

@media (max-width: 350px) {
    .field-row { grid-template-columns: 1fr; }
    .invoice-description span { display: none; }
    .invoice-description strong { width: 100%; text-align: left; }
}

@media (max-height: 680px) {
    .viewport-shell { padding-top: 8px; padding-bottom: 8px; }
    .payment-card { max-height: calc(100dvh - 16px); padding-top: 18px; padding-bottom: 18px; }
    .form-heading { margin-bottom: 11px; }
    .form-mark { width: 40px; height: 40px; flex-basis: 40px; border-radius: 13px; }
    .form-mark svg { width: 21px; height: 21px; }
    .form-heading p { margin-top: 3px; }
    #payment-form { gap: 9px; }
    .field-group > label { margin-bottom: 4px; }
    .input-control { height: 44px; }
    .field-meta { min-height: 12px; padding-top: 2px; }
    .field-error { min-height: 11px; padding-top: 2px; }
    .invoice-description { min-height: 40px; padding-top: 7px; padding-bottom: 7px; }
    .button { min-height: 45px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media print {
    html, body { height: auto; overflow: visible; background: #fff; }
    .viewport-shell { display: block; height: auto; padding: 0; }
    .payment-card { width: 100%; max-height: none; padding: 0; overflow: visible; border: 0; box-shadow: none; }
    .payment-card::before, #form-panel, #methods-panel, .invoice-actions, .loading-overlay, .toast, .alert { display: none !important; }
    #invoice-panel { display: block !important; max-height: none; }
    .invoice-scroll { overflow: visible; }
    .invoice-total { color: #000; border: 1px solid #aaa; background: #fff; box-shadow: none; }
    .invoice-total span, .invoice-total small { color: #444; }
}
