:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #1d4ed8;
  --primary-dark: #1e40af;
  --primary-soft: #dbeafe;
  --success: #15803d;
  --success-soft: #dcfce7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.12);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
h1, h2, h3, h4 { margin: 0 0 0.4em; font-weight: 600; line-height: 1.25; }
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; }

/* ── Layout ─────────────────────────────── */
.app-header {
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px; height: 60px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand .logo { font-size: 22px; }
.header-nav { display: flex; gap: 4px; margin-left: 12px; flex: 1; flex-wrap: wrap; }
.header-nav button {
  background: none; border: none; padding: 8px 14px; border-radius: 8px;
  color: var(--text-muted); font-weight: 500; font-size: 14px; cursor: pointer;
}
.header-nav button:hover { background: var(--surface-2); color: var(--text); }
.header-nav button.active { background: var(--primary-soft); color: var(--primary-dark); }
.header-user { display: flex; align-items: center; gap: 12px; margin-left: auto; }
.header-user .who { text-align: right; line-height: 1.2; }
.header-user .who .name { font-weight: 600; font-size: 14px; }
.header-user .who .role { font-size: 12px; color: var(--text-muted); }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--primary);
  color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 14px;
}

.container { max-width: 1180px; margin: 0 auto; padding: 28px 24px 60px; }
.page-title { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title h1 { font-size: 24px; margin: 0; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }

/* ── Cards / tiles ──────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 20px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; cursor: pointer; box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s, border-color .12s;
}
.tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); border-color: var(--primary); }
.tile .icon { font-size: 34px; }
.tile h3 { margin: 12px 0 6px; font-size: 18px; }
.tile p { margin: 0; color: var(--text-muted); font-size: 14px; }

/* ── Buttons ────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 9px 16px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 500; font-size: 14px;
  cursor: pointer; transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ── Forms ──────────────────────────────── */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 500; font-size: 14px; margin-bottom: 6px; }
.field .req { color: var(--danger); }
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-family: inherit; font-size: 14px; background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; min-height: 84px; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Tables ─────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

/* ── Badges ─────────────────────────────── */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-blue { background: var(--primary-soft); color: var(--primary-dark); }
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-gray { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.badge-amber { background: var(--warning-soft); color: var(--warning); }

/* ── Tabs ───────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.tabs button {
  background: none; border: none; padding: 10px 16px; cursor: pointer; font-size: 14px; font-weight: 500;
  color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Split layout for contract module ───── */
.split { display: grid; grid-template-columns: 380px 1fr; gap: 20px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } .header-user .who { display: none; } }

.list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent;
}
.list-item:hover { background: var(--surface-2); }
.list-item.active { background: var(--primary-soft); border-color: var(--primary); }
.list-item .li-title { font-weight: 600; font-size: 14px; }
.list-item .li-sub { font-size: 12px; color: var(--text-muted); }

/* ── Document preview ───────────────────── */
.doc-preview {
  background: #eef1f6; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; max-height: 70vh; overflow: auto;
}
.doc-preview .docx-wrapper { background: transparent; padding: 0; }
.doc-preview .docx-wrapper > section.docx {
  box-shadow: var(--shadow-lg); margin-bottom: 16px; background: #fff;
}

/* ── Login ──────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(135deg, #eef2ff 0%, #f4f6fb 100%); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 14px;
  box-shadow: var(--shadow-lg); padding: 34px; }
.login-card .brand { justify-content: center; font-size: 22px; margin-bottom: 6px; }
.login-card .sub { text-align: center; color: var(--text-muted); margin-bottom: 24px; font-size: 14px; }

/* ── Modal ──────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: grid; place-items: center;
  z-index: 50; padding: 20px;
}
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 22px; }
.modal-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.close-x { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); line-height: 1; }

/* ── Toast ──────────────────────────────── */
#toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { padding: 13px 18px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500;
  color: #fff; background: var(--text); min-width: 240px; animation: slidein .2s ease; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Misc ───────────────────────────────── */
.empty { text-align: center; padding: 50px 20px; color: var(--text-muted); }
.empty .icon { font-size: 42px; opacity: .5; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--primary-soft); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { display: grid; place-items: center; padding: 60px; }
.divider { height: 1px; background: var(--border); margin: 20px 0; border: 0; }
.flex { display: flex; gap: 12px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 14px; }
.tag-chip { font-family: ui-monospace, monospace; background: var(--surface-2); border: 1px solid var(--border);
  padding: 1px 7px; border-radius: 6px; font-size: 13px; }
.file-drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 26px; text-align: center;
  color: var(--text-muted); cursor: pointer; transition: border-color .12s, background .12s; }
.file-drop:hover, .file-drop.drag { border-color: var(--primary); background: var(--primary-soft); }

/* ══ Modul Organisation & Zuständigkeiten ══════════════════ */
/* Segmentierter Ansichtsumschalter */
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button { border: none; background: none; padding: 7px 14px; border-radius: 8px; font-size: 14px; font-weight: 500;
  color: var(--text-muted); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }

.org-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 22px; }
.search-box { position: relative; flex: 1; min-width: 220px; max-width: 420px; }
.search-box input { padding-left: 36px; }
.search-box .ico { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); opacity: .5; }

/* Avatare */
.av { border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-weight: 600; flex: none;
  background: var(--primary); line-height: 1; }
.av-sm { width: 30px; height: 30px; font-size: 12px; }
.av-md { width: 44px; height: 44px; font-size: 15px; }
.av-lg { width: 60px; height: 60px; font-size: 20px; }

/* Funktions-/Zuständigkeits-Chips */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  font-weight: 500; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.chip.primary { background: var(--success-soft); border-color: transparent; color: var(--success); }
.chip.deputy { background: var(--warning-soft); border-color: transparent; color: var(--warning); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Personen-Kachel */
.person-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.person-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; display: flex; flex-direction: column; gap: 12px; border-top: 3px solid var(--primary); transition: box-shadow .12s, transform .12s; }
.person-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.person-card .ph { display: flex; gap: 12px; align-items: center; }
.person-card .nm { font-weight: 600; font-size: 15px; }
.person-card .ti { font-size: 13px; color: var(--text-muted); }
.person-card .meta { font-size: 13px; color: var(--text-muted); display: flex; flex-direction: column; gap: 3px; }
.person-card .meta a { color: var(--text); }
.card-actions { display: flex; gap: 6px; margin-top: auto; }

/* Zuständigkeiten-Ansicht */
.func-cat { margin-bottom: 26px; }
.func-cat h3 { display: flex; align-items: center; gap: 8px; font-size: 15px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); margin-bottom: 12px; }
.func-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.func-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.func-card .fh { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.func-card .fi { font-size: 26px; line-height: 1; }
.func-card .fn { font-weight: 600; font-size: 16px; }
.func-card .fd { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.resp-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--border); }
.resp-row .who { font-size: 14px; font-weight: 500; }
.resp-row .role-tag { margin-left: auto; }

/* Organigramm – Layout per Flex (Knoten zentriert über Teilbaum),
   Verbindungslinien per SVG, Zoom per CSS-transform + Platzhalter (Sizer). */
.org-scroll { overflow: auto; max-height: 74vh; padding: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); }
.org-sizer { position: relative; }
.org-canvas { position: relative; width: max-content; transform-origin: 0 0; padding: 8px 24px 24px; }
.org-links { position: absolute; top: 0; left: 0; z-index: 1; pointer-events: none; overflow: visible; }
.org-links .org-link { fill: none; stroke: #64748b; stroke-width: 2; stroke-linejoin: round; }
.org-links .disc-link { fill: none; stroke: #d97706; stroke-width: 2.2; stroke-dasharray: 7 5; }
.org-links .disc-arrow-fill { fill: #d97706; }
.org-tree, .org-tree ul { display: flex; justify-content: center; align-items: flex-start; list-style: none; margin: 0; padding: 0; }
.org-tree ul { margin-top: 46px; }                 /* vertikaler Platz für die Verbindungslinie */
.org-tree li { display: flex; flex-direction: column; align-items: center; padding: 0 14px; }
.node-wrap { position: relative; }
.org-node { position: relative; z-index: 2; display: inline-flex; flex-direction: column; align-items: center; gap: 6px; width: 190px; padding: 12px;
  background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--primary); border-radius: 10px;
  box-shadow: var(--shadow); cursor: pointer; transition: box-shadow .12s, transform .12s; }
/* Zoom-Leiste */
.org-zoombar { display: flex; align-items: center; gap: 6px; justify-content: flex-end; margin-bottom: 10px; }
.org-zoombar .zoom-label { min-width: 48px; text-align: center; font-weight: 600; font-size: 13px; color: var(--text-muted); }
/* Legende: Linienmuster */
.legend-line { display: inline-flex; align-items: center; gap: 6px; }
.legend-line .ll { display: inline-block; width: 24px; height: 0; }
.legend-line .ll-solid { border-top: 2.5px solid #64748b; }
.legend-line .ll-dashed { border-top: 2.5px dashed #d97706; }
.org-node:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.org-node .nm { font-weight: 600; font-size: 14px; text-align: center; }
.org-node .ti { font-size: 12px; color: var(--text-muted); text-align: center; }
.org-node .chips { justify-content: center; }
.collapse-btn { position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%); width: 22px; height: 22px;
  border-radius: 50%; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 12px;
  display: grid; place-items: center; z-index: 2; color: var(--text-muted); }
.collapse-btn:hover { border-color: var(--primary); color: var(--primary); }

/* Detail-Zeilen */
.detail-row { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.detail-row .k { width: 130px; color: var(--text-muted); flex: none; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); margin-top: 8px; }

/* ══ Vorgehensweisen (aufklappbar) ═════════════════════════ */
.guidance { margin-bottom: 22px; overflow: hidden; }
.guidance > summary { list-style: none; cursor: pointer; padding: 16px 20px; display: flex; align-items: center; gap: 12px;
  font-weight: 600; font-size: 15px; user-select: none; }
.guidance > summary::-webkit-details-marker { display: none; }
.guidance > summary::before { content: '▸'; color: var(--text-muted); transition: transform .15s; }
.guidance[open] > summary::before { transform: rotate(90deg); }
.guidance > summary .badge { margin-left: auto; }
.guidance-body { padding: 0 20px 18px; }
.guidance-list { display: flex; flex-direction: column; gap: 8px; }
.guidance-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.guidance-item .gi-icon { font-size: 22px; }
.guidance-item .gi-title { font-weight: 600; font-size: 14px; }

/* ══ WorkJoin ══════════════════════════════════════════════ */
.wj-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.wj-stat { display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--primary); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.wj-stat-ic { font-size: 26px; }
.wj-stat-val { font-size: 24px; font-weight: 700; line-height: 1; }
.wj-stat-lbl { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.wj-kanban { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.wj-kanban-col { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.wj-kanban-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; font-weight: 600;
  background: var(--surface); border-top: 3px solid var(--primary); border-bottom: 1px solid var(--border); }
.wj-kanban-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; max-height: 460px; overflow-y: auto; }
.wj-task-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.wj-task-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.wj-task-title { font-weight: 500; font-size: 14px; margin-bottom: 4px; }
.wj-progress-wrap { display: flex; align-items: center; gap: 10px; }
.wj-progress { flex: 1; max-width: 220px; height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.wj-progress-fill { height: 100%; background: var(--primary); transition: width .2s; }
.wj-check-list { display: flex; flex-direction: column; gap: 6px; }
.wj-check-item { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.wj-check-item:hover { border-color: var(--primary); }
.wj-check-item.done .wj-check-title { text-decoration: line-through; color: var(--text-muted); }
.wj-check-item input[type=checkbox] { width: 18px; height: 18px; margin-top: 1px; flex: none; }
.wj-check-title { font-weight: 500; font-size: 14px; margin-bottom: 4px; }

/* ══ Felder-Sortierung (Drag & Drop) ═══════════════════════ */
.fields-table td.drag-cell { white-space: nowrap; width: 1%; }
.drag-handle { cursor: grab; font-size: 16px; color: var(--text-muted); padding: 0 6px; user-select: none; }
.field-row.dragging { opacity: .5; background: var(--primary-soft); }
.field-row { transition: background .1s; }
.fields-table tbody tr:hover .drag-handle { color: var(--primary); }
