/* member/css/messages.css - 쪽지 사이트 (member/messages.html, js/messages-site.js)
   신학원 쪽지함(pastor/messages.html)과 같은 디자인 - 아래 "신학원 쪽지함" 부분은 pastor/css/messages.css 를 그대로 옮겨 온 것
   좌측: 대화상대 목록 / 우측: 선택한 상대와 주고받은 쪽지(메일함처럼) → 누르면 메일 보기 + 답장, "+" = 새 쪽지 */

/* 신학원 css 이름 → 같은 색 (pastor/css/common.css 와 같은 값) */
:root {
    --primary-color: var(--brand-600);
    --error-color: #ef4444;
    --text-primary: var(--ink);
    --text-secondary: var(--ink-muted);
    --border-color: var(--line);
    --bg-light: var(--brand-50);
    --bg-white: #ffffff;
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Noto Sans KR', system-ui, sans-serif; color: var(--ink); }
[hidden] { display: none !important; }

/* 위쪽 바 = 행정 네트워크와 같은 흰 바 (도구 묶음 shared/site-header.js 가 .net-top-right 에 붙는다) */
.net-top { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 24px; }
.net-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.net-brand img { width: 38px; height: 38px; object-fit: contain; }
.net-brand span { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.net-brand small { font-size: 12px; }
.net-brand b { font-size: 19px; font-weight: 900; letter-spacing: -0.3px; }
.net-top-right { display: flex; align-items: center; gap: 12px; }

/* 본문 · 제목 띠 (신학원 .course-container / .course-header 와 같은 모양) */
.course-container { max-width: 1400px; margin: 0 auto; padding: 32px 24px 48px; }
.course-header {
    position: relative; overflow: hidden; padding: 40px 32px 36px; margin-bottom: 28px; border-radius: var(--radius-lg, 10px);
    color: #fff; text-align: center;
    background: radial-gradient(ellipse at 15% 0%, rgba(255, 255, 255, 0.28), transparent 55%),
        radial-gradient(ellipse at 90% 100%, rgba(201, 162, 39, 0.55), transparent 60%), var(--brand-gradient-deep, var(--brand-gradient));
    box-shadow: 0 14px 34px -14px rgba(22, 56, 41, 0.45);
}
.course-header h1 { margin: 0; color: #fff; font-size: 30px; font-weight: 900; letter-spacing: -0.5px; text-shadow: 0 2px 14px rgba(22, 56, 41, 0.35); }
.course-header p { margin: 8px 0 0; color: rgba(255, 255, 255, 0.92); font-size: 15px; font-weight: 600; }

/* 신학원 공용 조각 (pastor/css/common.css) */
.user-avatar {
    flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%; background: var(--brand-gradient); background-size: cover; background-position: center;
    display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 15px;
}
.message-badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: #d64545; color: #fff; font-size: 12px; font-weight: 800; }
.btn-cancel { padding: 12px 24px; background: var(--bg-light); color: var(--text-primary); border: 2px solid var(--border-color); border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; }
.btn-cancel:hover { border-color: var(--text-secondary); }
/* 이전 쪽지 더 보기 (왼쪽 대화 목록 맨 아래) */
.msg-more { display: block; width: calc(100% - 32px); margin: 14px 16px; padding: 12px 16px; background: var(--bg-light); color: var(--primary-color); border: 2px solid var(--border-color); border-radius: 10px; font: inherit; font-size: 15px; font-weight: 700; cursor: pointer; }
.msg-more:hover:not(:disabled) { border-color: var(--primary-color); }
.msg-more:disabled { opacity: .6; cursor: default; }
.msg-gate { max-width: 560px; margin: 40px auto; padding: 32px 24px; border-radius: 10px; background: #fff; box-shadow: var(--shadow-md); text-align: center; }
.msg-gate p { margin: 0 0 16px; font-size: 16px; line-height: 1.6; }
.msg-gate a { display: inline-block; padding: 11px 26px; border-radius: 999px; background: var(--brand-gradient); color: #fff; font-weight: 700; text-decoration: none; }
.msg-toast { position: fixed; left: 50%; bottom: 28px; z-index: 50; transform: translateX(-50%); padding: 12px 20px; border-radius: 999px; background: #121a17; color: #fff; font-size: 14px; font-weight: 700; box-shadow: var(--shadow-lg); }
.msg-toast.is-error { background: #b42318; }
.compose-file-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.compose-file-row .reply-attach { margin-right: 0; }
.message-view-file .msg-pdf { display: block; max-width: 100%; }

/* ══════════════ 신학원 쪽지함 (pastor/css/messages.css 그대로) ══════════════ */
body {
    background: var(--bg-light);
}

/* 화면 높이를 꽉 채운다 - 오른쪽(읽기·쓰기)이 메일 앱처럼 빈 공간 없이 펼쳐짐 */
.messages-layout {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 0;
    background: var(--bg-white);
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    height: calc(100vh - 220px);
    min-height: 560px;
}

/* ── 좌측: 대화상대 목록 ── */
.conversation-list-panel {
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.conversation-list-panel .panel-header {
    display: flex;
    justify-content: flex-end;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.conversation-list {
    overflow-y: auto;
    flex: 1;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s;
}

.conversation-item:hover {
    background: var(--bg-light);
}

.conversation-item.active {
    background: #e9f0e9;
}

.conversation-info {
    flex: 1;
    min-width: 0;
}

.conversation-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.conversation-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    flex-shrink: 0;
}

.conversation-date {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ── 우측: 선택된 상대와의 쪽지 목록 ── */
.thread-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

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

.thread-partner-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.thread-partner-name {
    font-weight: 700;
    font-size: 16px;
    color: var(--text-primary);
}

.btn-icon {
    background: var(--bg-light);
    border: none;
    border-radius: 8px;
    width: 36px;
    height: 36px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s;
}

.btn-icon:hover {
    background: var(--border-color);
}

.thread-message-list {
    overflow-y: auto;
    flex: 1;
}

.thread-message-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s;
}

.thread-message-item:hover,
.thread-message-item:focus-visible {
    background: var(--bg-light);
    outline: none;
}

.thread-message-item.unread {
    background: #e9f0e9;
}

.thread-message-item.unread .thread-message-subject {
    font-weight: 700;
}

.thread-direction {
    flex-shrink: 0;
    min-width: 46px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
}

.thread-direction.received { background: var(--brand-100); color: var(--brand-700); }
.thread-direction.sent { background: var(--bg-light); color: var(--text-secondary); }

.thread-message-body {
    flex: 1;
    min-width: 0;
}

.thread-message-subject {
    font-size: 14px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.thread-message-preview {
    margin-top: 2px;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── 쪽지 읽기 (메일 보기) ── */
.message-view {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.message-view[hidden] { display: none; }

.message-view-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
}

.btn-back,
.btn-delete-text {
    border: none;
    background: none;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
}

.btn-back { color: var(--brand-700); }
.btn-back:hover { background: var(--brand-100); }
.btn-delete-text { color: var(--error-color); }
.btn-delete-text:hover { background: #fdecec; }

.message-view-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 28px 32px;
}

.message-view-subject {
    margin: 0 0 18px;
    font-size: 22px;
    font-weight: 800;
    line-height: 1.35;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

.message-view-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 18px;
    margin-bottom: 22px;
    border-bottom: 1px solid var(--border-color);
}

.message-view-people {
    flex: 1;
    min-width: 0;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.7;
}

.meta-label {
    display: inline-block;
    min-width: 72px;
    color: var(--text-secondary);
    font-size: 13px;
}

.message-view-date {
    flex-shrink: 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.message-view-content {
    font-size: 15px;
    line-height: 1.8;
    color: var(--text-primary);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* 아래 답장 */
.reply-box {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border-color);
    background: #fefdfb;
}

.reply-note {
    margin: 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.reply-textarea {
    resize: vertical;
    min-height: 96px;
    line-height: 1.6;
}

.reply-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
}

/* 쪽지 첨부 파일 (41번 SQL) */
.reply-attach {
    margin-right: auto; padding: 7px 14px; border: 1px dashed var(--brand-200, #d9e6dc); border-radius: 999px;
    background: #fff; color: var(--brand-700, #1a4432); font: inherit; font-size: 13.5px; font-weight: 700; cursor: pointer;
}
.reply-attach[hidden] { display: none; }
.reply-actions { flex-wrap: wrap; }
.reply-file-list { list-style: none; margin: 0 auto 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.reply-file-list:empty { display: none; }
.reply-file-list li { display: inline-flex; align-items: center; gap: 6px; max-width: 240px; padding: 3px 4px 3px 10px; border-radius: 999px; background: var(--brand-50, #f6f3ea); border: 1px solid var(--border-color, #e7eee7); font-size: 12.5px; }
.reply-file-list span { min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-file-list small { color: var(--text-secondary, #64748b); white-space: nowrap; }
.reply-file-list .reply-file-x { width: 20px; height: 20px; font-size: 13px; flex-shrink: 0; }
.reply-file-x { width: 26px; height: 26px; border: none; border-radius: 50%; background: #fdecec; color: #d64545; font-size: 16px; cursor: pointer; }
.message-view-file { display: grid; gap: 10px; justify-items: start; margin-top: 18px; }
.message-view-file[hidden] { display: none; }
.message-file-img { display: block; max-width: 100%; max-height: 360px; border-radius: 8px; border: 1px solid var(--border-color, #e7eee7); }
.message-view-file audio { width: 100%; max-width: 480px; }
.message-file-card {
    display: inline-flex; align-items: center; gap: 8px; width: fit-content; max-width: 100%; padding: 10px 14px;
    border: 1px solid var(--border-color, #e7eee7); border-radius: 8px; background: var(--brand-50, #f6f3ea);
    color: var(--brand-700, #1a4432); font-weight: 700; text-decoration: none;
}
.message-file-card span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-file-card small { font-weight: 500; color: var(--text-secondary, #64748b); }

.reply-actions .compose-send-btn {
    flex: 0 0 auto;
    padding: 11px 28px;
}

.reply-actions .compose-send-btn:disabled { opacity: 0.6; cursor: wait; transform: none; }

.thread-message-date {
    font-size: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.messages-layout .empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}

/* ══════════════════════════════════════════════
   새 쪽지 작성 패널 - 나머지 사이트와는 살짝 다른, 좀 더 모던한 톤
   ══════════════════════════════════════════════ */
.compose-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    background: var(--bg-white);
}

.compose-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px;
    background: var(--primary-color);
    color: white;
}

.compose-header .btn-icon {
    background: rgba(255, 255, 255, 0.18);
    color: white;
}

.compose-header .btn-icon:hover {
    background: rgba(255, 255, 255, 0.3);
}

.compose-header-title {
    font-size: 16px;
    font-weight: 700;
}

.thread-header-spacer {
    width: 36px;
    flex-shrink: 0;
}

.compose-form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.compose-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.compose-field-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.compose-field-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.compose-input {
    padding: 13px 16px;
    border: none;
    background: var(--bg-light);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text-primary);
    transition: box-shadow 0.15s, background 0.15s;
}

.compose-input:focus {
    outline: none;
    background: var(--bg-white);
    box-shadow: 0 0 0 2px var(--primary-color);
}

.compose-content-group {
    flex: 1;
    min-height: 0;
}

/* 내용 칸이 남은 공간을 모두 채운다 */
.compose-textarea {
    flex: 1;
    resize: none;
    min-height: 220px;
    line-height: 1.7;
    font-size: 15px;
}

.compose-recipient-static {
    display: flex;
    align-items: center;
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-light);
    border-radius: 8px;
    padding: 12px 16px;
}

/* ── 받는 사람 검색 (이름/직분/아이디) ── */
.recipient-picker {
    position: relative;
}

.recipient-search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-light);
    border-radius: 8px;
    padding: 0 16px;
    transition: box-shadow 0.15s, background 0.15s;
}

.recipient-search-box:focus-within {
    background: var(--bg-white);
    box-shadow: 0 0 0 2px var(--primary-color);
}

.recipient-search-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 13px 0;
    font-size: 14px;
    font-family: inherit;
    color: var(--text-primary);
}

.recipient-search-input:focus {
    outline: none;
}

.recipient-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    max-height: 280px;
    overflow-y: auto;
    background: var(--bg-white);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    z-index: 20;
    padding: 6px;
}

.recipient-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.12s;
}

.recipient-result-item:hover {
    background: var(--bg-light);
}

.recipient-result-info {
    min-width: 0;
    flex: 1;
}

.recipient-result-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.recipient-result-username {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 1px;
}

.recipient-empty {
    padding: 16px;
    text-align: center;
    font-size: 13px;
    color: var(--text-secondary);
}

/* ── 받는 사람 선택 완료 상태 ── */
.recipient-selected {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-light);
    border-radius: 8px;
    padding: 10px 14px;
}

.recipient-selected-info {
    min-width: 0;
    flex: 1;
}

.recipient-selected-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.recipient-selected-username {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 1px;
}

.recipient-change-btn {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--primary-color);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
}

.recipient-change-btn:hover {
    background: var(--border-color);
}

/* ── 하단 액션 ── */
.compose-actions {
    display: flex;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

.compose-actions .btn-cancel {
    flex-shrink: 0;
}

.compose-send-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 999px;
    background: var(--primary-color);
    color: white;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.compose-send-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(31, 77, 58, 0.4);
}

/* ── 반응형 (사이트 공용 기준: 1024px / 600px) ── */
@media (max-width: 1024px) {
    .messages-layout {
        grid-template-columns: 260px 1fr;
    }
}

