/* ============================================================
 * application-form (Figma 4001:6833 + 4007:70 기준)
 * TV광고 신청 폼 모달 — 단일 컴포넌트 + variant 분기
 * 광고 계산기와 동일 디자인 토큰 패밀리 사용
 * ============================================================ */

/* 모달 오픈 시 페이지 전체 스크롤 잠금 */
body.appform-modal-open {
    overflow: hidden !important;
}

/* 모달 백드롭 — 스크롤 담당 (viewport 전체) + 스크롤바 시각 숨김
 * width:100vw로 페이지 우측 끝까지 dim. 백드롭 자체가 스크롤을 가지지만 스크롤바는 보이지 않게 처리.
 * → 사용자는 스크롤 가능하지만 페이지 우측에 두꺼운 스크롤바 영역이 보이지 않음. */
.appform-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100%;
    z-index: 999999;
    background: rgba(0, 0, 0, 0.5);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    /* 스크롤바 숨김 (기능은 유지, UI만 비공개) */
    scrollbar-width: none;          /* Firefox */
    -ms-overflow-style: none;       /* IE/Edge legacy */
}
.appform-backdrop::-webkit-scrollbar {
    display: none;                  /* Chrome / Safari / Edge */
}

.appform-shell {
    max-width: 480px;
    margin: 60px auto 40px;
    padding: 0 16px;
    position: relative;
}

/* 폼 컨테이너 */
.appform {
    /* 컬러 토큰 */
    --apf-primary: #5D2BF4;
    --apf-primary-hover: #4b22c4;
    --apf-text-strong: #111928;
    --apf-text: #1F2A37;
    --apf-text-muted: #6B7280;
    --apf-text-subtle: #9CA3AF;
    --apf-border: #E5E7EB;
    --apf-border-input: #BFC4CB;
    --apf-bg-readonly: #F9FAFB;
    --apf-bg-white: #FFFFFF;
    --apf-required: #F44336;
    --apf-error: #EF4444;
    --apf-checkbox-bg: #FFFFFF;

    /* 간격 */
    --apf-gap-section: 20px;
    --apf-gap-field: 8px;
    --apf-padding-modal: 24px;

    /* 라디우스 */
    --apf-radius-modal: 16px;
    --apf-radius-input: 8px;
    --apf-radius-cta: 8px;

    background: var(--apf-bg-white);
    border-radius: var(--apf-radius-modal);
    padding: var(--apf-padding-modal);
    box-sizing: border-box;
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: var(--apf-text);
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: contain;
}

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

/* ============== Header ============== */
.appform-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--apf-gap-section);
    gap: 8px;
}

.appform-back {
    background: transparent;
    border: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    cursor: pointer;
    color: var(--apf-text-strong);
    font-size: 28px;
    line-height: 1;
    display: none;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.appform-back:hover {
    color: var(--apf-primary);
}

.appform-title {
    flex: 1;
    font-size: 20px;
    font-weight: 700;
    line-height: 1.3;
    color: var(--apf-text-strong);
    margin: 0;
}

.appform-close {
    background: transparent;
    border: 0;
    width: 28px;
    height: 28px;
    padding: 0;
    cursor: pointer;
    color: var(--apf-text-strong);
    font-size: 28px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.appform-close:hover {
    color: var(--apf-primary);
}

/* ============== Variant 분기 ============== */
.appform[data-variant="direct"] .appform-prefill {
    display: none;
}
.appform[data-variant="direct"] .appform-back {
    display: none;
}
.appform[data-variant="withPrefill"] .appform-prefill {
    display: block;
}
.appform[data-variant="withPrefill"] .appform-back {
    display: inline-flex;
}
.appform[data-variant="withPrefill"] .appform-budget-field {
    display: none;
}

/* ============== Prefill Section ============== */
.appform-prefill {
    padding-bottom: var(--apf-gap-section);
    border-bottom: 1px solid var(--apf-border);
    margin-bottom: var(--apf-gap-section);
}

.appform-prefill .appform-field + .appform-field {
    margin-top: 16px;
}

/* ============== Inputs Section ============== */
.appform-inputs {
    padding-bottom: var(--apf-gap-section);
    border-bottom: 1px solid var(--apf-border);
    margin-bottom: var(--apf-gap-section);
}

.appform-inputs .appform-field + .appform-field {
    margin-top: 16px;
}

/* ============== Field 공통 ============== */
.appform-field {
    display: flex;
    flex-direction: column;
}

.appform-label-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: var(--apf-gap-field);
}

.appform-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--apf-text-strong);
    margin-bottom: var(--apf-gap-field);
    line-height: 1.43;
}

.appform-label-row .appform-label {
    margin-bottom: 0;
}

.appform-label-hint {
    font-size: 12px;
    font-weight: 400;
    color: var(--apf-text-muted);
    line-height: 1.4;
}

.appform-required {
    color: var(--apf-required);
    margin-left: 2px;
}

.appform-input-row {
    position: relative;
    display: flex;
    align-items: center;
    border: 1px solid var(--apf-border-input);
    border-radius: var(--apf-radius-input);
    background: var(--apf-bg-white);
    padding: 0 14px;
    height: 44px;
    transition: border-color 0.15s ease;
}

.appform-input-row:focus-within {
    border-color: var(--apf-primary);
}

.appform-input-row.appform-readonly {
    background: var(--apf-bg-readonly);
    border-color: var(--apf-border);
}

.appform-input {
    flex: 1;
    border: 0;
    outline: 0;
    background: transparent;
    font-size: 14px;
    font-weight: 500;
    color: var(--apf-text-strong);
    padding: 0;
    width: 100%;
    min-width: 0;
    font-family: inherit;
}

.appform-input::placeholder {
    color: var(--apf-text-subtle);
    font-weight: 400;
}

.appform-input:read-only {
    color: var(--apf-text);
    cursor: default;
}

.appform-input:disabled {
    color: var(--apf-text-subtle);
    cursor: not-allowed;
}

.appform-input::-webkit-inner-spin-button,
.appform-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.appform-input-suffix {
    font-size: 14px;
    color: var(--apf-text-muted);
    flex-shrink: 0;
    margin-left: 8px;
}

/* 입력 에러 상태 */
.appform-input-row:has(.appform-input-error) {
    border-color: var(--apf-error);
}

.appform-input.appform-input-error ~ .appform-input-suffix {
    color: var(--apf-error);
}

.appform-input-error {
    /* class만 부여, 부모 input-row 스타일은 :has로 처리 */
}

.appform-error {
    font-size: 12px;
    color: var(--apf-error);
    margin: 6px 0 0 2px;
    min-height: 0;
    line-height: 1.4;
}

.appform-error:empty {
    display: none;
}

/* ============== Checkbox 공통 ============== */
.appform-checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 6px 0;
}

.appform-checkbox-row input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 1.5px solid var(--apf-border-input);
    border-radius: 4px;
    background: var(--apf-checkbox-bg);
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    transition: all 0.15s ease;
}

.appform-checkbox-row input[type="checkbox"]:checked {
    background: var(--apf-primary);
    border-color: var(--apf-primary);
}

.appform-checkbox-row input[type="checkbox"]:checked::before {
    content: "";
    position: absolute;
    left: 5px;
    top: 1px;
    width: 5px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.appform-checkbox-row input[type="checkbox"]:focus-visible {
    outline: 2px solid var(--apf-primary);
    outline-offset: 2px;
}

.appform-checkbox-label {
    font-size: 14px;
    font-weight: 400;
    color: var(--apf-text);
    line-height: 1.4;
    flex: 1;
}

.appform-checkbox-label strong {
    font-weight: 500;
    color: var(--apf-text-strong);
}

/* 광고 예산 미정 체크 (input 아래 위치) */
.appform-inputs .appform-checkbox-row {
    padding: 8px 0 0 0;
}

/* ============== Agreements Section ============== */
.appform-agreements {
    padding-bottom: var(--apf-gap-section);
    border-bottom: 1px solid var(--apf-border);
    margin-bottom: var(--apf-gap-section);
}

.appform-agree-all {
    padding-bottom: 8px;
}

.appform-agree-all-label {
    font-weight: 700;
    color: var(--apf-text-strong);
}

.appform-agreements .appform-checkbox-row + .appform-checkbox-row:not(.appform-agree-all) {
    /* 자식 동의 항목 약간 들여쓰기는 하지 않고, 시안과 동일하게 */
}

.appform-agree-detail {
    background: transparent;
    border: 0;
    color: var(--apf-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    padding: 0;
    margin-left: auto;
    flex-shrink: 0;
    text-decoration: none;
    font-family: inherit;
}

.appform-agree-detail:hover {
    text-decoration: underline;
}

/* ============== Notice Section ============== */
.appform-notice {
    list-style: none;
    margin: 0 0 var(--apf-gap-section) 0;
    padding: 0;
}

.appform-notice li {
    position: relative;
    padding-left: 12px;
    font-size: 13px;
    color: var(--apf-text-muted);
    line-height: 1.6;
}

.appform-notice li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--apf-text-muted);
}

/* ============== CTA Submit ============== */
.appform-submit {
    display: block;
    width: 100%;
    padding: 16px 14px;
    background: var(--apf-primary);
    color: var(--apf-bg-white);
    border: 0;
    border-radius: var(--apf-radius-cta);
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.05s ease;
    font-family: inherit;
}

.appform-submit:hover {
    background: var(--apf-primary-hover);
}

.appform-submit:active {
    transform: translateY(1px);
}

.appform-submit:focus-visible {
    outline: 2px solid var(--apf-primary);
    outline-offset: 2px;
}

/* ============== Mobile (≤768px) ============== */
@media (max-width: 768px) {
    .appform-shell {
        max-width: 100%;
        margin: 0;
        padding: 0;
        height: 100dvh;
        display: flex;
        flex-direction: column;
    }

    .appform {
        --apf-padding-modal: 20px;
        --apf-gap-section: 18px;
        border-radius: 0;
        padding: var(--apf-padding-modal);
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .appform-title {
        font-size: 18px;
    }

    .appform-input-row {
        height: 48px;
    }

    .appform-input,
    .appform-input-suffix {
        font-size: 15px;
    }

    .appform-submit {
        font-size: 16px;
        padding: 16px 14px;
        position: sticky;
        bottom: 0;
        z-index: 1;
    }

    .appform-checkbox-label,
    .appform-agree-detail {
        font-size: 13px;
    }
}

/* iOS Safari: 키보드 올라올 때 입력 필드 가려지는 문제 완화 */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 768px) {
        .appform {
            padding-bottom: calc(var(--apf-padding-modal) + env(safe-area-inset-bottom, 0));
        }
    }
}
