:root {
  --blue: #0e7cbf;
  --blue-dark: #0a5f94;
  --bg: #f4f7f9;
  --panel: #ffffff;
  --border: #dde3e8;
  --text: #1c2b33;
  --text-dim: #667580;
  --danger: #d64545;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ---------- Auth screen ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0e7cbf 0%, #0a5f94 100%);
}
.auth-card {
  background: var(--panel);
  padding: 40px;
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.2);
  width: 340px;
}
.auth-card h1 { font-size: 20px; margin: 0 0 4px; }
.auth-subtitle { color: var(--text-dim); margin: 0 0 20px; font-size: 14px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; margin-bottom: 4px; color: var(--text-dim); }
.field input {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--blue); }
.auth-error {
  background: #fdeaea;
  color: var(--danger);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  margin: 0 0 14px;
}
#auth-submit {
  width: 100%;
  padding: 10px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
}
#auth-submit:hover { background: var(--blue-dark); }
.auth-switch { text-align: center; margin-top: 14px; font-size: 13px; color: var(--text-dim); }
.auth-switch a { color: var(--blue); cursor: pointer; text-decoration: none; }

/* ---------- App shell ---------- */
.app-screen { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  height: 56px;
  flex: none;
  background: var(--blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.btn-ghost {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
}
.btn-ghost:hover { background: rgba(255,255,255,0.28); }

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

/* ---------- Sidebar / tree ---------- */
.sidebar {
  width: 300px;
  flex: none;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.btn-icon {
  width: 24px; height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 16px;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
  color: var(--blue);
}
.btn-icon:hover { background: #eef6fb; }

.category-tree { flex: 1; overflow-y: auto; padding: 4px 8px 8px; }

.tree-node { user-select: none; }
.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 6px 6px 4px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  border: 1px solid transparent;
  position: relative;
}
.tree-row:hover { background: #f0f4f7; }
.tree-row.active { background: #e3f1fa; color: var(--blue-dark); font-weight: 600; }
.tree-row.drag-over-into { background: #d6ecfb; border-color: var(--blue); }
.tree-row.drag-over-before { box-shadow: inset 0 2px 0 var(--blue); }
.tree-row.drag-over-after { box-shadow: inset 0 -2px 0 var(--blue); }
.tree-row.dragging { opacity: 0.4; }

.tree-toggle {
  width: 16px; text-align: center; flex: none;
  color: var(--text-dim); font-size: 11px;
}
.tree-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-name-input {
  flex: 1; border: 1px solid var(--blue); border-radius: 4px; padding: 2px 5px; font-size: 14px;
}
.tree-actions { display: flex; gap: 2px; flex: none; opacity: 0.55; }
.tree-row:hover .tree-actions, .tree-row.active .tree-actions { opacity: 1; }
.tree-actions button {
  width: 22px; height: 22px;
  border: none; background: transparent; color: var(--text-dim);
  border-radius: 4px; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.tree-actions button:hover { background: #e0e7eb; color: var(--text); }
.tree-actions .del-btn:hover { background: #fbdada; color: var(--danger); }

.tree-children { margin-left: 18px; border-left: 1px dashed var(--border); padding-left: 4px; }

.root-drop-zone {
  margin: 8px; padding: 10px; text-align: center;
  font-size: 12px; color: var(--text-dim);
  border: 1px dashed var(--border); border-radius: 6px;
  flex: none;
}
.root-drop-zone.drag-over-into { border-color: var(--blue); background: #eef6fb; color: var(--blue-dark); }

/* ---------- Main content ---------- */
.content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.content-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--border); background: var(--panel);
}
.breadcrumb { font-size: 14px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.breadcrumb a { color: var(--blue); text-decoration: none; cursor: pointer; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .current { color: var(--text); font-weight: 600; }

.btn-primary {
  background: var(--blue); color: #fff; border: none;
  padding: 9px 16px; border-radius: 6px; font-size: 13px; font-weight: 600;
}
.btn-primary:hover { background: var(--blue-dark); }
.file-upload-btn { display: inline-flex; align-items: center; }

.dropzone {
  flex: 1; overflow-y: auto; padding: 24px;
  position: relative;
}
.dropzone.drag-active::after {
  content: 'Zet bestand neer om te uploaden';
  position: absolute; inset: 12px;
  border: 2px dashed var(--blue);
  border-radius: 10px;
  background: rgba(14,124,191,0.06);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 600; color: var(--blue-dark);
  pointer-events: none;
}

.manual-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.manual-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  cursor: grab;
  transition: box-shadow .15s, border-color .15s;
}
.manual-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.06); }
.manual-card.dragging { opacity: 0.4; }
.manual-icon { font-size: 26px; margin-bottom: 8px; }
.manual-title {
  font-weight: 600; font-size: 14px; margin-bottom: 4px;
  overflow-wrap: break-word;
}
.manual-title-input { width: 100%; font-size: 14px; font-weight: 600; border: 1px solid var(--blue); border-radius: 4px; padding: 2px 5px; }
.manual-meta { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.manual-actions { display: flex; gap: 8px; }
.manual-actions a, .manual-actions button {
  font-size: 12px; border: none; background: #f0f4f7; color: var(--text);
  padding: 5px 9px; border-radius: 5px; text-decoration: none;
}
.manual-actions a:hover, .manual-actions button:hover { background: #e0e7eb; }
.manual-actions .del-btn:hover { background: #fbdada; color: var(--danger); }

.empty-state {
  text-align: center; color: var(--text-dim); font-size: 14px;
  margin-top: 60px; line-height: 1.6;
}

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: #1c2b33; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 100; box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}
.toast.error { background: var(--danger); }

/* ---------- Confirm modal (replaces window.confirm) ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20,30,36,0.45);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal-card {
  background: var(--panel); border-radius: 10px; padding: 22px;
  width: 360px; max-width: 90vw;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.modal-card p { margin: 0 0 18px; font-size: 14px; line-height: 1.5; color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.modal-actions button {
  padding: 8px 16px; border-radius: 6px; border: none; font-size: 13px; font-weight: 600;
}
.btn-modal-cancel { background: #f0f4f7; color: var(--text); }
.btn-modal-cancel:hover { background: #e0e7eb; }
.btn-modal-danger { background: var(--danger); color: #fff; }
.btn-modal-danger:hover { background: #b83838; }
