/* #450-58: shared form/dialog finish. Product cards and actions-flow-v1 stay scoped out. */
:root {
    --component-surface: var(--color-surface, #fff);
    --component-ink: var(--color-text, #1e293b);
    --component-muted: var(--color-text-secondary, #475569);
    --component-line: #cbd5e1;
    --component-control-line: #64748b;
    --component-soft: #f1f5f9;
    --component-link: #2563eb;
}
:root[data-theme="dark"], body.dark-mode {
    --component-surface: var(--color-surface, #0f172a);
    --component-ink: var(--color-text, #e2e8f0);
    --component-muted: var(--color-text-secondary, #cbd5e1);
    --component-line: #475569;
    --component-control-line: #94a3b8;
    --component-soft: var(--color-surface-soft, #1e293b);
    --component-link: #93c5fd;
}
/* Keep the real inputs, native validation, labels and keyboard semantics. Existing
   app switches retain their slider and hidden input instead of a second graphic. */
html body :where(input:is([type="checkbox"], [type="radio"]):not([hidden],.sr-only,.visually-hidden,[aria-hidden="true"]):not(:where(.s-toggle, .toggle-switch, .switch, .toggle, [role="switch"]) input)) {
    appearance: none;
    -webkit-appearance: none;
    box-sizing: border-box;
    width: 20px;
    height: 20px;
    min-width: 20px;
    min-height: 20px;
    flex: 0 0 20px;
    vertical-align: middle;
    margin: 2px 8px 2px 0;
    border: 2px solid var(--component-control-line);
    border-radius: 4px;
    background-color: var(--component-surface);
    background-position: center;
    background-repeat: no-repeat;
    background-size: 16px;
    cursor: pointer;
}
html body input[type="radio"]:not(:where(.s-toggle, .toggle-switch, .switch, .toggle, [role="switch"]) input) { border-radius: 50%; }
html body input:is([type="checkbox"], [type="radio"]):checked:not(:where(.s-toggle, .toggle-switch, .switch, .toggle, [role="switch"]) input) {
    border-color: #2563eb;
    background-color: #2563eb;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round' d='m4 10 4 4 8-8'/%3E%3C/svg%3E");
}
html body input[type="radio"]:checked:not(:where(.s-toggle, .toggle-switch, .switch, .toggle, [role="switch"]) input) {
    background-image: radial-gradient(circle, white 0 4px, transparent 4.5px);
}
html body input:is([type="checkbox"], [type="radio"]):focus-visible {
    outline: 3px solid var(--component-link);
    outline-offset: 3px;
}
html body input:is([type="checkbox"], [type="radio"]):disabled { cursor: default; opacity: .65; }
html body dialog:is(.component-sheet,.component-confirm) {
    box-sizing: border-box;
    color: var(--component-ink);
    background: var(--component-surface);
    border: 1px solid var(--component-line);
    border-radius: 16px;
    padding: 24px;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    overflow: auto;
}
html body dialog:is(.component-sheet,.component-confirm)::backdrop { background: rgb(15 23 42 / 55%); }
html body dialog :is(h2,h3):first-child { margin-top: 0; }
html body :is(dialog, [role="dialog"]) :is(.modal-footer,.dialog-footer,.subscription-sheet-actions,.app-bottom-sheet-confirm-actions) {
    gap: 8px;
    padding-top: 16px;
}
html body :is(dialog, [role="dialog"]) :is(.btn,.btn-primary,.btn-secondary,.primary-btn,.secondary-btn):not(:where(#detailModal,.product-card,#appMenuRegion) *),
html body :is(dialog, [role="dialog"]) .component-button {
    min-height: 44px;
    border-radius: 8px;
    padding: 8px 16px;
    font: inherit;
    line-height: 1.4;
    white-space: normal;
    overflow-wrap: break-word;
}
html body :is(dialog, [role="dialog"]) :is(input:not([type]),input[type="text"],input[type="tel"],input[type="email"],textarea,select):not(:where(#detailModal,.product-card,#appMenuRegion) *) {
    box-sizing: border-box;
    max-width: 100%;
    min-height: 44px;
    border: 1px solid var(--component-control-line);
    border-radius: 8px;
    padding: 8px 12px;
    font: inherit;
    color: var(--component-ink);
    background: var(--component-surface);
}
html body :is(dialog, [role="dialog"]) :is(button,input,textarea,select,a):focus-visible {
    outline: 3px solid var(--component-link);
    outline-offset: 3px;
}
html body .component-text-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 8px 0;
    border: 0;
    background: transparent;
    color: var(--component-link);
    font: inherit;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}
@media (max-width: 767px) {
    html body dialog:is(.component-sheet,.component-confirm) {
        position: fixed;
        inset: auto 0 var(--app-bottom-reserved, 0px);
        margin: 0 auto;
        max-width: 100%;
        max-height: calc(100vh - var(--app-bottom-reserved, 0px) - max(16px, var(--app-frame-safe-top, env(safe-area-inset-top, 0px)) + 8px));
        max-height: calc(100dvh - var(--app-bottom-reserved, 0px) - max(16px, var(--app-frame-safe-top, env(safe-area-inset-top, 0px)) + 8px));
        border-radius: 16px 16px 0 0;
        padding: 16px 16px calc(16px + var(--app-frame-safe-remainder, max(0px, calc(env(safe-area-inset-bottom, 0px) - var(--app-bottom-reserved, 0px)))));
    }
}
/* Price/period/renewal are presentation only; the consent keys and payment gate
   stay in pricing.html. The footer remains reachable in the scrolling sheet. */
html body #paymentConsentModal .details-dialog { max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; overflow: hidden; width: min(600px, 100%); border-radius: 16px; background: var(--component-surface); color: var(--component-ink); }
html body #paymentConsentModal .details-head { padding: 16px 24px; gap: 16px; border-color: var(--component-line); }
html body #paymentConsentModal .details-body { padding: 24px; display: grid; gap: 16px; min-height: 0; overflow: auto; }
html body #paymentConsentModal .consent-summary { margin: 0; padding: 16px; border: 1px solid var(--component-line); border-radius: 12px; background: var(--component-soft); color: var(--component-ink); }
#paymentConsentSummary dl { margin: 0; display: grid; grid-template-columns: auto minmax(0,1fr); gap: 8px 16px; }
#paymentConsentSummary dt { color: var(--component-muted); }
#paymentConsentSummary dd { margin: 0; font-weight: 600; text-align: right; word-break: keep-all; overflow-wrap: anywhere; }
#paymentConsentSummary .consent-price { font-size: 1.25rem; }
#paymentConsentRefund { margin: 0; color: var(--component-muted); line-height: 1.6; font-size: .875rem; }
#paymentConsentModal .consent-policy-links { display: flex; flex-wrap: wrap; gap: 8px 24px; }
html body #paymentConsentModal .consent-checklist { gap: 8px; }
html body #paymentConsentModal .consent-check-row { margin: 0; padding: 16px; gap: 8px; align-items: flex-start; color: var(--component-ink); background: var(--component-surface); border-color: var(--component-line); border-radius: 12px; }
html body #paymentConsentModal .consent-check-row:has(input:checked) { border-color: var(--component-link); background: var(--component-soft); }
html body #paymentConsentModal .consent-check-row strong { color: var(--component-ink); font-size: .9375rem; }
html body #paymentConsentModal .consent-check-row small { margin-top: 8px; color: var(--component-muted); font-size: .8125rem; }
html body #paymentConsentModal .consent-check-row input { margin-right: 0; }
html body #paymentConsentModal .payment-contact { margin: 0; }
#paymentConsentHint { margin: 0; color: var(--component-muted); font-size: .875rem; line-height: 1.5; }
html body #paymentConsentModal .payment-consent-footer { flex: 0 0 auto; padding: 16px 24px; border-top: 1px solid var(--component-line); background: var(--component-surface); }
html body #paymentConsentModal .details-head { flex: 0 0 auto; }
html body #paymentConsentModal .payment-consent-actions { margin: 0; padding-top: 8px; gap: 8px; }
html body #paymentConsentContinue:disabled { opacity: 1; color: var(--component-muted); background: var(--component-soft); border: 1px dashed var(--component-line); cursor: not-allowed; }
html body #paymentConsentContinue:not(:disabled) { color: white; background: #2563eb; border-color: #2563eb; }
html body #paymentConsentCancel { color: var(--component-ink); background: var(--component-surface); border: 1px solid var(--component-line); }
html body #paymentConsentModal .consent-law-panel { margin: 0; padding: 16px; background: var(--component-soft); border-color: var(--component-line); color: var(--component-ink); }
@media (max-width: 767px) {
    /* Keep actions outside the measured banner track regardless of paint order. */
    html body.pricing-page .details-modal { box-sizing: border-box; padding-bottom: calc(18px + var(--app-bottom-reserved, 0px)); }
    html body.pricing-page .details-modal .details-dialog { max-height: calc(100vh - var(--app-bottom-reserved, 0px) - max(32px, var(--app-frame-safe-top, env(safe-area-inset-top, 0px)) + 8px)); max-height: calc(100dvh - var(--app-bottom-reserved, 0px) - max(32px, var(--app-frame-safe-top, env(safe-area-inset-top, 0px)) + 8px)); }
    html body #paymentConsentModal { padding: 16px 0 var(--app-bottom-reserved, 0px); align-items: flex-end; }
    html body #paymentConsentModal .details-dialog { max-height: calc(100vh - var(--app-bottom-reserved, 0px) - max(16px, var(--app-frame-safe-top, env(safe-area-inset-top, 0px)) + 8px)); max-height: calc(100dvh - var(--app-bottom-reserved, 0px) - max(16px, var(--app-frame-safe-top, env(safe-area-inset-top, 0px)) + 8px)); border-radius: 16px 16px 0 0; }
    html body #paymentConsentModal .details-head { padding: 16px; }
    html body #paymentConsentModal .details-body { padding: 16px; }
    html body #paymentConsentModal .payment-consent-footer { padding: 16px 16px calc(16px + var(--app-frame-safe-remainder, max(0px, calc(env(safe-area-inset-bottom, 0px) - var(--app-bottom-reserved, 0px))))); }
    html body #paymentConsentModal .payment-consent-actions { display: grid; grid-template-columns: minmax(64px,1fr) minmax(0,2fr); }
    html body #paymentConsentModal .payment-consent-actions .btn { width: 100%; min-width: 0; }
}
html body .component-confirm { width: min(480px, calc(100% - 32px)); }
.component-confirm p { white-space: pre-line; overflow-wrap: anywhere; line-height: 1.6; }
.component-confirm-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
html body .component-confirm-actions .btn { color: var(--component-ink); background: var(--component-surface); border: 1px solid var(--component-line); cursor: pointer; }
html body .component-confirm-actions .component-danger { color: #fff; background: #b91c1c; border-color: #b91c1c; }
html body .app-bottom-sheet-confirm { padding: 24px; border-radius: 16px; }
html body .app-bottom-sheet-confirm .app-bottom-sheet-actions { gap: 8px; margin-top: 24px; }
@media (max-width: 767px) {
    html body .component-confirm { width: 100%; }
    html body .app-bottom-sheet-confirm { padding: 16px 16px calc(16px + var(--app-frame-safe-remainder, max(0px, calc(env(safe-area-inset-bottom, 0px) - var(--app-bottom-reserved, 0px))))); border-radius: 16px 16px 0 0; }
}

html body .component-confirm-actions .component-primary { color: #fff; background: #2563eb; border-color: #2563eb; }
html body #paymentConsentModal .details-body,
html body .component-confirm p { word-break: keep-all; overflow-wrap: anywhere; }
/* A service form must scroll inside the bounded phone shell, above the ad track. */
@media (max-width: 767px) {
    html body.app-shared-shell #appServiceRegion > #qnaModal > .qna-panel {
        position: absolute !important;
        inset: 0 !important;
        width: 100% !important;
        max-height: 100% !important;
        height: 100% !important;
        transform: none !important;
        min-height: 0;
    }
    html body.app-shared-shell #appServiceRegion > #qnaModal #qnaContent {
        min-height: 0;
        overflow-y: auto;
    }
}
html body :where(label:has(> input:is([type="checkbox"],[type="radio"])):not(:where(.s-toggle,.toggle-switch,.switch,.toggle,[role="switch"]))):not(:where(#detailModal,.product-card,#appMenuRegion) *) {
    min-height: 44px;
    box-sizing: border-box;
    align-items: center;
}
html body :where(label:has(> input:is([type="checkbox"],[type="radio"])):not(:where(.s-toggle,.toggle-switch,.switch,.toggle,[role="switch"]))):not(:where(#detailModal,.product-card,#appMenuRegion) *) {
    display: inline-flex;
    gap: 8px;
}
html body label > input:is([type="checkbox"],[type="radio"]):not(:where(.s-toggle,.toggle-switch,.switch,.toggle,[role="switch"]) input) { margin-right: 0; }
/* Custom dialogs use the same spacing without changing full-page service roots. */
html body .details-dialog { border-radius: 16px; }
html body .details-dialog .details-head { padding: 16px 24px; gap: 16px; }
html body .details-dialog .details-body { padding: 24px; }
html body .details-dialog .details-close { min-width: 44px; min-height: 44px; border-radius: 8px; flex-shrink: 0; }
html body .comment-modal-content { padding: 24px; gap: 16px; color: var(--component-ink); background: var(--component-surface); }
html body .comment-modal-header { gap: 16px; }
html body .comment-modal-actions { gap: 8px; }
#paymentConsentLawRefs a { color: var(--component-link); }
@media (max-width: 767px) {
    html body .details-dialog .details-head, html body .details-dialog .details-body { padding: 16px; }
    html body .comment-modal { padding: 16px 0 0; align-items: flex-end; }
    html body .comment-modal-content { max-height: calc(100dvh - 16px); overflow-y: auto; padding: 16px 16px calc(16px + var(--app-frame-safe-bottom, env(safe-area-inset-bottom, 0px))); border-radius: 16px 16px 0 0; }
}
.component-confirm p { white-space: pre-line; }
/* The OS high-contrast control preserves selected state when images disappear. */
@media (forced-colors: active) {
    html body input:is([type="checkbox"],[type="radio"]):not(:where(.s-toggle,.toggle-switch,.switch,.toggle,[role="switch"]) input) {
        appearance: auto;
        -webkit-appearance: auto;
        background-image: none !important;
        forced-color-adjust: auto;
    }
}

#paymentConsentModal .consent-amount-note { margin: 0; color: var(--component-muted); font-size: .8125rem; line-height: 1.5; }
#componentConfirmLoadError, #componentConfirmStale { position: fixed; inset: auto 16px calc(16px + var(--app-frame-bottom, env(safe-area-inset-bottom, 0px))); z-index: 2147483000; max-width: 560px; margin: 0 auto; padding: 16px; border: 1px solid var(--component-control-line); border-radius: 12px; background: var(--component-surface); color: var(--component-ink); }
html body .comment-modal-content { grid-template-columns: minmax(0,1fr); min-width: 0; }
html body .comment-modal-content > * { min-width: 0; max-width: 100%; }
html body .comment-modal-content :is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),textarea,select) { min-width: 0; width: 100%; box-sizing: border-box; }

#componentPromptInput { width: 100%; min-width: 0; margin: 8px 0 0; }

html body input[type="checkbox"]:indeterminate { border-color: #2563eb; background-color: #2563eb; background-image: linear-gradient(white,white); background-size: 10px 2px; }

/* Existing pricing dark primary rules are !important; disabled consent remains visibly secondary. */
html[data-theme="dark"] body.pricing-page #paymentConsentContinue:disabled { color: var(--component-muted) !important; background: var(--component-soft) !important; border: 1px dashed var(--component-line) !important; }
/* Bounded service panels also fit a short desktop window. */
html body.app-shared-shell #appServiceRegion > #qnaModal > .qna-panel { max-height: 100% !important; min-height: 0; }
html body.app-shared-shell #appServiceRegion > #qnaModal #qnaContent { min-height: 0; }
html body #collabDetailModal .lobby-chat-compose #lobbyChatInput { min-width: 0; width: 0; }
html[data-theme="dark"] [id^="collabGroup"] :is(.collab-list-panel,.collab-list-header,[data-cgrp-async-body],.cgrp-m-row,.cgrp-pick-item) { background: var(--component-surface) !important; color: var(--component-ink) !important; border-color: var(--component-line) !important; }
html[data-theme="dark"] [id^="collabGroup"] .collab-list-header h3 { color: var(--component-ink) !important; }
html[data-theme="dark"] [id^="collabGroup"] :is([role="status"],label) { color: var(--component-muted) !important; }
html body [id^="collabGroup"] :is(.collab-list-header,[data-cgrp-async-body]) { padding: 16px !important; }
html body [id^="collabGroup"] .collab-list-panel { border-radius: 16px; max-width: calc(100vw - 32px); }
html body [id^="collabGroup"] :is(button,input:not([type="checkbox"],[type="radio"]),textarea) { box-sizing: border-box; min-height: 44px; }
/* Group editor actions remain visible instead of falling below a fixed body. */
html body [id^="collabGroup"] .component-group-actions { position: sticky; bottom: 0; padding-top: 16px; background: var(--component-surface); z-index: 1; }
html[data-theme="dark"] [id^="collabGroup"] .component-group-label { color: var(--component-muted) !important; }
@media (max-width: 767px) {
    html body [id^="collabGroup"] [data-cgrp-async-body] { flex: 1 1 auto; height: auto !important; min-height: 0 !important; max-height: none !important; }
}
@media (min-width: 768px) {
    html body dialog.component-confirm { position: fixed; inset: 0; margin: auto; transform: none; }
    html body.app-shared-shell dialog:is(.component-confirm,.component-sheet) {
        inset:var(--app-frame-safe-top) 0 var(--app-frame-bottom);
        max-height:calc(100dvh - var(--app-frame-safe-top) - var(--app-frame-bottom) - 32px);
    }
    /* Keep the full backdrop while centering desktop confirmations inside the
       same safe/ad boundaries as native dialogs. Mobile sheets retain their geometry. */
    html body.app-shared-shell .app-bottom-sheet-overlay--modal:not(.app-bottom-sheet-scrim) {
        padding: calc(24px + var(--app-frame-safe-top)) 24px calc(24px + var(--app-frame-bottom));
    }
    html body.app-shared-shell .app-bottom-sheet-confirm--modal:not(.app-bottom-sheet) {
        max-height: calc(100dvh - var(--app-frame-safe-top) - var(--app-frame-bottom) - 48px);
    }
    html body.pricing-page.app-shared-shell .details-modal {
        box-sizing:border-box; padding:16px 18px calc(18px + var(--app-frame-bottom));
    }
    html body.pricing-page.app-shared-shell .details-modal .details-dialog {
        max-height:calc(100dvh - var(--app-frame-safe-top) - var(--app-frame-bottom) - 32px);
    }
}
html[data-theme="dark"] [id^="collabGroup"] #_cgrpList > label { background: var(--component-soft) !important; color: var(--component-ink) !important; }

/* #450-60: the visible height already excludes the keyboard. Reserve only the
   remaining ad/safe inset, so neither the keyboard nor banner is counted twice. */
@media (max-width: 767px) {
    :root body.app-shared-shell .app-bottom-sheet.app-bottom-sheet {
        bottom: max(var(--app-bottom-reserved, 0px), var(--app-dialog-safe-bottom, 0px), var(--app-sheet-keyboard-inset, 0px)) !important;
        padding-bottom: max(0px, var(--app-frame-safe-bottom, env(safe-area-inset-bottom, 0px)) - max(var(--app-bottom-reserved, 0px), var(--app-dialog-safe-bottom, 0px))) !important;
        max-height: calc(
            var(--app-sheet-visible-height, 100dvh)
            - max(0px, max(var(--app-bottom-reserved, 0px), var(--app-dialog-safe-bottom, 0px)) - var(--app-sheet-keyboard-inset, 0px))
            - var(--app-overlay-safe-top, var(--app-frame-safe-top, env(safe-area-inset-top, 0px))) - 8px
        ) !important;
    }
}
