/* ─────────────────────────────────────────────────────────────
   PDF-Editor — minimal monochrome
   ───────────────────────────────────────────────────────────── */

:root {
  --bg: #ffffff;
  --bg-soft: #fafafa;
  --canvas-bg: #f4f4f5;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --ink: #18181b;
  --ink-2: #3f3f46;
  --ink-3: #52525b;
  --muted: #71717a;
  --muted-2: #a1a1aa;
  --accent: #18181b;
  --accent-soft: #f4f4f5;
  --focus-ring: rgba(24,24,27,.08);
  --selection: #2563eb;
  --selection-soft: rgba(37,99,235,.08);
  --danger: #b91c1c;
  --shadow: 0 1px 2px 0 rgb(0 0 0 / 0.04), 0 0 0 1px rgb(0 0 0 / 0.06);
  --shadow-lg: 0 16px 32px -8px rgb(0 0 0 / 0.12), 0 0 0 1px rgb(0 0 0 / 0.06);
  --r: 6px;
  --r-sm: 4px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Lato', 'Inter', -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body {
  display: grid;
  grid-template-rows: auto auto 1fr;
  height: 100vh;
  touch-action: manipulation;
}

button {
  font: inherit;
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: transparent;
  color: inherit;
}

input, select, textarea { font-family: inherit; }

/* ─── Top Bar ─────────────────────────────────────────────── */
.topbar {
  background: var(--bg);
  color: var(--ink);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 48px;
  user-select: none;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 2px; }
.topbar-right { gap: 6px; }
.doc-meta { display: flex; align-items: baseline; gap: 8px; margin-left: 6px; min-width: 0; }
.doc-name {
  font-weight: 500; font-size: 13px;
  max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.doc-pages { color: var(--muted); font-size: 12px; }

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

.btn-ghost {
  display: inline-flex;
  align-items: center; justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  font-weight: 500;
  font-size: 12px;
  transition: background .1s;
}
.btn-ghost:hover { background: var(--canvas-bg); color: var(--ink); }

.btn-primary, .btn-secondary {
  display: inline-flex;
  align-items: center; justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px;
  border-radius: var(--r-sm);
  font-weight: 500;
  font-size: 12px;
  transition: background .1s, color .1s;
}
.btn-primary {
  background: var(--ink);
  color: var(--bg);
}
.btn-primary:hover { background: var(--ink-2); }
.btn-secondary {
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--canvas-bg); }

/* ─── Toolbar ─────────────────────────────────────────────── */
.toolbar {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  min-height: 44px;
}
.tg { display: flex; align-items: center; gap: 4px; }
.tg-right { margin-left: auto; }
.tg-label {
  font-size: 11px; color: var(--muted);
  margin-right: 4px;
  white-space: nowrap;
}
.tg-val { font-variant-numeric: tabular-nums; min-width: 18px; text-align: right; color: var(--ink-3); font-size: 11px; }

.tool {
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  transition: background .1s, color .1s;
}
.tool:hover { background: var(--canvas-bg); color: var(--ink); }
.tool.active { background: var(--ink); color: var(--bg); }

.btn-icon {
  height: 30px; min-width: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  padding: 0 8px;
  font-size: 13px;
  transition: background .1s;
}
.btn-icon:hover { background: var(--canvas-bg); color: var(--ink); }
.btn-icon-sm {
  width: 24px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  color: var(--muted);
  font-size: 14px;
}
.btn-icon-sm:hover { background: var(--canvas-bg); color: var(--ink); }

.btn-toggle {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--ink-2);
  font-size: 12px;
}
.btn-toggle:hover { background: var(--canvas-bg); }
.btn-toggle.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.swatches { display: flex; align-items: center; gap: 3px; }
.swatch {
  width: 16px; height: 16px;
  border-radius: 3px;
  background: var(--c);
  position: relative;
  transition: transform .08s;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12);
}
.swatch:hover { transform: scale(1.15); }
.swatch.active { box-shadow: inset 0 0 0 1px rgba(0,0,0,.12), 0 0 0 2px var(--bg), 0 0 0 3px var(--ink); }
#custom-color {
  width: 22px; height: 22px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: none;
  cursor: pointer;
  margin-left: 2px;
}
#custom-color::-webkit-color-swatch { border: none; border-radius: 2px; }
#custom-color::-webkit-color-swatch-wrapper { padding: 0; }
#custom-color::-moz-color-swatch { border: none; border-radius: 2px; }

.slider {
  -webkit-appearance: none; appearance: none;
  width: 80px; height: 2px;
  background: var(--border-strong);
  border-radius: 1px;
  outline: none;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 12px; height: 12px;
  background: var(--ink);
  border-radius: 50%;
  cursor: pointer;
}
.slider::-moz-range-thumb {
  width: 12px; height: 12px;
  background: var(--ink);
  border: none; border-radius: 50%;
  cursor: pointer;
}

.select-input, .num-input {
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg);
  font-size: 12px;
  color: var(--ink);
  outline: none;
  transition: border-color .1s, box-shadow .1s;
}
.select-input:focus, .num-input:focus, .select-input:hover, .num-input:hover {
  border-color: var(--border-strong);
}
.select-input:focus, .num-input:focus { box-shadow: 0 0 0 3px var(--focus-ring); }
.num-input { width: 54px; }
.select-input { min-width: 120px; }

.zoom-label {
  font-variant-numeric: tabular-nums;
  min-width: 38px; text-align: center;
  color: var(--ink-2);
  font-size: 12px;
}

/* ─── Workspace ───────────────────────────────────────────── */
.workspace {
  display: grid;
  grid-template-columns: 180px 1fr 260px;
  overflow: hidden;
}
.workspace.no-sidebar { grid-template-columns: 0 1fr 260px; }
.workspace.no-props { grid-template-columns: 180px 1fr 0; }
.workspace.no-sidebar.no-props { grid-template-columns: 0 1fr 0; }

/* ─── Sidebar (Pages) ─────────────────────────────────────── */
.sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.muted { color: var(--muted-2); font-weight: 400; font-size: 11px; text-transform: none; letter-spacing: 0; }
.thumbs { padding: 4px 10px 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.thumb {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  position: relative;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  transition: border-color .1s;
}
.thumb:hover { border-color: var(--border-strong); }
.thumb.active { border-color: var(--ink); }
.thumb.dragging { opacity: .35; }
.thumb canvas { display: block; width: 100%; height: auto; }
.thumb-label {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,.4));
  color: var(--bg);
  font-size: 10px; font-weight: 500;
  text-align: center;
  padding: 10px 4px 3px;
  letter-spacing: .02em;
}
.thumb-actions {
  position: absolute; top: 4px; right: 4px;
  display: flex; gap: 1px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 1px;
  opacity: 0;
  transition: opacity .1s;
}
.thumb:hover .thumb-actions { opacity: 1; }
.thumb-actions button {
  width: 20px; height: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 2px;
  color: var(--ink-3);
}
.thumb-actions button:hover { background: var(--canvas-bg); color: var(--ink); }

/* ─── Canvas Area ─────────────────────────────────────────── */
.canvas-area {
  overflow: auto;
  background: var(--canvas-bg);
  position: relative;
}
.pages-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 20px;
  min-height: 100%;
}
.page-wrapper {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: visible;
}
.page-wrapper.deleted { display: none; }
.page-wrapper canvas { display: block; }
.page-wrapper .pdf-canvas { position: absolute; inset: 0; }
.page-wrapper .ann-canvas {
  position: relative;
  z-index: 2;
  touch-action: none;
}
.page-wrapper.tool-select .ann-canvas { cursor: default; }
.page-wrapper.tool-text .ann-canvas { cursor: text; }
.page-wrapper.tool-signature .ann-canvas,
.page-wrapper.tool-pen .ann-canvas,
.page-wrapper.tool-highlight .ann-canvas,
.page-wrapper.tool-rect .ann-canvas,
.page-wrapper.tool-cut .ann-canvas,
.page-wrapper.tool-crop .ann-canvas,
.page-wrapper.tool-extract .ann-canvas { cursor: crosshair; }

/* Extract-Aktionsleiste */
.extract-bar {
  position: fixed;
  z-index: 60;
  display: none;
  gap: 4px;
  padding: 5px;
  background: var(--ink, #18181b);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.28);
}
.extract-bar.open { display: flex; }
.extract-bar button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 11px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: #fff;
  font: 600 13px/1 'Lato', 'Inter', sans-serif;
  cursor: pointer;
}
.extract-bar button:hover { background: rgba(255,255,255,.16); }
.extract-bar .ex-close { padding: 7px 9px; opacity: .75; }

/* Word-Button im Ladezustand */
#btn-word.busy { opacity: .6; cursor: progress; }

/* Welcome */
.welcome {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 5;
}
.welcome.hidden { display: none; }
.welcome-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 32px;
  text-align: center;
  max-width: 420px;
}
.welcome-icon {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: 44px; height: 44px;
  color: var(--ink-3);
  margin-bottom: 12px;
}
.welcome-icon svg { width: 32px; height: 32px; }
.welcome h2 { margin: 0 0 4px; font-size: 16px; font-weight: 600; color: var(--ink); }
.welcome p { margin: 0; color: var(--muted); font-size: 13px; }
.welcome .hint { font-size: 11px; color: var(--muted-2); margin-top: 16px; line-height: 1.5; }
.welcome-actions {
  display: flex; gap: 6px; justify-content: center;
  margin-top: 16px;
  flex-wrap: wrap;
}
.drop-active .welcome-card { border-color: var(--ink); }

/* ─── Properties Panel ────────────────────────────────────── */
.props {
  background: var(--bg-soft);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.props-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px;
  font-weight: 500;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.props-body { overflow-y: auto; padding: 4px 14px 16px; flex: 1; }
.props-empty {
  text-align: center;
  color: var(--muted-2);
  padding: 32px 16px;
}
.props-empty svg { color: var(--border-strong); }
.props-empty p { font-size: 12px; margin-top: 8px; }

.prop-row { margin-bottom: 12px; }
.prop-row > label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}
.prop-row input[type=text], .prop-row input[type=number], .prop-row textarea, .prop-row select {
  width: 100%;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg);
  font-size: 12px;
  outline: none;
  transition: border-color .1s, box-shadow .1s;
}
.prop-row input[type=color] {
  width: 100%;
  height: 28px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg);
  cursor: pointer;
}
.prop-row input:focus, .prop-row textarea:focus, .prop-row select:focus {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.prop-row textarea { height: auto; min-height: 56px; padding: 6px 8px; resize: vertical; }
.prop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.prop-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.btn-danger {
  background: var(--bg); color: var(--danger);
  height: 28px; padding: 0 12px;
  border-radius: var(--r-sm);
  font-weight: 500; font-size: 12px;
  border: 1px solid var(--border);
}
.btn-danger:hover { background: #fef2f2; border-color: #fecaca; }

.prop-type-badge {
  display: inline-block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin: 8px 0 14px;
}

/* ─── Modals ──────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(24, 24, 27, .35);
  display: none;
  align-items: center; justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal.open { display: flex; }
.modal-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px 20px;
  max-width: 460px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  box-shadow: var(--shadow-lg);
}
.modal-card.modal-wide { max-width: 880px; }
.modal-card h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.modal-hint { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.modal-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 16px; }

#sig-canvas {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  width: 100%;
  height: 220px;
  max-width: 560px;
  display: block;
  margin: 0 auto;
  touch-action: none;
}

.form-row { margin-bottom: 12px; }
.form-row-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row label {
  display: block; font-size: 11px; color: var(--muted);
  margin-bottom: 4px;
}
.form-row input, .form-row select, .form-row textarea {
  width: 100%;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg);
  font-size: 13px;
  outline: none;
}
.form-row textarea { height: auto; min-height: 60px; padding: 6px 8px; resize: vertical; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

/* List Modal */
.list-controls { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.list-controls input, .list-controls select {
  padding: 0 8px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg);
  font-size: 12px;
}
.list-controls input { flex: 1; min-width: 200px; }
.list-table table { width: 100%; border-collapse: collapse; }
.list-table th, .list-table td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); font-size: 12px; }
.list-table th { color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.list-table tbody tr { transition: background .1s; }
.list-table tbody tr:hover { background: var(--bg-soft); cursor: pointer; }
.list-table .row-actions { white-space: nowrap; text-align: right; }
.list-table .row-actions button {
  padding: 0 8px;
  height: 24px;
  font-size: 11px;
  margin-left: 4px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--bg);
  color: var(--ink-2);
}
.list-table .row-actions button:hover { background: var(--canvas-bg); }
.list-table .row-actions button.danger { color: var(--danger); border-color: #fecaca; }
.list-table .row-actions button.danger:hover { background: #fef2f2; }
.list-empty { padding: 40px; text-align: center; color: var(--muted); font-size: 13px; }

/* ─── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(40px);
  background: var(--ink);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: transform .2s, opacity .2s;
  z-index: 300;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--ink); }
.toast.warn { background: var(--ink); }

/* ─── Text-Edit Input Overlay ─────────────────────────────── */
.text-input-overlay {
  position: absolute;
  z-index: 10;
  background: var(--bg);
  border: 1px solid var(--selection);
  padding: 2px 4px;
  font-family: inherit;
  outline: none;
  border-radius: 2px;
  min-width: 80px;
  box-shadow: 0 0 0 3px var(--selection-soft);
}

/* ─── Drag Overlay ────────────────────────────────────────── */
.drop-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,.85);
  border: 2px dashed var(--ink);
  display: none;
  align-items: center; justify-content: center;
  z-index: 250;
  pointer-events: none;
}
body.drag-over .drop-overlay { display: flex; }
.drop-overlay > div {
  padding: 32px 48px;
  text-align: center;
  color: var(--ink);
}
.drop-overlay p { margin: 12px 0 0; font-weight: 500; font-size: 14px; }

/* ─── Responsive ──────────────────────────────────────────── */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 160px 1fr 0; }
  .workspace.show-props { grid-template-columns: 0 1fr 260px; }
  .props { display: none; }
  .workspace.show-props .props { display: flex; }
  .workspace.show-props .sidebar { display: none; }
}
@media (max-width: 720px) {
  .topbar { padding: 0 6px; }
  .doc-name { max-width: 30vw; font-size: 12px; }
  .doc-pages { font-size: 10px; }
  .toolbar { padding: 4px 6px; gap: 8px; }
  .tg-label { display: none; }
  .btn-primary span, .btn-secondary span { display: none; }
  .workspace { grid-template-columns: 100px 1fr 0; }
  .workspace.show-props { grid-template-columns: 0 1fr 100vw; }
  .props { z-index: 50; }
  .sidebar-header { padding: 8px 10px; }
  .thumbs { padding: 4px 6px 10px; }
}
