/* ============================================================
   CustomAI - 제안서 작성 도우미 (네이비/슬레이트 테마)
   ============================================================ */

:root {
    --navy: #1f3a5f;
    --navy-2: #274b78;
    --accent: #2e6ca4;
    --accent-soft: #eaf1f8;
    --bg-1: #eef1f6;
    --bg-2: #e2e7ef;
    --surface: #ffffff;
    --surface-2: #f6f8fb;
    --line: #e3e7ee;
    --line-strong: #d3dae4;
    --text: #1f2937;
    --muted: #6b7280;
    --muted-2: #8a94a3;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 12px 34px rgba(23, 42, 69, 0.12);
    --shadow-sm: 0 1px 2px rgba(23, 42, 69, 0.06), 0 2px 8px rgba(23, 42, 69, 0.05);
    --ok: #2e9e5b;
    --warn: #d9a406;
    /* 16:9 와이드 레이아웃 */
    --app-max: 1760px;
    --app-gutter: 14px;
    --sidebar-w: 280px;
    --writer-chat-w: 40%;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Noto Sans KR', 'Noto Sans CJK KR', -apple-system, BlinkMacSystemFont,
        'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 100%);
    min-height: 100vh;
    padding: var(--app-gutter);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.container {
    width: min(100%, var(--app-max));
    max-width: var(--app-max);
    margin: 0 auto;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: calc(100vh - (var(--app-gutter) * 2));
}

/* ---------------- Header ---------------- */
header {
    background: linear-gradient(120deg, var(--navy) 0%, var(--accent) 100%);
    color: #fff;
    padding: 16px clamp(20px, 2.5vw, 36px);
    flex-shrink: 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
    width: 44px; height: 44px; border-radius: 12px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.25);
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; letter-spacing: 1px; color: #fff;
}

.brand-text h1 {
    font-size: 1.28em;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.25;
}

/* ---------------- App mode nav ---------------- */
.app-mode-nav {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding: 4px;
    width: fit-content;
    max-width: 100%;
    background: rgba(0, 0, 0, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 12px;
}
.app-mode-btn {
    appearance: none;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.78);
    font-family: inherit;
    font-size: 0.92em;
    font-weight: 600;
    padding: 9px 16px;
    border-radius: 9px;
    cursor: pointer;
    transition: background 0.18s, color 0.18s;
    white-space: nowrap;
}
.app-mode-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.1); }
.app-mode-btn.active {
    background: #fff;
    color: var(--navy);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* ---------------- Search (chat) view ---------------- */
.search-view {
    flex: 1;
    display: flex;
    flex-direction: row;
    min-height: 0;
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
}
.search-view[hidden] { display: none; }

.chat-sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: #f3f5f9;
    border-right: 1px solid var(--line);
    min-height: 0;
}
.chat-new-btn {
    margin: 12px 12px 8px;
    padding: 11px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: #fff;
    color: var(--navy);
    font-family: inherit;
    font-size: 0.9em;
    font-weight: 700;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s, border-color 0.15s;
}
.chat-new-btn:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
}
.chat-history-label {
    padding: 6px 16px 4px;
    font-size: 0.72em;
    font-weight: 700;
    color: var(--muted-2);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.chat-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px 12px;
}
.chat-history-empty {
    padding: 18px 12px;
    text-align: center;
    color: var(--muted-2);
    font-size: 0.84em;
    line-height: 1.45;
}
.chat-history-item {
    display: flex;
    align-items: stretch;
    gap: 2px;
    margin-bottom: 2px;
    border-radius: 9px;
}
.chat-history-item.active {
    background: #fff;
    box-shadow: var(--shadow-sm);
}
.chat-history-main {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    text-align: left;
    padding: 10px 10px;
    border-radius: 9px;
    cursor: pointer;
    font-family: inherit;
    color: var(--text);
}
.chat-history-main:hover { background: rgba(255,255,255,0.7); }
.chat-history-item.active .chat-history-main { background: transparent; }
.chat-history-title {
    font-size: 0.88em;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}
.chat-history-meta {
    margin-top: 3px;
    font-size: 0.72em;
    color: var(--muted-2);
}
.chat-history-del {
    flex-shrink: 0;
    width: 32px;
    border: none;
    background: transparent;
    color: var(--muted-2);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85em;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.chat-history-item:hover .chat-history-del,
.chat-history-item.active .chat-history-del { opacity: 1; }
.chat-history-del:hover { color: #c0392b; background: #fdecea; }

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.writer-view {
    flex: 1;
    display: flex;
    flex-direction: row;
    min-height: 0;
    background: #eef2f7;
}
.writer-view[hidden] { display: none; }

.writer-pane {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}
.writer-chat-pane {
    flex: 0 0 var(--writer-chat-w);
    max-width: none;
    min-width: 360px;
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
    border-right: 1px solid var(--line);
}
.writer-preview-pane {
    flex: 1;
    background: #fff;
}
.writer-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 18px 10px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.writer-chat-input-area {
    flex-shrink: 0;
    padding: 10px 16px 18px;
}
.writer-chat-input-area .chat-input-box {
    align-items: flex-end;
}
.writer-chat-input-area .chat-send-btn {
    margin-bottom: 0;
}
.writer-preview-toolbar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
}
.writer-preview-label {
    font-size: 0.82em;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: 0.03em;
}
.writer-preview-body {
    flex: 1;
    overflow-y: auto;
    padding: 28px clamp(24px, 4vw, 56px) 48px;
}
.writer-preview-empty {
    margin: 12vh auto 0;
    text-align: center;
    color: var(--muted-2);
    font-size: 0.95em;
    line-height: 1.6;
}
.writer-preview-empty[hidden],
.writer-preview-md[hidden] { display: none; }
.writer-preview-md {
    max-width: min(1100px, 100%);
    margin: 0 auto;
    font-size: 1em;
    line-height: 1.75;
    color: var(--text);
}
.writer-preview-md h1,
.writer-preview-md h2,
.writer-preview-md h3 {
    color: var(--navy);
    margin: 1.2em 0 0.45em;
    line-height: 1.35;
}
.writer-preview-md h1 { font-size: 1.55em; border-bottom: 1px solid var(--line); padding-bottom: 0.35em; }
.writer-preview-md h2 { font-size: 1.28em; }
.writer-preview-md h3 { font-size: 1.08em; }
.writer-preview-md p { margin: 0.55em 0; }
.writer-preview-md ul, .writer-preview-md ol { margin: 0.5em 0 0.5em 1.3em; }
.writer-preview-md table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.9em 0;
    font-size: 0.92em;
}
.writer-preview-md th, .writer-preview-md td {
    border: 1px solid var(--line-strong);
    padding: 8px 10px;
    text-align: left;
}
.writer-preview-md th { background: var(--surface-2); }
.writer-preview-md code {
    background: var(--surface-2);
    padding: 0.1em 0.35em;
    border-radius: 4px;
    font-size: 0.9em;
}
.writer-preview-md pre {
    background: #f3f5f9;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    overflow-x: auto;
}

@media (max-width: 900px) {
    .writer-view { flex-direction: column; }
    .writer-chat-pane {
        flex: 0 0 42%;
        max-width: none;
        min-width: 0;
        border-right: none;
        border-bottom: 1px solid var(--line);
    }
    .writer-preview-body { padding: 18px 16px 28px; }
}

@media (min-width: 1600px) {
    :root {
        --app-max: 1840px;
        --sidebar-w: 300px;
        --writer-chat-w: 38%;
    }
}

@media (min-width: 1920px) {
    :root {
        --app-max: 1920px;
        --app-gutter: 12px;
    }
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px clamp(20px, 3vw, 40px) 12px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.chat-welcome {
    margin: auto;
    text-align: center;
    max-width: 480px;
    padding: 40px 20px;
    color: var(--muted);
}
.chat-welcome h2 {
    color: var(--navy);
    font-size: 1.55em;
    font-weight: 700;
    margin-bottom: 10px;
    letter-spacing: -0.02em;
}
.chat-welcome p { font-size: 0.95em; line-height: 1.55; }
.chat-welcome[hidden] { display: none; }

.chat-msg {
    display: flex;
    gap: 12px;
    max-width: min(980px, 92%);
    width: 100%;
    align-self: flex-start;
}
.chat-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.chat-avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75em;
    font-weight: 700;
    background: var(--accent-soft);
    color: var(--navy);
}
.chat-msg-user .chat-avatar {
    background: var(--navy);
    color: #fff;
}
.chat-bubble {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    min-width: 0;
    max-width: 100%;
}
.chat-msg-user .chat-bubble {
    background: var(--navy);
    border-color: transparent;
    color: #fff;
}
.chat-content {
    font-size: 0.95em;
    line-height: 1.65;
    word-break: break-word;
}
.chat-content p { margin: 0.55em 0; }
.chat-content p:first-child { margin-top: 0; }
.chat-content p:last-child { margin-bottom: 0; }
.chat-content ul, .chat-content ol { margin: 0.5em 0 0.5em 1.2em; }
.chat-content table {
    border-collapse: collapse;
    margin: 0.7em 0;
    font-size: 0.9em;
    width: 100%;
}
.chat-content th, .chat-content td {
    border: 1px solid var(--line-strong);
    padding: 6px 8px;
    text-align: left;
}
.chat-content th { background: var(--surface-2); }
.chat-typing { color: var(--muted); font-style: italic; }
.chat-error { color: #c0392b; }

.chat-sources {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}
.chat-sources-title {
    font-size: 0.78em;
    font-weight: 700;
    color: var(--muted);
    margin-bottom: 8px;
    letter-spacing: 0.02em;
}
.chat-sources ul {
    margin: 0;
    padding-left: 1.1em;
    font-size: 0.82em;
    color: var(--muted);
}
.chat-sources li { margin: 3px 0; }
.chat-citations {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.chat-citations > li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-2);
}
.chat-citation-main {
    font-size: 0.86em;
    color: var(--text);
    line-height: 1.4;
    min-width: 0;
    flex: 1;
}
.chat-citation-page {
    color: var(--muted);
    font-weight: 600;
    margin-left: 4px;
    white-space: nowrap;
}
.chat-citation-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.chat-citation-btn,
.chat-citation-link {
    appearance: none;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 0.78em;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.2;
}
.chat-citation-btn:hover,
.chat-citation-link:hover {
    background: var(--surface-2);
}

.excerpt-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.excerpt-modal.is-open { display: flex; }
.excerpt-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(12, 16, 24, 0.72);
    cursor: pointer;
}
.excerpt-modal-panel {
    position: relative;
    z-index: 1;
    width: min(720px, 96vw);
    max-height: 86vh;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.excerpt-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
}
.excerpt-modal-title {
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.4;
}
.excerpt-modal-close {
    border: 0;
    border-radius: 999px;
    padding: 6px 12px;
    background: var(--surface-2);
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
}
.excerpt-modal-body {
    margin: 0;
    padding: 16px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: ui-sans-serif, system-ui, sans-serif;
    font-size: 0.9rem;
    line-height: 1.55;
    color: #222;
}
.excerpt-modal-actions {
    padding: 12px 16px 16px;
    border-top: 1px solid var(--line);
}
.excerpt-pdf-link {
    display: inline-block;
    padding: 8px 14px;
    border-radius: 999px;
    background: #1f4b99;
    color: #fff;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 700;
}
.chat-images {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}
.chat-images-title {
    font-size: 0.78em;
    font-weight: 700;
    color: var(--muted);
    margin-bottom: 10px;
    letter-spacing: 0.02em;
}
.chat-images-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
}
.chat-image-card {
    margin: 0;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
}
.chat-image-card .chat-image-open {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    background: #fff;
    cursor: zoom-in;
}
.chat-image-card img {
    display: block;
    width: 100%;
    max-height: 220px;
    object-fit: contain;
    background: #fff;
}
.chat-image-card figcaption {
    padding: 8px 10px;
    font-size: 0.75em;
    color: var(--muted);
    line-height: 1.35;
    border-top: 1px solid var(--line);
}

/* 이미지 확대 라이트박스 (같은 화면 오버레이) */
.image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.image-lightbox.is-open {
    display: flex;
}
.image-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(12, 16, 24, 0.72);
    cursor: pointer;
}
.image-lightbox-panel {
    position: relative;
    z-index: 1;
    max-width: min(96vw, 1200px);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}
.image-lightbox-close {
    border: 0;
    border-radius: 999px;
    padding: 8px 16px;
    background: #fff;
    color: #111;
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
.image-lightbox-close:hover {
    background: #f3f4f6;
}
.image-lightbox-img {
    display: block;
    max-width: 96vw;
    max-height: calc(92vh - 48px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.chat-input-area {
    flex-shrink: 0;
    padding: 12px clamp(20px, 3vw, 40px) 22px;
    background: transparent;
}
.chat-input-box {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: #fff;
    border: 1px solid var(--line-strong);
    border-radius: 16px;
    padding: 10px 12px 10px 16px;
    box-shadow: var(--shadow-sm);
}
.chat-input-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(46, 108, 164, 0.12);
}
#chat-input,
#writer-chat-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 0.98em;
    line-height: 1.5;
    color: var(--text);
    background: transparent;
    max-height: 160px;
    min-height: 28px;
    padding: 6px 0;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
}
#chat-input:focus,
#writer-chat-input:focus {
    outline: none;
    border: none;
    box-shadow: none;
}
.chat-send-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 12px;
    background: var(--navy);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, opacity 0.15s;
}
.chat-send-btn:hover { background: var(--navy-2); }
.chat-send-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.chat-input-hint {
    margin-top: 8px;
    text-align: center;
    font-size: 0.75em;
    color: var(--muted-2);
}

@media (max-width: 720px) {
    .app-mode-nav { width: 100%; }
    .app-mode-btn { flex: 1; text-align: center; padding: 9px 10px; font-size: 0.86em; }
    .chat-sidebar {
        width: 200px;
    }
    .chat-messages, .chat-input-area { padding-left: 16px; padding-right: 16px; }
    .chat-history-del { opacity: 1; }
}

.admin-button {
    display: inline-flex; align-items: center; gap: 7px;
    background: rgba(255, 255, 255, 0.1); color: #fff;
    padding: 9px 16px; border-radius: var(--radius-sm);
    text-decoration: none; border: 1px solid rgba(255, 255, 255, 0.28);
    transition: background 0.2s, border-color 0.2s; font-weight: 500; font-size: 0.9em;
}
.admin-button:hover { background: rgba(255, 255, 255, 0.2); border-color: rgba(255, 255, 255, 0.5); }

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-chip {
    font-size: 0.86em;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.92);
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-ghost-btn {
    background: transparent;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 8px 12px;
    font-family: inherit;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
}
.header-ghost-btn:hover { background: rgba(255, 255, 255, 0.12); }

.project-menu { position: relative; }
.project-menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 10px;
    padding: 9px 14px;
    font-family: inherit;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    max-width: 260px;
}
.project-menu-btn:hover { background: rgba(255, 255, 255, 0.2); }
.project-menu-btn .caret { opacity: 0.8; font-size: 0.8em; }
#current-project-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.project-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 320px;
    max-height: 420px;
    overflow-y: auto;
    background: #fff;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 14px 36px rgba(23, 42, 69, 0.22);
    z-index: 80;
    padding: 8px;
}
.project-dropdown[hidden] { display: none; }

.dropdown-item {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border: none;
    background: transparent;
    text-align: left;
    padding: 10px 12px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9em;
    color: var(--text);
    cursor: pointer;
}
.dropdown-item:hover { background: var(--accent-soft); }
.dropdown-item.primary {
    font-weight: 700;
    color: var(--navy);
}
.dropdown-item.active {
    background: var(--accent-soft);
    font-weight: 700;
}
.dropdown-divider {
    height: 1px;
    background: var(--line);
    margin: 6px 4px;
}
.dropdown-empty {
    padding: 14px 12px;
    color: var(--muted-2);
    font-size: 0.86em;
    text-align: center;
}
.project-list-item {
    display: flex;
    align-items: stretch;
    gap: 4px;
}
.project-list-item .item-main {
    flex: 1;
    min-width: 0;
}
.project-list-item .item-title {
    font-weight: 600;
    font-size: 0.9em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.project-list-item .item-meta {
    font-size: 0.75em;
    color: var(--muted-2);
    margin-top: 2px;
}
.project-list-item .item-del {
    border: none;
    background: transparent;
    color: #9ca3af;
    border-radius: 8px;
    padding: 0 10px;
    cursor: pointer;
    font-size: 0.85em;
}
.project-list-item .item-del:hover {
    background: #fde8ef;
    color: #b3306e;
}

.save-status {
    font-size: 0.78em;
    color: rgba(255,255,255,0.75);
    min-width: 56px;
}

/* ---------------- 버튼 공통 ---------------- */
.btn-primary, .btn-secondary, .btn-ghost, .ghost-btn {
    font-family: inherit; cursor: pointer; border-radius: 10px;
    font-weight: 600; transition: all 0.15s ease;
}

.btn-primary {
    background: var(--navy); color: #fff; border: 1px solid var(--navy);
    padding: 11px 20px; font-size: 0.95em;
}
.btn-primary:hover:not(:disabled) { background: var(--accent); border-color: var(--accent); box-shadow: 0 6px 16px rgba(46, 108, 164, 0.32); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
    background: #fff; color: var(--navy); border: 1px solid var(--navy);
    padding: 10px 18px; font-size: 0.9em;
}
.btn-secondary:hover:not(:disabled) { background: var(--navy); color: #fff; }
.btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
    background: #fff; color: var(--muted); border: 1px solid var(--line-strong);
    padding: 10px 18px; font-size: 0.9em;
}
.btn-ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn-ghost:disabled { opacity: 0.45; cursor: not-allowed; }

.ghost-btn {
    background: #fff; color: var(--muted); border: 1px dashed var(--line-strong);
    padding: 6px 12px; font-size: 0.82em; font-weight: 500;
}
.ghost-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.ghost-btn[hidden] { display: none; }

.muted { color: var(--muted-2); font-size: 0.88em; }

/* ============================================================
   설정 뷰
   ============================================================ */
.setup-view {
    flex: 1; overflow-y: auto; padding: 36px 24px;
    display: flex; justify-content: center; align-items: flex-start;
    background: var(--surface-2);
}
.setup-view[hidden] { display: none; }

.setup-card {
    background: #fff; width: 100%; max-width: 640px;
    border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); padding: 32px 34px;
}

.setup-card h2 { font-size: 1.4em; color: var(--navy); letter-spacing: -0.01em; }
.setup-desc { color: var(--muted); font-size: 0.92em; margin: 8px 0 24px; line-height: 1.6; }

.form-row { margin-bottom: 22px; display: flex; flex-direction: column; gap: 8px; }
.form-row > label { font-weight: 600; font-size: 0.92em; color: var(--text); }
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.form-hint { color: var(--muted-2); font-size: 0.82em; font-weight: 400; }

.setup-card input[type="text"],
.setup-card input[type="number"],
.setup-card textarea {
    width: 100%; padding: 12px 14px; font-family: inherit; font-size: 0.96em;
    border: 1.5px solid var(--line-strong); border-radius: 10px;
    background: var(--surface-2); color: var(--text); outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.setup-card input:focus, .setup-card textarea:focus {
    border-color: var(--accent); background: #fff;
    box-shadow: 0 0 0 3px rgba(46, 108, 164, 0.14);
}
.setup-card input[type="number"] { max-width: 160px; }
.setup-card textarea { resize: vertical; line-height: 1.7; min-height: 160px; }

.setup-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ============================================================
   빌더 뷰 (탭바 + 패널)
   ============================================================ */
.builder-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.builder-view[hidden] { display: none; }

.tabbar {
    display: flex; gap: 6px; padding: 12px 16px; overflow-x: auto;
    background: var(--surface); border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}
.tabbar::-webkit-scrollbar { height: 6px; }
.tabbar::-webkit-scrollbar-thumb { background: #c4ccd8; border-radius: 4px; }

.tab {
    display: inline-flex; align-items: center; gap: 8px; white-space: nowrap;
    padding: 9px 15px; border: 1px solid var(--line-strong); background: #fff;
    color: var(--muted); border-radius: 9px; font-size: 0.86em; font-weight: 500;
    font-family: inherit; cursor: pointer; transition: all 0.15s ease; flex-shrink: 0;
}
.tab:hover:not(:disabled):not(.active) { border-color: var(--accent); color: var(--accent); }
.tab.active { background: var(--navy); border-color: var(--navy); color: #fff; font-weight: 600; }
.tab:disabled { opacity: 0.55; cursor: not-allowed; }
.tab-settings { color: var(--navy); border-style: dashed; }
.tab-preview { margin-left: 4px; }

.tab-dot { width: 8px; height: 8px; border-radius: 50%; background: #c4ccd8; flex-shrink: 0; }
.tab-dot.done { background: var(--ok); }
.tab-dot.generating { background: var(--warn); animation: pulse 1s ease-in-out infinite; }
.tab.active .tab-dot.empty { background: rgba(255, 255, 255, 0.5); }

@keyframes pulse { 50% { opacity: 0.35; } }

.tab-panel { flex: 1; overflow: hidden; min-height: 0; background: var(--surface-2); }

/* ---------------- 섹션 에디터 ---------------- */
.section-editor { height: 100%; display: flex; flex-direction: column; padding: 18px 20px; gap: 14px; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-shrink: 0; }
.section-index { font-size: 0.78em; font-weight: 700; color: var(--accent); letter-spacing: 0.03em; text-transform: uppercase; }
.section-title-wrap h2 { font-size: 1.3em; color: var(--navy); margin-top: 2px; letter-spacing: -0.01em; }
.section-actions { display: flex; gap: 8px; }

.editor-split { flex: 1; display: flex; gap: 14px; min-height: 0; }
.editor-pane, .preview-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.pane-label { font-size: 0.78em; font-weight: 700; color: var(--muted-2); letter-spacing: 0.03em; text-transform: uppercase; }

.section-textarea {
    flex: 1; width: 100%; resize: none; padding: 16px 18px;
    border: 1.5px solid var(--line-strong); border-radius: 12px;
    font-family: 'SFMono-Regular', 'Noto Sans KR', monospace; font-size: 0.9em; line-height: 1.75;
    background: #fff; color: var(--text); outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
.section-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(46, 108, 164, 0.12); }
.section-textarea[readonly] { background: var(--surface-2); }

.section-preview {
    flex: 1; overflow-y: auto; background: #fff;
    border: 1px solid var(--line); border-radius: 12px;
}

.revise-row { display: flex; gap: 8px; flex-shrink: 0; }
.revise-input {
    flex: 1; padding: 11px 15px; font-family: inherit; font-size: 0.92em;
    border: 1.5px solid var(--line-strong); border-radius: 10px; background: #fff;
    outline: none; transition: border-color 0.2s, box-shadow 0.2s;
}
.revise-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(46, 108, 164, 0.12); }

.section-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-shrink: 0; }

/* ---------------- 최종 미리보기 ---------------- */
.final-preview { height: 100%; display: flex; flex-direction: column; padding: 18px 20px; gap: 14px; }
.final-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-shrink: 0; }
.final-head h2 { font-size: 1.3em; color: var(--navy); }
.final-scroll { flex: 1; overflow-y: auto; background: #dfe3ea; border-radius: 12px; padding: 20px; min-height: 0; }
.final-doc { margin: 0 auto; max-width: 800px; }

/* ============================================================
   문서 페이지 (미리보기 공통) - docx/PDF 디자인과 통일
   ============================================================ */
.doc-page {
    background: #fff; padding: 40px 42px; font-size: 14px; line-height: 1.75; color: #222;
}
.section-preview.doc-page { border-radius: 12px; }
.final-doc.doc-page { box-shadow: 0 4px 18px rgba(23, 42, 69, 0.16); border-radius: 2px; }

.doc-page h1 { font-size: 20px; color: #1F4E79; border-bottom: 2px solid #1F4E79; padding-bottom: 6px; margin: 22px 0 10px; }
.doc-page h1:first-child, .doc-page h2:first-child, .doc-page h3:first-child { margin-top: 0; }
.doc-page h2 { font-size: 16px; color: #1F4E79; border-left: 5px solid #2E6CA4; padding-left: 10px; margin: 20px 0 8px; }
.doc-page h3 { font-size: 14px; color: #2E6CA4; margin: 16px 0 6px; }
.doc-page p { margin: 8px 0; text-align: justify; }
.doc-page ul, .doc-page ol { margin: 8px 0 8px 6px; padding-left: 22px; }
.doc-page li { margin: 4px 0; }
.doc-page table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13px; }
.doc-page th { background: #1F4E79; color: #fff; padding: 7px 8px; border: 1px solid #1F4E79; text-align: center; }
.doc-page td { border: 1px solid #c9d2dc; padding: 6px 8px; }
.doc-page tbody tr:nth-child(even) { background: #f4f7fb; }
.doc-page strong { font-weight: 700; }
.doc-page code { background: #f2f4f7; padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.doc-page blockquote { border-left: 4px solid #2E6CA4; background: #eaf1f8; padding: 8px 14px; border-radius: 0 8px 8px 0; margin: 10px 0; color: #3d566e; }
.doc-page .muted { color: var(--muted-2); }

/* ---------------- Loading ---------------- */
.loading {
    position: fixed; inset: 0; background: rgba(16, 25, 40, 0.55); backdrop-filter: blur(2px);
    display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 1000; color: #fff;
}
.spinner {
    width: 46px; height: 46px; border: 3px solid rgba(255, 255, 255, 0.25); border-top: 3px solid #fff;
    border-radius: 50%; animation: spin 0.9s linear infinite; margin-bottom: 18px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading p { font-size: 1em; font-weight: 500; }

/* ---------------- Scrollbar ---------------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c4ccd8; border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #a9b3c2; background-clip: padding-box; }

/* ---------------- Responsive ---------------- */
@media (max-width: 900px) {
    body { padding: 0; }
    .container { height: 100vh; border-radius: 0; border: none; }
    header { padding: 16px 18px; }
    .admin-button span { display: none; }
    .editor-split { flex-direction: column; }
    .section-editor, .final-preview { padding: 14px; }
}
