/* ============================================================
   리브레토 마케팅 — 이메일 뉴스레터 (Phase M6.3)
   - 책 모달 [📧 뉴스레터] 탭 (.nl)
   - 사이드바 [뉴스레터] 도구 (.nl-root)
   - 캠페인 편집/미리보기 모달 (.nl-modal)
   - 모바일=PC 동일 동작 (768/480 반응형)
   ============================================================ */

/* ─── 책 모달 [📧 뉴스레터] 탭 ─────────────────────────────── */
.nl {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 8px 0 24px;
}

.nl--loading,
.nl--empty {
    align-items: center;
    justify-content: center;
    min-height: 240px;
    color: var(--text-muted);
}

.nl__loader,
.nl-loading {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 16px;
    font-size: 13px;
}

.nl-error {
    padding: 24px;
    text-align: center;
    color: var(--red, #c0392b);
    background: var(--bg-light, #fafafa);
    border: 1px solid var(--border-light);
    border-radius: 8px;
}

.nl__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 4px;
}

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

.nl__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* 블록 (구독자/시퀀스/단발) */
.nl-block {
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 16px;
    background: var(--bg-card, #fff);
}

.nl-block__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}

.nl-block__title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.nl-block__count {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-light, #f5f5f5);
    padding: 2px 8px;
    border-radius: 999px;
}

.nl-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    padding: 16px 8px;
    margin: 0;
}

/* 책 매핑 구독자 행 */
.nl-bsubs {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
    max-height: 320px;
    overflow-y: auto;
}

.nl-bsub {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-light, #fafafa);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    font-size: 13px;
}

.nl-bsub__main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 200px;
}

.nl-bsub__email {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-primary);
}

.nl-bsub__name {
    font-size: 11px;
    color: var(--text-muted);
}

.nl-bsub__meta {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.nl-bsub__date {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.nl-bsub__del {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-muted);
    width: 22px;
    height: 22px;
    line-height: 1;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

.nl-bsub__del:hover {
    color: var(--red, #c0392b);
    border-color: var(--red, #c0392b);
}

/* 빠른 추가 폼 */
.nl-quick-add {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr auto;
    gap: 6px;
    align-items: stretch;
}

.nl-quick-add__input {
    padding: 8px 10px;
    border: 1px solid var(--border-medium);
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
    min-height: 36px;
}

.nl-quick-add__input:focus {
    outline: none;
    border-color: var(--sage);
    box-shadow: 0 0 0 3px rgba(111, 143, 114, 0.2);
}

/* 시퀀스 그리드 */
.nl-seq-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.nl-seq {
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 14px;
    background: var(--bg-card, #fff);
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 140px;
}

.nl-seq__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.nl-seq__label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}

.nl-seq__status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--bg-light, #f5f5f5);
    color: var(--text-muted);
}

.nl-seq__status--draft     { background: #e8f0e9; color: #4a6b4d; }
.nl-seq__status--scheduled { background: #fff4d6; color: #8a6d18; }
.nl-seq__status--sending   { background: #d6e8ff; color: #1a4f8a; }
.nl-seq__status--sent      { background: #d6f5e0; color: #1a6e3c; }
.nl-seq__status--failed    { background: #ffd6d6; color: #8a1a1a; }
.nl-seq__status--none      { background: #f5f5f5; color: #999; }

.nl-seq__subject {
    font-size: 12px;
    color: var(--text-secondary, #555);
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    flex: 1;
}

.nl-seq__actions {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.nl-seq__actions .btn {
    font-size: 11px;
    padding: 4px 8px;
}

/* 단발 캠페인 행 */
.nl-cmp-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nl-cmp {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-light, #fafafa);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    flex-wrap: wrap;
}

.nl-cmp__main {
    flex: 1;
    min-width: 200px;
}

.nl-cmp__title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 2px;
}

.nl-cmp__subject {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0;
}

.nl-cmp__meta {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.nl-cmp__date {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.nl-cmp__edit {
    font-size: 11px;
    padding: 4px 8px;
}

/* 칩 */
.nl-chip {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--bg-light, #f5f5f5);
    color: var(--text-secondary, #555);
    white-space: nowrap;
}

.nl-chip--seq      { background: #e8f0fa; color: #1a4f8a; }
.nl-chip--book     { background: #faf3e8; color: #8a5a18; }
.nl-chip--source   { background: #f0e8fa; color: #5a1a8a; }

.nl-chip--interest          { background: #f5f5f5; color: #555; }
.nl-chip--interest.nl-chip--preorder { background: #fff4d6; color: #8a6d18; }
.nl-chip--interest.nl-chip--reviewer { background: #d6f5e0; color: #1a6e3c; }
.nl-chip--interest.nl-chip--reader   { background: #e8f0e9; color: #4a6b4d; }
.nl-chip--interest.nl-chip--tester   { background: #d6e8ff; color: #1a4f8a; }
.nl-chip--interest.nl-chip--other    { background: #f5f5f5; color: #777; }

.nl-chip--status         { background: #f5f5f5; color: #555; }
.nl-chip--status.nl-chip--active        { background: #d6f5e0; color: #1a6e3c; }
.nl-chip--status.nl-chip--unsubscribed  { background: #ffe8e8; color: #8a3a3a; }
.nl-chip--status.nl-chip--bounced       { background: #ffd6d6; color: #8a1a1a; }
.nl-chip--status.nl-chip--pending       { background: #fff4d6; color: #8a6d18; }

.nl-chip--status.nl-chip--draft     { background: #e8f0e9; color: #4a6b4d; }
.nl-chip--status.nl-chip--scheduled { background: #fff4d6; color: #8a6d18; }
.nl-chip--status.nl-chip--sending   { background: #d6e8ff; color: #1a4f8a; }
.nl-chip--status.nl-chip--sent      { background: #d6f5e0; color: #1a6e3c; }
.nl-chip--status.nl-chip--failed    { background: #ffd6d6; color: #8a1a1a; }

/* ─── 사이드바 도구 [📧 뉴스레터] ─────────────────────────── */
.nl-root {
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
}

.nl-toolbar {
    margin-bottom: 16px;
}

.nl-toolbar__heading {
    font-family: var(--font-serif);
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.nl-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border-light);
    margin-bottom: 20px;
    overflow-x: auto;
    scrollbar-width: none;
}

.nl-tabs::-webkit-scrollbar { display: none; }

.nl-tab {
    background: transparent;
    border: 0;
    padding: 10px 16px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    font-family: inherit;
}

.nl-tab.is-active {
    color: var(--text-primary);
    border-bottom-color: var(--sage);
    font-weight: 600;
}

.nl-tab-panels {
    min-height: 200px;
}

.nl-tab-panel:not(.is-active) { display: none; }

/* 구독자 탭 */
.nl-subs__summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.nl-stat {
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 12px;
    background: var(--bg-card, #fff);
    text-align: center;
}

.nl-stat__label {
    font-size: 11px;
    color: var(--text-muted);
    margin: 0 0 4px;
    display: block;
}

.nl-stat__value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.nl-subs__filters {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr auto;
    gap: 6px;
    margin-bottom: 12px;
}

.nl-subs__actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.nl-input {
    padding: 8px 10px;
    border: 1px solid var(--border-medium);
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
    font-family: inherit;
    min-height: 36px;
    width: 100%;
    box-sizing: border-box;
}

.nl-input:focus {
    outline: none;
    border-color: var(--sage);
    box-shadow: 0 0 0 3px rgba(111, 143, 114, 0.2);
}

.nl-input--ta {
    min-height: 100px;
    resize: vertical;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
}

.nl-subs__list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.nl-sub {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    background: var(--bg-card, #fff);
    flex-wrap: wrap;
}

.nl-sub__main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 200px;
}

.nl-sub__email {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-primary);
}

.nl-sub__name {
    font-size: 12px;
    color: var(--text-muted);
}

.nl-sub__meta {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.nl-sub__tags {
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
}

.nl-sub__date {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.nl-sub__del {
    font-size: 11px;
    padding: 4px 8px;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
}

.nl-sub__del:hover {
    color: var(--red, #c0392b);
    border-color: var(--red, #c0392b);
}

.nl-subs__add,
.nl-subs__import {
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 16px;
    background: var(--bg-light, #fafafa);
    margin-bottom: 12px;
}

.nl-subs__add h5,
.nl-subs__import h5 {
    font-size: 13px;
    font-weight: 600;
    margin: 0 0 12px;
    color: var(--text-primary);
}

.nl-subs__add form,
.nl-subs__import form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nl-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin: 0 0 8px;
}

/* 캠페인 탭 (사이드바) */
.nl-cmps__filters {
    display: grid;
    grid-template-columns: 1fr 1fr auto auto;
    gap: 6px;
    margin-bottom: 16px;
}

.nl-cmps__list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nl-cmp-card {
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 14px;
    background: var(--bg-card, #fff);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nl-cmp-card__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.nl-cmp-card__title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.nl-cmp-card__subject {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0;
}

.nl-cmp-card__meta {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
    font-size: 11px;
}

.nl-cmp-card__count {
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.nl-cmp-card__date {
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.nl-cmp-card__actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.nl-cmp-card__actions .btn {
    font-size: 11px;
    padding: 4px 8px;
}

.nl-cmp-card__del:hover {
    color: var(--red, #c0392b);
    border-color: var(--red, #c0392b);
}

/* 통계 탭 */
.nl-stats {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.nl-stats__heading {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-light);
}

.nl-stats__grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.nl-stat-box {
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 14px;
    background: var(--bg-card, #fff);
    text-align: center;
}

.nl-stat-box__label {
    font-size: 11px;
    color: var(--text-muted);
    margin: 0 0 6px;
}

.nl-stat-box__value {
    font-size: 22px;
    font-weight: 600;
    color: var(--text-primary);
    font-family: var(--font-mono);
    margin: 0;
}

.nl-stat-box--pos .nl-stat-box__value { color: #1a6e3c; }
.nl-stat-box--neg .nl-stat-box__value { color: #8a3a3a; }
.nl-stat-box--na  .nl-stat-box__value { color: var(--text-secondary, #555); }

/* ─── 모달 (편집/미리보기) ───────────────────────────────── */
.nl-modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.nl-modal[hidden] { display: none; }

.nl-modal__backdrop {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
}

.nl-modal__panel {
    position: relative;
    background: #fff;
    border-radius: 12px;
    max-width: 720px;
    width: 100%;
    max-height: calc(100vh - 48px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.nl-modal__panel--preview {
    max-width: 800px;
}

.nl-modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
}

.nl-modal__title {
    font-family: var(--font-serif);
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.nl-modal__close {
    background: transparent;
    border: 0;
    font-size: 24px;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
}

.nl-modal__body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

/* 편집 폼 */
.nl-editor {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.nl-editor__row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nl-editor__row--2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.nl-editor__label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
}

.nl-editor__inline {
    display: flex;
    gap: 6px;
    align-items: flex-start;
}

.nl-editor__inline .nl-input {
    flex: 1;
}

.nl-editor__cv-btn,
.nl-editor__fs-btn {
    font-size: 11px;
    padding: 6px 10px;
    white-space: nowrap;
    flex-shrink: 0;
}

.nl-editor__hint {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-light, #fafafa);
    padding: 10px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-light);
}

.nl-editor__hint p {
    margin: 0 0 4px;
}

.nl-editor__hint code {
    display: block;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary, #555);
    word-break: break-all;
    line-height: 1.6;
}

.nl-editor__actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
    padding-top: 8px;
    border-top: 1px solid var(--border-light);
    margin-top: 8px;
}

.nl-editor__del {
    margin-right: auto;
    color: var(--red, #c0392b);
}

.nl-editor__del:hover {
    background: var(--red, #c0392b);
    color: #fff;
    border-color: var(--red, #c0392b);
}

/* 미리보기 */
.nl-prev {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.nl-prev__head {
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 10px;
}

.nl-prev__subject,
.nl-prev__pre {
    margin: 0;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
}

.nl-prev__pre {
    color: var(--text-muted);
    font-size: 12px;
}

.nl-prev__iframe {
    width: 100%;
    min-height: 480px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    background: #fff;
}

.nl-prev__text {
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 8px 12px;
    background: var(--bg-light, #fafafa);
}

.nl-prev__text summary {
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary, #555);
}

.nl-prev__text pre {
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-secondary, #555);
    white-space: pre-wrap;
    word-break: break-word;
    margin: 8px 0 0;
}

/* ─── 모바일 768px ─────────────────────────────────────────── */
@media (max-width: 768px) {
    .nl-root {
        padding: 16px;
    }

    .nl-quick-add {
        grid-template-columns: 1fr;
    }

    .nl-seq-grid {
        grid-template-columns: 1fr;
    }

    .nl-subs__summary {
        grid-template-columns: repeat(2, 1fr);
    }

    .nl-subs__filters {
        grid-template-columns: 1fr 1fr;
    }

    .nl-subs__filters button { grid-column: span 2; }

    .nl-cmps__filters {
        grid-template-columns: 1fr 1fr;
    }

    .nl-cmps__filters button { grid-column: span 2; }

    .nl-stats__grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .nl-modal {
        padding: 0;
    }

    .nl-modal__panel {
        max-width: 100%;
        max-height: 100vh;
        height: 100%;
        border-radius: 0;
    }

    .nl-editor__row--2col {
        grid-template-columns: 1fr;
    }

    .nl-prev__iframe {
        min-height: 360px;
    }
}

/* ─── 모바일 480px ─────────────────────────────────────────── */
@media (max-width: 480px) {
    .nl-toolbar__heading {
        font-size: 18px;
    }

    .nl-subs__summary {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .nl-stats__grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .nl-stat-box__value {
        font-size: 18px;
    }

    .nl-bsub,
    .nl-sub,
    .nl-cmp {
        flex-direction: column;
        align-items: stretch;
    }

    .nl-bsub__meta,
    .nl-sub__meta,
    .nl-cmp__meta {
        justify-content: flex-start;
    }

    .nl-editor__inline {
        flex-direction: column;
    }

    .nl-editor__actions {
        flex-direction: column;
    }

    .nl-editor__actions .btn {
        width: 100%;
    }

    .nl-editor__del {
        margin-right: 0;
        order: 99;
    }
}
