:root {
  --color-primary:        #000000;
  --color-primary-hover:  #1c1c1c;
  --color-primary-muted:  #333333;
  --color-link:           #286df8;
  --color-link-hover:     #3363c3;
  --color-bg:             #ffffff;
  --color-bg-01:          #fafafa;
  --color-bg-02:          #f0f0f0;
  --color-bg-03:          #e6e6e6;
  --color-text:           rgba(0,0,0,0.90);
  --color-text-secondary: rgba(0,0,0,0.75);
  --color-text-muted:     rgba(0,0,0,0.55);
  --color-border:         #e6e6e6;
  --color-border-strong:  #cccccc;
  --color-success:        #00a43f;
  --color-info:           #286df8;
  --color-warning:        #ec5b13;
  --color-danger:         #dc2626;
  --control-h:     32px;
  --control-h-sm:  28px;
  --control-px:    0.8rem;
  --control-px-sm: 0.6rem;
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --shadow-01: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-02: 0 2px 8px rgba(0,0,0,0.10);
  --shadow-03: 0 4px 16px rgba(0,0,0,0.20);
  --font-sans: "Hanken Grotesk", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "DM Mono", "SF Mono", Monaco, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-link); text-decoration: none; }
a:hover { color: var(--color-link-hover); }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: var(--control-h);
  padding: 0 1rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
summary.btn { display: inline-flex; list-style: none; }
summary.btn::-webkit-details-marker { display: none; }
summary.btn::marker { content: ""; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-ghost { color: var(--color-text-secondary); border: 1px solid var(--color-border); background: #fff; }
.btn-ghost:hover { background: var(--color-bg-01); border-color: var(--color-border-strong); }
.btn-block { width: 100%; justify-content: center; }

.input {
  width: 100%;
  height: var(--control-h);
  padding: 0 var(--control-px);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.2;
  color: var(--color-text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 0.65rem var(--control-px); }
select.input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
}
.input:focus {
  outline: none;
  border-color: var(--color-primary-muted);
  box-shadow: 0 0 0 3px rgba(0,0,0,0.06);
}

.field { margin-bottom: 1rem; }
.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: 0.35rem;
}

/* ---- Login ---- */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--color-bg-01);
  padding: 1.5rem;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-02);
  padding: 2.25rem 2rem;
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.75rem;
}
.login-brand .mark {
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 800; font-size: 1.1rem;
}
.login-brand .name { font-size: 1.25rem; font-weight: 800; letter-spacing: -0.02em; }
.login-card h1 { font-size: 1.05rem; font-weight: 700; margin-bottom: 0.25rem; }
.login-card .sub { color: var(--color-text-muted); font-size: 0.85rem; margin-bottom: 1.5rem; }
.alert {
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.alert-error { background: #fef2f2; color: var(--color-danger); border: 1px solid #fecaca; }

/* ---- App-Shell ---- */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 320px;
  flex-shrink: 0;
  background: var(--color-bg-01);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
}
.sidebar-head {
  height: 56px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0 1.1rem;
  border-bottom: 1px solid var(--color-border);
}
.sidebar-head .mark {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  background: var(--color-primary);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 800;
}
.sidebar-head .name { font-weight: 800; letter-spacing: -0.02em; }
.sidebar-tools {
  display: flex; flex-wrap: wrap; gap: 0.4rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
}
.sidebar-tools .btn { flex: 1 1 auto; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.tree { flex: 1; overflow-y: auto; padding: 0.5rem; }

.node { user-select: none; }
.node-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  color: var(--color-text-secondary);
  cursor: pointer;
}
.node-row:hover { background: var(--color-bg-02); }
.node-row.active { background: var(--color-bg-03); color: var(--color-text); }
.node-row.drop-target { box-shadow: inset 0 0 0 2px var(--color-link); }
.node-row .twisty { width: 14px; display: inline-flex; align-items: center; justify-content: center; color: var(--color-text-muted); flex: none; }
.node-row .twisty svg { width: 12px; height: 12px; transition: transform 0.12s ease; }
.node-row.open .twisty svg { transform: rotate(90deg); }
.node-row .icon { width: 16px; display: inline-flex; align-items: center; justify-content: center; color: var(--color-text-secondary); flex: none; }
.node-row .icon svg { width: 16px; height: 16px; }
.node-row .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-row .dept-bubble {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
  background: var(--bubble, var(--color-border-strong));
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}
.node-children { margin-left: 0.9rem; }
.node-row.dragging { opacity: 0.45; }
.node-row .share-badge {
  flex: none;
  width: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  color: var(--color-text-secondary);
}

.sidebar-foot {
  border-top: 1px solid var(--color-border);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}
.sidebar-foot a {
  color: var(--color-text-secondary);
  font-weight: 400;
  text-decoration: underline;
}
.sidebar-foot a:hover { color: var(--color-text); }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: 56px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1.5rem;
}
.greet {
  font-weight: 700;
  font-size: 1.02rem;
  white-space: nowrap;
}
.search-form {
  flex: 1;
  max-width: 560px;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.search-form .search {
  flex: 1;
  max-width: none;
}
.search-btn { flex: none; }
.content { flex: 1; overflow-y: auto; padding: 2rem; }
.content .empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  gap: 0.5rem;
}

/* ---- Kontextmenü ---- */
.ctx-menu {
  position: fixed;
  z-index: 1000;
  min-width: 170px;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-03);
  padding: 0.35rem;
  display: none;
}
.ctx-menu.open { display: block; }
.ctx-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  text-align: left;
}
.ctx-item:hover { background: var(--color-bg-02); color: var(--color-text); }
.ctx-item.current { font-weight: 700; color: var(--color-text); }
.ctx-item.current::after { content: '·'; margin-left: auto; }
.ctx-item.danger:hover { background: #fef2f2; color: var(--color-danger); }
.ctx-sep { height: 1px; background: var(--color-border); margin: 0.35rem 0.2rem; }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1100;
}
.modal-backdrop.open { display: flex; }
.modal {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-03);
  padding: 1.5rem;
}
.modal h2 { font-size: 1.05rem; margin-bottom: 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.25rem; }

/* ---- Drop-Zone für Upload ---- */
.app.drag-over::after {
  content: "Dateien hier ablegen";
  position: fixed; inset: 0;
  background: rgba(40,109,248,0.06);
  border: 3px dashed var(--color-link);
  display: grid; place-items: center;
  font-weight: 700; font-size: 1.5rem;
  color: var(--color-link);
  z-index: 1200;
  pointer-events: none;
}

.alert-ok { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

.account-card { max-width: 520px; }
.account-card h2 { font-size: 0.95rem; font-weight: 700; margin: 0 0 0.6rem; }
.account-section { margin-top: 1.25rem; padding-top: 1.25rem; border-top: 1px solid var(--color-border); }
.account-status { color: var(--color-text-muted); font-size: 0.85rem; margin-bottom: 1rem; }
.account-status.on { color: #15803d; }
.account-secret { font-size: 0.8rem; color: var(--color-text-muted); margin: 0.75rem 0 1rem; }
.account-secret code { font-family: "DM Mono", monospace; letter-spacing: 0.05em; color: var(--color-text); }
.qr { display: flex; justify-content: center; margin: 0.5rem 0; }
.qr canvas { border-radius: var(--radius-md); }
.confirm-form { margin-top: 0.5rem; }
.account-foot { display: flex; justify-content: space-between; margin-top: 1.75rem; padding-top: 1rem; border-top: 1px solid var(--color-border); font-size: 0.85rem; }
.account-foot a { color: var(--color-text-muted); text-decoration: none; }
.account-foot a:hover { color: var(--color-text); }
.btn-ghost.danger { color: var(--color-danger); border-color: #fecaca; }
.btn-ghost.danger:hover { background: #fef2f2; }

/* ── Inline-Icons ───────────────────────────────────────── */
.ic { width: 16px; height: 16px; flex: none; }
.ic-lg { width: 40px; height: 40px; flex: none; color: var(--color-border-strong); }
.empty svg.ic-lg { margin-bottom: 0.75rem; }

/* ── Formular-Helfer ────────────────────────────────────── */
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
@media (max-width: 480px) { .field-row { grid-template-columns: 1fr; } }
.login-hint {
  margin-top: 1rem;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  text-align: center;
}

/* ── Verwaltung (admin.php) ─────────────────────────────── */
.admin-body { min-height: 100%; background: var(--color-bg-01); }
.admin-top {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.5rem;
  height: 56px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}
.admin-brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; }
.admin-brand .mark {
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--color-primary); color: #fff;
  border-radius: var(--radius-sm); font-weight: 800; font-size: 0.85rem;
}
.admin-nav { display: flex; gap: 0.25rem; margin-left: auto; }
.admin-nav a {
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  font-size: 0.9rem; font-weight: 500;
}
.admin-nav a:hover { background: var(--color-bg-02); color: var(--color-text); }
.admin-nav a.active { background: var(--color-bg-03); color: var(--color-text); }

.admin-main { max-width: 980px; margin: 0 auto; padding: 1.75rem 1.5rem 4rem; }
.admin-panel {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.admin-panel > h2 { font-size: 1.1rem; margin-bottom: 0.25rem; }
.panel-sub { color: var(--color-text-muted); font-size: 0.85rem; margin-bottom: 1.25rem; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.admin-table th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  font-weight: 600;
  padding: 0 0.6rem 0.6rem;
  border-bottom: 1px solid var(--color-border);
}
.admin-table td {
  padding: 0.7rem 0.6rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.users-table td { vertical-align: top; }
.users-table th:nth-child(4), .users-table td:nth-child(4) { text-align: center; }

.u-name { font-weight: 600; }
.u-meta { color: var(--color-text-muted); font-size: 0.8rem; margin-top: 0.15rem; }
.mono { font-family: var(--font-mono); font-size: 0.85rem; }

.badge {
  display: inline-block;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  background: var(--color-bg-02);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}
.badge.admin { background: #000; color: #fff; border-color: #000; }
.badge.editor { background: var(--color-bg-03); }

.checks { display: flex; flex-wrap: wrap; gap: 0.4rem 0.9rem; }
.check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}
.check input { accent-color: var(--color-primary); }

.inline-form { display: inline-flex; align-items: center; gap: 0.4rem; }
.input-sm {
  height: var(--control-h-sm);
  padding: 0 var(--control-px-sm);
  font-size: 0.85rem;
  line-height: 1.2;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  font-family: inherit;
  color: var(--color-text);
  background: #fff;
}
.input-sm:focus { outline: none; border-color: var(--color-primary); }
select.input-sm {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 1.8rem;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
}

.btn-sm { height: var(--control-h-sm); padding: 0 0.7rem; font-size: 0.82rem; }

.row-actions { text-align: right; white-space: nowrap; }
.add-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}
.add-row .dept-name { flex: 1; min-width: 11rem; }
.add-user { margin-top: 1.25rem; }
.new-user-form {
  margin-top: 0.75rem;
  padding: 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-01);
}
.new-user-form .field-row { margin-bottom: 1rem; }
.new-user-form .field { margin-bottom: 0; }
.new-user-form > .field { margin-bottom: 1rem; }
.new-user-form button[type="submit"] { margin-top: 0.5rem; }

.color-bubble {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex: none;
  background: var(--bubble, var(--color-border-strong));
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08);
}

.color-dd { position: relative; flex: none; }
.color-dd > summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: var(--control-h-sm);
  padding: 0 0.5rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: #fff;
  cursor: pointer;
}
.color-dd > summary::-webkit-details-marker { display: none; }
.color-dd > summary::marker { content: ""; }
.color-dd > summary::after {
  content: "";
  width: 14px; height: 14px;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>") no-repeat center;
}
.color-dd .color-bubble { width: 16px; height: 16px; }
.color-dd-body {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
  padding: 0.5rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-02);
}
.color-dd[open] .color-dd-body { display: grid; }
.color-dd.drop-up .color-dd-body { top: auto; bottom: calc(100% + 4px); }
.color-opt { position: relative; display: inline-flex; cursor: pointer; }
.color-opt input { position: absolute; opacity: 0; pointer-events: none; }
.color-opt .color-bubble {
  width: 20px; height: 20px;
  transition: transform .1s, box-shadow .1s;
}
.color-opt:hover .color-bubble { transform: scale(1.12); }
.color-opt:has(input:checked) .color-bubble {
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--color-primary);
}

.dept-list { display: flex; flex-direction: column; gap: 0.5rem; }
.dept-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--color-border);
}
.dept-edit,
.add-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}
.dept-edit { flex: 1; }
.add-row {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}
.dept-edit .dept-name { flex: 1; min-width: 10rem; }
.dept-del { display: inline-flex; margin-left: auto; }
.empty-row td { text-align: center; color: var(--color-text-muted); padding: 1.5rem; }

.stack { display: flex; flex-direction: column; gap: 0.5rem; }

.depts-form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.depts-form .check { margin: 0; }

.row-menu { position: relative; display: inline-block; }
.row-menu > summary { list-style: none; }
.row-menu > summary::-webkit-details-marker { display: none; }
.row-menu > summary::marker { content: ""; }
.row-menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--control-h-sm);
  width: var(--control-h-sm);
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  cursor: pointer;
}
.row-menu-toggle:hover { background: var(--color-bg-01); color: var(--color-text); }
.row-menu-body {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  min-width: 180px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-02);
  padding: 0.3rem;
}
.row-menu[open] .row-menu-body { display: block; }
.row-menu.drop-up .row-menu-body { top: auto; bottom: calc(100% + 4px); }
.row-menu-body > form:not(.stack) > button,
.row-menu-body .ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--color-text);
}
.row-menu-body > form:not(.stack) > button:hover,
.row-menu-body .ctx-item:hover { background: var(--color-bg-02); }
.row-menu-body .stack { display: flex; flex-direction: column; gap: 0.4rem; }
.row-menu-body .stack button { width: 100%; }
.row-menu-body .danger { color: var(--color-danger); }

.key-reveal {
  margin-bottom: 1rem;
  padding: 0.8rem 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-01);
}
.key-reveal-label { font-size: 0.85rem; font-weight: 600; margin-bottom: 0.5rem; }
.key-reveal-row { display: flex; align-items: center; gap: 0.6rem; }
.key-plain {
  flex: 1;
  font-family: 'DM Mono', monospace;
  font-size: 0.85rem;
  word-break: break-all;
  padding: 0.4rem 0.6rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.md-body h1, .md-body h2, .md-body h3, .md-body h4, .md-body h5, .md-body h6 { line-height: 1.25; margin: 1.1em 0 .4em; }
.md-body h1 { font-size: 1.4rem; }
.md-body h2 { font-size: 1.2rem; }
.md-body h3 { font-size: 1.05rem; }
.md-body p { margin: 0 0 .8em; }
.md-body ul, .md-body ol { margin: 0 0 .8em 1.4em; padding: 0; }
.md-body li { margin: .15em 0; }
.md-body img, .md-body .md-img { max-width: 100%; height: auto; border-radius: 8px; margin: .4rem 0; }
.md-body code { background: var(--color-surface-2, #f3f3f3); padding: .1em .35em; border-radius: 4px; font-size: .9em; }
.md-body pre.md-code { background: var(--color-surface-2, #f3f3f3); padding: .7rem .9rem; border-radius: 8px; overflow-x: auto; font-size: .85rem; line-height: 1.45; margin: .6rem 0; }
.md-body pre.md-code code { background: none; padding: 0; font-size: inherit; border-radius: 0; }
.md-body a { color: var(--color-accent, #0a66c2); }
.md-body blockquote {
  border-left: 3px solid var(--color-border-strong, var(--color-border));
  margin: 1rem 0;
  padding: .2rem 0 .2rem 1rem;
  color: var(--color-text-muted);
}
.md-body :first-child { margin-top: 0; }

/* ---- Suchergebnisse ---- */
.results { display: flex; flex-direction: column; gap: 0.75rem; }
.result-item {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow-01);
  overflow: hidden;
}
.result-item.is-clickable { cursor: pointer; transition: border-color .12s, box-shadow .12s, background .12s; }
.result-item.is-clickable:hover {
  border-color: var(--color-border-strong);
  box-shadow: var(--shadow-02);
  background: var(--color-bg-01);
}
.result-thumb {
  float: right;
  max-width: 120px;
  max-height: 90px;
  border-radius: var(--radius-sm);
  margin: 0 0 .5rem .75rem;
  border: 1px solid var(--color-border);
}
.result-head { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; margin-bottom: .25rem; }
.result-title { font-weight: 600; }
.result-score {
  flex: none;
  font-size: .7rem;
  font-weight: 500;
  color: var(--color-text-muted);
  background: var(--color-bg-02);
  border-radius: var(--radius-sm);
  padding: .1rem .4rem;
}
.result-snippet { color: var(--color-text-muted); line-height: 1.5; font-size: .9rem; }

/* ---- Such-Trigger + Overlay ---- */
.topbar .greet { flex: 1; }
.search-trigger {
  flex: none;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: background .12s, color .12s;
}
.search-trigger:hover {
  background: var(--color-bg-02);
  color: var(--color-text);
}
.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  justify-content: center;
  align-items: flex-start;
  padding-top: 14vh;
  background: rgba(0,0,0,0.35);
  backdrop-filter: blur(2px);
}
.search-overlay.open { display: flex; }
.search-box {
  width: min(640px, 90vw);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-03);
  padding: 0.9rem 1.1rem;
}
.search-box-ic { flex: none; color: var(--color-text-muted); }
.search-box .search {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 1.1rem;
  padding: 0;
}
.search-box .search:focus { outline: none; box-shadow: none; border-color: transparent; }


/* ---- Ordner-Inhaltsansicht (Finder-Stil) ---- */
.folder-view-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 1rem; }
.folder-view-head h1 { font-size: 1.5rem; margin: 0; }
.folder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.6rem; }
.folder-card {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  background: var(--color-bg); cursor: pointer;
  transition: border-color .12s, box-shadow .12s;
}
.folder-card:hover { border-color: var(--color-border-strong); box-shadow: var(--shadow-01); }
.folder-card .fc-icon { flex: none; width: 22px; height: 22px; display: grid; place-items: center; color: var(--color-text-secondary); }
.folder-card .fc-icon svg { width: 20px; height: 20px; }
.folder-card .fc-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.92rem; }
.folder-empty { color: var(--color-text-muted); }

.brain-check {
  margin-top: 0.75rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-bg-01);
}
.brain-check.is-ok { border-color: var(--color-success); }
.brain-check.is-warn { border-color: var(--color-warning); }
.brain-check-head { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.brain-check.is-ok .brain-check-head strong { color: var(--color-success); }
.brain-check.is-warn .brain-check-head strong { color: var(--color-warning); }
.brain-check-list { list-style: none; margin: 0.5rem 0 0; padding: 0; display: flex; gap: 1.2rem; flex-wrap: wrap; font-size: 0.85rem; }
.brain-check-table { width: 100%; margin-top: 0.6rem; border-collapse: collapse; font-size: 0.85rem; }
.brain-check-table th, .brain-check-table td { text-align: left; padding: 0.3rem 0.5rem; border-bottom: 1px solid var(--color-border); }
.brain-check-table th { color: var(--color-text-muted); font-weight: 600; }

.storage-bar { position: relative; height: 14px; border-radius: 7px; background: var(--color-border); overflow: hidden; margin: 0.6rem 0 0.3rem; }
.storage-bar-used { position: absolute; inset: 0; background: var(--color-success); }
.storage-bar-orphan { position: absolute; top: 0; bottom: 0; left: 0; background: var(--color-warning); }
.storage-stats { list-style: none; margin: 0.3rem 0 0.6rem; padding: 0; display: flex; gap: 1.2rem; flex-wrap: wrap; font-size: 0.85rem; }


/* ---- Erwähnungen (Bell) ---- */
.mention-wrap { position: relative; display: inline-flex; }
.mention-badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--color-danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
  pointer-events: none;
}
.mention-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.14);
  z-index: 60;
  padding: 4px;
}
.mention-empty { padding: 1rem; color: var(--color-text-muted); font-size: 0.85rem; text-align: center; }
.mention-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 7px;
  padding: 8px 10px;
  cursor: pointer;
}
.mention-item:hover { background: var(--color-bg-02); }
.mention-item.is-unseen { background: #eef4ff; }
.mention-item.is-unseen:hover { background: #e2ecff; }
.mention-item-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.8rem;
  margin-bottom: 2px;
}
.mention-from { font-weight: 700; color: var(--color-text); }
.mention-doc { color: var(--color-text-secondary); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mention-time { color: var(--color-text-muted); font-size: 0.7rem; flex: none; }
.mention-snip { font-size: 0.8rem; color: var(--color-text-secondary); line-height: 1.35; }

/* ---- Kommentare ---- */
.comments { margin-top: 2.5rem; border-top: 1px solid var(--color-border); padding-top: 1.5rem; }
.comments-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 1rem; display: flex; align-items: center; gap: 8px; }
.comments-count {
  font-size: 0.75rem; font-weight: 600;
  background: var(--color-bg-02); color: var(--color-text-secondary);
  border-radius: 999px; padding: 1px 8px;
}
.comment-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 1.25rem; }
.comment-empty { color: var(--color-text-muted); font-size: 0.85rem; }
.comment { background: var(--color-bg-01); border: 1px solid var(--color-border); border-radius: 8px; padding: 10px 12px; }
.comment-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.comment-author { font-weight: 700; font-size: 0.85rem; }
.comment-date { font-size: 0.72rem; color: var(--color-text-muted); flex: 1; }
.comment-del {
  background: none; border: none; cursor: pointer;
  color: var(--color-text-muted); font-size: 1.1rem; line-height: 1;
  padding: 0 4px; flex: none;
}
.comment-del:hover { color: var(--color-danger); }
.comment-body { font-size: 0.9rem; line-height: 1.5; color: var(--color-text); word-wrap: break-word; }
.comment-body .mention { color: var(--color-text-muted); font-weight: 600; }
.comment-body .mention.is-user { color: var(--color-danger); background: #fef2f2; border-radius: 4px; padding: 0 3px; }
.comment-form { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.comment-input {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.9rem;
  color: var(--color-text);
  background: var(--color-bg);
}
.comment-input:focus { outline: none; border-color: var(--color-primary-muted); }
.comment-send { align-self: flex-end; }
.comment-input-wrap { position: relative; width: 100%; }
.mention-suggest {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  margin-bottom: 8px;
  z-index: 30;
  background: var(--color-bg);
  border: 1px solid var(--color-border-strong);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.16);
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
}
.mention-suggest::after {
  content: "";
  position: absolute;
  left: 18px;
  top: 100%;
  width: 12px;
  height: 12px;
  background: var(--color-bg);
  border-right: 1px solid var(--color-border-strong);
  border-bottom: 1px solid var(--color-border-strong);
  transform: translateY(-6px) rotate(45deg);
}
.mention-suggest-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
}
.mention-suggest-item.is-active,
.mention-suggest-item:hover { background: var(--color-bg-02); }
.mention-suggest-item .ms-name { color: var(--color-text); font-weight: 500; }
.mention-suggest-item .ms-user { color: var(--color-text-muted); font-size: 0.8rem; }

/* ---- Markdown-Tabellen ---- */
.md-table { border-collapse: collapse; margin: 1rem 0; width: auto; max-width: 100%; font-size: 0.9rem; }
.md-table th, .md-table td { border: 1px solid var(--color-border); padding: 6px 12px; text-align: left; }
.md-table th { background: var(--color-bg-01); font-weight: 700; }
.md-table tbody tr:nth-child(even) { background: var(--color-bg-01); }

.audit-table { font-size: 0.82rem; }
.audit-table td, .audit-table th { padding: 5px 10px; vertical-align: top; }


/* TipTap / ProseMirror Editor */
.md-body .ProseMirror { outline: none; min-height: 56vh; }
.md-body .ProseMirror:focus { outline: none; }
.md-body .ProseMirror > :first-child { margin-top: 0; }
.md-body .ProseMirror table { border-collapse: collapse; margin: 1rem 0; width: auto; max-width: 100%; font-size: 0.9rem; }
.md-body .ProseMirror th, .md-body .ProseMirror td { border: 1px solid var(--color-border); padding: 6px 12px; text-align: left; min-width: 4em; vertical-align: top; }
.md-body .ProseMirror th { background: var(--color-bg-01); font-weight: 700; }
.md-body .ProseMirror .selectedCell { background: var(--color-surface-2, #eef4fb); }
.md-body .ProseMirror pre { background: var(--color-surface-2, #f3f3f3); padding: .7rem .9rem; border-radius: 8px; overflow-x: auto; font-size: .85rem; line-height: 1.45; }
.md-body .ProseMirror pre code { background: none; padding: 0; }
.md-body .ProseMirror p.is-editor-empty:first-child::before { content: attr(data-placeholder); color: var(--color-text-muted); float: left; height: 0; pointer-events: none; }

/* Editor: Header + Toolbar (sticky, deckend) */
.md-edit-header {
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--color-bg);
  padding: .6rem 0;
  margin-bottom: 0;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
}
.md-edit-header h1 { font-size: 1.5rem; margin: 0; flex: 1; min-width: 12rem; }
.md-toolbar {
  position: sticky;
  top: 3.4rem;
  z-index: 5;
  background: var(--color-bg);
  display: flex;
  flex-wrap: wrap;
  gap: .25rem;
  padding: .4rem 0;
  margin-bottom: .5rem;
  border-bottom: 1px solid var(--color-border);
}
.md-tablebar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: var(--color-bg);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem;
  padding: .4rem .6rem;
  margin-top: .5rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}
.md-tablebar[hidden] { display: none; }
.md-tablebar::before {
  content: "Tabelle";
  font-size: .8rem;
  color: var(--color-text-muted);
  margin-right: .35rem;
}
.md-tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--color-text);
  cursor: pointer;
}
.md-tb-btn:hover { background: var(--color-bg-02); border-color: var(--color-border); }
.md-tb-btn:active { background: var(--color-bg-03); }
.md-tb-btn.is-active { background: #111; border-color: #111; color: #fff; }
.md-tb-btn.is-active:hover { background: #111; border-color: #111; }
.md-tb-btn svg { width: 1.15rem; height: 1.15rem; }
.md-tb-btn:disabled { opacity: .45; cursor: default; }
.md-tb-btn:disabled:hover { background: none; border-color: transparent; }
.md-tb-primary { color: var(--color-link); }
#mdImageBar::before { content: "Bild"; }
.md-tb-btn { font-size: .85rem; font-weight: 600; }
.md-body mark, .md-img-wrap mark, mark {
  background: rgba(255, 214, 0, .38);
  color: inherit;
  padding: 0 .12em;
  border-radius: 3px;
}
mark[data-color="gelb"] { background: rgba(255, 214, 0, .38); }
mark[data-color="gruen"] { background: rgba(46, 204, 113, .35); }
mark[data-color="blau"] { background: rgba(52, 152, 219, .33); }
mark[data-color="rot"] { background: rgba(231, 76, 60, .32); }
.emoji-pop {
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: .1rem;
  width: 268px;
  max-height: 240px;
  overflow-y: auto;
  padding: .4rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
}
.emoji-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
  padding: .25rem;
  border-radius: 6px;
}
.emoji-btn:hover { background: var(--color-bg-02); }
.hl-pop {
  z-index: 50;
  display: flex;
  gap: .35rem;
  align-items: center;
  padding: .4rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
}
.hl-swatch {
  width: 26px;
  height: 26px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
  padding: 0;
}
.hl-swatch:hover { outline: 2px solid var(--color-border); }
.hl-off {
  border: none;
  background: none;
  cursor: pointer;
  font-size: .82rem;
  color: var(--color-text-soft, #888);
  padding: .25rem .4rem;
  border-radius: 6px;
}
.hl-off:hover { background: var(--color-bg-02); }
.md-tb-primary:hover { background: var(--color-bg-02); border-color: var(--color-link); }
.md-body .ProseMirror blockquote {
  border-left: 3px solid var(--color-border-strong, var(--color-border));
  margin: 1rem 0;
  padding: .2rem 0 .2rem 1rem;
  color: var(--color-text-muted);
}
.md-body .ProseMirror a { color: var(--color-link); text-decoration: underline; }
