:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --text: #1e293b;
  --text-soft: #64748b;
  --border: #e2e8f0;
  --bg: #f1f5f9;
  --card: #ffffff;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: #fff;
  padding: 20px 0 54px;
}

.header-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .5px;
}

.brand-sub {
  margin: 4px 0 0;
  font-size: 12.5px;
  opacity: .85;
}

.install-btn {
  color: #fff !important;
  border-color: rgba(255, 255, 255, .5) !important;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.install-btn:hover {
  background: rgba(255, 255, 255, .12) !important;
}

/* ---------- Tabs ---------- */
.tabs {
  max-width: 860px;
  width: calc(100% - 40px);
  margin: -34px auto 0;
  display: flex;
  gap: 8px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  position: relative;
  z-index: 2;
}

.tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  background: transparent;
  color: var(--text-soft);
  font-size: 14.5px;
  font-weight: 600;
  padding: 12px 8px;
  border-radius: 10px;
  cursor: pointer;
  transition: all .18s ease;
  white-space: nowrap;
}

.tab:hover { color: var(--primary); background: var(--primary-soft); }

.tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, .35);
}

/* ---------- Main / cards ---------- */
.main {
  flex: 1;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

.panel { display: none; }
.panel.active { display: block; animation: fadeIn .25s ease; }

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

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.card h2 {
  margin: 0 0 6px;
  font-size: 19px;
  font-weight: 700;
}

.hint {
  margin: 0 0 20px;
  color: var(--text-soft);
  font-size: 13.5px;
  line-height: 1.6;
}

/* ---------- Dropzone ---------- */
.dropzone {
  border: 2px dashed #c7d2fe;
  border-radius: 12px;
  background: #fafbff;
  padding: 36px 20px;
  text-align: center;
  color: var(--text-soft);
  cursor: pointer;
  transition: all .18s ease;
}

.dropzone svg { color: var(--primary); margin-bottom: 8px; }
.dropzone p { margin: 0; font-size: 14px; }

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

/* ---------- File list (merge) ---------- */
.file-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: grab;
  transition: border-color .15s ease;
}

.file-item.dragging { opacity: .45; }
.file-item.drag-over { border-color: var(--primary); border-style: solid; }

.file-item .file-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 10px;
  font-weight: 800;
}

.file-item .file-meta {
  flex: 1;
  min-width: 0;
}

.file-item .file-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item .file-size {
  font-size: 12px;
  color: var(--text-soft);
}

.file-item .file-order {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-soft);
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-btn:hover { background: var(--primary-soft); color: var(--primary); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- Buttons ---------- */
.actions {
  margin-top: 20px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  padding: 11px 20px;
  cursor: pointer;
  transition: all .18s ease;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 70, 229, .3);
}

.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-ghost {
  background: transparent;
  color: var(--text-soft);
  border: 1px solid var(--border);
}

.btn-ghost:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }

.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-soft);
}

.btn-sm:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-soft); }

.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.btn-image { color: #059669; }
.btn-image:hover { border-color: #10b981; color: #047857; background: #ecfdf5; }

/* 图片页徽标（网格卡片右下角） */
.page-card .page-kind {
  position: absolute;
  right: 5px;
  bottom: 26px;
  background: #10b981;
  color: #fff;
  font-size: 9.5px;
  font-weight: 800;
  border-radius: 4px;
  padding: 1px 4px;
  z-index: 2;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .25);
}

/* ---------- Organize workspace ---------- */
.file-info {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--primary-soft);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px;
  margin-bottom: 16px;
}

.file-info strong { font-weight: 700; color: var(--primary); }

.page-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

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

.toolbar-spacer { flex: 1; }

.page-count {
  font-size: 12.5px;
  color: var(--text-soft);
  font-weight: 600;
}

.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 10px;
}

.page-card {
  position: relative;
  aspect-ratio: 3 / 4;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: grab;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all .15s ease;
  user-select: none;
}

.page-card:hover { border-color: #a5b4fc; }

.page-card.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}

.page-card .page-thumb {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px 7px 0;
  overflow: hidden;
}

.page-card .page-thumb img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, .18);
  transition: transform .25s ease;
  display: block;
}

.page-card .page-thumb img.thumb-loading {
  opacity: .35;
  filter: grayscale(.4);
}

/* 旋转预览：90°/270° 时缩放，避免超出卡片被裁剪 */
.page-card.rot-90 .page-thumb img { transform: rotate(90deg) scale(.68); }
.page-card.rot-180 .page-thumb img { transform: rotate(180deg); }
.page-card.rot-270 .page-thumb img { transform: rotate(270deg) scale(.68); }

/* 无缩略图时的占位文档图标 */
.page-card .page-doc {
  width: 34px;
  height: 44px;
  border-radius: 5px;
  background: linear-gradient(180deg, #eef2ff, #e0e7ff);
  border: 1px solid #c7d2fe;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: transform .25s ease;
}

.page-card .page-doc i {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: #a5b4fc;
}

.page-card.rot-90 .page-doc { transform: rotate(90deg); }
.page-card.rot-180 .page-doc { transform: rotate(180deg); }
.page-card.rot-270 .page-doc { transform: rotate(270deg); }

.page-card .page-num {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-soft);
  padding: 4px 0 6px;
}

.page-card.selected .page-num { color: var(--primary); }

.page-card .rot-badge {
  position: absolute;
  top: 5px;
  right: 5px;
  background: var(--primary);
  color: #fff;
  font-size: 9.5px;
  font-weight: 800;
  border-radius: 5px;
  padding: 1px 4px;
  display: none;
}

.page-card.rot-90 .rot-badge,
.page-card.rot-180 .rot-badge,
.page-card.rot-270 .rot-badge { display: block; }

.page-card .check {
  position: absolute;
  top: 5px;
  left: 5px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 2px solid #cbd5e1;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s ease;
}

.page-card.selected .check {
  background: var(--primary);
  border-color: var(--primary);
}

.page-card.selected .check::after {
  content: "";
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  margin-top: -2px;
}

.page-card .del-mark {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  background: rgba(220, 38, 38, .12);
  border: 2px dashed var(--danger);
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--danger);
  font-size: 11px;
  font-weight: 800;
}

.page-card.marked-del .del-mark { display: flex; }

/* 拖动排序 */
.page-card.dragging { opacity: .4; cursor: grabbing; }
.page-card.drag-over {
  border-color: var(--primary);
  border-style: solid;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .18);
}

/* ---------- Split ---------- */
.split-modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

@media (max-width: 620px) {
  .split-modes { grid-template-columns: 1fr; }
}

.radio-card {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: all .15s ease;
}

.radio-card:hover { border-color: #a5b4fc; }

.radio-card:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.radio-card input { display: none; }

.radio-title { font-size: 14px; font-weight: 700; }
.radio-desc { font-size: 12px; color: var(--text-soft); line-height: 1.5; }
.radio-desc code {
  background: #e0e7ff;
  color: var(--primary);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11.5px;
}

.split-config {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.split-config label { font-size: 13.5px; font-weight: 600; white-space: nowrap; }

.split-config input[type="text"],
.split-config input[type="number"] {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s ease;
}

.split-config input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, .12); }

/* ---------- Footer / toast / loading ---------- */
.app-footer {
  text-align: center;
  padding: 20px;
  color: var(--text-soft);
  font-size: 12.5px;
}

.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #1e293b;
  color: #fff;
  padding: 11px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  opacity: 0;
  transition: all .3s ease;
  z-index: 100;
  max-width: calc(100vw - 40px);
}

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

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

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  backdrop-filter: blur(3px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 99;
  color: #fff;
  font-size: 14.5px;
}

.loading-overlay.hidden { display: none; }

/* ---------- 页面大图预览 ---------- */
.preview-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .62);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 110;
  padding: 24px;
}

.preview-overlay.hidden { display: none; }

.preview-box {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 24px 64px rgba(0, 0, 0, .35);
  width: min(760px, 96vw);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.preview-bar span {
  font-size: 14px;
  font-weight: 700;
  flex: 1;
}

.preview-close:hover { background: var(--danger-soft); color: var(--danger); }

.preview-stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: #f1f5f9;
}

.preview-stage canvas {
  border-radius: 6px;
  box-shadow: 0 8px 32px rgba(15, 23, 42, .25);
  background: #fff;
  max-width: 100%;
}

.preview-stage .spinner {
  border-color: rgba(79, 70, 229, .25);
  border-top-color: var(--primary);
}

.spinner {
  width: 38px;
  height: 38px;
  border: 4px solid rgba(255, 255, 255, .3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

@media (max-width: 560px) {
  .card { padding: 20px 16px; }
  .brand h1 { font-size: 18px; }
  .brand-sub { display: none; }
  .tab { font-size: 13px; gap: 5px; }
  .page-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
}
