:root {
    color-scheme: light;
    --bg: #f7f8fc;
    --panel: #ffffff;
    --text: #182042;
    --muted: #4d577a;
    --border: #d9def5;
    --accent: #2536ff;
    --color-env-banner: #c1121f;
    --shadow-card: 0 24px 60px rgba(28, 36, 74, 0.16);
    --shadow-soft: 0 12px 30px rgba(24, 32, 66, 0.1);
    --radius-pill: 999px;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(circle at 20% 20%, #eef2ff, var(--bg) 70%);
    color: var(--text);
    font-family: inherit;
    line-height: 1.6;
}

.wrapper {
    width: min(800px, calc(100% - 2rem));
    margin: 0 auto;
}

.environment-banner {
    background: var(--color-env-banner);
    color: #ffffff;
    text-align: center;
    padding: 0.6rem 1rem;
    font-weight: 600;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    font-size: 0.85rem;
    position: sticky;
    top: 0;
    z-index: 20;
    display: none;
}

.has-environment-banner .environment-banner {
    display: block;
}

.confirmation {
    padding: 2rem 0 4rem;
}

.letter {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 1.5rem;
    padding: min(4vw, 3rem);
    box-shadow: var(--shadow-card);
    position: relative;
}

.customer-id {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    border-radius: 999px;
    border: 1px solid rgba(37, 54, 255, 0.35);
    background: rgba(37, 54, 255, 0.08);
    color: var(--text);
    font-size: 0.75rem;
    padding: 0.35rem 0.8rem;
    font-weight: 600;
    cursor: pointer;
    text-shadow: 0 0 10px rgba(37, 54, 255, 0.25);
    transition: box-shadow 0.2s ease, transform 0.2s ease, background 0.2s ease;
    animation: customer-id-glow 2.6s ease-in-out infinite;
}

.save-pdf-btn {
    left: 1.5rem;
    right: auto;
}

.customer-id:focus-visible {
    outline: 2px solid rgba(37, 54, 255, 0.35);
    outline-offset: 2px;
}

.customer-id:hover {
    transform: translateY(-1px);
    background: rgba(37, 54, 255, 0.12);
    box-shadow: 0 0 18px rgba(37, 54, 255, 0.35);
}

.customer-id::after {
    content: attr(data-copy-status);
    position: absolute;
    right: 0.5rem;
    top: calc(100% + 0.35rem);
    font-size: 0.7rem;
    color: var(--muted);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.customer-id[data-copied="true"]::after {
    opacity: 1;
}

.customer-id-label {
    color: var(--muted);
    font-weight: 600;
}

#customer-id-value {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    letter-spacing: 0.03em;
}

.letter-header h1 {
    margin: 0 0 0.75rem;
    font-size: clamp(1.9rem, 4vw, 2.6rem);
}

.lede {
    color: var(--muted);
    margin: 0 0 0.25rem;
}

.total-line {
    font-weight: 600;
    margin: 1.5rem 0;
    font-size: 1.1rem;
}

.items-block {
    margin: 2rem 0;
}

.agreements-block {
    margin: 2rem 0;
}

.items-heading {
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.items-list {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 1rem;
}

.item-row {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(24, 32, 66, 0.08);
}

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

.agreement-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.agreement-content {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.item-title {
    display: block;
    font-weight: 600;
}

.agreement-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.95rem;
}

.agreement-link:hover {
    text-decoration: underline;
}

.agreement-status {
    border-radius: var(--radius-pill);
    border: 1px solid rgba(24, 32, 66, 0.18);
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    background: rgba(24, 32, 66, 0.04);
    flex-shrink: 0;
}

.agreement-status.is-accepted {
    color: #0f9d6f;
    border-color: rgba(22, 194, 170, 0.6);
    background: rgba(22, 194, 170, 0.16);
}

.agreement-helper {
    margin-top: 0.85rem;
}

.item-quantity {
    display: block;
    font-size: 0.85rem;
    color: var(--muted);
    margin-top: 0.25rem;
}

.api-placeholder {
    display: inline-block;
    margin-top: 0.35rem;
    font-size: 0.9rem;
    color: var(--muted);
}

.api-key-container {
    margin-top: 0.35rem;
}

.item-expiry {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.85rem;
    color: var(--muted);
}

.api-key-list {
    list-style: none;
    padding: 0;
    margin: 0.25rem 0 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.api-key-chip {
    display: inline-block;
    background: rgba(37, 54, 255, 0.08);
    border: 1px solid rgba(37, 54, 255, 0.3);
    border-radius: 0.65rem;
    padding: 0.5rem 0.75rem;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 0.9rem;
    word-break: break-all;
}

.muted {
    text-align: center;
    color: var(--muted);
}

.resources p {
    margin: 0.75rem 0;
}

.resources a {
    color: var(--accent);
    text-decoration: none;
}

.resources a:hover {
    text-decoration: underline;
}

.policy-links {
    list-style: none;
    padding: 0;
    margin: 1rem 0 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.signature {
    margin: 2rem 0 0;
    line-height: 1.6;
}

.session-meta {
    margin-top: 2.5rem;
    padding-top: 1.75rem;
    border-top: 1px solid rgba(24, 32, 66, 0.08);
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.btn {
    border-radius: var(--radius-pill);
    padding: 0.6rem 1.4rem;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

#agreement-accept-btn {
    border-color: rgba(37, 54, 255, 0.35);
    color: var(--accent);
    background: rgba(37, 54, 255, 0.08);
}

#agreement-accept-btn:not(:disabled):hover,
#agreement-accept-btn:not(:disabled):focus-visible {
    background: rgba(37, 54, 255, 0.14);
    box-shadow: 0 10px 22px rgba(37, 54, 255, 0.2);
}

#agreement-accept-btn:disabled {
    background: transparent;
    color: var(--muted);
    border-color: var(--border);
    box-shadow: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn:hover:not(:disabled) {
    opacity: 0.85;
    transform: translateY(-1px);
}

.notice {
    margin-top: 1.5rem;
    background: rgba(193, 18, 31, 0.12);
    border: 1px solid rgba(193, 18, 31, 0.3);
    border-radius: 1rem;
    padding: 1rem 1.5rem;
}

.site-footer {
    padding: 1.5rem 0 3rem;
    text-align: center;
    color: var(--muted);
}

.footer-action {
    border: none;
    background: none;
    padding: 0;
    font: inherit;
    color: inherit;
    cursor: default;
    text-decoration: none;
}

.footer-action:hover,
.footer-action:focus-visible {
    text-decoration: none;
}

.footer-action:focus-visible {
    outline: none;
}

.footer-action:disabled {
    opacity: 0.6;
    cursor: wait;
}

.helper-text {
    color: var(--muted);
    margin: 1rem 0;
}

.is-invisible {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.is-hidden {
    display: none !important;
}

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(24, 32, 66, 0.45);
    backdrop-filter: blur(6px);
    z-index: 40;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: min(75vw, calc(100% - 2rem));
    height: 75vh;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 1.5rem;
    box-shadow: 0 30px 80px rgba(24, 32, 66, 0.2);
    display: flex;
    flex-direction: column;
    max-height: 75vh;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.5rem;
    border-bottom: 1px solid rgba(24, 32, 66, 0.08);
}

.modal-body {
    padding: 1.5rem;
    padding-top: 1.25rem;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.modal-frame {
    width: 100%;
    flex: 1;
    min-height: 0;
    height: auto;
    border: 1px solid var(--border);
    border-radius: 1rem;
    background: #f7f8fc;
}

.modal-meta {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.5rem;
}

.hash-note {
    margin: 0;
    font-size: 0.75rem;
    color: var(--muted);
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    word-break: break-all;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 1.5rem 1.5rem;
    flex-wrap: wrap;
    background: var(--panel);
}

@media (max-width: 540px) {
    .letter {
        padding: 1.75rem;
    }

    .customer-id {
        top: 1rem;
        right: 1rem;
        font-size: 0.7rem;
    }

    .save-pdf-btn {
        top: 1rem;
        left: 1rem;
        right: auto;
        font-size: 0.7rem;
    }

    .session-meta {
        flex-direction: column;
        align-items: flex-start;
    }

    .agreement-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .modal-body {
        padding: 1.25rem;
    }

    .modal-frame {
        min-height: 0;
    }
}

@keyframes customer-id-glow {
    0%,
    100% {
        box-shadow: 0 0 0 rgba(37, 54, 255, 0.2);
    }
    50% {
        box-shadow: 0 0 16px rgba(37, 54, 255, 0.35);
    }
}

@media print {
    @page {
        margin: 0.5in;
    }

    body {
        background: #ffffff;
        min-height: auto;
    }

    .environment-banner {
        display: none !important;
    }

    .confirmation {
        padding: 0;
    }

    .letter {
        border: none;
        box-shadow: none;
        padding: 0;
    }

    .site-footer {
        padding: 0.5rem 0 0;
    }

    .save-pdf-btn {
        display: none !important;
    }
}
