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

:root {
  --primary: #e74c3c;
  --primary-dark: #c0392b;
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --border: #2d3561;
  --text: #e8e8e8;
  --text-muted: #8899aa;
  --selected: rgba(231, 76, 60, 0.15);
  --selected-border: #e74c3c;
  --radius: 8px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

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

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

/* ── Sidebar ── */
.sidebar {
  width: 200px;
  min-width: 200px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 8px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px 16px;
  color: var(--primary);
  font-weight: 700;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: transparent;
  border: none;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  width: 100%;
}

.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: rgba(231, 76, 60, 0.15); color: var(--primary); }

.sidebar-info {
  margin-top: auto;
  padding: 12px;
  background: var(--surface2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.file-name { font-size: 12px; font-weight: 600; color: var(--text); word-break: break-all; margin-bottom: 4px; }
.file-meta { font-size: 11px; color: var(--text-muted); }

/* ── Main ── */
.main {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tab-content { display: none; flex: 1; overflow: hidden; flex-direction: column; }
.tab-content.active { display: flex; }

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-shrink: 0;
}

.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.separator { width: 1px; height: 22px; background: var(--border); margin: 0 2px; }
.page-count { font-size: 12px; color: var(--text-muted); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  border: none;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-icon { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-icon:hover { background: var(--border); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: rgba(231, 76, 60, 0.12); color: var(--primary); border: 1px solid rgba(231, 76, 60, 0.3); }
.btn-danger:hover { background: rgba(231, 76, 60, 0.22); }
.btn-large { padding: 11px 22px; font-size: 14px; }

/* ── Upload Zone ── */
.upload-zone {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  transition: background 0.2s;
}

.upload-zone.drag-over { background: rgba(231, 76, 60, 0.05); }

.upload-content { text-align: center; max-width: 400px; }
.upload-icon { color: var(--primary); margin-bottom: 20px; opacity: 0.8; }
.upload-content h2 { font-size: 20px; font-weight: 600; margin-bottom: 8px; }
.upload-content p { color: var(--text-muted); margin-bottom: 24px; font-size: 14px; line-height: 1.6; }

/* ── Editor Layout (왼쪽 목록 + 오른쪽 미리보기) ── */
.editor-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* 왼쪽 페이지 목록 패널 */
.page-list-panel {
  width: 260px;
  min-width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.btn-add-more {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
}

.btn-add-more:hover { color: var(--primary); border-color: var(--primary); }

.page-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.page-list::-webkit-scrollbar { width: 5px; }
.page-list::-webkit-scrollbar-track { background: transparent; }
.page-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* 페이지 목록 아이템 */
.page-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.page-list-item:hover {
  background: var(--surface2);
  border-color: var(--border);
}

.page-list-item.active {
  background: var(--selected);
  border-color: var(--selected-border);
}

.page-list-item.sortable-ghost { opacity: 0.25; }
.page-list-item.sortable-chosen { background: var(--surface2); box-shadow: var(--shadow); }

.page-list-drag {
  color: var(--text-muted);
  cursor: grab;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
  padding: 2px;
}

.page-list-item:hover .page-list-drag { opacity: 1; }

/* 썸네일 */
.page-list-thumb {
  width: 48px;
  min-width: 48px;
  height: 64px;
  background: #fff;
  border-radius: 3px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}

.page-list-thumb canvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
}

/* 페이지 정보 */
.page-list-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.page-list-num {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

.page-list-file {
  font-size: 10px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-list-rot {
  font-size: 10px;
  color: var(--primary);
  background: rgba(231, 76, 60, 0.12);
  padding: 1px 5px;
  border-radius: 3px;
  align-self: flex-start;
}

/* 액션 버튼 */
.page-list-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.page-list-item:hover .page-list-actions { opacity: 1; }

.page-action-btn {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 11px;
  transition: all 0.15s;
}

.page-action-btn:hover { background: var(--primary); color: white; border-color: var(--primary); }
.page-action-del:hover { background: #c0392b !important; }

/* ── 오른쪽 미리보기 패널 ── */
.preview-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  min-width: 0;
}

.preview-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.preview-nav-btn {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text);
  transition: all 0.15s;
}

.preview-nav-btn:hover:not(:disabled) {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.preview-nav-btn:disabled { opacity: 0.3; cursor: default; }

.preview-page-info {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  min-width: 70px;
  text-align: center;
}

/* 미리보기 캔버스 영역 */
.preview-canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
}

#previewCanvas {
  max-width: 100%;
  max-height: 100%;
  display: block;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  border-radius: 3px;
  background: white;
}

/* 미리보기 파일 정보 */
.preview-file-info {
  padding: 9px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  flex-shrink: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── 병합 탭 ── */
.merge-container { padding: 36px; max-width: 680px; margin: 0 auto; }
.merge-container h2 { font-size: 22px; margin-bottom: 8px; }
.merge-desc { color: var(--text-muted); margin-bottom: 24px; font-size: 14px; }

.merge-upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
  margin-bottom: 20px;
}

.merge-upload-zone:hover { border-color: var(--primary); color: var(--primary); background: rgba(231, 76, 60, 0.05); }
.merge-upload-zone svg { margin-bottom: 8px; }
.merge-upload-zone p { font-size: 14px; }

.merge-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }

.merge-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: grab;
  transition: all 0.2s;
}

.merge-item:hover { border-color: var(--text-muted); }
.merge-item.sortable-ghost { opacity: 0.3; }
.merge-item.sortable-chosen { box-shadow: var(--shadow); cursor: grabbing; }

.merge-drag-handle { color: var(--text-muted); cursor: grab; }
.merge-item-name { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.merge-item-index { font-size: 12px; color: var(--text-muted); background: var(--surface2); padding: 2px 8px; border-radius: 12px; }

.merge-item-remove {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  border-radius: 4px;
  transition: all 0.15s;
}

.merge-item-remove:hover { color: var(--primary); background: rgba(231, 76, 60, 0.1); }
.merge-actions { display: flex; gap: 12px; justify-content: flex-end; }

/* ── Loading ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.loading-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 48px;
  text-align: center;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 14px;
}

@keyframes spin { to { transform: rotate(360deg); } }
.loading-box p { color: var(--text-muted); font-size: 13px; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 11px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 2000;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s;
  pointer-events: none;
  max-width: 400px;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { border-color: #27ae60; color: #2ecc71; }
.toast.error { border-color: var(--primary); color: #ff6b6b; }
.toast.info { border-color: #3498db; color: #74b9ff; }
