* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: #f4f5f7;
  color: #1f2328;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 24px; background: #1f2937; color: white;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.badge {
  font-size: 12px; padding: 4px 10px; border-radius: 12px; background: #374151;
}
button {
  cursor: pointer; border: none; border-radius: 6px; padding: 8px 14px;
  background: #2563eb; color: white; font-size: 13px;
}
button:hover { background: #1d4ed8; }
button.danger { background: #dc2626; }
button.danger:hover { background: #b91c1c; }

.tabs {
  display: flex; gap: 4px; padding: 10px 24px 0; background: white;
  border-bottom: 1px solid #e5e7eb;
}
.tab-btn {
  background: transparent; color: #6b7280; padding: 10px 16px;
  border-radius: 6px 6px 0 0; font-weight: 600;
}
.tab-btn.active { color: #2563eb; border-bottom: 2px solid #2563eb; background: #eff6ff; }

main { padding: 20px 24px; }
.tab-content { display: none; }
.tab-content.active { display: block; }

.hint { color: #9ca3af; font-size: 13px; }

.layout { display: flex; gap: 16px; }
.sidebar {
  width: 220px; background: white; border-radius: 8px; padding: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,.05); height: fit-content;
}
.cat-item {
  display: flex; justify-content: space-between; padding: 8px 10px;
  border-radius: 6px; cursor: pointer; font-size: 14px; margin-bottom: 2px;
}
.cat-item:hover, .cat-item.active { background: #eff6ff; color: #1d4ed8; }
.cat-actions { display: flex; align-items: center; gap: 4px; }
.cat-count {
  background: #e5e7eb; color: #374151; border-radius: 10px;
  padding: 1px 8px; font-size: 12px;
}
.cat-del-btn, .cat-rename-btn {
  background: transparent; color: #9ca3af; padding: 0 4px; font-size: 14px;
  border-radius: 4px; line-height: 1.4;
}
.cat-del-btn:hover { background: #fee2e2; color: #dc2626; }
.cat-rename-btn:hover { background: #dbeafe; color: #1d4ed8; }
.cat-item.cat-drop-hover { background: #dbeafe; outline: 2px dashed #2563eb; outline-offset: -2px; }
.add-folder-btn {
  width: 100%; background: white; color: #2563eb; border: 1px dashed #93c5fd;
  margin-bottom: 8px; font-size: 13px;
}
.add-folder-btn:hover { background: #eff6ff; }

.tag-btn[draggable="true"] { cursor: grab; }
.tag-btn[draggable="true"]:active { cursor: grabbing; }

.folder-suggest-panel {
  background: white; border-radius: 8px; padding: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.05);
  margin-bottom: 14px; display: flex; flex-direction: column; gap: 10px;
}
.folder-suggest-item { border: 1px solid #e5e7eb; border-radius: 6px; padding: 10px; font-size: 13px; }
.folder-suggest-item .acceptSuggestBtn, .folder-suggest-item button { margin-top: 6px; }

.email-list { flex: 1; background: white; border-radius: 8px; padding: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.email-item { padding: 12px; border-bottom: 1px solid #f1f1f1; position: relative; }
.email-delete-btn { position: absolute; top: 8px; right: 8px; background: none; border: none;
  font-size: 14px; cursor: pointer; opacity: 0.45; padding: 2px 6px; }
.email-delete-btn:hover { opacity: 1; }
.source-badge { font-size: 12px; color: #4b5563; white-space: nowrap; }
.email-item:last-child { border-bottom: none; }
.email-item .subject { font-weight: 600; font-size: 14px; }
.email-item .meta { font-size: 12px; color: #9ca3af; margin: 2px 0; }
.email-item .snippet { font-size: 13px; color: #4b5563; }
.email-item-clickable { cursor: pointer; border-radius: 6px; }
.email-item-clickable:hover { background: #f9fafb; }
.email-item-hint { font-size: 11px; color: #9ca3af; margin-top: 6px; }

.digest-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.digest-card { background: white; border-radius: 8px; padding: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.05); border: 1px solid transparent; }
.digest-card.digest-card-urgent { border-color: #f59e0b; }
.digest-card h3 { margin: 0 0 8px; font-size: 15px; }
.digest-card pre { white-space: pre-wrap; font-family: inherit; font-size: 13px; color: #374151; margin: 0; }
.digest-urgent-badge { font-size: 12px; font-weight: 600; color: #dc2626; }

.ai-template-panel {
  background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 8px; padding: 12px;
  margin-bottom: 14px; display: flex; flex-direction: column; gap: 8px;
}
.ai-template-panel input, .ai-template-panel textarea {
  padding: 8px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 13px; width: 100%;
}

.field-chip-bar { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 12px; }
.field-chip {
  display: inline-flex; align-items: center; background: #eff6ff; color: #1d4ed8;
  border: 1px solid #bfdbfe; border-radius: 14px; padding: 4px 10px; font-size: 12px;
  cursor: grab; user-select: none;
}
.field-chip:hover { background: #dbeafe; }
.field-chip:active { cursor: grabbing; }

.mailmerge-grid { display: flex; gap: 20px; }
#mmForm { flex: 1; background: white; padding: 16px; border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
#mmForm label { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 600; color: #374151; }
#mmForm input, #mmForm textarea, #mmForm select {
  width: 100%; margin-top: 4px; padding: 8px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 13px;
}
.mm-actions { display: flex; gap: 8px; }
.mm-result { flex: 1; background: white; padding: 16px; border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.05); overflow-y: auto; max-height: 600px; }
.mm-preview-item { border: 1px solid #e5e7eb; border-radius: 6px; padding: 10px; margin-bottom: 10px; font-size: 13px; }
.mm-preview-item .to { color: #2563eb; font-weight: 600; }

.mm-recipient-list-wrap { margin-bottom: 16px; }
.mm-recipient-list-label, .mm-preview-label { font-size: 12px; font-weight: 600; color: #6b7280; margin-bottom: 6px; }
.mm-recipient-list { max-height: 180px; overflow-y: auto; border: 1px solid #e5e7eb; border-radius: 6px; }
.mm-recipient-row { display: flex; justify-content: space-between; gap: 10px; padding: 5px 10px; font-size: 12px; border-bottom: 1px solid #f1f1f1; }
.mm-recipient-row:last-child { border-bottom: none; }
.mm-recipient-row-invalid { background: #fef2f2; color: #dc2626; }
.result-row { font-size: 13px; padding: 4px 0; border-bottom: 1px solid #f1f1f1; }
.result-row.sent { color: #059669; }
.result-row.failed { color: #dc2626; }

.mm-result-col { flex: 1; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.mm-live-preview {
  background: white; border-radius: 8px; padding: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.mm-live-preview-label { font-size: 12px; font-weight: 600; color: #6b7280; margin-bottom: 8px; }
.mm-live-preview .mm-preview-item { margin-bottom: 0; }
.mm-preview-item .subject { font-weight: 600; margin: 4px 0; }
.mm-preview-item .body { color: #374151; white-space: pre-wrap; }
.mm-result-col .mm-result { max-height: 420px; }

.mm-autocomplete {
  position: fixed; background: white; border: 1px solid #d1d5db; border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15); z-index: 1200; max-height: 180px; overflow-y: auto; display: none;
}
.mm-autocomplete-item { padding: 6px 10px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.mm-autocomplete-item.active, .mm-autocomplete-item:hover { background: #eff6ff; color: #1d4ed8; }

.mini-badge {
  display: inline-block; min-width: 16px; padding: 0 5px; border-radius: 10px;
  background: #dc2626; color: white; font-size: 11px; margin-left: 4px;
}

.ct-custom-field-row { display: flex; gap: 6px; align-items: center; }
.ct-custom-field-row input { flex: 1; min-width: 0; }
.ct-custom-field-row .ctRemoveFieldBtn { flex: none; padding: 6px 9px; }
.ct-custom-badge {
  display: inline-block; background: #eff6ff; color: #1d4ed8; border-radius: 5px;
  padding: 1px 6px; font-size: 11px; margin: 1px 3px 1px 0;
}

.tag-toggle { display: flex; gap: 8px; margin-bottom: 14px; align-items: center; }
.tag-btn { background: white; color: #374151; border: 1px solid #d1d5db; }
.tag-btn.active { background: #1d4ed8; color: white; border-color: #1d4ed8; }

.approval-list { display: flex; flex-direction: column; gap: 12px; }
.approval-item { background: white; border-radius: 8px; padding: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.approval-item .meta { font-size: 12px; color: #9ca3af; margin-bottom: 4px; }
.approval-item .body-preview { font-size: 13px; color: #374151; margin: 6px 0; white-space: pre-wrap; }
.ai-source-badge { display: inline-block; background: #ede9fe; color: #6d28d9; border-radius: 4px; padding: 1px 6px; font-size: 11px; font-weight: 600; }
.priority-badge { display: inline-block; background: #fef2f2; color: #b91c1c; border-radius: 4px; padding: 1px 6px; font-size: 12px; font-weight: 600; }
.link-preview-item { border: 1px solid #e5e7eb; border-radius: 6px; padding: 8px 10px; margin-bottom: 6px; font-size: 12px; word-break: break-all; }
.link-preview-item.suspicious { border-color: #fca5a5; background: #fef2f2; }

.rules-grid { display: flex; flex-direction: column; gap: 28px; }
.rule-block { background: white; border-radius: 8px; padding: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.rule-block h2 { margin: 0 0 4px; font-size: 16px; }

.rule-table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13px; }
.rule-table th { text-align: left; color: #6b7280; padding: 6px 8px; border-bottom: 1px solid #e5e7eb; }
.rule-table td { padding: 8px; border-bottom: 1px solid #f1f1f1; }

.rule-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.rule-form input, .rule-form select, .rule-form textarea {
  padding: 7px 9px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 13px;
}
.rule-form textarea { width: 100%; }
.rule-form .inline-check { font-size: 13px; display: flex; align-items: center; gap: 4px; }

.account-form { flex-direction: column; align-items: stretch; max-width: 420px; }
.account-form input, .account-form select { width: 100%; }
#imapFields { display: flex; flex-direction: column; gap: 8px; }

#settingsForm label { display: flex; align-items: center; gap: 8px; font-size: 13px; }
#settingsForm input { width: 90px; }

.sender-form { max-width: 480px; }
.sender-form .slValue { flex: 1; min-width: 200px; }

.stat-summary { display: flex; gap: 14px; margin-bottom: 18px; }
.stat-tile { background: white; border-radius: 8px; padding: 16px 24px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.stat-num { font-size: 28px; font-weight: 700; color: #1d4ed8; }
.stat-label { font-size: 12px; color: #6b7280; margin-top: 2px; }

.stat-bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.stat-bar-label { width: 120px; flex-shrink: 0; }
.stat-bar-track { flex: 1; background: #f1f1f1; border-radius: 4px; height: 12px; overflow: hidden; }
.stat-bar-fill { background: #2563eb; height: 100%; }
.stat-bar-count { width: 36px; text-align: right; color: #6b7280; }

/* ---------- 로그인/설정 화면 ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #f4f5f7; }
.auth-card {
  background: white; padding: 32px; border-radius: 12px; width: 340px;
  box-shadow: 0 4px 12px rgba(0,0,0,.08); display: flex; flex-direction: column; gap: 12px;
}
.auth-card h1 { font-size: 18px; margin: 0 0 4px; }
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: #374151; }
.auth-card input {
  padding: 9px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px; font-weight: 400;
}
.auth-card button { margin-top: 6px; padding: 10px; font-size: 14px; }
.auth-error { color: #dc2626; font-size: 13px; background: #fef2f2; padding: 8px; border-radius: 6px; }
.auth-slack-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 14px;
  font-weight: 600; color: #1f2937; background: #fff; text-decoration: none;
}
.auth-slack-btn:hover { background: #f9fafb; }
.auth-divider { display: flex; align-items: center; gap: 8px; color: #9ca3af; font-size: 12px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: #e5e7eb; }
body.dark-mode .auth-slack-btn { background: #111827; border-color: #374151; color: #e5e7eb; }
body.dark-mode .auth-slack-btn:hover { background: #1f2937; }

/* ---------- AI 비서: 채널톡 스타일 플로팅 챗봇 ---------- */
.assistant-fab {
  position: fixed; right: 24px; bottom: 24px; width: 56px; height: 56px;
  border-radius: 50%; background: #2563eb; color: white; font-size: 24px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,.25); z-index: 1000; padding: 0;
}
.assistant-fab:hover { background: #1d4ed8; }
.assistant-fab.assistant-fab-active { background: #374151; }

.assistant-panel {
  position: fixed; right: 24px; bottom: 92px; width: 360px; max-width: calc(100vw - 32px);
  height: 520px; max-height: calc(100vh - 140px);
  background: white; border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.2);
  z-index: 1000; flex-direction: column; overflow: hidden;
}
.assistant-panel-header {
  background: #1f2937; color: white; padding: 12px 14px; font-weight: 600; font-size: 14px;
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.assistant-panel-close { background: transparent; padding: 2px 6px; font-size: 14px; }
.assistant-panel-close:hover { background: #4b5563; }
.assistant-panel-hint { padding: 10px 14px 0; margin: 0; flex-shrink: 0; }

.assistant-chat {
  flex: 1; overflow-y: auto; padding: 12px 14px;
}
.assistant-turn { padding: 8px 10px; border-radius: 8px; margin-bottom: 8px; font-size: 13px; line-height: 1.5; }
.assistant-turn b { margin-right: 6px; }
.assistant-turn.assistant-user { background: #eff6ff; color: #1d4ed8; }
.assistant-turn.assistant-ai { background: #f9fafb; color: #1f2328; }
.assistant-matches { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.assistant-match { border-left: 3px solid #2563eb; padding: 4px 8px; background: white; border-radius: 4px; }
.assistant-match .subject { font-weight: 600; font-size: 12px; }
.assistant-match .meta { font-size: 11px; color: #9ca3af; }
.assistant-form { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid #f1f1f1; flex-shrink: 0; }
.assistant-form input { flex: 1; padding: 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 13px; }

.user-menu { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #e5e7eb; }
.user-menu button { background: #4b5563; }
.user-menu button:hover { background: #374151; }
.admin-badge { background: #7c3aed; padding: 2px 8px; border-radius: 10px; font-size: 11px; }

/* 새 메일 작성 / 메일 원본 보기 공용 모달 */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(17,24,39,.5);
  display: flex; align-items: center; justify-content: center; z-index: 1300;
}
.modal-box {
  background: white; border-radius: 12px; width: 560px; max-width: calc(100vw - 32px);
  max-height: calc(100vh - 80px); display: flex; flex-direction: column;
  box-shadow: 0 12px 32px rgba(0,0,0,.25); overflow: hidden;
}
.modal-header {
  background: #1f2937; color: white; padding: 12px 16px; font-weight: 600; font-size: 15px;
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.modal-box .rule-form { padding: 16px; margin: 0; }
.modal-box .rule-form select, .modal-box .rule-form input, .modal-box .rule-form textarea { width: 100%; }
#mailViewContent { padding: 16px; overflow-y: auto; }
#mailViewContent .mv-meta { font-size: 12px; color: #6b7280; margin-bottom: 4px; }
#mailViewContent .mv-subject { font-size: 16px; font-weight: 700; margin-bottom: 10px; }
#mailViewContent .mv-body { border-top: 1px solid #e5e7eb; padding-top: 10px; margin-top: 10px; font-size: 13px; }
#mailViewContent .mv-attachments { margin-top: 14px; padding-top: 10px; border-top: 1px solid #e5e7eb; }
#mailViewContent .mv-attachment-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 13px; }

/* 예약 발송 / 발송 취소(Undo Send) 배너 */
.compose-undo-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: #fffbeb; border: 1px solid #fbbf24; color: #92400e;
  padding: 8px 12px; border-radius: 8px; font-size: 13px; margin-top: 4px;
}
.compose-undo-banner button { background: #b45309; }
.compose-undo-banner button:hover { background: #92400e; }

/* 메일 본문 툴바 (이미지 삽입 / 미리보기) - 1:1 작성 & 메일머지 공용 */
.body-toolbar { display: flex; gap: 6px; margin-top: 4px; }
.body-toolbar button { background: #0891b2; font-size: 12px; padding: 6px 10px; }
.body-toolbar button:hover { background: #0e7490; }
.body-preview {
  border: 1px solid #e5e7eb; border-radius: 8px; padding: 8px; margin-top: 4px; background: #fafafa;
}

/* 메일머지 AI 점검 결과 */
.mm-ai-review {
  margin-top: 10px; padding: 10px 12px; background: #f5f3ff; border: 1px solid #c4b5fd;
  border-radius: 8px; font-size: 13px; line-height: 1.6; color: #4c1d95; white-space: pre-wrap;
}

/* 오늘의 일정 위젯 (받은편지함 상단) */
.today-events-widget {
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 8px;
  padding: 8px 12px; margin-bottom: 10px; font-size: 13px; color: #1d4ed8;
}
.today-event-chip {
  display: inline-block; background: white; border: 1px solid #bfdbfe; border-radius: 12px;
  padding: 2px 10px; margin: 2px 6px 2px 0; font-size: 12px;
}

/* 메일 원본 보기: AI 일정 추출 + 개인 메모 */
.mv-ai-event, .mv-notes { border-top: 1px solid #e5e7eb; margin-top: 14px; padding-top: 10px; }
.mv-ai-event-suggestion {
  margin-top: 8px; padding: 8px 10px; background: #f0fdf4; border: 1px solid #86efac;
  border-radius: 8px; font-size: 13px;
}
.mv-ai-event-suggestion button { margin-top: 6px; }
.mv-note-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 6px 0; border-bottom: 1px solid #f1f1f1; font-size: 13px;
}
.mv-ai-toolbar { border-top: 1px solid #e5e7eb; margin-top: 14px; padding-top: 10px; }
.mv-ai-btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.mv-ai-btns button { background: #7c3aed; font-size: 12px; padding: 6px 10px; }
.mv-ai-btns button:hover { background: #6d28d9; }
.mv-ai-result {
  margin-top: 8px; padding: 8px 10px; background: #f5f3ff; border: 1px solid #c4b5fd;
  border-radius: 8px; font-size: 13px; line-height: 1.6; color: #4c1d95;
}
.mv-attachment-summary { font-size: 12px; color: #4c1d95; padding: 2px 0 8px; }
.aiAttachmentSummaryBtn { background: #7c3aed; font-size: 11px; padding: 4px 8px; }
.aiAttachmentSummaryBtn:hover { background: #6d28d9; }

/* 사내 메신저 */
.im-layout { display: flex; gap: 14px; height: 560px; }
.im-sidebar { width: 220px; flex: none; display: flex; flex-direction: column; background: white; border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.05); overflow: hidden; }
.im-sidebar-header { padding: 10px; border-bottom: 1px solid #e5e7eb; }
.im-sidebar-header select { width: 100%; padding: 6px 8px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 13px; }
.im-conversation-list { flex: 1; overflow-y: auto; }
.im-conv-item { padding: 10px 12px; border-bottom: 1px solid #f1f1f1; cursor: pointer; }
.im-conv-item:hover { background: #f9fafb; }
.im-conv-item.active { background: #eff6ff; }
.im-conv-name { font-weight: 600; font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.im-conv-preview { font-size: 12px; color: #9ca3af; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.im-chat { flex: 1; display: flex; flex-direction: column; background: white; border-radius: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.05); overflow: hidden; min-width: 0; }
.im-chat-header { padding: 12px 14px; border-bottom: 1px solid #e5e7eb; font-weight: 600; font-size: 14px; }
.im-chat-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.im-msg { max-width: 70%; padding: 8px 12px; border-radius: 12px; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.im-msg-mine { align-self: flex-end; background: #1d4ed8; color: white; border-bottom-right-radius: 3px; }
.im-msg-theirs { align-self: flex-start; background: #f1f1f1; color: #111827; border-bottom-left-radius: 3px; }
.im-msg-time { font-size: 10px; opacity: .7; margin-top: 3px; }
.im-chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #e5e7eb; }
.im-chat-form textarea { flex: 1; resize: none; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px; font-size: 13px; font-family: inherit; }

/* 다크모드 */
body.dark-mode { background: #111827; color: #e5e7eb; }
body.dark-mode .sidebar, body.dark-mode .email-list, body.dark-mode .mailmerge-grid form,
body.dark-mode .mm-result, body.dark-mode .mm-live-preview, body.dark-mode .modal-box,
body.dark-mode .digest-grid .digest-card, body.dark-mode .rule-block,
body.dark-mode .today-events-widget, body.dark-mode .body-preview,
body.dark-mode .im-sidebar, body.dark-mode .im-chat {
  background: #1f2937; color: #e5e7eb; border-color: #374151;
}
body.dark-mode .im-sidebar-header, body.dark-mode .im-chat-header, body.dark-mode .im-chat-form { border-color: #374151; }
body.dark-mode .im-conv-item { border-color: #374151; }
body.dark-mode .im-conv-item:hover { background: #111827; }
body.dark-mode .im-conv-item.active { background: #1e3a5f; }
body.dark-mode .im-msg-theirs { background: #374151; color: #e5e7eb; }
body.dark-mode .auth-wrap { background: #111827; }
body.dark-mode .auth-card { background: #1f2937; color: #e5e7eb; }
body.dark-mode .tabs { background: #1f2937; border-color: #374151; }
body.dark-mode .tab-btn { color: #d1d5db; }
body.dark-mode .tab-btn.active { background: #111827; color: #60a5fa; }
body.dark-mode input, body.dark-mode select, body.dark-mode textarea {
  background: #111827; color: #e5e7eb; border-color: #374151;
}
body.dark-mode .rule-table th { color: #9ca3af; border-color: #374151; }
body.dark-mode .rule-table td { border-color: #374151; }
body.dark-mode .hint { color: #9ca3af; }
body.dark-mode .cat-item:hover, body.dark-mode .cat-item.active { background: #1e3a5f; color: #93c5fd; }
body.dark-mode code { background: #111827; color: #93c5fd; padding: 2px 4px; border-radius: 4px; }

/* ---------- 모바일 대응 (휴대폰 접속용) ----------
   레이아웃/치수 속성만 덮어쓴다. background/color/border-color 는 건드리지 않으므로
   위의 body.dark-mode 규칙(특정도 0,2,0)과 충돌하지 않는다. */
@media (max-width: 768px) {
  /* iOS 사파리는 16px 미만 입력창에 포커스가 가면 화면을 자동 확대한다 */
  input, select, textarea { font-size: 16px; }
  /* 터치 타겟 최소 높이. 체크박스/라디오는 제외(정사각형이 뭉개짐) */
  button, textarea, select,
  input:not([type="checkbox"]):not([type="radio"]) { min-height: 40px; }

  /* 상단바 / 본문 여백 축소로 화면 폭 확보 */
  .topbar { padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
  .topbar h1 { font-size: 15px; }
  .topbar-actions { gap: 8px; }
  main { padding: 14px 12px; }

  /* 탭 14개 → 가로 스크롤. flex:none 이 없으면 버튼이 찌그러지며 글자가 줄바꿈된다 */
  .tabs {
    padding: 8px 12px 0; flex-wrap: nowrap; overflow-x: auto;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn { flex: none; white-space: nowrap; padding: 10px 12px; }

  /* 사이드바 + 본문 → 세로 스택 */
  .layout { flex-direction: column; }
  .sidebar { width: 100%; }

  /* 메일머지 2단 → 1단 */
  .mailmerge-grid { flex-direction: column; gap: 14px; }
  .mm-result, .mm-result-col .mm-result { max-height: 380px; }

  /* 표(관리자/규칙 탭 등)는 열이 많아 화면을 넘긴다 → 표 자체를 가로 스크롤 */
  .rule-table {
    display: block; overflow-x: auto; white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  /* 폼 입력은 한 줄에 하나씩 (직계 자식만 — 중첩된 .ct-custom-field-row 등은 유지) */
  .rule-form > input, .rule-form > select { width: 100%; }
  .account-form, .sender-form { max-width: none; }

  /* 다이제스트 카드 1열 */
  .digest-grid { grid-template-columns: 1fr; }

  /* 통계 */
  .stat-summary { flex-wrap: wrap; gap: 10px; }
  .stat-tile { padding: 12px 16px; }
  .stat-bar-label { width: 84px; }

  /* 사내 메신저: 대화목록 + 채팅창 세로 스택 */
  .im-layout { flex-direction: column; height: auto; }
  .im-sidebar { width: 100%; max-height: 220px; }
  .im-chat { height: 60vh; }
  .im-msg { max-width: 85%; }

  /* 모달이 화면 밖으로 나가지 않게 (기존 max-width: calc(100vw - 32px) 를 덮어씀) */
  .modal-box { width: 95vw; max-width: 95vw; max-height: 90vh; }

  /* AI 비서 패널: 좌우 폭을 거의 다 사용 */
  .assistant-fab { right: 16px; bottom: 16px; }
  .assistant-panel {
    left: 12px; right: 12px; bottom: 84px; width: auto; max-width: none;
    height: calc(100vh - 160px);
  }

  /* 로그인 카드 */
  .auth-wrap { padding: 16px; }
  .auth-card { width: 100%; max-width: 340px; padding: 24px; }
}
