:root {
  --bg: #eef0f4;
  --panel: #ffffff;
  --line: #dde1e8;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --danger: #dc2626;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Toolbar */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--accent); margin-right: 4px; }
.group { display: flex; align-items: center; gap: 4px; padding-right: 12px; border-right: 1px solid var(--line); }
.group:last-child, .group.right { border-right: 0; }
.group.right { margin-left: auto; }
.btn {
  appearance: none; border: 1px solid var(--line); background: #fff; color: var(--text);
  padding: 6px 10px; border-radius: 6px; font: inherit; cursor: pointer; white-space: nowrap;
  user-select: none;
}
.btn:hover { background: #f5f6f8; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.tool.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.zoom-label { min-width: 48px; text-align: center; font-variant-numeric: tabular-nums; }
input[type=color] { width: 34px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; }
input[type=range] { width: 80px; }

/* Layout */
.layout { flex: 1; display: flex; min-height: 0; }
.pages {
  width: 170px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.pages-head { display: flex; justify-content: space-between; align-items: center; padding: 10px; font-weight: 600; border-bottom: 1px solid var(--line); }
#pageList { overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 12px; }
.thumb { position: relative; cursor: pointer; border: 2px solid transparent; border-radius: 6px; padding: 4px; background: #f7f8fa; }
.thumb.active { border-color: var(--accent); }
.thumb img { display: block; width: 100%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.thumb .num { display: block; text-align: center; font-size: 12px; color: var(--muted); margin-top: 4px; }
.thumb .del {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; display: none; line-height: 22px; padding: 0;
}
.thumb:hover .del { display: block; }

.workspace { flex: 1; overflow: auto; display: flex; padding: 24px; position: relative; }
.stage { margin: auto; box-shadow: 0 4px 24px rgba(0,0,0,.18); background: #fff; }
.hidden { display: none !important; }
.empty { margin: auto; }
.drop {
  border: 2px dashed #b8bfcc; border-radius: 14px; padding: 60px 70px; text-align: center; color: var(--muted); background: rgba(255,255,255,.6);
}
.drop { display: flex; flex-direction: column; align-items: center; gap: 14px; cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover { border-color: var(--accent); background: #fff; }
.drop p { margin: 0; line-height: 1.6; }
.drop-icon { color: var(--accent); }
.btn.big { font-size: 17px; padding: 12px 26px; border-radius: 10px; font-weight: 600; }
.workspace.dragover .drop, .workspace.dragover .stage { outline: 3px solid var(--accent); }

.status { padding: 6px 12px; background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }

.busy {
  position: fixed; inset: 0; background: rgba(255,255,255,.7); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; z-index: 100; font-weight: 600;
}
.spinner { width: 36px; height: 36px; border: 4px solid #d6d9f5; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 700px) {
  .pages { width: 110px; }
  .group { border-right: 0; padding-right: 0; }
}
.check { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.save-state { font-size: 12px; color: var(--muted); margin-right: 4px; white-space: nowrap; }
.save-state.ok { color: #15803d; }
.save-state.pending { color: #b45309; }
.save-state.err { color: var(--danger); }
