/* ============================================================
   리브레토 마케팅 — 카피 A/B 변형 위젯 (Phase 1 / T4)
   - 단독 모드 + 임베드 모드 + 모달
   - 모든 색/폰트/간격 = styles.css CSS 변수
   - 모바일 표준: 폰트 16px / min-height 44-48px / sticky 액션
   ============================================================ */

/* ===== 단독 모드 패널 ===== */
#panelCopyvariant {
    position: fixed;
    top: var(--header-height);
    left: var(--sidebar-width);
    right: 0;
    bottom: 0;
    overflow-y: auto;
    background: var(--bg-primary);
    -webkit-overflow-scrolling: touch;
}

.cv-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 28px 120px;
    font-family: var(--font-sans);
}
.cv-container--embed {
    padding: 16px;
}

/* ===== 헤더 ===== */
.cv-header {
    margin-bottom: 24px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border-light);
}
.cv-title {
    font-family: var(--font-serif);
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 6px 0;
    letter-spacing: -0.02em;
}
.cv-subtitle {
    margin: 0;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ===== 폼 ===== */
.cv-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 18px;
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, .03);
    margin-bottom: 16px;
}
.cv-form__row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}
.cv-form__label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1.4;
}
.cv-form__hint {
    display: block;
    font-weight: 400;
    color: var(--text-muted);
    margin-top: 2px;
}
.cv-form__grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

/* 입력 (텍스트/셀렉트) */
.cv-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--text-primary);
    transition: border-color .15s, box-shadow .15s;
    min-height: 44px;
    line-height: 1.4;
}
.cv-input:focus {
    outline: none;
    border-color: var(--sage);
    box-shadow: 0 0 0 3px var(--sage-light);
}
.cv-input--textarea {
    min-height: 84px;
    resize: vertical;
    font-family: var(--font-sans);
}
.cv-input--sm {
    padding: 6px 10px;
    font-size: 13px;
    min-height: 36px;
}

/* 라디오 그룹 */
.cv-radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.cv-radio {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: 999px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s;
    min-height: 36px;
    user-select: none;
}
.cv-radio input[type="radio"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0; height: 0;
}
.cv-radio:has(input:checked),
.cv-radio.is-active {
    background: var(--sage-light);
    border-color: var(--sage);
    color: var(--sage-dark);
    font-weight: 600;
}
.cv-radio:hover {
    background: var(--bg-secondary);
}

/* ===== 액션 바 (생성/이력 버튼) ===== */
.cv-action-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: flex-end;
    padding: 12px 0;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}
.cv-action-bar__history {
    margin-right: auto;
    padding: 10px 16px;
    font-size: 13px;
    min-height: 44px;
}
.cv-action-bar__generate {
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 600;
    min-height: 48px;
    min-width: 140px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.cv-action-bar__spin {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, .35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: cv-spin .7s linear infinite;
}
@keyframes cv-spin {
    to { transform: rotate(360deg); }
}

/* ===== 결과 섹션 ===== */
.cv-result {
    min-height: 200px;
}
.cv-result__head {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.cv-result__filters {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}
.cv-result__sort {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.cv-result__sort-label {
    font-size: 12px;
    color: var(--text-muted);
}

.cv-chip {
    padding: 6px 12px;
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: 999px;
    font-size: 12px;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
    min-height: 32px;
}
.cv-chip:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}
.cv-chip.is-active {
    background: var(--sage-light);
    border-color: var(--sage);
    color: var(--sage-dark);
    font-weight: 600;
}

.cv-summary {
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-left: 3px solid var(--sage);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin: 0 0 16px 0;
}

/* ===== 결과 그리드 ===== */
.cv-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

/* ===== 카드 ===== */
.cv-card {
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: border-color .15s, box-shadow .15s, transform .15s;
}
.cv-card:hover {
    border-color: var(--border-medium);
    box-shadow: 0 2px 6px rgba(0, 0, 0, .04);
}
.cv-card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.cv-card__category {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    line-height: 1.2;
}
/* 카테고리별 색상 (12종) */
.cv-card__category[data-cat="question"]    { background: #FEF3E2; color: #B45309; }
.cv-card__category[data-cat="declarative"] { background: #E0E7FF; color: #3730A3; }
.cv-card__category[data-cat="number"]      { background: #DCFCE7; color: #166534; }
.cv-card__category[data-cat="forbid"]      { background: #FECACA; color: #991B1B; }
.cv-card__category[data-cat="benefit"]     { background: #E8F0E8; color: #5F7F62; }
.cv-card__category[data-cat="urgent"]      { background: #FFE4E6; color: #BE123C; }
.cv-card__category[data-cat="curiosity"]   { background: #F3E8FF; color: #6B21A8; }
.cv-card__category[data-cat="empathy"]     { background: #FCE7F3; color: #9D174D; }
.cv-card__category[data-cat="contrast"]    { background: #DBEAFE; color: #1E40AF; }
.cv-card__category[data-cat="story"]       { background: #FEF9C3; color: #854D0E; }
.cv-card__category[data-cat="command"]     { background: #E2E8F0; color: #334155; }
.cv-card__category[data-cat="promise"]     { background: #CFFAFE; color: #155E75; }

/* 점수 (숫자 + 막대) */
.cv-card__score {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
}
.cv-card__score-num {
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 24px;
    text-align: right;
}
.cv-card__score-bar {
    display: inline-block;
    width: 56px;
    height: 6px;
    background: var(--bg-secondary);
    border-radius: 999px;
    overflow: hidden;
}
.cv-card__score-fill {
    display: block;
    height: 100%;
    background: var(--sage);
    transition: width .2s ease-out;
}
.cv-card__score.is-strong .cv-card__score-fill { background: var(--sage); }
.cv-card__score.is-strong .cv-card__score-num  { color: var(--sage-dark); }
.cv-card__score.is-mid .cv-card__score-fill    { background: #F4B860; }
.cv-card__score.is-soft .cv-card__score-fill   { background: var(--border-medium); }

.cv-card__text {
    margin: 0;
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 500;
    line-height: 1.55;
    color: var(--text-primary);
    word-break: keep-all;
    overflow-wrap: break-word;
}
.cv-card__rationale {
    margin: 0;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}
.cv-card__actions {
    display: flex;
    gap: 6px;
    margin-top: auto;
    padding-top: 6px;
    border-top: 1px dashed var(--border-light);
}
.cv-card__copy,
.cv-card__pick {
    padding: 6px 14px;
    font-size: 12px;
    min-height: 36px;
    cursor: pointer;
}
.cv-card__pick {
    background: var(--sage-light);
    border-color: var(--sage);
    color: var(--sage-dark);
    font-weight: 600;
}
.cv-card__pick:hover {
    background: var(--sage);
    color: #fff;
}
.cv-card__fav {
    margin-left: auto;
    width: 36px;
    height: 36px;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    transition: all .15s;
}
.cv-card__fav:hover { color: var(--text-secondary); }
.cv-card__fav.is-on {
    color: #F4B860;
    border-color: #F4B860;
    background: #FFF6E5;
}

.cv-btn-save {
    padding: 6px 14px;
    font-size: 12px;
    min-height: 36px;
    background: var(--bg-white);
    border: 1px solid var(--sage);
    color: var(--sage-dark);
    cursor: pointer;
}
.cv-btn-save:hover { background: var(--sage-light); }

/* ===== 빈 상태 / 로딩 / 에러 ===== */
.cv-empty {
    text-align: center;
    padding: 60px 20px;
    background: var(--bg-white);
    border: 1px dashed var(--border-light);
    border-radius: var(--radius-lg);
}
.cv-empty__icon { font-size: 36px; margin-bottom: 12px; }
.cv-empty__title { font-size: 15px; font-weight: 600; color: var(--text-primary); margin: 0 0 6px 0; }
.cv-empty__desc { font-size: 12px; color: var(--text-muted); margin: 0; line-height: 1.5; }

.cv-card--skel {
    background: var(--bg-secondary);
    border-color: transparent;
    pointer-events: none;
}
.cv-card__skel-line {
    height: 14px;
    background: linear-gradient(90deg, var(--bg-tertiary), var(--bg-secondary), var(--bg-tertiary));
    background-size: 200% 100%;
    animation: cv-skel 1.4s ease-in-out infinite;
    border-radius: var(--radius-sm);
}
.cv-card__skel-line--head { width: 40%; }
.cv-card__skel-line--short { width: 60%; }
@keyframes cv-skel {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.cv-error {
    padding: 20px;
    background: #FEF2F2;
    border: 1px solid #FCA5A5;
    border-radius: var(--radius-lg);
    color: #991B1B;
}
.cv-error__title { margin: 0 0 8px 0; font-weight: 700; font-size: 14px; }
.cv-error__msg {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    color: #7F1D1D;
}

/* ===== 이력 드로어 ===== */
.cv-history {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: stretch;
    justify-content: flex-end;
}
.cv-history[hidden] { display: none; }
.cv-history__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .42);
}
.cv-history__panel {
    position: relative;
    background: var(--bg-white);
    width: min(420px, 90vw);
    max-width: 100%;
    display: flex;
    flex-direction: column;
    box-shadow: -12px 0 32px rgba(0, 0, 0, .12);
    animation: cv-slide-in .18s ease-out;
}
@keyframes cv-slide-in {
    from { transform: translateX(20px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
.cv-history__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
}
.cv-history__title {
    margin: 0;
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}
.cv-history__close {
    width: 32px; height: 32px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}
.cv-history__close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}
.cv-history__list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    -webkit-overflow-scrolling: touch;
}
.cv-history__item {
    display: block;
    width: 100%;
    text-align: left;
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color .15s, background .15s;
    font-family: var(--font-sans);
}
.cv-history__item:hover {
    border-color: var(--sage);
    background: var(--bg-secondary);
}
.cv-history__item-head {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    font-size: 11px;
}
.cv-history__item-channel {
    color: var(--sage-dark);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.cv-history__item-score {
    color: var(--text-muted);
    font-family: var(--font-mono);
}
.cv-history__item-source {
    margin: 2px 0;
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.4;
    word-break: keep-all;
}
.cv-history__item-meta {
    margin: 0;
    font-size: 11px;
    color: var(--text-muted);
}
.cv-history__loading,
.cv-history__empty {
    padding: 24px 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

body.cv-history-open { overflow: hidden; }

/* ===== 모달 (임베드 모드 openModal) ===== */
.cv-modal {
    position: fixed;
    inset: 0;
    z-index: 250;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cv-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .42);
    animation: cv-fade-in .14s ease-out;
}
.cv-modal__panel {
    position: relative;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    width: min(900px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 64px rgba(0, 0, 0, .22);
    animation: cv-pop-in .16s ease-out;
    overflow: hidden;
}
.cv-modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}
.cv-modal__title {
    margin: 0;
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}
.cv-modal__close {
    width: 32px; height: 32px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}
.cv-modal__close:hover { background: var(--bg-secondary); color: var(--text-primary); }
.cv-modal__body {
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}
@keyframes cv-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes cv-pop-in {
    from { opacity: 0; transform: translateY(12px) scale(.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
body.cv-modal-open { overflow: hidden; }

/* ===== 임베드 모드 컨테이너 ===== */
.cv-embed-host {
    background: var(--bg-white);
}
.cv-embed-host .cv-form { padding: 14px; box-shadow: none; }

/* ============================================================
   모바일 (768px 이하) — PC와 동일 동작 보장
   ============================================================ */
@media (max-width: 768px) {
    #panelCopyvariant {
        left: 0;
    }
    .cv-container {
        padding: 16px 14px calc(120px + var(--safe-bottom, 0px));
    }
    .cv-form {
        padding: 14px;
        gap: 14px;
    }
    .cv-form__grid {
        grid-template-columns: 1fr;
    }
    .cv-input,
    .cv-input--textarea {
        font-size: 16px; /* iOS 자동 줌 방지 */
    }
    .cv-radio {
        font-size: 14px;
        padding: 10px 14px;
        min-height: 44px;
    }

    /* 결과 1열 */
    .cv-grid {
        grid-template-columns: 1fr;
    }

    /* 카드 액션 터치 영역 */
    .cv-card__copy,
    .cv-card__pick {
        font-size: 13px;
        min-height: 44px;
        padding: 10px 16px;
    }
    .cv-card__fav {
        width: 44px; height: 44px;
    }

    /* 액션 바를 sticky 하단으로 */
    .cv-action-bar {
        position: sticky;
        bottom: 0;
        left: 0;
        right: 0;
        padding: 12px 14px calc(12px + var(--safe-bottom, 0px));
        background: var(--bg-white);
        border-top: 1px solid var(--border-light);
        border-bottom: none;
        margin: 0 -14px 14px;
        z-index: 10;
        box-shadow: 0 -2px 12px rgba(0, 0, 0, .04);
    }
    .cv-action-bar__generate {
        flex: 1;
        min-width: 0;
    }

    /* 이력 드로어 — 풀스크린 */
    .cv-history__panel {
        width: 100%;
    }

    /* 결과 head — 정렬을 줄바꿈 */
    .cv-result__head {
        flex-direction: column;
        align-items: stretch;
    }
    .cv-result__sort {
        justify-content: flex-end;
    }

    /* 모달 — 풀스크린 */
    .cv-modal__panel {
        width: 100vw;
        max-width: 100vw;
        max-height: 100vh;
        height: 100vh;
        border-radius: 0;
    }

    /* 임베드 호스트 */
    .cv-container--embed { padding: 12px; }
}

/* ============================================================
   매우 작은 화면 (360px 이하)
   ============================================================ */
@media (max-width: 360px) {
    .cv-card__text { font-size: 15px; }
    .cv-radio { padding: 10px 12px; }
}
