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

:root {
    --primary-color: #5b7ff5;
    --primary-light: #eef2ff;
    --bg-color: #f7f8fa;
    --sidebar-bg: #ffffff;
    --border-color: #eaedf0;
    --text-color: #1a1d23;
    --text-light: #6b7280;
    --hover-bg: #f3f4f6;
    --danger-color: #ef4444;
    --danger-light: #fef2f2;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* 사이드바 공통 스타일 */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 48px !important;
    min-width: 0;
}

.sidebar.collapsed .sidebar-content {
    display: none;
}

.sidebar.collapsed .sidebar-collapsed-bar {
    display: flex;
}

.sidebar-collapsed-bar {
    display: none;
    width: 48px;
    height: 100%;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding-top: 12px;
    cursor: pointer;
    color: #666;
}

/* 좌측 rail은 내부 버튼이 클릭을 받으므로 div 자체 hover 강조는 두지 않는다.
   우측 rail(.sidebar-collapsed-bar[onclick])은 div 클릭 패턴이라 hover 유지. */
.right-sidebar .sidebar-collapsed-bar:hover {
    background: #f5f5f5;
    color: var(--primary-color);
}

.left-sidebar .sidebar-collapsed-bar {
    cursor: default;
}

.rail-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: 8px;
    color: #666;
}

.rail-btn:hover {
    background: var(--hover-bg);
    color: var(--primary-color);
}

.sidebar-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.right-sidebar {
    width: 360px;
    border-right: none;
    border-left: 1px solid var(--border-color);
}

/* 채팅 패널 리사이즈 핸들 (PC 인라인 사이드바 사이에 위치) */
.panel-resize-handle {
    width: 1px;
    cursor: col-resize;
    background: var(--border-color);
    flex-shrink: 0;
    position: relative;
}

.panel-resize-handle::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: -4px;
    right: -4px;
    z-index: 10;
}

.panel-resize-handle:hover,
.panel-resize-handle.active {
    background: var(--primary-color);
    width: 2px;
}

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

.sidebar-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color);
    letter-spacing: -0.01em;
}

.btn-expand {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    color: #666;
    display: flex;
    align-items: center;
}

.btn-expand:hover {
    background: #f0f0f0;
    color: var(--primary-color);
}

.sidebar-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-controls {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 6px;
    align-items: center;
}

.search-container {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 7px 28px 7px 30px;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 13px;
    outline: none;
    background: var(--hover-bg);
    color: var(--text-color);
    box-sizing: border-box;
}

.search-input:focus {
    border-color: var(--primary-color);
    background: var(--sidebar-bg);
}

.search-clear {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: #999;
    font-size: 16px;
    padding: 0 4px;
    line-height: 1;
}

.search-clear:hover {
    color: #333;
}

.search-badge {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 3px;
    flex-shrink: 0;
    margin-left: 4px;
}

.search-badge-title {
    background: var(--primary-color);
    color: white;
}

.search-badge-content {
    background: #e8e8e8;
    color: #666;
}

.search-no-results,
.search-loading {
    padding: 20px;
    text-align: center;
    color: #999;
    font-size: 13px;
}

.btn-collapse {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    color: #666;
    display: flex;
    align-items: center;
}

.btn-collapse:hover {
    background: #f0f0f0;
    color: var(--primary-color);
}

/* 모바일 전용 사이드바 닫기 버튼 (데스크톱에서는 숨김) */
.mobile-close-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    color: #555;
    align-items: center;
    justify-content: center;
}

.mobile-close-btn:hover {
    background: #f0f0f0;
    color: var(--primary-color);
}

/* 문서 목록 */
.document-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.document-item {
    min-height: 36px;
    padding: 6px 8px;
    padding-left: calc(8px + var(--tree-level, 0) * 16px);
    border-radius: 8px;
    cursor: grab;
    margin-bottom: 1px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.document-item:active {
    cursor: grabbing;
}

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

.document-item.active {
    background: var(--primary-light);
}

.document-item.active .document-item-title {
    font-weight: 500;
}

/* 트리 노드 래퍼 (.tree-node) — Sortable draggable 단위 */
.tree-node {
    display: block;
}

/* 자식 컨테이너: 접힌 상태는 숨김 (드래그 중에도 동일 — 자동 펼침은 hover-expand JS가 담당) */
.tree-children[data-collapsed="true"] {
    display: none;
}

/* 빈 폴더에는 거의 보이지 않는 hit zone만 부여 (SortableJS emptyInsertThreshold 인식용) */
.tree-children:empty {
    min-height: 2px;
}

/* hover-expand 직후 짧은 시각 강조 */
.tree-children.drag-hover-expanded {
    background: rgba(91, 127, 245, 0.05);
    border-radius: 4px;
}

/* SortableJS 시각 피드백 */
/* Ghost(원래 자리 placeholder) — 빈 박스 대신 얇은 drop indicator bar로만 표시 */
.sortable-ghost {
    height: 3px !important;
    min-height: 3px !important;
    padding: 0 !important;
    margin: 3px 8px !important;
    background: var(--primary-color);
    border-radius: 2px;
    opacity: 0.9;
    overflow: hidden;
}

.sortable-ghost > * {
    display: none !important;
}

/* 마우스 따라가는 드래그 미리보기 */
.sortable-drag > .document-item {
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
    border-radius: 6px;
    opacity: 0.95;
}

/* 드롭 타겟 부모 컨테이너(어디로 들어가는지) 강조 */
.tree-children:has(> .sortable-ghost) {
    background: rgba(91, 127, 245, 0.08);
    border-radius: 4px;
    outline: 1px dashed rgba(91, 127, 245, 0.4);
    outline-offset: -2px;
}

/* 루트 컨테이너로 빼는 경우 */
.document-list:has(> .sortable-ghost) {
    background: rgba(91, 127, 245, 0.04);
}

/* 드롭 타겟이 폴더 안일 때, 그 폴더 자체(부모 .document-item) 강조 */
.tree-node:has(> .tree-children > .sortable-ghost) > .document-item {
    background: rgba(91, 127, 245, 0.14);
    box-shadow: inset 3px 0 0 var(--primary-color);
}

.tree-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    font-size: 10px;
    color: #999;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 3px;
    user-select: none;
}

.tree-toggle:hover {
    background: #e0e0e0;
    color: #333;
}

.tree-toggle-spacer {
    display: inline-block;
    width: 18px;
    flex-shrink: 0;
}

/* 제목 왼쪽 문서 아이콘 — 토글/스페이서와 제목 사이, 은은한 회색 */
.document-item-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #9aa0a6;
    margin-right: 3px;
}

.document-item.active .document-item-icon {
    color: var(--primary-color);
}

.document-item-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.document-item-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
}

.document-item-preview {
    font-size: 11px;
    color: #999;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
    line-height: 1.3;
}

.document-item.active .document-item-preview {
    color: #6b7a90;
}

/* hover 액션: 케밥 '⋯' 버튼 1개 + 드롭다운 메뉴 (ChatGPT 패턴) */
.document-item-actions {
    position: relative;
    display: flex;
    align-items: center;
    opacity: 0;
    flex-shrink: 0;
}

.document-item:hover .document-item-actions,
.document-item-actions.menu-open {
    opacity: 1;
}

.document-item-kebab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: none;
    border: none;
    color: var(--text-light);
    cursor: pointer;
    border-radius: 6px;
}

.document-item-kebab:hover,
.document-item-actions.menu-open .document-item-kebab {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-color);
}

.document-item-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 148px;
    padding: 4px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    z-index: 50;
}

.document-item-actions.menu-open .document-item-menu {
    display: block;
}

.document-item-menu button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-color);
    line-height: 1.2;
}

.document-item-menu button:hover {
    background: var(--hover-bg);
}

.document-item-menu button.document-item-menu-delete {
    color: var(--danger-color);
}

.document-item-menu button.document-item-menu-delete:hover {
    background: var(--danger-light);
}

/* 버튼 스타일 */
.btn-new-icon {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-new-icon:hover {
    background: var(--hover-bg);
    color: var(--primary-color);
}

/* 메인 컨텐츠 영역 — body가 스크롤 컨테이너이므로 main-content는 overflow visible */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: visible;
}

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

.document-title {
    flex: 1;
    border: none;
    font-size: 18px;
    font-weight: 600;
    outline: none;
    padding: 8px 0;
}

/* 에디터 툴바 */
.editor-toolbar {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    background: #fafafa;
    border-bottom: 1px solid var(--border-color);
    gap: 4px;
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    color: #555;
    font-size: 14px;
    transition: all 0.15s ease;
}

.toolbar-btn:hover {
    background: #e8e8e8;
    border-color: #ddd;
    color: var(--primary-color);
}

.toolbar-btn:active {
    background: #d8d8d8;
}

.toolbar-btn strong {
    font-weight: 700;
}

.toolbar-btn em {
    font-style: italic;
}

.toolbar-btn s {
    text-decoration: line-through;
}

.toolbar-btn code {
    font-family: monospace;
    font-size: 11px;
}

.toolbar-select {
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: white;
    font-size: 13px;
    color: #555;
    cursor: pointer;
    outline: none;
}

.toolbar-select:hover {
    border-color: var(--primary-color);
}

.toolbar-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: var(--border-color);
    margin: 0 8px;
}

/* 테이블 선택 그리드 */
.table-picker-container {
    position: relative;
    display: inline-block;
}

.table-picker-popup {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
}

.table-picker-popup.visible {
    display: block;
}

.table-picker-grid {
    display: grid;
    grid-template-columns: repeat(8, 20px);
    grid-template-rows: repeat(8, 20px);
    gap: 3px;
}

.table-picker-cell {
    width: 20px;
    height: 20px;
    border: 1px solid #ddd;
    border-radius: 2px;
    background: #f8f8f8;
    cursor: pointer;
    transition: all 0.1s ease;
}

.table-picker-cell:hover {
    border-color: var(--primary-color);
}

.table-picker-cell.highlighted {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.table-picker-label {
    text-align: center;
    margin-top: 8px;
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

/* 에디터 */
.editor-container {
    flex: 1;
    overflow-y: auto;
    background: white;
}

.markdown-editor {
    min-height: 100%;
    padding: 20px 40px;
    outline: none;
    font-size: 16px;
    line-height: 1.8;
}

.markdown-editor:empty:before {
    content: attr(data-placeholder);
    color: #999;
}

/* 마크다운 스타일링 */
.markdown-editor p {
    margin: 0.4em 0;
}

.markdown-editor h1 {
    font-size: 2em;
    font-weight: 700;
    margin: 0.5em 0;
}

.markdown-editor h2 {
    font-size: 1.5em;
    font-weight: 600;
    margin: 0.5em 0;
}

.markdown-editor h3 {
    font-size: 1.25em;
    font-weight: 600;
    margin: 0.5em 0;
}

.markdown-editor h4 {
    font-size: 1.1em;
    font-weight: 600;
    margin: 0.4em 0;
}

.markdown-editor h5 {
    font-size: 1em;
    font-weight: 600;
    margin: 0.4em 0;
    color: var(--text-light);
}

.markdown-editor ul, .markdown-editor ol {
    margin: 0.5em 0;
    padding-left: 2em;
}

.markdown-editor li {
    margin: 0.25em 0;
}

.markdown-editor code {
    background: #f5f5f5;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.9em;
}

.markdown-editor pre {
    background: #f5f5f5;
    padding: 16px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 1em 0;
}

.markdown-editor blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 16px;
    margin: 1em 0;
    color: var(--text-light);
}

/* 에디터 내 테이블 스타일 */
.markdown-editor table,
.markdown-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    font-size: 14px;
}

.markdown-editor th,
.markdown-editor td,
.markdown-table th,
.markdown-table td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}

.markdown-editor th,
.markdown-table th {
    background: #f5f5f5;
    font-weight: 600;
}

.markdown-editor tr:hover,
.markdown-table tr:hover {
    background: #fafafa;
}

/* 인라인 스타일 */
.markdown-editor strong,
.markdown-editor b {
    font-weight: 700;
}

.markdown-editor em,
.markdown-editor i {
    font-style: italic;
}

.markdown-editor del,
.markdown-editor s {
    text-decoration: line-through;
    color: #999;
}

.markdown-editor a {
    color: var(--primary-color);
    text-decoration: underline;
}

.markdown-editor img {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin: 0.8em auto;
    cursor: pointer;
    transition: outline 0.15s ease;
}

.markdown-editor img:hover {
    outline: 2px solid rgba(74, 144, 217, 0.5);
}

.markdown-editor img.selected-image {
    outline: 2px solid var(--primary-color);
}

/* 이미지 리사이즈 래퍼 */
.image-resize-wrapper {
    position: relative;
    display: inline-block;
    line-height: 0;
}

/* 리사이즈 핸들 */
.resize-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--primary-color);
    border: 2px solid white;
    border-radius: 50%;
    z-index: 10;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.resize-handle-nw {
    top: -6px;
    left: -6px;
    cursor: nw-resize;
}

.resize-handle-ne {
    top: -6px;
    right: -6px;
    cursor: ne-resize;
}

.resize-handle-sw {
    bottom: -6px;
    left: -6px;
    cursor: sw-resize;
}

.resize-handle-se {
    bottom: -6px;
    right: -6px;
    cursor: se-resize;
}

/* 이미지 컨텍스트 메뉴 */
.image-context-menu {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
}

.image-context-menu button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: #555;
    transition: all 0.15s ease;
}

.image-context-menu button:hover {
    background: #f0f0f0;
    color: var(--primary-color);
}

.image-context-menu button.delete-btn:hover {
    background: #ffebee;
    color: #e53935;
}

.image-context-menu .menu-divider {
    width: 1px;
    height: 20px;
    background: var(--border-color);
    margin: 0 4px;
}

/* 테이블 선택 스타일 */
.markdown-table.selected-table {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* 테이블 컨텍스트 메뉴 */
.table-context-menu {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 100;
}

.table-context-menu button {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: #555;
    font-size: 12px;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.table-context-menu button:hover {
    background: #f0f0f0;
    color: var(--primary-color);
}

.table-context-menu button.delete-btn:hover {
    background: #ffebee;
    color: #e53935;
}

.table-context-menu .menu-divider {
    width: 1px;
    height: 20px;
    background: var(--border-color);
    margin: 0 4px;
}

.markdown-editor hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 1.5em 0;
}

/* 정렬 스타일 */
.markdown-editor [style*="text-align: center"] {
    text-align: center;
}

.markdown-editor [style*="text-align: right"] {
    text-align: right;
}

/* 입력창 내 액션 버튼 (파일 첨부, 템플릿) */
.chat-input-actions {
    position: absolute;
    right: 8px;
    bottom: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-template-quick {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    color: #999;
    display: flex;
    align-items: center;
}

.btn-template-quick:hover {
    color: var(--primary-color);
    background: #f0f0f0;
}

/* 모달 내 템플릿 목록 */
.template-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.template-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #fafafa;
}

.template-list-item .template-name {
    font-size: 13px;
    font-weight: 500;
}

.template-item-actions {
    display: flex;
    gap: 4px;
}

.btn-apply-template {
    padding: 4px 10px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.btn-apply-template:hover {
    background: #3a7bc8;
}

.btn-delete-template {
    padding: 4px 8px;
    background: none;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    color: #999;
}

.btn-delete-template:hover {
    color: #e53935;
    border-color: #e53935;
}

/* 모달 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.modal-header h3 {
    margin: 0;
    font-size: 18px;
}

.btn-close-modal {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
}

.modal-body {
    padding: 16px;
    overflow-y: auto;
}

.template-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    background: #f0f0f0;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.tab-btn.active {
    background: var(--primary-color);
    color: white;
}

.tab-content input,
.tab-content select,
.tab-content textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 12px;
    font-family: inherit;
    font-size: 14px;
}

.tab-content textarea {
    resize: vertical;
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

.btn-primary:hover {
    background: #3a7bc8;
}

.hint {
    color: #666;
    font-size: 13px;
    margin-bottom: 12px;
}

/* 템플릿 추출 - 파일 업로드 영역 */
.extract-upload-area {
    margin-bottom: 10px;
}

.extract-upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px;
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-light);
    font-size: 13px;
    transition: border-color 0.2s, background 0.2s;
}

.extract-upload-label:hover {
    border-color: var(--primary-color);
    background: #f0f6ff;
    color: var(--primary-color);
}

.extract-upload-label svg {
    opacity: 0.5;
}

.extract-upload-label:hover svg {
    opacity: 1;
    stroke: var(--primary-color);
}

/* 문서 가져오기 드롭존 */
.import-drop-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 36px 20px;
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-light);
    font-size: 13px;
    text-align: center;
    line-height: 1.6;
    transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.import-drop-zone svg {
    opacity: 0.5;
}

.import-drop-zone small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    opacity: 0.7;
}

.import-drop-zone:hover,
.import-drop-zone.dragover {
    border-color: var(--primary-color);
    background: #f0f6ff;
    color: var(--primary-color);
}

.import-drop-zone:hover svg,
.import-drop-zone.dragover svg {
    opacity: 1;
    stroke: var(--primary-color);
}

.import-drop-zone.busy {
    pointer-events: none;
    opacity: 0.6;
}

.import-status {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 13px;
    background: #f0f6ff;
    color: var(--primary-color);
}

.import-status.error {
    background: #fdecec;
    color: #c0392b;
}

/* 참조 문서 영역 */
.reference-docs-container {
    border-top: 1px solid var(--border-color);
    max-height: 200px;
    overflow-y: auto;
}

.reference-section {
    border-bottom: 1px solid var(--border-color);
}

.reference-section:last-child {
    border-bottom: none;
}

.reference-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #fafafa;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    color: #666;
}

.reference-header:hover {
    background: #f0f0f0;
}

.reference-toggle {
    font-size: 10px;
    color: #999;
}

.reference-list {
    padding: 4px 8px;
    max-height: 120px;
    overflow-y: auto;
}

.reference-list:empty::after {
    content: '문서가 없습니다';
    display: block;
    padding: 8px;
    color: #999;
    font-size: 12px;
    text-align: center;
}

.reference-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
}

.reference-item:hover {
    background: #f5f5f5;
}

.reference-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    cursor: pointer;
    overflow: hidden;
}

.reference-checkbox input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--primary-color);
}

.reference-checkbox input[type="checkbox"]:disabled {
    cursor: not-allowed;
}

.reference-checkbox .file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.current-badge {
    font-size: 10px;
    padding: 2px 6px;
    background: #e3f2fd;
    color: var(--primary-color);
    border-radius: 10px;
    margin-left: 4px;
}

.reference-item .btn-remove {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    opacity: 0;
    transition: opacity 0.2s;
}

.reference-item:hover .btn-remove {
    opacity: 1;
}

.reference-item .btn-remove:hover {
    background: #ffebee;
    color: #e53935;
}

/* 레거시 호환용 (기존 uploaded-files 스타일) */
.uploaded-files {
    padding: 4px 8px;
}

.uploaded-files:empty::after {
    content: '업로드된 문서가 없습니다';
    display: block;
    padding: 8px;
    color: #999;
    font-size: 12px;
    text-align: center;
}

.uploaded-file-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px 4px 12px;
    background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%);
    border: 1px solid #d1c4e9;
    border-radius: 16px;
    font-size: 12px;
}

.uploaded-file-item .file-name {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.uploaded-file-item .btn-remove {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
}

.uploaded-file-item .btn-remove:hover {
    background: rgba(0,0,0,0.1);
    color: #e53935;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    scroll-behavior: smooth;
    background: white;
}

.chat-message {
    margin-bottom: 20px;
    animation: msgFadeIn 0.2s ease;
}

@keyframes msgFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 사용자 메시지 */
.chat-message.user {
    display: flex;
    justify-content: flex-end;
}

.chat-message.user .chat-message-content {
    display: inline-block;
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 18px;
    border-bottom-right-radius: 4px;
    font-size: 13.5px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    background: var(--primary-color);
    color: white;
}

/* AI 응답 - ChatGPT/Gemini 스타일 */
.chat-message.assistant {
    position: relative;
}

.chat-message.assistant .chat-message-content {
    display: block;
    max-width: 100%;
    padding: 0;
    font-size: 13.5px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    background: transparent;
    color: var(--text-color);
    position: relative;
    border-radius: 0;
    box-shadow: none;
    padding-left: 28px;
}

/* AI 아이콘 */
.chat-message.assistant .chat-message-content::before {
    content: '';
    position: absolute;
    left: 0;
    top: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    flex-shrink: 0;
}

/* 응답 내 구분선 */
.chat-message.assistant + .chat-message.user {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

/* 복사 버튼 */
.btn-copy-msg {
    position: absolute;
    top: 0;
    right: 0;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    color: #999;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.chat-message.assistant:hover .btn-copy-msg {
    opacity: 1;
}

.btn-copy-msg:hover {
    color: var(--text-color);
    background: var(--hover-bg);
    border-color: #ccc;
}

.btn-copy-msg.copied {
    color: #22c55e;
    opacity: 1;
    border-color: #86efac;
}

/* 시스템 메시지 */
.chat-message.system {
    text-align: center;
}

.chat-message.system .chat-message-content {
    display: inline-block;
    background: var(--hover-bg);
    color: var(--text-light);
    font-size: 11.5px;
    padding: 4px 12px;
    border-radius: 20px;
    max-width: 90%;
    border: none;
    box-shadow: none;
}


.chat-input-container {
    padding: 12px;
    border-top: 1px solid var(--border-color);
    background: white;
}

.pending-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-bottom: 8px;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--bg-secondary, #f0f0f0);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    font-size: 12px;
    color: var(--text-secondary, #555);
}

.attachment-chip .attachment-name {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-chip .attachment-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-tertiary, #999);
    font-size: 12px;
    padding: 0 2px;
    line-height: 1;
}

.attachment-chip .attachment-remove:hover {
    color: var(--danger-color, #dc3545);
}

.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 4px;
    max-width: 80%;
}

.message-attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: white;
    border: 1px solid var(--border-color, #ddd);
    border-radius: 10px;
    font-size: 12px;
    color: var(--text-primary, #333);
}

.chat-input-wrapper {
    position: relative;
    display: flex;
    align-items: flex-end;
}

.chat-input {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px 12px;
    padding-right: 40px;
    font-size: 13.5px;
    resize: none;
    outline: none;
    font-family: inherit;
    background: var(--bg-color);
    transition: border-color 0.15s, box-shadow 0.15s;
    min-height: 76px;
    max-height: 160px;
    overflow-y: auto;
}

.chat-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(91, 127, 245, 0.1);
    background: white;
}

.btn-attach {
    cursor: pointer;
    color: var(--text-light);
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.btn-attach:hover {
    color: var(--primary-color);
    background: var(--primary-light);
}

.chat-send-area {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.btn-send {
    flex: 1;
    padding: 9px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s, transform 0.1s;
}

.btn-send:hover {
    background: #4a6fe0;
}

.btn-send:active {
    transform: scale(0.98);
}

.btn-send:disabled {
    background: #d1d5db;
    cursor: not-allowed;
    transform: none;
}

.btn-stop {
    flex: 1;
    padding: 9px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s;
}

.btn-stop:hover {
    background: #dc2626;
}

.mobile-overlay {
    display: none;
}

/* PC(>768)에선 모바일 FAB/햄버거 숨김 — 사이드바가 인라인이라 진입 버튼 불필요 */
.mobile-nav,
.mobile-nav-fab-tl,
.editor-mobile-menu {
    display: none;
}

/* 커스텀 confirm 다이얼로그 — 사이드바보다 항상 위 */
.app-confirm-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(15, 23, 42, 0.42);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: appConfirmFadeIn 0.15s ease;
}

@keyframes appConfirmFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.app-confirm-dialog {
    width: 100%;
    max-width: 360px;
    background: #fff;
    border-radius: 14px;
    padding: 22px 22px 16px;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.32);
    animation: appConfirmRise 0.18s ease;
}

@keyframes appConfirmRise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.app-confirm-msg {
    font-size: 14.5px;
    line-height: 1.55;
    color: #1a1d23;
    white-space: pre-wrap;
    margin-bottom: 18px;
}

.app-confirm-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.app-confirm-actions button {
    min-height: 40px;
    padding: 0 18px;
    font-size: 14px;
    font-weight: 600;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    background: #fff;
    color: var(--text-color);
    transition: background 0.12s ease, border-color 0.12s ease;
}

.app-confirm-cancel:hover {
    background: #f3f4f6;
}

.app-confirm-ok {
    background: var(--danger-color);
    border-color: var(--danger-color);
    color: #fff;
}

.app-confirm-ok:hover {
    background: #dc2626;
    border-color: #dc2626;
}

.model-select {
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 11px;
    outline: none;
    color: var(--text-light);
    background: var(--bg-color);
}

.btn-clear-chat {
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    border-radius: 6px;
    color: var(--text-light);
    display: flex;
    align-items: center;
    transition: all 0.15s;
}

.btn-clear-chat:hover {
    background: var(--danger-light);
    color: var(--danger-color);
}

/* 에디터 액션 버튼 */
.editor-action-buttons {
    display: flex;
    gap: 4px;
    margin-top: 10px;
    padding-top: 0;
    opacity: 0;
    transition: opacity 0.15s;
}

.chat-message:hover .editor-action-buttons {
    opacity: 1;
}

.plan-action-buttons {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid var(--border-color);
}

.editor-action-buttons button,
.plan-action-buttons button {
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 11px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s;
    background: white;
    color: var(--text-light);
}

.editor-action-buttons button:hover,
.plan-action-buttons button:hover {
    background: var(--primary-light);
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.editor-action-buttons button:active,
.plan-action-buttons button:active {
    transform: scale(0.97);
}

.btn-icon {
    font-size: 12px;
    line-height: 1;
}

.editor-action-buttons button:disabled,
.plan-action-buttons button:disabled {
    opacity: 0.5;
    cursor: default;
    transform: none;
    background: var(--hover-bg);
    color: var(--text-light);
    border-color: var(--border-color);
}

/* Plan 응답 분리 영역 */
.plan-explanation {
    padding: 10px 14px;
    margin-bottom: 12px;
    background: #f8f9fa;
    border-left: 3px solid #adb5bd;
    border-radius: 4px;
    color: #495057;
    font-size: 13px;
    line-height: 1.6;
}

.plan-explanation p {
    margin: 0;
}

.plan-structure {
    padding: 14px 16px;
    background: #f0f7ff;
    border: 1px solid #d0e3f7;
    border-radius: 6px;
}

.plan-structure h1,
.plan-structure h2,
.plan-structure h3 {
    margin-top: 10px;
    margin-bottom: 4px;
    color: #1a5276;
}

.plan-structure h1:first-child,
.plan-structure h2:first-child,
.plan-structure h3:first-child {
    margin-top: 0;
}

.plan-structure p {
    margin: 0 0 6px 0;
    color: #34495e;
    font-size: 13px;
}

/* 이미지 placeholder */
.image-placeholder {
    display: inline-block;
    padding: 4px 8px;
    background: #f5f5f5;
    border: 1px dashed #ccc;
    border-radius: 4px;
    color: #666;
    font-size: 12px;
    font-style: italic;
}

/* 채팅 메시지 내 마크다운 스타일 */
.chat-message-content h1,
.chat-message-content h2,
.chat-message-content h3 {
    margin: 0.5em 0 0.3em 0;
    line-height: 1.3;
}

.chat-message-content h1 {
    font-size: 1.3em;
}

.chat-message-content h2 {
    font-size: 1.15em;
}

.chat-message-content h3 {
    font-size: 1.05em;
}

.chat-message-content p {
    margin: 0.5em 0;
}

.chat-message-content ul,
.chat-message-content ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.chat-message-content li {
    margin: 0.25em 0;
}

.chat-message-content code {
    background: rgba(0,0,0,0.08);
    padding: 2px 5px;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.9em;
}

.chat-message-content pre {
    background: rgba(0,0,0,0.08);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5em 0;
}

.chat-message-content pre code {
    background: none;
    padding: 0;
}

.mermaid-pending, .mermaid-rendered {
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 16px;
    margin: 0.5em 0;
    text-align: center;
    overflow-x: auto;
}

.mermaid-pending {
    font-family: monospace;
    font-size: 0.85em;
    white-space: pre;
    text-align: left;
    color: #666;
}

.mermaid-error {
    background: #fff3f3;
    border: 1px solid #ffcdd2;
    border-radius: 8px;
    padding: 16px;
    margin: 0.5em 0;
    font-family: monospace;
    font-size: 0.85em;
    color: #c62828;
}

.chart-pending {
    background: #fafafa;
    border: 1px dashed #ccc;
    border-radius: 8px;
    padding: 12px;
    margin: 0.5em 0;
    font-family: monospace;
    font-size: 0.8em;
    color: #888;
    white-space: pre;
}

.chart-rendered {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 12px;
    margin: 0.5em 0;
    height: 320px;
}

.chart-error {
    background: #fff3f3;
    border: 1px solid #ffcdd2;
    border-radius: 8px;
    padding: 16px;
    margin: 0.5em 0;
    font-family: monospace;
    font-size: 0.85em;
    color: #c62828;
}

.chart-error .chart-error-msg {
    font-family: inherit;
    font-weight: 600;
    margin-bottom: 8px;
    color: #b71c1c;
}

.chart-error pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.mermaid-error .mermaid-error-msg {
    font-family: inherit;
    font-weight: 600;
    margin-bottom: 8px;
    color: #b71c1c;
}

.mermaid-error pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-message-content blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 10px;
    margin: 0.5em 0;
    color: #666;
}

.chat-message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.5em 0;
    font-size: 12px;
}

.chat-message-content th,
.chat-message-content td {
    border: 1px solid #ddd;
    padding: 6px 8px;
    text-align: left;
}

.chat-message-content th {
    background: #f0f0f0;
    font-weight: 600;
}

.chat-message.assistant .chat-message-content {
    white-space: normal;
}

/* 추론 과정 (qwen3 등 추론형 모델용) */
.thinking-container {
    margin-bottom: 8px;
    max-width: 85%;
}

.thinking-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: linear-gradient(135deg, #e8f5e9 0%, #f3e5f5 100%);
    border: 1px solid #c8e6c9;
    border-radius: 16px;
    cursor: pointer;
    font-size: 12px;
    color: #666;
    transition: all 0.2s ease;
}

.thinking-toggle:hover {
    background: linear-gradient(135deg, #c8e6c9 0%, #e1bee7 100%);
}

.thinking-icon {
    font-size: 14px;
}

.thinking-label {
    font-weight: 500;
}

.thinking-arrow {
    font-size: 10px;
    transition: transform 0.2s ease;
}

.thinking-content {
    margin-top: 8px;
    padding: 12px;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.6;
    color: #666;
    max-height: 300px;
    overflow-y: auto;
}

.thinking-content p {
    margin: 0.4em 0;
}

.thinking-indicator {
    color: #9c27b0;
    font-style: italic;
    animation: pulse 1.5s ease-in-out infinite;
}

.loading-indicator {
    color: #888;
    font-size: 0.9em;
}

.loading-dots::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ============ 글 다듬기 플로팅 툴바 ============ */
.polish-toolbar {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 200;
    animation: fadeInUp 0.15s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.polish-toolbar button {
    padding: 5px 10px;
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    color: #444;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.polish-toolbar button:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.polish-highlight {
    background: rgba(74, 144, 217, 0.15);
    border-radius: 2px;
}

/* ============ 상태 표시줄 ============ */
.status-line {
    font-size: 12px;
    color: #888;
    margin-bottom: 6px;
    padding: 2px 0;
}



/* ============ 에이전트 모드 ============ */
/* 에이전트 계획 UI */
.agent-plan {
    margin-bottom: 10px;
    padding: 10px 14px;
    background: linear-gradient(135deg, #fff8e1 0%, #fff3e0 100%);
    border: 1px solid #ffe0b2;
    border-radius: 10px;
}

.agent-plan-title {
    font-size: 13px;
    font-weight: 600;
    color: #e65100;
    margin-bottom: 8px;
}

.agent-plan-steps {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.agent-plan-step {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    font-size: 12px;
    color: #555;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.agent-plan-check {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1.5px solid #bbb;
    font-size: 11px;
    color: #bbb;
    transition: all 0.3s ease;
}

.agent-plan-step.completed {
    color: #2e7d32;
}

.agent-plan-step.completed .agent-plan-check {
    background: #4caf50;
    border-color: #4caf50;
    color: white;
    font-weight: bold;
}

.agent-plan-step.completed .agent-plan-text {
    text-decoration: line-through;
    opacity: 0.7;
}

.agent-steps-container {
    margin-bottom: 8px;
    max-width: 85%;
}

.agent-steps-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: linear-gradient(135deg, #e3f2fd 0%, #e8f5e9 100%);
    border: 1px solid #b3d4fc;
    border-radius: 16px;
    cursor: pointer;
    font-size: 12px;
    color: #1565c0;
    transition: all 0.2s ease;
}

.agent-steps-toggle:hover {
    background: linear-gradient(135deg, #bbdefb 0%, #c8e6c9 100%);
}

.agent-steps-icon {
    font-size: 14px;
}

.agent-steps-label {
    font-weight: 500;
}

.agent-steps-count {
    background: #1565c0;
    color: white;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.agent-steps-arrow {
    font-size: 10px;
    transition: transform 0.2s ease;
}

.agent-steps-list {
    margin-top: 8px;
    padding: 8px 12px;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    max-height: 400px;
    overflow-y: auto;
}

.agent-step {
    padding: 6px 0;
    border-bottom: 1px solid #f0f0f0;
    font-size: 12px;
    line-height: 1.5;
    display: flex;
    gap: 6px;
    align-items: flex-start;
}

.agent-step:last-child {
    border-bottom: none;
}

.step-icon {
    flex-shrink: 0;
    font-size: 13px;
}

.step-text {
    color: #666;
    font-style: italic;
}

.step-label {
    color: #333;
    font-weight: 500;
}

.agent-step code {
    background: #e8eaf6;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 11px;
    color: #283593;
}

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

.step-result-preview,
.step-result-full {
    background: #f5f5f5;
    padding: 6px 8px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 11px;
    white-space: pre-wrap;
    word-break: break-all;
    color: #555;
}

.step-result-expand {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 11px;
    padding: 2px 0;
    margin-top: 4px;
}

.step-result-expand:hover {
    text-decoration: underline;
}

/* 반응형: 모바일에선 사이드바를 슬라이드 패널 + FAB 패턴으로,
   PC(>768)에선 인라인 사이드바를 그대로 유지하여 본문이 좌/우로 밀리는 동작. */
@media (max-width: 768px) {
    /* iOS Safari pull-to-refresh는 document(viewport) 스크롤일 때만 안정적으로 동작.
       body { overflow: auto }는 별도 스크롤 컨테이너가 되어 한 번 스크롤 후 깨지므로
       default(visible)로 두고, PC base 룰의 height:100vh / overflow:hidden을 푼다. */
    body {
        overflow: visible;
        height: auto;
        background: var(--sidebar-bg);
    }

    body.mobile-panel-open {
        overflow: hidden;
        height: 100dvh;
    }

    .app-container {
        height: auto;
        min-height: 100dvh;
    }
    
    .sidebar {
        position: fixed;
        top: 0;
        /* 100vh fallback → 100dvh (주소표시줄 접힘 대응) → 키보드 인셋만큼 상단으로 줄임 */
        height: 100vh;
        height: 100dvh;
        max-height: calc(100vh - var(--keyboard-inset, 0px));
        max-height: calc(100dvh - var(--keyboard-inset, 0px));
        z-index: 100;
        transition: transform 0.22s ease, width 0.22s ease, max-height 0.18s ease;
        width: min(88vw, 360px);
        box-shadow: 0 18px 48px rgba(11, 19, 36, 0.18);
    }
    
    .left-sidebar {
        left: 0;
        transform: translateX(-100%);
        border-right: none;
        border-top-right-radius: 16px;
        border-bottom-right-radius: 16px;
    }
    
    .left-sidebar.visible {
        transform: translateX(0);
    }
    
    .right-sidebar {
        right: 0;
        transform: translateX(100%);
        width: min(88vw, 480px);
        max-width: 100vw;
    }
    
    .right-sidebar.visible {
        transform: translateX(0);
    }
    
    .sidebar.collapsed {
        width: inherit !important;
    }
    
    .sidebar.collapsed .sidebar-content {
        display: flex;
    }
    
    .sidebar.collapsed .sidebar-collapsed-bar {
        display: none;
    }
    
    /* 모바일에선 데스크톱 축소(collapse) 버튼 대신 닫기 버튼 사용 */
    .sidebar .btn-collapse {
        display: none;
    }
    
    .mobile-close-btn {
        display: inline-flex;
    }
    
    /* body가 native 스크롤 컨테이너 — main-content는 자체 스크롤 없이 body 스크롤에 위임.
       pull-to-refresh가 정상 동작하려면 body가 스크롤되어야 함. */
    .main-content {
        overflow-x: hidden;
        padding-bottom: calc(env(safe-area-inset-bottom) + 12px);
    }
    
    .mobile-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: transparent;
        opacity: 0;
        pointer-events: none;
        /* background는 transition 제외 → .visible 빠지는 즉시 transparent.
           opacity만 페이드해도 어두움 효과는 자연스러움. 회색 잔영 차단. */
        transition: opacity 0.2s ease;
        z-index: 90;
    }

    .mobile-overlay.visible {
        opacity: 1;
        pointer-events: auto;
        background: rgba(15, 23, 42, 0.32);
    }
    
    /* FAB(Floating Action Button) 패턴 — 우측 하단 세로 스택 */
    .mobile-nav {
        position: fixed;
        left: auto;
        right: 16px;
        bottom: calc(16px + env(safe-area-inset-bottom));
        display: flex;
        flex-direction: column-reverse; /* primary(AI 채팅)가 가장 아래 */
        align-items: flex-end;
        gap: 12px;
        z-index: 80;
        transition: transform 0.25s ease, opacity 0.2s ease;
    }
    
    .mobile-nav.scroll-hidden {
        transform: translateY(calc(100% + 32px));
        opacity: 0;
        pointer-events: none;
    }
    
    .mobile-nav-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 52px;
        height: 52px;
        padding: 0;
        gap: 0;
        border: 1px solid rgba(91, 127, 245, 0.12);
        background: rgba(255, 255, 255, 0.94);
        color: var(--text-color);
        backdrop-filter: blur(18px);
        border-radius: 50%;
        font-size: 14px;
        font-weight: 600;
        box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
        transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
    }
    
    .mobile-nav-btn:active {
        transform: scale(0.94);
    }
    
    .mobile-nav-icon {
        flex-shrink: 0;
        width: 22px;
        height: 22px;
    }
    
    /* FAB는 아이콘 전용 — 라벨은 스크린리더만 인식 */
    .mobile-nav-label {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
    
    .mobile-nav-btn.is-active {
        background: rgba(91, 127, 245, 0.18);
        border-color: rgba(91, 127, 245, 0.5);
        color: #4d6ff0;
    }
    
    /* AI 채팅 = 메인 FAB (더 크고 강조) */
    .mobile-nav-btn-primary {
        width: 60px;
        height: 60px;
        background: linear-gradient(135deg, #4d6ff0, #6b8bff);
        color: white;
        border-color: transparent;
        box-shadow: 0 16px 36px rgba(77, 111, 240, 0.42);
    }
    
    .mobile-nav-btn-primary .mobile-nav-icon {
        width: 26px;
        height: 26px;
    }
    
    .mobile-nav-btn-primary.is-active {
        box-shadow: 0 16px 36px rgba(77, 111, 240, 0.55), inset 0 0 0 2px rgba(255, 255, 255, 0.5);
    }
    
    .editor-toolbar {
        overflow-x: auto;
        padding-bottom: 4px;
    }
    
    .reference-docs-container {
        max-height: 28vh;
        overflow-y: auto;
    }
    
    .chat-messages {
        padding: 12px 12px 16px;
    }
    
    .chat-input-container {
        position: sticky;
        bottom: 0;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(14px);
        box-shadow: 0 -10px 24px rgba(15, 23, 42, 0.08);
    }
    
    .pending-attachments {
        gap: 8px;
        padding-bottom: 10px;
    }
    
    .chat-input {
        min-height: 88px;
        max-height: 220px;
        font-size: 16px;
        line-height: 1.45;
        padding: 14px 14px 52px 14px;
        border-radius: 14px;
    }
    
    .chat-input-actions {
        right: 10px;
        bottom: 10px;
        gap: 6px;
    }
    
    .btn-attach,
    .btn-template-quick {
        width: 36px;
        height: 36px;
        border-radius: 10px;
        background: rgba(91, 127, 245, 0.08);
    }
    
    .chat-send-area {
        margin-top: 10px;
    }
    
    .btn-send,
    .btn-stop {
        min-height: 48px;
        font-size: 14px;
        border-radius: 12px;
    }
    
    .document-item {
        min-height: 42px;
        margin-bottom: 4px;
    }
    
    .document-item-actions {
        opacity: 1;
    }
    
    /* 좌상단 둥근 FAB — 우측 하단 AI 채팅 FAB와 대각 배치 */
    .mobile-nav-fab-tl {
        position: fixed;
        top: calc(12px + env(safe-area-inset-top));
        left: 16px;
        z-index: 80;
        width: 48px;
        height: 48px;
        padding: 0;
        border-radius: 50%;
        border: 1px solid rgba(91, 127, 245, 0.12);
        background: rgba(255, 255, 255, 0.94);
        color: var(--text-color);
        backdrop-filter: blur(18px);
        box-shadow: 0 8px 24px rgba(15, 23, 42, 0.14);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        transition: transform 0.12s ease, opacity 0.2s ease, background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
    }
    
    .mobile-nav-fab-tl:active {
        transform: scale(0.94);
    }
    
    .mobile-nav-fab-tl.is-active {
        background: rgba(91, 127, 245, 0.18);
        border-color: rgba(91, 127, 245, 0.5);
        color: #4d6ff0;
    }
    
    .mobile-nav-fab-tl.scroll-hidden {
        transform: translateY(calc(-100% - 24px));
        opacity: 0;
        pointer-events: none;
    }
    
    /* 에디터 화면에선 좌상단 FAB는 숨기고 헤더 햄버거가 그 역할을 대신 — 제목 입력란 가림 방지 */
    body.in-editor .mobile-nav-fab-tl {
        display: none;
    }
    
    .editor-mobile-menu {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        margin-right: 8px;
        padding: 0;
        border: none;
        background: transparent;
        color: var(--text-color);
        border-radius: 10px;
        cursor: pointer;
        flex-shrink: 0;
        transition: background 0.15s ease;
    }
    
    .editor-mobile-menu:active {
        background: rgba(91, 127, 245, 0.12);
    }
    
    .editor-header {
        gap: 4px;
    }

    .app-container, .main-content {
        background: var(--sidebar-bg);
    }

    .right-sidebar {
        width: 100vw;
        max-width: 100vw;
    }

    /* 모바일에선 사이드바가 화면 전체를 덮으므로 리사이즈 불필요 */
    .panel-resize-handle {
        display: none;
    }

    /* 에디터 헤더가 viewport-fit=cover로 시스템바 아래까지 확장돼도 제목이 가려지지 않도록 */
    .editor-header {
        padding-top: calc(12px + env(safe-area-inset-top));
    }

    /* 터치 히트영역 ≥44px — 시각 크기(26px)는 유지하고 가상 오버레이로 확장
       (min-height 로 늘리면 부모 flex 행/헤더 높이가 팽창하므로 ::before 사용) */
    .document-item-kebab,
    .btn-new-icon {
        position: relative;
    }

    .document-item-kebab::before,
    .btn-new-icon::before {
        content: '';
        position: absolute;
    }

    /* 좌측 확장을 main↔actions gap(4px) 안으로 제한 — 제목 우측 잠식 방지
       (invisible 케밥이 제목 탭을 먹어 문서 열기를 막는 dead zone 차단) */
    .document-item-kebab::before {
        inset: -9px -9px -9px -4px;
    }

    /* 우측 확장을 헤더 버튼 간 gap 안으로 제한 — mobile-close-btn 침범 방지 */
    .btn-new-icon::before {
        inset: -9px -4px -9px -9px;
    }
}

/* 채팅 삭제 확인 바 */
.chat-clear-confirm {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--danger-light);
    border-top: 1px solid #fecaca;
    font-size: 12.5px;
    color: var(--danger-color);
    animation: slideUp 0.15s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-clear-actions {
    display: flex;
    gap: 6px;
}

.chat-clear-yes {
    padding: 4px 12px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.15s;
}

.chat-clear-yes:hover {
    background: #dc2626;
}

.chat-clear-no {
    padding: 4px 12px;
    background: white;
    color: var(--text-light);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.15s;
}

.chat-clear-no:hover {
    background: var(--hover-bg);
}

/* 토스트 알림 */
.toast-notification {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text-color);
    color: white;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 13px;
    box-shadow: var(--shadow-md);
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 9999;
    pointer-events: none;
}

.toast-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* 템플릿 추출 진행 바 */
.extract-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
}

.extract-progress-bar {
    flex: 1;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
}

.extract-progress-fill {
    height: 100%;
    background: var(--primary-color);
    border-radius: 3px;
    width: 0%;
    transition: width 0.3s ease;
}

.extract-progress-text {
    font-size: 12px;
    color: var(--text-light);
    white-space: nowrap;
    min-width: 80px;
}

.extract-cancel-btn {
    padding: 4px 10px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
    color: var(--danger-color);
    transition: all 0.15s;
    white-space: nowrap;
}

.extract-cancel-btn:hover {
    background: var(--danger-light);
    border-color: var(--danger-color);
}

.extract-cancel-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

/* ============ 대시보드 ============ */
.dashboard {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    background: #fafbfc;
}

.dashboard-inner {
    max-width: 640px;
    width: 100%;
    padding: 40px 24px;
    text-align: center;
}

.dashboard-title {
    font-size: 28px;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 8px;
}

.dashboard-subtitle {
    font-size: 14px;
    color: #888;
    margin-bottom: 32px;
}

.dashboard-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 36px;
}

.dashboard-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background: #fff;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s;
}

.dashboard-btn:hover {
    border-color: #4a90d9;
    color: #4a90d9;
    box-shadow: 0 2px 8px rgba(74, 144, 217, 0.1);
}

.dashboard-btn-icon {
    font-weight: 700;
    font-size: 16px;
    color: #4a90d9;
}

/* Hero CTA — 단일 강조 버튼 (새 문서 작성) */
.dashboard-cta {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    padding: 16px 28px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, #4d6ff0, #6b8bff);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.2px;
    cursor: pointer;
    box-shadow: 0 12px 28px rgba(77, 111, 240, 0.32);
    transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.dashboard-cta:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 36px rgba(77, 111, 240, 0.42);
    filter: brightness(1.05);
}

.dashboard-cta:active {
    transform: translateY(0);
    box-shadow: 0 8px 18px rgba(77, 111, 240, 0.28);
}

.dashboard-cta-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.22);
}

.dashboard-cta-icon svg {
    width: 20px;
    height: 20px;
}

.dashboard-section {
    text-align: left;
}

.dashboard-section h3 {
    font-size: 13px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.recent-docs-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.recent-doc-item {
    padding: 12px;
    border: 1px solid #eee;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    transition: all 0.15s;
}

.recent-doc-item:hover {
    border-color: #4a90d9;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.recent-doc-title {
    font-size: 13px;
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recent-doc-meta {
    font-size: 11px;
    color: #999;
    margin-bottom: 4px;
}

.recent-doc-preview {
    font-size: 12px;
    color: #777;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.editor-area {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* ============ Export 드롭다운 ============ */
.export-dropdown-container {
    position: relative;
}

#exportBtn,
#importBtn {
    width: auto;
    min-width: auto;
    padding: 0 10px;
    gap: 4px;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 500;
    flex-shrink: 0;
}

#exportBtn svg,
#importBtn svg {
    flex-shrink: 0;
}

#exportBtn > span,
#importBtn > span {
    white-space: nowrap;
    margin-left: 0 !important;
}

.export-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: #fff;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    min-width: 200px;
    z-index: 1000;
    display: none;
    overflow: hidden;
}

.export-menu.open {
    display: block;
}

.export-menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: transparent;
    text-align: left;
    font-size: 13px;
    color: #333;
    cursor: pointer;
    transition: background 0.12s;
}

.export-menu button:hover {
    background: #f4f6f8;
}

.export-menu-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 22px;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    background: #4a6cf7;
    border-radius: 3px;
    letter-spacing: 0.5px;
}

.export-menu button:nth-child(2) .export-menu-icon { background: #e74c3c; }
.export-menu button:nth-child(3) .export-menu-icon { background: #2b579a; }

/* ============ Quick Edit 팝업 ============ */
.quick-edit-pin {
    position: fixed;
    z-index: 950;
    background: #1f2937;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    gap: 4px;
    transition: transform 0.1s, background 0.12s, box-shadow 0.12s;
    white-space: nowrap;
    line-height: 1.3;
}
.quick-edit-pin:hover {
    background: #4a6cf7;
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(74, 108, 247, 0.35);
}
.quick-edit-pin .qe-kbd {
    background: rgba(255, 255, 255, 0.2);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 10px;
    margin-left: 2px;
    font-family: ui-monospace, monospace;
}

.quick-edit-modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 2000;
    justify-content: center;
    align-items: center;
}
.quick-edit-modal.open { display: flex; }
.quick-edit-modal .qe-content {
    background: #fff;
    width: min(720px, 92vw);
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    border-radius: 10px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}
.qe-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
}
.qe-header h3 { margin: 0; font-size: 15px; font-weight: 600; }
.qe-close {
    border: none;
    background: transparent;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: #6b7280;
}
.qe-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    gap: 10px;
    padding: 12px 16px;
}

/* 원본 (접힘형) */
.qe-original-details {
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    overflow: hidden;
}
.qe-original-details summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    font-size: 12px;
    color: #475569;
    cursor: pointer;
    user-select: none;
    list-style: none;
}
.qe-original-details summary::-webkit-details-marker { display: none; }
.qe-original-details summary::before {
    content: '▶';
    font-size: 9px;
    color: #94a3b8;
    transition: transform 0.15s;
}
.qe-original-details[open] summary::before { transform: rotate(90deg); }
.qe-label {
    background: #64748b;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
}
.qe-original-preview {
    flex: 1;
    font-size: 12px;
    color: #475569;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.qe-orig-chars { font-size: 11px; color: #94a3b8; }
.qe-original-full {
    padding: 8px 12px;
    border-top: 1px solid #e5e7eb;
    font-size: 12.5px;
    line-height: 1.55;
    color: #334155;
    max-height: 180px;
    overflow: auto;
    word-wrap: break-word;
    background: #fff;
}
.qe-original-full > *:first-child { margin-top: 0; }
.qe-original-full > *:last-child { margin-bottom: 0; }
.qe-original-full h1, .qe-original-full h2, .qe-original-full h3 {
    margin: 6px 0 4px;
    font-weight: 700;
}
.qe-original-full h1 { font-size: 15px; }
.qe-original-full h2 { font-size: 13.5px; }
.qe-original-full h3 { font-size: 12.5px; }
.qe-original-full p { margin: 3px 0; }
.qe-original-full ul, .qe-original-full ol { margin: 3px 0; padding-left: 18px; }
.qe-original-full code {
    background: #e5e7eb;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 11.5px;
}
.qe-original-full pre {
    background: #e5e7eb;
    padding: 6px;
    border-radius: 3px;
    overflow-x: auto;
    font-size: 11.5px;
}
.qe-original-full table {
    border-collapse: collapse;
    margin: 4px 0;
    width: 100%;
    font-size: 11.5px;
}
.qe-original-full th, .qe-original-full td {
    border: 1px solid #cbd5e1;
    padding: 3px 6px;
}
.qe-original-full th { background: #f1f5f9; font-weight: 700; }
.qe-original-full img {
    max-width: 100%;
    height: auto;
    border-radius: 3px;
    margin: 3px 0;
}
.qe-original-full blockquote {
    border-left: 3px solid #94a3b8;
    padding: 2px 8px;
    margin: 4px 0;
    color: #475569;
}

/* 미리보기 (통합: 스트리밍 + 적용 대상) */
.qe-preview-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    border: 1px solid #fde68a;
    border-radius: 6px;
    overflow: hidden;
    background: #fffbeb;
    min-height: 140px;
}
.qe-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: rgba(251, 191, 36, 0.15);
    border-bottom: 1px solid rgba(251, 191, 36, 0.35);
}
.qe-preview-label-badge {
    display: inline-block;
    background: #f59e0b;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
}
.qe-preview-status {
    font-size: 11px;
    color: #92400e;
    font-weight: 600;
}
.qe-preview-body {
    flex: 1;
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.65;
    overflow-y: auto;
}
.qe-preview-body.qe-empty {
    color: #94a3b8;
    font-style: italic;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}
.qe-preview-body.qe-streaming { color: #1f2937; }
.qe-preview-body.qe-ready { color: #1f2937; background: #fff; }
.qe-preview-body > *:first-child { margin-top: 0; }
.qe-preview-body > *:last-child { margin-bottom: 0; }
.qe-preview-body h1, .qe-preview-body h2, .qe-preview-body h3 {
    margin: 8px 0 6px;
    font-weight: 700;
}
.qe-preview-body h1 { font-size: 17px; }
.qe-preview-body h2 { font-size: 15px; }
.qe-preview-body h3 { font-size: 14px; }
.qe-preview-body p { margin: 4px 0; }
.qe-preview-body ul, .qe-preview-body ol { margin: 4px 0; padding-left: 20px; }
.qe-preview-body code {
    background: #f3f4f6;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 12px;
}
.qe-preview-body pre {
    background: #f3f4f6;
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
}
.qe-preview-body table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
    font-size: 12px;
}
.qe-preview-body th, .qe-preview-body td {
    border: 1px solid #cbd5e1;
    padding: 5px 8px;
    text-align: left;
}
.qe-preview-body th {
    background: #f1f5f9;
    font-weight: 700;
}
.qe-preview-body img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin: 4px 0;
}
.qe-preview-body blockquote {
    border-left: 3px solid #fbbf24;
    padding: 4px 10px;
    margin: 6px 0;
    color: #78350f;
    background: rgba(251, 191, 36, 0.08);
}
.qe-hint {
    font-size: 11px;
    color: #6b7280;
    padding: 2px 4px;
}
.qe-hint.error { color: #dc2626; font-weight: 600; }
.qe-cursor {
    display: inline-block;
    animation: qe-blink 1s infinite;
    color: #f59e0b;
    font-weight: 700;
    margin-left: 1px;
}
@keyframes qe-blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

/* 지시 기록 */
.qe-history {
    padding: 6px 0;
    font-size: 11px;
}
.qe-history-label {
    color: #6b7280;
    font-weight: 600;
    margin-bottom: 4px;
}
.qe-history-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.qe-history-chip {
    display: inline-block;
    background: #eff6ff;
    color: #1e3a8a;
    padding: 3px 8px;
    border-radius: 10px;
    font-size: 11px;
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.qe-footer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 16px 14px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
}
.qe-input-row {
    display: flex;
    gap: 8px;
}
.qe-input-row textarea {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 13px;
    resize: none;
    font-family: inherit;
    min-height: 42px;
    max-height: 120px;
}
.qe-input-row button {
    padding: 0 14px;
    border: none;
    border-radius: 6px;
    background: #4a6cf7;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.qe-input-row button:disabled {
    background: #94a3b8;
    cursor: not-allowed;
}
.qe-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.qe-actions button {
    padding: 6px 14px;
    border-radius: 5px;
    border: 1px solid #d1d5db;
    background: #fff;
    font-size: 12px;
    cursor: pointer;
}
.qe-actions button.qe-apply {
    background: #16a34a;
    color: #fff;
    border-color: #16a34a;
    font-weight: 600;
}
.qe-actions button.qe-apply:disabled {
    background: #86efac;
    border-color: #86efac;
    cursor: not-allowed;
}
.qe-actions button:not(.qe-apply):hover {
    background: #f3f4f6;
}

/* 모바일: 대시보드 세로정렬 + 최근 문서 카드 잘림 수정 */
@media (max-width: 768px) {
    /* 콘텐츠가 길면 위가 잘리는 문제 → 위에서부터 시작 */
    .dashboard {
        align-items: flex-start;
        height: auto;
        min-height: 100%;
    }

    .dashboard-inner {
        padding: calc(24px + env(safe-area-inset-top)) 20px 24px;
    }

    .recent-docs-list {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .recent-doc-title {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        word-break: break-word;
    }

    .recent-doc-preview {
        white-space: normal;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        overflow: hidden;
    }

    .dashboard-cta {
        padding: 14px 22px;
        font-size: 14.5px;
    }

    /* 모바일에선 dashboard 배경도 사이드바와 동일한 흰색으로 — 사이드바 보고 닫을 때
       #fafbfc 회색빛이 노출되어 색이 변한 것처럼 보이는 문제 방지 */
    .dashboard {
        background: var(--sidebar-bg);
    }
}

/* ── 계정 영역 (좌측 사이드바 하단) ── */
.sidebar-account {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid var(--border-color);
    font-size: 13px;
    flex-shrink: 0;
}

/* 계정 요소는 사이드바·대시보드 양쪽에서 같은 마크업을 쓰므로 스코프를 나누지 않는다 */
.sidebar-account .account-name {
    flex: 1;
}

.account-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.account-login-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.account-admin-link {
    color: var(--text-light);
    text-decoration: none;
    flex-shrink: 0;
}

.account-admin-link:hover,
.account-login-link:hover {
    text-decoration: underline;
}

.account-logout-btn {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    flex-shrink: 0;
}

.account-logout-btn:hover {
    background: var(--hover-bg);
    color: var(--danger-color);
}

/* ── 섹션 트리 헤더 (로그인 시: 내 문서 / 공유받은 문서 / 공용 문서) ── */
.tree-section-header {
    padding: 10px 16px 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-light);
    letter-spacing: 0.4px;
    text-transform: uppercase;
    user-select: none;
}

.tree-section {
    min-height: 8px; /* 빈 섹션에도 드롭 가능 */
}

/* ── 읽기 전용 배너 ── */
.readonly-banner {
    padding: 6px 16px;
    font-size: 12px;
    color: #92600a;
    background: #fef7e6;
    border-bottom: 1px solid #f5e3b8;
}

#editor[contenteditable="false"] {
    background: var(--bg-color);
    cursor: default;
}

/* ── 문서 공유 모달 ── */
.share-add-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 12px 0;
    flex-wrap: wrap;
}

.share-add-row input,
.share-add-row select {
    padding: 8px 10px;
    font-size: 13px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    outline: none;
}

.share-add-row input[type="email"] {
    flex: 1;
    min-width: 160px;
}

.share-add-row input:focus,
.share-add-row select:focus {
    border-color: var(--primary-color);
}

.share-error {
    margin-bottom: 10px;
    padding: 8px 10px;
    font-size: 13px;
    color: var(--danger-color);
    background: var(--danger-light);
    border-radius: var(--radius);
}

.share-list {
    margin-top: 8px;
}

.share-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
}

.share-item-target {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.share-item-perm {
    padding: 2px 8px;
    font-size: 11px;
    color: var(--primary-color);
    background: var(--primary-light);
    border-radius: 10px;
    flex-shrink: 0;
}

.share-item-remove {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    flex-shrink: 0;
}

.share-item-remove:hover {
    background: var(--danger-light);
    color: var(--danger-color);
}

/* ── 대시보드 계정 영역 (우측 상단 고정) ── */
.dashboard { position: relative; }

.dashboard-account {
    position: absolute;
    top: 16px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.dashboard-account .account-name {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.btn-login-cta {
    padding: 7px 16px;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    background: var(--primary-color);
    border-radius: 999px;
    text-decoration: none;
}

.btn-login-cta:hover { filter: brightness(0.95); }

/* ── 접힌 레일 계정 아이콘 (사이드바 접힘 상태에서도 로그인 가능) ── */
.rail-account {
    margin-top: auto;
    margin-bottom: 12px;
}

.rail-account .rail-btn {
    text-decoration: none;
    color: var(--text-light);
}

.rail-avatar {
    font-size: 13px;
    font-weight: 700;
    color: #fff !important;
    background: var(--primary-color);
    border-radius: 50%;
    width: 30px;
    height: 30px;
}

.rail-avatar:hover { filter: brightness(0.95); background: var(--primary-color); }

@media (max-width: 768px) {
    .dashboard-account { top: 10px; right: 12px; }
}

/* ── 그룹 관리 모달 ── */
.modal-content.modal-wide { max-width: 720px; }

.btn-manage-groups {
    padding: 8px 12px;
    font-size: 13px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-color);
    flex-shrink: 0;
}

.btn-manage-groups:hover { background: var(--bg-color); }

.group-create-row {
    display: flex;
    gap: 8px;
    margin: 12px 0;
}

.group-create-row input {
    flex: 1;
    padding: 8px 10px;
    font-size: 13px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    outline: none;
}

.group-create-row input:focus { border-color: var(--primary-color); }

.group-error {
    margin-bottom: 10px;
    padding: 8px 10px;
    font-size: 13px;
    color: var(--danger-color);
    background: var(--danger-light);
    border-radius: var(--radius);
}

.group-panes {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.group-pane-list { width: 220px; flex-shrink: 0; }
.group-pane-detail { flex: 1; min-width: 0; }

.group-pane-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-light);
    margin-bottom: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.group-list { max-height: 320px; overflow-y: auto; }

.group-item {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 8px 10px;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
}

.group-item:hover { background: var(--hover-bg); }
.group-item.active { background: var(--primary-light); color: var(--primary-color); }

.group-item-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.group-item-meta { font-size: 11px; color: var(--text-light); flex-shrink: 0; }

.group-add-row { display: flex; gap: 8px; margin-bottom: 12px; }

.group-add-row input {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    font-size: 13px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    outline: none;
}

.group-add-row input:focus { border-color: var(--primary-color); }

.group-members { max-height: 260px; overflow-y: auto; }

.group-member {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 13px;
}

.group-member-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.group-member-owner {
    padding: 2px 8px;
    font-size: 11px;
    color: var(--primary-color);
    background: var(--primary-light);
    border-radius: 10px;
    flex-shrink: 0;
}

.group-member-remove,
.group-delete-btn {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    flex-shrink: 0;
}

.group-member-remove:hover,
.group-delete-btn:hover { background: var(--danger-light); color: var(--danger-color); }

.group-delete-btn {
    margin-top: 14px;
    border: 1px solid var(--border-color);
}

@media (max-width: 640px) {
    .group-panes { flex-direction: column; }
    .group-pane-list { width: 100%; }
}

.account-group-btn {
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    flex-shrink: 0;
}

.account-group-btn:hover { background: var(--hover-bg); color: var(--primary-color); }

/* ── 최근 문서 소유 구분 배지 ── */
.recent-doc-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;   /* 기존 .recent-doc-title의 margin을 행으로 옮김 */
}

/* span으로 바뀐 제목이 flex 안에서 말줄임되도록 */
.recent-doc-title-row .recent-doc-title {
    min-width: 0;
    margin-bottom: 0;
}

.recent-doc-badge {
    flex-shrink: 0;
    padding: 1px 7px;
    font-size: 10px;
    font-weight: 600;
    border-radius: 10px;
    background: var(--hover-bg);
    color: var(--text-light);
}

.recent-doc-badge.badge-own { background: var(--primary-light); color: var(--primary-color); }
.recent-doc-badge.badge-shared { background: #fff4e5; color: #b26a00; }

/* 공유·그룹 모달의 인라인 버튼: 전역 .btn-primary(width:100%, padding:12px)를 행 크기에 맞춘다 */
.share-add-row .btn-primary,
.group-create-row .btn-primary,
.group-add-row .btn-primary {
    width: auto;
    padding: 8px 14px;
    font-size: 13px;
    border-radius: var(--radius);
    flex-shrink: 0;
    white-space: nowrap;
}

/* 그룹 상세: 멤버 목록과 위험 동작 사이 간격 정리 */
.group-detail .hint { margin-bottom: 8px; }
.group-members:empty { display: none; }

/* 내가 남에게 공유 중인 문서 표시 */
.document-item-shared {
    display: inline-flex;
    align-items: center;
    margin-left: 5px;
    color: var(--primary-color);
    flex-shrink: 0;
    vertical-align: middle;
}

.recent-doc-badge.badge-sharing { background: #e6f4ea; color: #1e7e34; }
