/* ============================================================
   리브레토 마케팅 — 메인 탭 + 카드뉴스 생성기 스타일
   기존 css/styles.css 의 변수 (--sage, --bg-*, --text-*) 재사용
   ============================================================ */

:root {
    /* Phase 0 이후 가로 메인탭 제거됨. 후방호환을 위해 변수 유지 (값 0). */
    --main-tab-height: 0px;
}

/* ─── Phase 0 이후 ─────────────────────────────────────────
   기존 가로 .main-tabs / .main-tab 셀렉터는 더이상 DOM 에 없음.
   .main-tab-panel--* 는 후방호환으로 클래스명이 남아있을 뿐,
   레이아웃은 css/sidebar.css 의 .tool-panel--* 가 책임짐.
   ────────────────────────────────────────────────────────── */
.main-tab-panel { display: none; }
.main-tab-panel.active,
.main-tab-panel.is-active { display: block; }

/* 카드뉴스 패널은 sidebar.css 에서 .tool-panel--cardnews 로 fixed 처리됨.
   여기선 후방호환 차원의 최소 정의만 유지. */
.main-tab-panel--cardnews.active,
.main-tab-panel--cardnews.is-active { display: block; }

/* ============================================================
   카드뉴스 생성기 (.cn-*)
   ============================================================ */

.cn-app {
    display: grid;
    grid-template-columns: 240px minmax(340px, 440px) 1fr;
    gap: 20px;
    padding: 20px 24px;
    max-width: 1800px;
    margin: 0 auto;
    align-items: start;
}

/* 프로젝트 사이드바 */
.cn-sidebar {
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: calc(100vh - var(--header-height) - var(--main-tab-height) - 40px);
    position: sticky;
    top: 0;
}
.cn-sidebar__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.cn-project-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-right: 2px;
}
.cn-project-list__empty {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 24px 8px;
}
.cn-project-item {
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: background .12s, border-color .12s;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.cn-project-item:hover { background: var(--bg-secondary); }
.cn-project-item.active {
    border-color: var(--sage);
    background: var(--sage-light);
}
.cn-project-item__name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.cn-project-item__meta {
    font-size: 10px;
    color: var(--text-muted);
    display: flex;
    gap: 6px;
}
.cn-project-item__status {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 600;
    background: var(--bg-secondary);
    color: var(--text-secondary);
}
.cn-project-item__status--generated { background: var(--sage-light); color: var(--sage-dark); }
.cn-project-item__status--exported  { background: var(--amber-light); color: #9A6028; }

/* 프로젝트 헤더 (현재 편집 중인) */
.cn-project-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-light);
}
.cn-project-name {
    flex: 1;
    border: none;
    background: transparent;
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    padding: 4px 6px;
    border-radius: var(--radius-sm);
}
.cn-project-name:focus {
    outline: none;
    background: var(--bg-secondary);
}
.cn-save-status {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
}
.cn-save-status--saving { color: var(--amber-dark, #9A6028); }
.cn-save-status--saved  { color: var(--sage-dark); }

.cn-panel {
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 22px;
}
/* 채널 운영의 .step-section-title 와 동일 톤 (font-serif 16px, text-primary) */
.cn-section-title {
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 24px 0 14px;
}
.cn-section-title:first-child { margin-top: 0; }

/* 입력 */
.cn-textarea {
    width: 100%;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.7;
    resize: vertical;
    background: var(--bg-white);
    color: var(--text-primary);
}
.cn-textarea:focus {
    outline: none;
    border-color: var(--sage);
    box-shadow: 0 0 0 3px rgba(111, 143, 114, 0.10);
}

.cn-upload-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.cn-upload-card {
    display: block;
    cursor: pointer;
}
.cn-upload-card input[type="file"] {
    position: absolute;
    width: 1px; height: 1px;
    opacity: 0;
    pointer-events: none;
}
.cn-upload-card__label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.cn-req { color: var(--amber); font-style: normal; margin-left: 6px; font-size: 10px; }
.cn-opt { color: var(--text-muted); font-style: normal; margin-left: 6px; font-size: 10px; }

/* 채널 운영의 .srt-upload-zone 톤과 통일 (2px dashed, hover 시 sage tint 배경) */
.cn-upload-card__preview {
    aspect-ratio: 4 / 5;
    border: 2px dashed var(--border-medium);
    border-radius: var(--radius-md);
    background: var(--bg-secondary) center/cover no-repeat;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    transition: border-color .12s, background-color .12s;
}
.cn-upload-card:hover .cn-upload-card__preview {
    border-color: var(--sage);
    background-color: var(--sage-light);
}
.cn-upload-card__preview.has-image {
    border-style: solid;
    border-color: var(--sage);
}
.cn-upload-card:hover .cn-upload-card__preview.has-image {
    background-color: transparent; /* 이미지가 있으면 sage tint 미적용 */
}
.cn-upload-card__hint {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.5;
    padding: 8px;
}

.cn-opts { display: grid; gap: 10px; }
.cn-opt-row {
    display: grid;
    grid-template-columns: 90px 1fr;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}
.cn-opt-row span { color: var(--text-secondary); font-weight: 500; }
.cn-opt-row select,
.cn-opt-row input {
    padding: 7px 10px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font: inherit;
    background: var(--bg-white);
    transition: border-color .12s, box-shadow .12s;
}
.cn-opt-row select:focus,
.cn-opt-row input:focus {
    outline: none;
    border-color: var(--sage);
    box-shadow: 0 0 0 3px rgba(111, 143, 114, 0.10);
}
.cn-project-name:focus,
.cn-editor-field input:focus,
.cn-editor-field textarea:focus {
    outline: none;
    border-color: var(--sage);
    box-shadow: 0 0 0 3px rgba(111, 143, 114, 0.10);
}

.cn-btn-block {
    display: block;
    width: 100%;
    margin-top: 18px;
}
.cn-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin: 8px 0 0;
    line-height: 1.5;
}
.cn-link {
    background: none;
    border: none;
    color: var(--sage-dark);
    text-decoration: underline;
    cursor: pointer;
    padding: 0;
    font: inherit;
    margin-left: 4px;
}
.cn-diag {
    margin-top: 8px;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.55;
    white-space: pre-wrap;
    max-height: 280px;
    overflow-y: auto;
}

/* 우측 영역 */
.cn-empty, .cn-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 460px;
    color: var(--text-muted);
    gap: 16px;
}
.cn-spinner {
    width: 38px; height: 38px;
    border: 3px solid var(--sage-light);
    border-top-color: var(--sage);
    border-radius: 50%;
    animation: cnSpin .8s linear infinite;
}
@keyframes cnSpin { to { transform: rotate(360deg); } }

.cn-strip {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 0 14px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border-light);
}
.cn-strip::-webkit-scrollbar { height: 6px; }
.cn-strip::-webkit-scrollbar-thumb {
    background: var(--border-medium);
    border-radius: 3px;
}
.cn-thumb {
    flex: 0 0 auto;
    padding: 7px 12px;
    font-size: 11px;
    background: var(--bg-secondary);
    border: 1.5px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    user-select: none;
    transition: all .12s;
}
.cn-thumb:hover { background: var(--sage-light); }
.cn-thumb--active {
    border-color: var(--sage);
    background: var(--sage-light);
    color: var(--text-primary);
    font-weight: 600;
}

.cn-detail {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
    gap: 28px;
    align-items: start;
}
.cn-preview-wrap { display: flex; justify-content: center; }
.cn-preview-frame {
    width: 100%;
    max-width: 380px;
}
.cn-preview-frame canvas {
    width: 100%;
    height: auto;
    display: block;
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

.cn-editor {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.cn-editor-head {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-light);
}
.cn-editor-field { display: flex; flex-direction: column; gap: 4px; }
.cn-editor-field span {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 600;
}
.cn-editor-field input,
.cn-editor-field textarea {
    padding: 8px 10px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font: inherit;
    background: var(--bg-white);
}
.cn-editor-field input:focus,
.cn-editor-field textarea:focus {
    outline: none;
    border-color: var(--sage);
    box-shadow: 0 0 0 3px rgba(111, 143, 114, 0.10);
}
.cn-editor-field textarea {
    min-height: 90px;
    resize: vertical;
    line-height: 1.55;
}

.cn-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 18px;
    margin-top: 22px;
    border-top: 1px solid var(--border-light);
}

/* 반응형 */
@media (max-width: 1280px) {
    .cn-app { grid-template-columns: 200px 1fr; }
    .cn-panel--preview { grid-column: 1 / -1; }
}
@media (max-width: 1024px) {
    .cn-app { grid-template-columns: 1fr; }
    .cn-sidebar { position: static; max-height: 280px; }
    .cn-detail { grid-template-columns: 1fr; }
}

/* ============================================================
   Phase 4 / T2 — 인용구 카드 모드
   ============================================================ */

/* 모드 뱃지 (header 우측) */
.cn-mode-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    background: var(--bg-soft, #f5f5f5);
    color: var(--text-secondary, #666);
    margin-left: 8px;
}
.cn-mode-badge[data-mode="quote"] {
    background: var(--sage, #698264);
    color: #fff;
}

/* 프로젝트 리스트 모드 아이콘 */
.cn-project-item__mode {
    display: inline-block;
    width: 18px;
    text-align: center;
    color: var(--sage, #698264);
    font-size: 12px;
    margin-right: 2px;
}

/* ─── 모드 선택 모달 ─── */
.cn-modal {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}
.cn-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    cursor: pointer;
}
.cn-modal__panel {
    position: relative;
    background: var(--bg-white, #fff);
    border-radius: var(--radius-lg, 12px);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.22);
    max-width: 640px;
    width: calc(100vw - 32px);
    max-height: calc(100vh - 64px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.cn-modal__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-light, #eee);
}
.cn-modal__title {
    margin: 0;
    font-family: var(--font-serif, "Noto Serif KR", serif);
    font-size: 18px;
    color: var(--text-primary, #222);
}
.cn-modal__close {
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: var(--text-muted, #888);
    line-height: 1;
}
.cn-modal__close:hover { background: var(--bg-soft, #f5f5f5); }
.cn-modal__body {
    padding: 22px;
    overflow-y: auto;
    flex: 1;
}
body.cn-modal-open { overflow: hidden; }

/* 모드 선택 그리드 */
.cn-mode-picker__lead {
    margin: 0 0 16px;
    color: var(--text-secondary, #555);
    font-size: 14px;
}
.cn-mode-picker__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.cn-mode-card {
    background: var(--bg-white, #fff);
    border: 2px solid var(--border-light, #e6e6e6);
    border-radius: var(--radius-md, 10px);
    padding: 22px 18px;
    text-align: left;
    cursor: pointer;
    transition: border-color .14s, box-shadow .14s, transform .12s;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font: inherit;
    color: inherit;
}
.cn-mode-card:hover {
    border-color: var(--sage, #698264);
    box-shadow: 0 6px 18px rgba(105, 130, 100, 0.12);
    transform: translateY(-1px);
}
.cn-mode-card__icon {
    font-size: 32px;
    line-height: 1;
}
.cn-mode-card__title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary, #222);
}
.cn-mode-card__desc {
    font-size: 13px;
    color: var(--text-secondary, #666);
    line-height: 1.55;
}
.cn-mode-card--quote .cn-mode-card__icon {
    font-family: var(--font-serif, "Noto Serif KR", serif);
    color: var(--sage, #698264);
    font-size: 42px;
}

@media (max-width: 600px) {
    .cn-mode-picker__grid { grid-template-columns: 1fr; }
    .cn-modal__panel { max-height: 92vh; }
}

/* ─── 인용구 입력 패널 ─── */
.cn-quote-panel {
    display: flex;
    flex-direction: column;
}
.cn-quote-bookrow {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 14px;
}
.cn-quote-bookrow .cn-quote-book {
    flex: 1;
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid var(--border-light, #e6e6e6);
    border-radius: var(--radius-sm, 6px);
    background: var(--bg-white, #fff);
    font-size: 14px;
}
.cn-quote-bookrow .cn-quote-book:focus {
    outline: none;
    border-color: var(--sage, #698264);
    box-shadow: 0 0 0 3px rgba(105, 130, 100, 0.18);
}
.cn-quote-source {
    font-family: var(--font-serif, "Noto Serif KR", serif);
    line-height: 1.6;
}

/* ─── 인용구 추출 결과 ─── */
.cn-quote-results {
    margin-top: 14px;
    padding: 14px;
    background: var(--bg-soft, #f8f8f7);
    border-radius: var(--radius-md, 10px);
    border: 1px solid var(--border-light, #e6e6e6);
}
.cn-quote-results__loading {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-secondary, #555);
}
.cn-quote-results__loading p { margin-top: 12px; font-size: 13px; }
.cn-quote-results__error {
    text-align: center;
    padding: 24px;
    color: var(--red, #c0392b);
    font-size: 13px;
}
.cn-quote-results__empty {
    text-align: center;
    padding: 24px;
    color: var(--text-muted, #888);
    font-size: 13px;
}
.cn-quote-summary {
    background: var(--bg-white, #fff);
    border-left: 3px solid var(--sage, #698264);
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 13px;
    color: var(--text-secondary, #555);
    line-height: 1.55;
    border-radius: 0 var(--radius-sm, 6px) var(--radius-sm, 6px) 0;
}
.cn-quote-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

@media (max-width: 1280px) {
    .cn-quote-cards { grid-template-columns: 1fr; }
}

.cn-quote-card {
    background: var(--bg-white, #fff);
    border: 2px solid var(--border-light, #e6e6e6);
    border-radius: var(--radius-md, 10px);
    padding: 14px 14px 12px;
    cursor: pointer;
    transition: border-color .14s, box-shadow .14s;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.cn-quote-card:hover {
    border-color: var(--sage-light, #a8b9a3);
}
.cn-quote-card.is-selected {
    border-color: var(--sage, #698264);
    box-shadow: 0 4px 12px rgba(105, 130, 100, 0.14);
    background: rgba(105, 130, 100, 0.04);
}
.cn-quote-card__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.cn-quote-card__cat {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: var(--sage, #698264);
}
.cn-quote-card__cat[data-cat="명언"]   { background: #8b6f47; }
.cn-quote-card__cat[data-cat="핵심"]   { background: var(--sage, #698264); }
.cn-quote-card__cat[data-cat="질문"]   { background: #5e8aa8; }
.cn-quote-card__cat[data-cat="선언"]   { background: #b85c5c; }
.cn-quote-card__cat[data-cat="이미지"] { background: #9c7eb1; }
.cn-quote-card__len {
    font-size: 10px;
    color: var(--text-muted, #999);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.cn-quote-card__text {
    font-family: var(--font-serif, "Noto Serif KR", serif);
    font-size: 15px;
    line-height: 1.55;
    color: var(--text-primary, #222);
    word-break: keep-all;
    overflow-wrap: break-word;
}
.cn-quote-card__rationale {
    font-size: 11.5px;
    color: var(--text-muted, #888);
    line-height: 1.5;
    padding-top: 6px;
    border-top: 1px dashed var(--border-light, #e6e6e6);
}
.cn-quote-card__hint {
    font-size: 11px;
    color: var(--text-muted, #888);
}
.cn-quote-card__actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}
.cn-quote-card__actions button {
    background: transparent;
    border: 1px solid var(--border-light, #e6e6e6);
    border-radius: var(--radius-sm, 6px);
    padding: 4px 10px;
    font-size: 11.5px;
    cursor: pointer;
    color: var(--text-secondary, #555);
}
.cn-quote-card__actions button:hover {
    border-color: var(--sage, #698264);
    color: var(--sage, #698264);
}
.cn-quote-card.is-selected .cn-quote-card__toggle {
    background: var(--sage, #698264);
    color: #fff;
    border-color: var(--sage, #698264);
}

/* 변환 액션 바 */
.cn-quote-actions {
    margin-top: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--bg-white, #fff);
    border: 1px solid var(--border-light, #e6e6e6);
    border-radius: var(--radius-md, 10px);
    position: sticky;
    bottom: 0;
    z-index: 5;
}
.cn-quote-actions__count {
    flex: 1;
    font-size: 13px;
    color: var(--text-secondary, #555);
    font-weight: 500;
}
.cn-quote-actions .btn-confirm {
    flex-shrink: 0;
}

/* ─── 모바일 표준 (768px 이하) ─── */
@media (max-width: 768px) {
    .cn-modal__panel {
        max-height: 100vh;
        height: 100vh;
        max-width: 100vw;
        width: 100vw;
        border-radius: 0;
    }
    .cn-modal__body { padding: 18px; }
    .cn-mode-picker__grid { grid-template-columns: 1fr; }
    .cn-quote-cards { grid-template-columns: 1fr; }
    .cn-quote-bookrow {
        flex-direction: column;
        align-items: stretch;
    }
    .cn-quote-bookrow .btn { width: 100%; min-height: 44px; }
    .cn-quote-bookrow .cn-quote-book { min-height: 44px; font-size: 16px; }  /* iOS 줌 방지 */
    .cn-quote-source { font-size: 16px; }
    .cn-quote-actions {
        flex-direction: column;
        align-items: stretch;
        position: sticky;
        bottom: env(safe-area-inset-bottom, 0);
    }
    .cn-quote-actions .btn,
    .cn-quote-actions .btn-confirm {
        width: 100%;
        min-height: 44px;
    }
}
