/* ============================================================
   리브레토 마케팅 — 홈 대시보드 (Phase 0.6)
   - 위젯 1개: "진행 중인 책 프로젝트"
   - 책 카드: 표지 + 제목/저자 + 상태 뱃지 + D-day + 진행률 4/4
   - 모바일: 1컬럼, 표지 위 정보 아래
   - 모든 색/폰트/간격 = CSS 변수
   ============================================================ */

/* ─── 컨테이너 ─────────────────────────────────────────────── */
.dash-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 32px 96px;
}

.dash-header {
    margin-bottom: 28px;
}

.dash-title {
    font-family: var(--font-serif);
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    margin: 0 0 6px 0;
}

.dash-greeting {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
}
.dash-greeting strong {
    color: var(--sage-dark);
    font-weight: 700;
}
.dash-greeting .dash-greeting__hint {
    color: var(--text-muted);
}

/* ─── 섹션 (위젯 컨테이너) ────────────────────────────────── */
.dash-section {
    background: transparent;
    margin-bottom: 32px;
}

.dash-section__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 14px;
}

.dash-section__title {
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.dash-section__actions {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.dash-section__actions::-webkit-scrollbar { display: none; }

/* ─── 작은 버튼 (필터) ────────────────────────────────────── */
.dash-section__actions .btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s;
    line-height: 1.2;
}
.dash-section__actions .btn-sm:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border-medium);
}
.dash-section__actions .btn-sm.is-active,
.dash-section__actions .btn-sm[data-active="true"] {
    background: var(--sage-light);
    color: var(--sage-dark);
    border-color: var(--sage);
    font-weight: 600;
}

/* ─── 카드 그리드 ─────────────────────────────────────────── */
.dash-books {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

/* ─── 책 카드 ─────────────────────────────────────────────── */
.dash-book-card {
    display: flex;
    gap: 14px;
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 14px;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s, transform .15s;
    text-align: left;
    width: 100%;
    font-family: var(--font-sans);
}
.dash-book-card:hover,
.dash-book-card:focus-visible {
    border-color: var(--border-medium);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
    outline: none;
}
.dash-book-card:focus-visible {
    box-shadow: 0 0 0 3px var(--sage-light);
}

.dash-book-card__cover {
    flex: 0 0 auto;
    width: 80px;
    height: 112px;
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.dash-book-card__cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.dash-book-card__cover-ph {
    color: var(--text-muted);
    font-size: 28px;
}

.dash-book-card__body {
    flex: 1 1 auto;
    min-width: 0; /* flex 자식 ellipsis 보호 */
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dash-book-card__title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.4;
    margin: 0;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    word-break: keep-all;
}

.dash-book-card__author {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dash-book-card__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 4px;
}

.dash-status {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 10px;
    background: var(--sage-light);
    color: var(--sage-dark);
    line-height: 1.2;
}
.dash-status[data-status="planning"]  { background: var(--bg-tertiary); color: var(--text-secondary); }
.dash-status[data-status="editing"]   { background: #FFF3E0; color: #B45309; }
.dash-status[data-status="marketing"] { background: var(--sage-light); color: var(--sage-dark); }
.dash-status[data-status="published"] { background: #E8E8E8; color: #6B7280; }

.dash-dday {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-muted);
    font-family: var(--font-mono);
    letter-spacing: -0.02em;
}
.dash-dday.is-soon    { color: #DC2626; } /* D-7 이내 */
.dash-dday.is-near    { color: #D97706; } /* D-30 이내 */
.dash-dday.is-future  { color: var(--sage-dark); }
.dash-dday.is-today   { color: #DC2626; font-weight: 800; }
.dash-dday.is-past    { color: var(--text-muted); }

/* ─── 진행률 ─────────────────────────────────────────────── */
.dash-progress {
    margin-top: 8px;
}
.dash-progress__bar {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}
.dash-progress__fill {
    height: 100%;
    background: var(--sage);
    transition: width .25s ease;
    border-radius: 3px;
}
.dash-progress__meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-muted);
}
.dash-progress__meta > .dash-progress__count { margin-right: auto; }
.dash-progress__count {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-secondary);
}

/* 진행률 9-항목 그리드 (M5-A 확장)
   - 데스크톱: 9칸 1행 (auto-fit, 최소 60px) — 좁아지면 자동 줄바꿈
   - 768px 이하: 5×2 (5칸 + 4칸) 또는 자동 흐름
   - 480px 이하: 폰트 9px 까지 압축 + 칸 더 작게
*/
.dash-progress__items {
    display: grid;
    grid-template-columns: repeat(9, minmax(0, 1fr));
    gap: 4px;
    margin-top: 6px;
}
.dash-progress__item {
    font-size: 10px;
    padding: 3px 4px;
    border-radius: 6px;
    background: var(--bg-secondary);
    color: var(--text-muted);
    border: 1px solid transparent;
    line-height: 1.3;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: background .15s, color .15s, border-color .15s;
    cursor: help; /* tip 안내 */
}
.dash-progress__item.is-done {
    background: var(--sage-light);
    color: var(--sage-dark);
    border-color: var(--sage);
    font-weight: 600;
}
.dash-progress__item .ck {
    font-family: var(--font-mono);
    margin-right: 2px;
    display: inline-block;
}
.dash-progress__item-label {
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: bottom;
    max-width: 100%;
}

/* 100% 완성 배지 / 0건 힌트 */
.dash-progress__badge {
    margin-left: auto;
    font-size: 10px;
    font-weight: 700;
    color: var(--sage-dark);
    background: var(--sage-light);
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid var(--sage);
    letter-spacing: 0.02em;
}
.dash-progress__hint {
    margin-left: auto;
    font-size: 10px;
    color: var(--text-muted);
    font-style: italic;
}
.dash-progress__percent {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-secondary);
}

/* 진행률 단계 테마 — fill bar 색을 단계별로 변화 */
.dash-book-card.is-stage-empty .dash-progress__fill { background: var(--bg-tertiary); }
.dash-book-card.is-stage-mid .dash-progress__fill   { background: var(--sage); opacity: 0.55; }
.dash-book-card.is-stage-near .dash-progress__fill  { background: var(--sage); opacity: 0.85; }
.dash-book-card.is-stage-complete .dash-progress__fill {
    background: var(--sage);
    box-shadow: 0 0 0 1px var(--sage-dark) inset;
}
.dash-book-card.is-stage-complete {
    border-color: var(--sage);
    background: linear-gradient(180deg, var(--bg-white) 0%, var(--bg-white) 70%, var(--sage-light) 100%);
}

/* ─── 빈 상태 ─────────────────────────────────────────────── */
.dash-empty {
    text-align: center;
    padding: 56px 20px;
    background: var(--bg-white);
    border: 1px dashed var(--border-medium);
    border-radius: var(--radius-lg);
}
.dash-empty__icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.6;
}
.dash-empty__title {
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 6px 0;
}
.dash-empty__desc {
    font-size: 13px;
    color: var(--text-muted);
    margin: 0 0 20px 0;
}

/* ─── 로딩 스켈레톤 ──────────────────────────────────────── */
.dash-skeleton {
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-tertiary) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    animation: dashShimmer 1.4s infinite;
    border-radius: var(--radius-md);
    color: transparent;
}
@keyframes dashShimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ─── 모바일 ─────────────────────────────────────────────── */
@media (max-width: 768px) {
    .dash-container {
        padding: 16px 16px calc(80px + var(--safe-bottom, 0px));
        padding-left: max(16px, var(--safe-left, 0px));
        padding-right: max(16px, var(--safe-right, 0px));
    }
    .dash-title {
        font-size: 22px;
    }
    .dash-greeting { font-size: 13px; }
    .dash-section__head {
        flex-direction: column;
        align-items: flex-start;
    }
    .dash-section__actions {
        width: 100%;
        padding-bottom: 4px;
    }
    .dash-section__actions .btn-sm {
        min-height: 36px;     /* 모바일 가독성 (필터는 본문 액션이 아니라 36px 허용) */
        padding: 8px 14px;
    }
    .dash-books {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .dash-book-card {
        padding: 12px;
        gap: 12px;
    }
    .dash-book-card__cover {
        width: 72px;
        height: 100px;
    }
    .dash-book-card__title { font-size: 14px; }
    .dash-empty {
        padding: 40px 16px;
    }
}

/* 768px 이하: 9칸 1행 → 5칸 + 4칸 (2행) 자동 흐름. min-width 0 으로 ellipsis 안전 */
@media (max-width: 768px) {
    .dash-progress__items {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 4px;
    }
    .dash-progress__item {
        font-size: 9px;
        padding: 3px 3px;
    }
}

/* 더 작은 화면 (480px 이하) — 표지 위, 정보 아래 */
@media (max-width: 480px) {
    .dash-book-card {
        flex-direction: row; /* 작은 모바일에서도 가로 유지가 더 정보 밀도 높음 */
    }
    .dash-book-card__cover {
        width: 64px;
        height: 90px;
    }
    /* 9칸 그대로 유지 — 너비가 좁아도 한 줄에 9칸 (체크 + 짧은 라벨) 가독성 한계까지 */
    .dash-progress__items {
        grid-template-columns: repeat(9, minmax(0, 1fr));
        gap: 2px;
    }
    .dash-progress__item {
        font-size: 8px;
        padding: 2px 1px;
        border-radius: 4px;
    }
    .dash-progress__item .ck {
        margin-right: 1px;
    }
    /* 480px 에서는 라벨 숨기고 체크 아이콘만 표시 — 9칸 모두 보이게 */
    .dash-progress__item-label {
        display: none;
    }
    .dash-progress__item .ck {
        font-size: 11px;
    }
    /* 100% 배지/힌트는 줄 끝 */
    .dash-progress__badge {
        font-size: 9px;
        padding: 2px 6px;
    }
}
