:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --border: #dde1e6;
  --text: #1c2025;
  --muted: #667080;
  --accent: #2b59d9;
  --accent-text: #ffffff;
  --accent-soft: #e3eafc;
  --danger: #c62828;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.06);
  --radius: 10px;
  --thumb: 170px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --surface: #1e2126;
    --surface-2: #272b31;
    --border: #343941;
    --text: #e6e8eb;
    --muted: #9aa3ae;
    --accent: #6f93ff;
    --accent-text: #0d1430;
    --accent-soft: #233056;
    --danger: #ff6b6b;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.brand svg { stroke: none; color: var(--accent); }
[hidden] { display: none !important; }
code { background: var(--surface-2); padding: 0 4px; border-radius: 4px; font-size: 12px; }

/* Knoppen */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.sm { height: 32px; padding: 0 10px; }
.btn.icon { width: 32px; padding: 0; justify-content: center; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.danger { color: var(--danger); }
.linklike { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  flex: none;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.topbar-actions { display: flex; gap: 8px; }

.layout { flex: 1; display: flex; min-height: 0; }

/* Sidebar */
.sidebar {
  width: 290px; flex: none; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 8px 0 24px;
}
.panel { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.panel h2, .panel summary { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 4px 0 8px; }
.panel summary { cursor: pointer; list-style-position: inside; }
.panel h2 small { font-weight: 500; text-transform: none; letter-spacing: 0; }
.panel label { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--muted); margin: 8px 0; }
.panel label.row, label.row { flex-direction: row; align-items: center; gap: 7px; color: var(--text); font-size: 13.5px; }
.panel input[type=text], .panel input[type=number], .panel select,
dialog input[type=text], dialog input[type=password], dialog input[type=number], dialog select {
  height: 32px; padding: 0 8px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--bg); color: var(--text); font: inherit; width: 100%;
}
.panel input[type=color] { width: 100%; height: 32px; padding: 2px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.hint { font-size: 12px; color: var(--muted); margin: 4px 0; }

.file-list { list-style: none; margin: 6px 0 0; padding: 0; }
.file-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; margin-bottom: 5px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  cursor: grab;
}
.file-list li .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.file-list li .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.file-list li .fpages { font-size: 11.5px; color: var(--muted); }
.file-list li button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px; border-radius: 5px; display: flex; }
.file-list li button:hover { color: var(--danger); background: var(--surface-2); }
.file-list .sortable-ghost { opacity: .4; }

/* Main */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.toolbar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.toolbar .sep, .editor-bar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.toolbar .spacer, .spacer { flex: 1; }
.sel-info { font-size: 13px; color: var(--muted); min-width: 110px; }
.zoom { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.zoom input { width: 110px; }

.dropzone { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; overflow: auto; }
.dz-inner {
  max-width: 620px; width: 100%; text-align: center;
  border: 2px dashed var(--border); border-radius: 18px; padding: 36px 32px;
  background: var(--surface);
}
.dz-icon { width: 54px; height: 54px; color: var(--accent); stroke-width: 1.5; }
.dz-inner h1 { margin: 8px 0 4px; font-size: 24px; }
.dz-inner p { color: var(--muted); margin: 6px 0; }
.features { text-align: left; margin: 20px auto 10px; padding: 0; list-style: none; max-width: 470px; }
.features li { padding: 5px 0 5px 22px; position: relative; color: var(--muted); }
.features li::before { content: ""; position: absolute; left: 4px; top: 12px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.features b { color: var(--text); }
.privacy { font-size: 12px; margin-top: 16px !important; }

.page-grid {
  flex: 1; overflow-y: auto; padding: 20px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--thumb), 1fr));
  gap: 18px; align-content: start;
}
.page-grid:empty { display: none; }
.page {
  position: relative; background: var(--surface); border: 2px solid transparent;
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px 8px 6px;
  cursor: pointer; user-select: none;
}
.page.selected { border-color: var(--accent); background: var(--accent-soft); }
.page .thumb {
  aspect-ratio: 1 / 1.1; display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.page .thumb canvas {
  max-width: 100%; max-height: 100%; background: #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.12);
  transition: transform .2s;
}
.page .thumb .ph { width: 70%; aspect-ratio: 1/1.41; background: var(--surface-2); border-radius: 3px; }
.page .meta { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; }
.page .meta .num { font-weight: 650; }
.page .meta .src { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.page .meta .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.page .badge {
  position: absolute; top: 12px; left: 12px; font-size: 10.5px; font-weight: 600;
  background: var(--accent); color: var(--accent-text); padding: 1px 6px; border-radius: 10px;
}
.page .actions {
  position: absolute; top: 10px; right: 10px; display: flex; gap: 3px;
  opacity: 0; transition: opacity .12s;
}
.page:hover .actions, .page:focus-within .actions { opacity: 1; }
@media (hover: none) { .page .actions { opacity: 1; } }
.page .actions button {
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text); cursor: pointer; padding: 0;
}
.page .actions button:hover { background: var(--surface-2); }
.page .actions button svg { width: 16px; height: 16px; }
.page.sortable-ghost { opacity: .35; }
.page.sortable-chosen { box-shadow: 0 8px 24px rgba(0,0,0,.25); }

.drop-overlay {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 3px dashed var(--accent); border-radius: 12px; margin: 8px; pointer-events: none;
  font-size: 20px; font-weight: 650; color: var(--accent); z-index: 5;
}
.drop-overlay.show { display: flex; }

/* Editor */
.editor { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; background: var(--bg); }
.editor-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px;
  padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.tools { display: flex; gap: 2px; flex-wrap: wrap; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 58px; padding: 5px 6px; border: 1px solid transparent; border-radius: 8px;
  background: none; color: var(--text); font: inherit; font-size: 11px; cursor: pointer;
}
.tool:hover { background: var(--surface-2); }
.tool.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.props { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; flex: 1; }
.props label { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted); }
.props input[type=color] { width: 34px; height: 30px; padding: 2px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); }
.props input[type=number], .props select { height: 30px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); color: var(--text); font: inherit; padding: 0 6px; }
.props input[type=number] { width: 62px; }
.props input[type=range] { width: 80px; }
.editor-actions { display: flex; align-items: center; gap: 4px; }
.page-info { font-size: 13px; min-width: 64px; text-align: center; color: var(--muted); }
.editor-body { flex: 1; overflow: auto; display: flex; padding: 24px; }
.stage-wrap { position: relative; margin: auto; flex: none; }
.stage {
  position: absolute; left: 50%; top: 50%;
  box-shadow: 0 2px 12px rgba(0,0,0,.25); background: #fff;
  touch-action: none;
}
.stage canvas { position: absolute; left: 0; top: 0; }
.stage textarea.text-edit {
  position: absolute; z-index: 3; margin: 0; padding: 0; border: 1px dashed var(--accent);
  background: rgba(255,255,255,.85); outline: none; resize: none; overflow: hidden;
  line-height: 1.2; white-space: pre; min-width: 40px;
}

/* Dialogen */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 20px 22px;
  background: var(--surface); color: var(--text); width: min(480px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
dialog::backdrop { background: rgba(10,14,20,.5); }
dialog h3 { margin: 0 0 12px; font-size: 18px; }
dialog label { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-size: 13px; color: var(--muted); }
dialog label.row { flex-direction: row; color: var(--text); }
dialog .opt { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; margin: 6px 0; cursor: pointer; color: var(--text); flex-direction: row; }
dialog .opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
dialog .opt input[type=radio] { margin-top: 3px; }
dialog .opt small { display: block; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.sig-dialog { width: min(680px, calc(100vw - 32px)); }
#sigCanvas { width: 100%; height: auto; aspect-ratio: 600/220; background: #fff; border: 1px solid var(--border); border-radius: 8px; touch-action: none; cursor: crosshair; }
.saved-sigs { display: flex; gap: 8px; flex-wrap: wrap; }
.saved-sigs:empty { display: none; }
.saved-sig { position: relative; border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: 4px; cursor: pointer; }
.saved-sig img { height: 50px; display: block; }
.saved-sig:hover { border-color: var(--accent); }
.saved-sig .rm { position: absolute; top: -8px; right: -8px; width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 12px; line-height: 1; cursor: pointer; padding: 0; }

/* Busy & toasts */
.busy {
  position: fixed; inset: 0; z-index: 100; background: rgba(10,14,20,.45);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  color: #fff; font-weight: 600;
}
.spinner { width: 42px; height: 42px; 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); } }
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 110; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #222831; color: #fff; padding: 10px 16px; border-radius: 9px; box-shadow: var(--shadow); font-size: 13.5px; max-width: 90vw; animation: fadein .2s; }
.toast.error { background: #b71c1c; }
.toast.ok { background: #1b5e20; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

/* Responsief */
@media (max-width: 860px) {
  .layout { flex-direction: column-reverse; }
  .sidebar { width: auto; max-height: 38vh; border-right: 0; border-top: 1px solid var(--border); }
  .topbar-actions .btn span { display: none; }
  .topbar-actions .btn { padding: 0 10px; }
  .page-grid { padding: 12px; gap: 12px; }
  .tool span { display: none; }
  .tool { min-width: 38px; }
}
