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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ツールバー */
#toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: #16213e;
  border-bottom: 1px solid #0f3460;
  flex-wrap: wrap;
  min-height: 44px;
}

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

.toolbar-separator {
  width: 1px;
  height: 28px;
  background: #0f3460;
  margin: 0 4px;
}

#toolbar button {
  background: #0f3460;
  color: #e0e0e0;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}

#toolbar button:hover { background: #1a4a8a; }
#toolbar button:disabled { opacity: 0.4; cursor: default; }
#toolbar button.active { background: #e94560; border-color: #e94560; }

.tool-btn.active { background: #e94560 !important; }

#toolbar label {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

#toolbar input[type="number"] {
  background: #0f3460;
  color: #e0e0e0;
  border: 1px solid #1a4a8a;
  border-radius: 3px;
  padding: 2px 4px;
}

#toolbar input[type="color"] {
  width: 28px;
  height: 24px;
  border: none;
  cursor: pointer;
}

#zoom-level {
  font-size: 13px;
  min-width: 48px;
  text-align: center;
}

/* メインレイアウト */
#app {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* サイドバー */
#sidebar {
  width: 160px;
  background: #16213e;
  border-right: 1px solid #0f3460;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  font-size: 13px;
  font-weight: bold;
  border-bottom: 1px solid #0f3460;
}

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

.sidebar-actions button {
  background: #0f3460;
  color: #e0e0e0;
  border: none;
  border-radius: 3px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 14px;
}

.sidebar-actions button:hover { background: #1a4a8a; }

#thumbnail-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.thumbnail {
  position: relative;
  border: 2px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.15s;
}

.thumbnail.active { border-color: #e94560; }
.thumbnail:hover { border-color: #1a4a8a; }

.thumbnail canvas {
  width: 100%;
  display: block;
  border-radius: 2px;
}

.thumbnail .page-number {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 10px;
  color: #fff;
  background: rgba(0,0,0,0.6);
  padding: 1px 4px;
  border-radius: 2px;
}

.thumb-actions {
  position: absolute;
  top: 2px;
  right: 2px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.15s;
}

.thumbnail:hover .thumb-actions { opacity: 1; }

.thumb-btn {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  line-height: 22px;
  text-align: center;
  padding: 0;
  color: #fff;
}

.thumb-rotate { background: rgba(15, 52, 96, 0.85); }
.thumb-rotate:hover { background: #1a4a8a; }
.thumb-delete { background: rgba(233, 69, 96, 0.85); }
.thumb-delete:hover { background: #e94560; }

.thumbnail.dragging { opacity: 0.4; }
.thumbnail.drag-over { border-color: #e94560; border-style: dashed; }

/* キャンバスエリア */
#canvas-area {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
  position: relative;
}

#canvas-container {
  position: relative;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  display: none;
}

#pdf-canvas {
  display: block;
}

#fabric-canvas {
  position: absolute !important;
  top: 0;
  left: 0;
}

/* fabric.jsのキャンバスコンテナ */
#canvas-container .canvas-container {
  position: absolute !important;
  top: 0;
  left: 0;
}

#empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  text-align: center;
  color: #666;
  font-size: 18px;
  line-height: 1.6;
}

/* ドロップオーバーレイ */
#drop-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(233, 69, 96, 0.15);
  border: 3px dashed #e94560;
  z-index: 9999;
  align-items: center;
  justify-content: center;
}

#drop-overlay.visible { display: flex; }

.drop-message {
  font-size: 28px;
  color: #e94560;
  font-weight: bold;
}

/* ダイアログ */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.dialog {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 20px;
  min-width: 360px;
  max-width: 480px;
}

.dialog h3 {
  margin-bottom: 16px;
  color: #e94560;
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog fieldset {
  border: 1px solid #0f3460;
  border-radius: 4px;
  padding: 10px;
}

.dialog legend {
  font-size: 13px;
  color: #e94560;
  padding: 0 4px;
}

.dialog label {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.dialog input[type="text"],
.dialog select {
  background: #0f3460;
  color: #e0e0e0;
  border: 1px solid #1a4a8a;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 13px;
  margin-top: 4px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.dialog-actions button {
  padding: 8px 16px;
  border-radius: 4px;
  border: 1px solid #0f3460;
  background: #0f3460;
  color: #e0e0e0;
  cursor: pointer;
  font-size: 13px;
}

.dialog-actions button:hover { background: #1a4a8a; }
.dialog-actions button.primary { background: #e94560; border-color: #e94560; }
.dialog-actions button.primary:hover { background: #c0374e; }

/* 右クリックメニュー */
.context-menu {
  position: fixed;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 4px;
  z-index: 1001;
  min-width: 140px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border: none;
  background: none;
  color: #e0e0e0;
  cursor: pointer;
  font-size: 13px;
}

.context-menu button:hover { background: #0f3460; }

/* スクロールバー */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #1a1a2e; }
::-webkit-scrollbar-thumb { background: #0f3460; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #1a4a8a; }

/* 目次ダイアログ */
.dialog-wide { max-width: 640px; width: 90vw; }
.toc-entries { max-height: 50vh; overflow-y: auto; margin-bottom: 12px; }
.toc-entry {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-bottom: 1px solid #0f3460;
}
.toc-entry:hover { background: rgba(255,255,255,0.05); }
.toc-entry input[type="checkbox"] { flex-shrink: 0; }
.toc-entry select { background: #16213e; color: #e0e0e0; border: 1px solid #0f3460; border-radius: 4px; padding: 2px 4px; font-size: 12px; }
.toc-entry .toc-text { flex: 1; background: #16213e; color: #e0e0e0; border: 1px solid #0f3460; border-radius: 4px; padding: 4px 8px; font-size: 13px; }
.toc-entry .toc-page { width: 40px; text-align: center; color: #888; font-size: 12px; flex-shrink: 0; }

/* 進捗バー */
.progress-bar { width: 100%; height: 8px; background: #0f3460; border-radius: 4px; margin-top: 12px; overflow: hidden; }
.progress-fill { height: 100%; background: #4cc9f0; border-radius: 4px; transition: width 0.3s ease; width: 0%; }
