/* ============================================================
   리브레토 마케팅 — 모바일 반응형 보강
   브레이크포인트:
     - 1024px 이하: 태블릿/소형 노트북 (이미 cardnews.css 가 일부 처리)
     - 768px 이하:  세로 태블릿/큰 폰
     - 480px 이하:  일반 폰
     - 360px 이하:  소형 폰
   ============================================================ */

/* ─── 공통 (모든 작은 화면) ─────────────────────────────────── */
@media (max-width: 1024px) {
    :root {
        --header-height: 48px;
        --main-tab-height: 0px;       /* Phase 0 이후 가로 메인탭 제거 */
        --sidebar-width: 200px;        /* 태블릿: 살짝 좁게 */
    }
}

/* ============================================================
   768px 이하 — 세로 태블릿 / 큰 폰
   ============================================================ */
@media (max-width: 768px) {

    body { font-size: 14px; line-height: 1.65; }

    /* ── 헤더 ────────────────────────── */
    .header { padding: 0 12px; }
    .logo { font-size: 14px; }
    .hdr-div { display: none; }
    .hdr-page { font-size: 12px; color: var(--text-muted); }
    .hdr-btn {
        padding: 6px 10px;
        font-size: 11px;
    }

    /* ── 로그인 ──────────────────────── */
    .login-box {
        width: calc(100vw - 32px);
        max-width: 360px;
        padding: 24px 20px;
    }

    /* ── 사이드바 → off-canvas drawer ────── */
    .sidebar-toggle {
        display: inline-flex;       /* 햄버거 노출 */
    }
    .sidebar {
        width: 240px;
        transform: translateX(-100%);
        transition: transform .22s ease-out;
        box-shadow: 4px 0 16px rgba(0, 0, 0, .08);
        top: var(--header-height);
        bottom: 0;
        z-index: 95;                /* 헤더 100 보다 낮지만 콘텐츠 위 */
    }
    .sidebar.is-open {
        transform: translateX(0);
    }
    /* 모바일에선 콘텐츠가 사이드바와 겹치지 않도록 좌측 마진 제거 */
    .content { margin-left: 0; }
    .project-dashboard,
    .project-detail,
    .tool-panel--cardnews,
    .main-tab-panel--cardnews {
        left: 0;
    }
    /* 스크롤 잠금 (drawer 열렸을 때 본문 스크롤 방지) */
    body.sidebar-open { overflow: hidden; }

    /* ── 프로젝트 대시보드 ──────────────── */
    .project-dashboard { padding: 14px 12px; }
    .dashboard-header {
        flex-wrap: wrap;
        gap: 10px;
        margin-bottom: 14px;
    }
    .dashboard-title { font-size: 18px; }
    .dashboard-count { font-size: 12px; }
    .btn-new-project {
        width: 100%;
        order: 3;
        padding: 10px;
        font-size: 13px;
    }
    .project-grid {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    /* ── 프로젝트 상세 / 파이프라인 ──────── */
    .project-detail { overflow-y: auto; }
    .detail-header {
        padding: 10px 12px;
        flex-wrap: wrap;
        gap: 8px;
    }
    .detail-title {
        font-size: 16px;
        flex-basis: 100%;
        order: 3;
    }
    .btn-back-list, .btn-delete-project { font-size: 11px; padding: 6px 10px; }

    .pipeline-steps {
        padding: 10px 12px;
        gap: 6px;
    }
    .pipeline-step {
        padding: 8px 10px;
        font-size: 11px;
    }
    .step-number { width: 20px; height: 20px; font-size: 10px; }
    .step-name { font-size: 11px; }
    .pipeline-connector { display: none; }

    .step-scroll, .step-section { padding: 14px 12px; }
    .step-section-title { font-size: 14px; margin-bottom: 10px; }

    /* 폼 */
    .confirm-grid { grid-template-columns: 1fr !important; gap: 10px; }
    .confirm-input,
    .trend-input,
    select {
        font-size: 16px; /* iOS 자동 줌 방지 */
        padding: 10px 12px;
    }
    .confirm-actions { flex-wrap: wrap; }

    /* 결과 탭 */
    .result-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
    }
    .result-tabs::-webkit-scrollbar { display: none; }
    .result-tab { flex-shrink: 0; font-size: 11px; padding: 8px 10px; }

    .section { margin-bottom: 16px; }
    .section-header { flex-wrap: wrap; gap: 6px; }
    .section-actions { flex-wrap: wrap; }

    /* 버튼 — 터치 타겟 최소 36px */
    .btn, .btn-confirm, .btn-trend, .btn-ai-suggest,
    .btn-generate, .btn-download, .btn-copy {
        min-height: 36px;
        padding: 8px 14px;
        font-size: 13px;
    }
    .btn { padding: 7px 12px; font-size: 12px; min-height: 32px; }

    /* 모달 — 거의 풀스크린 */
    .modal-overlay { padding: 12px; }
    .modal {
        width: 100%;
        max-width: 100%;
        max-height: calc(100vh - 24px);
        overflow-y: auto;
        padding: 18px 16px;
        border-radius: var(--radius-md);
    }
    .modal-title { font-size: 15px; }

    /* 토스트 */
    .toast {
        bottom: 16px;
        right: 12px;
        left: 12px;
        text-align: center;
    }
}

/* ============================================================
   480px 이하 — 일반 폰
   ============================================================ */
@media (max-width: 480px) {

    .login-logo { font-size: 18px; }
    .login-input { padding: 12px 14px; font-size: 16px; }

    /* 사이드바 — 매우 작은 폰: 화면 전체 너비 */
    .sidebar { width: min(85vw, 280px); }

    .dashboard-title { font-size: 16px; }
    .step-section-title { font-size: 13px; }

    /* 파이프라인은 두 줄 허용 */
    .pipeline-steps { flex-wrap: wrap; }

    /* 모달 — 헤더 픽스 */
    .modal-overlay { padding: 0; align-items: flex-end; }
    .modal {
        max-height: 92vh;
        border-radius: var(--radius-md) var(--radius-md) 0 0;
    }
}

/* 360px 이하 — 매우 작은 폰 (iPhone SE 1세대 등) */
@media (max-width: 360px) {
    .header { padding: 0 8px; }
    .hdr-btn { padding: 5px 8px; font-size: 10px; }
    .logo { font-size: 13px; }
    .hdr-page { display: none; }
}

/* ============================================================
   카드뉴스 (.cn-*) — 모바일
   ============================================================ */
@media (max-width: 1024px) {
    .cn-app {
        grid-template-columns: 1fr;
        padding: 16px 12px;
        gap: 14px;
    }
    .cn-sidebar {
        position: static;
        max-height: 240px;
    }
    .cn-detail { grid-template-columns: 1fr; gap: 18px; }
    .cn-preview-frame { max-width: 100%; }
}

@media (max-width: 768px) {
    .cn-panel { padding: 16px 14px; }
    .cn-section-title { font-size: 14px; margin: 18px 0 10px; }

    /* 사이드바를 가로 스크롤 strip으로 */
    .cn-sidebar {
        max-height: none;
        padding: 12px;
    }
    .cn-project-list {
        flex-direction: row;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 8px;
        padding-bottom: 4px;
    }
    .cn-project-list::-webkit-scrollbar { display: none; }
    .cn-project-list__empty { width: 100%; }
    .cn-project-item {
        flex: 0 0 auto;
        min-width: 160px;
        max-width: 220px;
    }

    /* 프로젝트 헤더 */
    .cn-project-header {
        flex-wrap: wrap;
        gap: 6px;
    }
    .cn-project-name { font-size: 15px; flex-basis: 100%; }
    .cn-save-status { font-size: 10px; }

    /* 업로드 카드 — 두 개 가로 유지하되 좁아짐 보정 */
    .cn-upload-grid { gap: 8px; }
    .cn-upload-card__hint { font-size: 10px; padding: 6px; }

    /* 옵션 행 */
    .cn-opt-row {
        grid-template-columns: 80px 1fr;
        font-size: 13px;
    }
    .cn-opt-row select,
    .cn-opt-row input {
        padding: 8px 10px;
        font-size: 16px; /* iOS 줌 방지 */
    }

    .cn-textarea { font-size: 16px; padding: 10px 12px; }

    /* 미리보기 */
    .cn-strip { gap: 6px; padding: 4px 0 10px; }
    .cn-thumb { padding: 6px 10px; font-size: 11px; }

    .cn-preview-frame { max-width: 100%; }

    /* 편집 패널 */
    .cn-editor-field input,
    .cn-editor-field textarea {
        font-size: 16px;
        padding: 10px 12px;
    }

    /* 액션 버튼은 풀폭 */
    .cn-actions { flex-direction: column-reverse; gap: 8px; }
    .cn-actions .btn,
    .cn-actions .btn-confirm { width: 100%; min-height: 40px; }

    /* 진단 출력 */
    .cn-diag { max-height: 200px; font-size: 10px; }
}

@media (max-width: 480px) {
    .cn-upload-grid { grid-template-columns: 1fr; }
    .cn-upload-card__preview { aspect-ratio: 16 / 9; max-height: 180px; }
    .cn-opt-row {
        grid-template-columns: 1fr;
        gap: 4px;
    }
    .cn-opt-row span {
        font-size: 11px;
        font-weight: 600;
        color: var(--text-muted);
    }
}

/* iOS safe-area (노치 폰) */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .header { padding-left: max(12px, env(safe-area-inset-left));
                  padding-right: max(12px, env(safe-area-inset-right)); }
        .sidebar { padding-left: max(10px, env(safe-area-inset-left)); }
        .project-dashboard,
        .step-scroll,
        .cn-app {
            padding-left: max(12px, env(safe-area-inset-left));
            padding-right: max(12px, env(safe-area-inset-right));
            padding-bottom: max(16px, env(safe-area-inset-bottom));
        }
    }
}

/* ============================================================
   ▼ Phase 0.5 — 공통 모바일 표준 (모든 신규 도구가 따라야 할 베이스)
   "PC 와 동일 동작" 원칙: 데스크톱 전용 기능 없음
   ============================================================ */

:root {
    /* safe-area fallback 0 명시 (구버전 브라우저 보호) */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

/* ── 768px 이하 — 모든 폼/버튼/모달의 모바일 표준 ───────────── */
@media (max-width: 768px) {

    /* iOS 자동 줌 방지: 모든 텍스트 입력은 16px 이상 */
    input[type="text"],
    input[type="email"],
    input[type="number"],
    input[type="search"],
    input[type="url"],
    input[type="tel"],
    input[type="password"],
    input[type="date"],
    input[type="datetime-local"],
    input[type="time"],
    textarea,
    select {
        font-size: 16px;
    }

    /* 터치 타깃 — Apple HIG 44×44px 최소 보장
       (기존 0.4em 이하 .btn 룰을 덮지 않도록 textarea/select/input 한정) */
    input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
    select,
    button,
    .btn,
    .btn-confirm,
    .login-input,
    .login-btn,
    .hdr-btn,
    .sidebar__item {
        min-height: 44px;
    }
    /* 단, 헤더 안의 .hdr-btn 은 헤더 높이 52px 안에 들어가야 하므로 36px 유지 */
    .hdr-btn { min-height: 36px; }

    /* textarea 줄간격 보정 (16px * 1.5) */
    textarea { line-height: 1.55; }

    /* 모달은 768px 이하에서 풀스크린 슬라이드업 (sticky header/footer 가능) */
    .modal-overlay {
        padding: 0;
        align-items: stretch;
    }
    .modal {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100vh;
        max-height: 100dvh; /* 키보드 올라올 때 정확 */
        border-radius: 0;
        display: flex;
        flex-direction: column;
        padding-top: max(18px, var(--safe-top));
        padding-bottom: max(18px, var(--safe-bottom));
    }
}

/* ── 공통 컴포넌트: 모바일 하단 sticky 액션 바 ───────────── */
.mobile-action-bar {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: 8px;
    padding: 10px 12px calc(10px + var(--safe-bottom));
    background: var(--bg-white);
    border-top: 1px solid var(--border-light);
    z-index: 50;
}
.mobile-action-bar .btn,
.mobile-action-bar .btn-confirm {
    flex: 1;
    min-height: 48px;
    font-size: 14px;
}

/* ── 토스트: 모바일에서 FAB(56px) 안 가리도록 80px 위로 ───── */
@media (max-width: 768px) {
    .toast {
        bottom: calc(80px + var(--safe-bottom));
        right: 12px;
        left: 12px;
        max-width: none;
        text-align: center;
        padding: 12px 16px;
        font-size: 13px;
    }
}

/* ============================================================
   ▼ 풀스크린 텍스트 편집기 (OWFullscreenEditor) — 모든 도구 공통
   js/common-mobile.js 가 .ow-fse-* 클래스를 토글
   ============================================================ */
.ow-fse-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 9000;
    display: none;
    align-items: stretch;
    justify-content: center;
}
.ow-fse-overlay.is-open { display: flex; }

.ow-fse-modal {
    background: var(--bg-white);
    width: 100%;
    max-width: 720px;
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
}
@media (min-width: 769px) {
    .ow-fse-modal {
        height: auto;
        max-height: 88vh;
        margin: 4vh auto;
        border-radius: var(--radius-lg);
    }
}

.ow-fse-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 12px 14px;
    padding-top: max(12px, var(--safe-top));
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-white);
    flex-shrink: 0;
}
.ow-fse-title {
    font-family: var(--font-serif);
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ow-fse-close {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1;
}

.ow-fse-body {
    flex: 1;
    min-height: 0;
    display: flex;
    overflow: hidden;
}
.ow-fse-textarea {
    flex: 1;
    width: 100%;
    height: 100%;
    border: 0;
    outline: 0;
    padding: 16px;
    font-size: 16px;
    line-height: 1.65;
    font-family: var(--font-sans);
    color: var(--text-primary);
    background: var(--bg-white);
    resize: none;
}

.ow-fse-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 14px;
    padding-bottom: max(10px, var(--safe-bottom));
    border-top: 1px solid var(--border-light);
    background: var(--bg-white);
    flex-shrink: 0;
}
.ow-fse-meta {
    font-size: 12px;
    color: var(--text-muted);
    flex: 1;
    min-width: 0;
}
.ow-fse-actions { display: flex; gap: 8px; }
.ow-fse-actions .btn,
.ow-fse-actions .btn-confirm { min-height: 44px; padding: 10px 16px; }

/* 풀스크린 토글 버튼 (textarea 옆에 붙는 트리거) */
.ow-fse-trigger {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    line-height: 1;
}
.ow-fse-trigger:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.ow-fse-trigger svg { width: 12px; height: 12px; }

/* body 스크롤 잠금 (편집기 열렸을 때) */
body.ow-fse-open { overflow: hidden; }

/* ============================================================
   480px 이하 — 사이드바 폭 보정, 헤더 로고 축소
   ============================================================ */
@media (max-width: 480px) {
    .sidebar { width: min(90vw, 300px); }
    .login-logo { font-size: 17px; }
}
