/* ══════════════════════════════════════════════════════════
   QManual Editor – Style Sheet
   Modern Blue & Gray Palette
   ══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;500;600;700&display=swap');

/* ── CSS Variables ─────────────────────────────────────── */
:root {
    --bg: #F8F9FA;
    --surface: #FFFFFF;
    --text: #212529;
    --text-secondary: #6C757D;
    --primary: #0D6EFD;
    --primary-hover: #0B5ED7;
    --primary-light: #E7F1FF;
    --danger: #DC3545;
    --danger-hover: #BB2D3B;
    --success: #198754;
    --warning: #FFC107;
    --border: #DEE2E6;
    --border-light: #E9ECEF;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --transition: 0.2s ease;
    --sidebar-width: 280px;
    --topbar-height: 60px;
}

/* ── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    line-height: 1.6;
}

/* ── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #CED4DA;
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: #ADB5BD;
}

/* ══════════════════════════════════════════════════════════
   TOP BAR
   ══════════════════════════════════════════════════════════ */
#topbar {
    display: flex;
    align-items: center;
    height: var(--topbar-height);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    gap: 12px;
    box-shadow: var(--shadow-sm);
    z-index: 100;
    position: relative;
}

#topbar-logo {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    object-fit: contain;
    flex-shrink: 0;
}

#manual-title-input {
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    width: 200px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

#manual-title-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13,110,253,0.15);
}

#manual-title-input::placeholder {
    color: var(--text-secondary);
}

.topbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.topbar-actions-right {
    margin-left: auto;
}

/* ── Buttons ───────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    line-height: 1.4;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: var(--shadow-sm);
}

.btn-secondary {
    background: #495057;
    color: #fff;
}
.btn-secondary:hover {
    background: #343A40;
    box-shadow: var(--shadow-sm);
}

.btn-outline {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-outline:hover {
    background: var(--bg);
    border-color: #ADB5BD;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-success {
    background: var(--success);
    color: #fff;
}
.btn-success:hover {
    background: #157347;
}

.btn .material-symbols-outlined {
    font-size: 18px;
}

/* ══════════════════════════════════════════════════════════
   MAIN LAYOUT
   ══════════════════════════════════════════════════════════ */
#main-container {
    display: flex;
    height: calc(100vh - var(--topbar-height));
}

/* ══════════════════════════════════════════════════════════
   SIDEBAR (Tree)
   ══════════════════════════════════════════════════════════ */
#sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#sidebar-header {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-light);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 6px;
}

#tree-container {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

/* ── Tree Items ────────────────────────────────────────── */
.tree-item {
    position: relative;
    user-select: none;
}

.tree-item-row {
    display: flex;
    align-items: center;
    padding: 6px 14px;
    cursor: pointer;
    transition: background var(--transition);
    gap: 6px;
    min-height: 36px;
    position: relative;
}

.tree-item-row:hover {
    background: var(--primary-light);
}

.tree-item-row.selected {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 500;
}

.tree-item-row.selected::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary);
    border-radius: 0 2px 2px 0;
}

.tree-item-row.drag-over {
    background: rgba(13, 110, 253, 0.12);
    outline: 2px dashed var(--primary);
    outline-offset: -2px;
}

.tree-item-row.dragging {
    opacity: 0.4;
}

.tree-icon {
    font-size: 18px;
    flex-shrink: 0;
    line-height: 1;
}

.tree-label {
    font-size: 13px;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tree-default-badge {
    font-size: 10px;
    font-weight: 700;
    color: var(--primary);
    background: var(--primary-light);
    border: 1px solid rgba(13,110,253,0.2);
    padding: 1px 6px;
    border-radius: 10px;
    flex-shrink: 0;
}

.tree-folder-toggle {
    font-size: 16px;
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
    transition: transform var(--transition);
    line-height: 1;
    display: flex;
    align-items: center;
}

.tree-folder-toggle.collapsed {
    transform: rotate(-90deg);
}

.tree-children {
    padding-left: 20px;
}

.tree-children.collapsed {
    display: none;
}

/* indent guide */
.tree-children {
    position: relative;
}
.tree-children::before {
    content: '';
    position: absolute;
    left: 22px;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--border-light);
}

/* ── Drag placeholder ─────────────────────────────────── */
.drag-placeholder {
    height: 3px;
    background: var(--primary);
    border-radius: 2px;
    margin: 0 14px;
    transition: all 0.15s ease;
}

/* ── Rename input ──────────────────────────────────────── */
.tree-rename-input {
    font-family: inherit;
    font-size: 13px;
    padding: 2px 6px;
    border: 1px solid var(--primary);
    border-radius: 3px;
    outline: none;
    background: var(--surface);
    color: var(--text);
    width: 100%;
    box-shadow: 0 0 0 2px rgba(13,110,253,0.2);
}

/* ══════════════════════════════════════════════════════════
   SIDEBAR RESIZE HANDLE
   ══════════════════════════════════════════════════════════ */
#sidebar-resize {
    width: 4px;
    cursor: col-resize;
    background: transparent;
    transition: background var(--transition);
    flex-shrink: 0;
}

#sidebar-resize:hover,
#sidebar-resize.active {
    background: var(--primary);
}

/* ══════════════════════════════════════════════════════════
   EDITOR AREA
   ══════════════════════════════════════════════════════════ */
#editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

/* ── Editor Toolbar ────────────────────────────────────── */
#editor-toolbar {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    gap: 6px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 6px 12px;
    font-family: inherit;
    font-size: 12px;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

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

.toolbar-btn:active {
    transform: scale(0.96);
}

.toolbar-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.toolbar-btn .material-symbols-outlined {
    font-size: 18px;
}

.toolbar-separator {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 4px;
}

/* ── Font size selector ────────────────────────────────── */
.toolbar-select {
    font-family: inherit;
    font-size: 12px;
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: border-color var(--transition);
}

.toolbar-select:focus {
    outline: none;
    border-color: var(--primary);
}

/* ── Color input wrapper ───────────────────────────────── */
.color-btn-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.color-btn-wrapper input[type="color"] {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

/* ── Breadcrumb ────────────────────────────────────────── */
#breadcrumb {
    display: flex;
    align-items: center;
    padding: 6px 16px;
    gap: 4px;
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--surface);
    border-bottom: 1px solid var(--border-light);
    min-height: 32px;
}

.breadcrumb-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.breadcrumb-sep {
    color: var(--border);
    font-size: 14px;
}

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

/* ── WYSIWYG Editor ────────────────────────────────────── */
#editor-wrapper {
    flex: 1;
    padding: 16px;
    overflow: hidden;
    display: flex;
}

#wysiwyg-editor {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 24px;
    overflow-y: auto;
    outline: none;
    box-shadow: var(--shadow-sm);
    font-size: 14px;
    line-height: 1.8;
    min-height: 200px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

#wysiwyg-editor:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13,110,253,0.1);
}

#wysiwyg-editor:empty::before {
    content: '여기에 내용을 입력하세요...';
    color: var(--text-secondary);
    pointer-events: none;
}

#wysiwyg-editor img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    margin: 8px 0;
}

#wysiwyg-editor .content-box {
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin: 12px 0;
    background: var(--bg);
    min-height: 60px;
}

/* ── No selection placeholder ──────────────────────────── */
#no-selection {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    gap: 12px;
}

#no-selection .material-symbols-outlined {
    font-size: 64px;
    opacity: 0.3;
}

#no-selection p {
    font-size: 15px;
}

/* ══════════════════════════════════════════════════════════
   CONTEXT MENU
   ══════════════════════════════════════════════════════════ */
#context-menu {
    position: fixed;
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 180px;
    padding: 6px;
    z-index: 1000;
    animation: contextFadeIn 0.15s ease;
}

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

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
    color: var(--text);
}

.context-menu-item:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.context-menu-item.danger {
    color: var(--danger);
}
.context-menu-item.danger:hover {
    background: #FFF5F5;
}

.context-menu-item .material-symbols-outlined {
    font-size: 18px;
}

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

/* ══════════════════════════════════════════════════════════
   MODAL / DIALOG
   ══════════════════════════════════════════════════════════ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: modalFadeIn 0.2s ease;
}

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

.modal-box {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 28px;
    min-width: 360px;
    max-width: 480px;
    animation: modalSlideIn 0.25s ease;
}

@keyframes modalSlideIn {
    from { transform: translateY(-16px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 12px;
}

.modal-body {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 20px;
    line-height: 1.6;
}

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

/* ══════════════════════════════════════════════════════════
   TOAST NOTIFICATION
   ══════════════════════════════════════════════════════════ */
#toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: var(--text);
    color: #fff;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 13px;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
    max-width: 360px;
}

.toast.success {
    background: var(--success);
}
.toast.error {
    background: var(--danger);
}

.toast .material-symbols-outlined {
    font-size: 20px;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(40px); }
}

/* ══════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 220px;
    }

    #manual-title-input {
        width: 120px;
    }

    .btn span:not(.material-symbols-outlined) {
        display: none;
    }

    .btn {
        padding: 8px 10px;
    }
}
