/* Avtalsskaparen (/skapa) and Avtalsgranskaren (/granska): the start
   screen with the paywall, the question steps, the wait screens and the
   finished document. Everything here is rendered into #stage, either by
   the page itself or by an htmx swap. */

/* Page shell */
.create {
    min-height: 100vh;
    background: linear-gradient(180deg, var(--white) 0, var(--beige) 420px);
    padding: calc(var(--header-height) + clamp(32px, 5vw, 64px)) var(--gutter)
        clamp(80px, 10vw, 132px);
}
.start,
.questions,
.complete {
    max-width: 820px;
    margin: 0 auto;
}
.start {
    position: relative;
}

/* Intro banner (start, questions, review upload) */
.start-banner {
    margin-bottom: 44px;
}
.start-banner .eyebrow {
    margin-bottom: 18px;
}
.start-banner-title {
    font-family: var(--serif);
    font-weight: 400;
    font-size: clamp(38px, 4.6vw, 58px);
    line-height: 1.06;
    color: var(--ink);
    letter-spacing: -0.018em;
    max-width: none;
}
.start-banner-title em {
    font-style: italic;
    color: var(--khaki);
}
.questions-banner-title {
    font-size: clamp(22px, 1.9vw, 26px);
    font-style: italic;
    color: var(--khaki);
    margin-top: 10px;
}
.start-banner-text {
    max-width: 62ch;
    margin-top: 18px;
    font-size: clamp(16px, 1.25vw, 18px);
    line-height: 1.7;
    color: var(--text-muted);
}
.complete-text {
    margin: 0 0 28px;
}

/* Paywall: what you pay, and the promise that it's only reserved */
.paywall {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 32px;
    align-items: start;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: clamp(24px, 3vw, 36px);
    margin-bottom: 36px;
}
.paywall-price {
    grid-row: span 3;
    font-family: var(--serif);
    font-size: clamp(34px, 3.4vw, 44px);
    line-height: 1;
    color: var(--ink);
    white-space: nowrap;
    padding-right: 32px;
    border-right: 1px solid var(--line);
    min-height: 100%;
}
.paywall-price small {
    display: block;
    margin-top: 10px;
    font-family: var(--sans);
    font-size: 11.5px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--text-muted);
}
.paywall-text {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-muted);
}
.paywall-text strong {
    color: var(--ink);
    font-weight: 500;
}
.paywall-consent {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-top: 8px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    cursor: pointer;
}
.paywall-consent a {
    color: var(--ink);
    text-decoration: none;
    border-bottom: 1px solid var(--khaki);
}
.paywall-consent a:hover {
    color: var(--khaki);
}
.paywall-consent input {
    width: 17px;
    height: 17px;
    margin-top: 2px;
    flex-shrink: 0;
}
.paywall .auth-message {
    grid-column: 2;
    margin: 6px 0 0;
}
.paywall > .btn {
    grid-column: 2;
    justify-self: start;
    margin-top: 12px;
}

/* Selectable cards: free text + catalog types */
.start-textarea,
.start-types-container {
    position: relative;
    min-width: 0;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: clamp(24px, 3vw, 34px);
    cursor: pointer;
    transition:
        border-color 0.2s,
        transform 0.25s,
        box-shadow 0.25s;
}
.start-textarea:hover,
.start-types-container:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-soft);
}
.start-textarea.is-open,
.start-types-container.is-open {
    border-color: var(--khaki-light);
    box-shadow: var(--shadow-soft);
    cursor: default;
    transform: none;
}
.start-textarea-confirm,
.start-types-container-confirm {
    position: absolute;
    top: 20px;
    right: 22px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 100px;
    background: var(--sand);
    color: var(--ink);
    font-size: 11.5px;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    opacity: 0;
    transform: translateY(-4px);
    transition:
        opacity 0.2s,
        transform 0.2s;
}
.start-textarea-confirm::before,
.start-types-container-confirm::before {
    content: "✓";
    color: var(--khaki);
}
.start-textarea.is-open .start-textarea-confirm,
.start-types-container.is-open .start-types-container-confirm {
    opacity: 1;
    transform: none;
}
.start-textarea-text {
    max-width: calc(100% - 90px);
    font-family: var(--serif);
    font-size: clamp(20px, 1.7vw, 23px);
    line-height: 1.3;
    color: var(--ink);
}
.start-textarea-input {
    display: block;
    width: 100%;
    min-height: 110px;
    max-height: 320px;
    margin-top: 18px;
    padding: 14px 16px;
    resize: vertical;
    border: 1px solid var(--line);
    border-radius: var(--radius-small);
    background: var(--beige);
    color: var(--ink);
    font-size: 15.5px;
    line-height: 1.6;
    transition:
        border-color 0.2s,
        background 0.2s;
}
.start-textarea-input:focus {
    outline: none;
    background: var(--white);
    border-color: var(--khaki-light);
}
.start-textarea-button,
.start-types-container-button {
    display: none;
    margin-top: 22px;
}
.start-textarea.is-open .start-textarea-button,
.start-types-container.is-open .start-types-container-button {
    display: inline-block;
}
.start-divider {
    display: flex;
    align-items: center;
    gap: 18px;
    margin: 44px 0 24px;
}
.start-divider::before,
.start-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line);
}
.start-divider span {
    font-size: 11.5px;
    font-weight: 500;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: var(--text-muted);
    white-space: nowrap;
}
.start-types {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}
.start-types-container-title {
    max-width: calc(100% - 90px);
    font-family: var(--serif);
    font-size: clamp(21px, 1.8vw, 24px);
    font-weight: 500;
    line-height: 1.2;
    color: var(--ink);
}
.start-types-container-text {
    margin-top: 10px;
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-muted);
}

/* Questions */
@keyframes stageFadeIn {
    from {
        opacity: 0;
        transform: translateY(14px);
    }
}
.questions-container {
    position: relative;
    overflow: hidden;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: clamp(24px, 3.4vw, 44px);
    animation: stageFadeIn 0.4s ease both;
    counter-reset: question;
}
.question {
    counter-increment: question;
    padding: 28px 0;
    border-top: 1px solid var(--line);
}
.question-number::before {
    content: counter(question, decimal-leading-zero);
}
.questions-autosave + .question,
.stage-loading + .question {
    border-top: 0;
    padding-top: 4px;
}
.question-number {
    display: block;
    font-family: var(--serif);
    font-style: italic;
    color: var(--khaki);
    font-size: 22px;
    line-height: 1;
    margin-bottom: 12px;
}
.questions-container-title-text {
    display: block;
    margin-bottom: 16px;
    font-family: var(--serif);
    font-size: clamp(20px, 1.7vw, 23px);
    line-height: 1.35;
    color: var(--ink);
    white-space: pre-line;
}
.questions-container-answer {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    margin-bottom: 8px;
    border: 1px solid var(--line);
    border-radius: var(--radius-small);
    font-size: 15.5px;
    line-height: 1.5;
    color: var(--text);
    cursor: pointer;
    transition:
        border-color 0.2s,
        background 0.2s;
}
.questions-container-answer:hover {
    border-color: var(--khaki-light);
}
.questions-container-answer:has(input:checked) {
    border-color: var(--khaki-light);
    background: var(--beige);
    color: var(--ink);
}
.questions-container-answer-radio {
    width: 17px;
    height: 17px;
    margin-top: 2px;
    flex-shrink: 0;
    cursor: pointer;
}
.question .start-textarea-input {
    margin-top: 4px;
}
.textmark-extra {
    display: none;
    min-height: 80px;
}
.textmark-extra.visible {
    display: block;
}
.questions-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-top: 28px;
    border-top: 1px solid var(--line);
}
.questions.active .questions-container {
    pointer-events: none;
    opacity: 0.6;
}
.questions-autosave {
    position: absolute;
    top: 18px;
    right: 24px;
    font-size: 12.5px;
    color: var(--text-muted);
}

/* htmx loading overlay over the question card */
.stage-loading {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 40px;
    text-align: center;
    background: rgba(255, 255, 255, 0.94);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}
.stage-loading.htmx-request {
    opacity: 1;
    pointer-events: all;
}
.stage-loading-title {
    font-family: var(--serif);
    font-size: 24px;
    color: var(--ink);
}
.stage-loading-sub {
    max-width: 36ch;
    margin-top: -6px;
    font-size: 14.5px;
    color: var(--text-muted);
}
@keyframes dotPulse {
    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.35;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}
.stage-loading-dots span {
    display: inline-block;
    width: 9px;
    height: 9px;
    margin: 0 4px;
    border-radius: 50%;
    background: var(--khaki);
    animation: dotPulse 1.2s infinite ease-in-out;
}
.stage-loading-dots span:nth-child(2) {
    animation-delay: 0.15s;
}
.stage-loading-dots span:nth-child(3) {
    animation-delay: 0.3s;
}
.stage-loading-doc {
    width: 64px;
    height: 78px;
    padding: 13px 11px;
    display: flex;
    flex-direction: column;
    gap: 7px;
    background: var(--white);
    border: 1px solid var(--sand-deep);
    border-radius: 10px;
    box-shadow: var(--shadow-soft);
}
.stage-loading-doc span {
    display: block;
    height: 4px;
    border-radius: 2px;
    animation: docLineIn 2.4s infinite ease-in-out;
}
.stage-loading-doc span:nth-child(1) {
    width: 100%;
}
.stage-loading-doc span:nth-child(2) {
    width: 80%;
    animation-delay: 0.3s;
}
.stage-loading-doc span:nth-child(3) {
    width: 90%;
    animation-delay: 0.6s;
}
@keyframes docLineIn {
    0%,
    100% {
        background: var(--line);
    }
    50% {
        background: var(--khaki-light);
    }
}

/* Finished contract / review */
@keyframes completeFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
}
.complete {
    animation: completeFadeIn 0.5s ease both;
}
.complete-banner {
    margin-bottom: 40px;
}
.complete-check {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    margin-bottom: 22px;
    border-radius: 50%;
    background: var(--sand);
    color: var(--khaki);
    font-size: 22px;
}
.complete-title {
    font-size: clamp(36px, 4.2vw, 54px);
    line-height: 1.08;
    max-width: 20ch;
}
.complete-subtitle {
    margin-top: 16px;
    font-family: var(--serif);
    font-style: italic;
    font-size: clamp(19px, 1.6vw, 22px);
    line-height: 1.45;
    color: var(--text-muted);
}
.complete-contract {
    max-width: none;
    margin: 0;
    padding: clamp(28px, 5vw, 64px);
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    font-family: var(--serif);
    font-size: 17.5px;
    line-height: 1.85;
    color: var(--ink);
    white-space: pre-line;
    overflow-wrap: break-word;
    animation: completeFadeIn 0.6s ease 0.1s both;
}
.complete-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 28px 0 8px;
}
.complete-actions form {
    display: contents;
}
.complete-status {
    min-height: 22px;
    margin-top: 6px;
    font-size: 14px;
    color: var(--text-muted);
}

/* Review upload */
.review-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 22px;
    padding: clamp(28px, 4vw, 48px);
    background: var(--white);
    border: 1px dashed var(--khaki-light);
    border-radius: var(--radius);
}
.review-container-hint {
    font-size: 14.5px;
    color: var(--text-muted);
}
.review-container input[type="file"] {
    font-size: 15px;
    color: var(--text-muted);
    max-width: 100%;
}
.review-container input[type="file"]::file-selector-button {
    margin-right: 16px;
    padding: 11px 22px;
    border-radius: 100px;
    border: 1px solid var(--line);
    background: var(--white);
    color: var(--ink);
    font: 500 14px var(--sans);
    cursor: pointer;
    transition: border-color 0.2s;
}
.review-container input[type="file"]::file-selector-button:hover {
    border-color: var(--ink);
}

/* flow-wait: the standalone "something is happening" panel (payment
   being confirmed, an AI call running on the server). Not .stage-loading
   — that one is htmx's invisible-until-requesting overlay. */
.flow-wait {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    max-width: 620px;
    min-height: 360px;
    margin: 0 auto;
    padding: clamp(32px, 5vw, 56px);
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    text-align: center;
    animation: stageFadeIn 0.4s ease both;
}
.flow-wait-title {
    font-size: clamp(26px, 2.6vw, 34px);
    max-width: none;
}
.flow-wait-sub {
    max-width: 44ch;
    font-size: 15.5px;
    color: var(--text-muted);
}
.flow-wait-bar {
    position: relative;
    width: min(320px, 80%);
    height: 3px;
    margin-top: 6px;
    border-radius: 100px;
    background: var(--line);
    overflow: hidden;
}
.flow-wait-bar span {
    position: absolute;
    inset: 0 auto 0 0;
    width: 40%;
    border-radius: 100px;
    background: var(--khaki);
    animation: flowWaitSlide 1.6s ease-in-out infinite;
}
@keyframes flowWaitSlide {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(250%);
    }
}
@keyframes flowWaitReveal {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}
.flow-wait-slow {
    max-width: 46ch;
    font-size: 14px;
    color: var(--text-muted);
    opacity: 0;
    animation: flowWaitReveal 0.6s ease 25s both;
}
.flow-wait-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    opacity: 0;
    animation: flowWaitReveal 0.6s ease 8s both;
}
.flow-wait-safe {
    max-width: 46ch;
    font-size: 13.5px;
    color: var(--muted);
}

/* The pay button while the checkout request is in flight */
.btn.is-busy {
    pointer-events: none;
    opacity: 0.75;
}
.btn.is-busy::after {
    content: "";
    display: inline-block;
    width: 0.75em;
    height: 0.75em;
    margin-left: 0.5em;
    vertical-align: -0.1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: flowSpin 0.7s linear infinite;
}
@keyframes flowSpin {
    to {
        transform: rotate(360deg);
    }
}

/* Shown when someone comes back from Stripe having cancelled */
.flow-notice {
    max-width: 820px;
    margin: 0 auto 28px;
    padding: 14px 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius-small);
    background: var(--white);
    font-size: 15px;
    color: var(--text);
}

@media (max-width: 760px) {
    .start-types {
        grid-template-columns: 1fr;
    }
    .paywall {
        grid-template-columns: 1fr;
    }
    .paywall-price {
        grid-row: auto;
        padding: 0 0 18px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        margin-bottom: 10px;
    }
    .paywall .auth-message,
    .paywall > .btn {
        grid-column: 1;
    }
    .questions-actions {
        flex-direction: column-reverse;
        align-items: stretch;
    }
    .complete-actions .btn {
        flex: 1 1 100%;
    }
}
@media (prefers-reduced-motion: reduce) {
    .questions-container,
    .complete,
    .complete-contract,
    .flow-wait {
        animation: none;
    }
}
