:root {
  --brown: #5E4028;
  --brown-dark: #3A281A;
  --brown-soft: #8a6b52;
  --cream: #F6F1EA;
  --card: #ffffff;
  --line: #E3D8CD;
  --ink: #2A2320;
  --muted: #8b7d70;
  --accent: #5E4028;
  --shadow: 0 1px 3px rgba(58,40,26,.08), 0 4px 16px rgba(58,40,26,.06);
  /* Element-Farben */
  --el-Metall: #9aa0a6;
  --el-Wasser: #3f6fb0;
  --el-Holz: #4f8a52;
  --el-Feuer: #c0563f;
  --el-Erde: #b9922e;
  --el-Neutral: #a99a8c;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--cream);
  font-size: 14px;
}
h1, h2, h3 { font-weight: 700; letter-spacing: .2px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--brown-dark); }
.brand img { width: 34px; height: 34px; }
.brand span { font-size: 17px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.sep { width: 1px; height: 24px; background: var(--line); }

.btn {
  border: 1px solid var(--brown); background: var(--brown); color: #fff;
  padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 600;
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--brown); border-color: var(--line); }
.btn.ghost:hover { background: #efe7dd; }
.btn.accent { background: var(--brown-dark); border-color: var(--brown-dark); }

/* ---------- Layout ---------- */
.layout {
  display: grid; grid-template-columns: 380px 1fr; gap: 16px;
  padding: 16px; align-items: start;
  height: calc(100vh - 56px);
}
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; min-height: 0; height: 100%; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; }
.panel-head h2 { margin: 0; font-size: 16px; color: var(--brown-dark); }
.panel-head #search { flex: 1; }

input, select {
  font-family: inherit; font-size: 13px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: #fff;
}
input:focus, select:focus { outline: 2px solid #d8c4b0; border-color: var(--brown-soft); }

/* ---------- Filters ---------- */
.filters { padding: 0 16px 8px; border-bottom: 1px solid var(--line); }
.filter-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.group-row { justify-content: space-between; }
.group-row label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.chip {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.chip.active { background: var(--brown); color: #fff; border-color: var(--brown); }
.chip.el.active { color: #fff; }

/* ---------- Library list ---------- */
.library-list { overflow-y: auto; padding: 10px 12px 20px; flex: 1; }
.lib-group-title { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--brown-soft); margin: 12px 4px 6px; font-weight: 700; }
.ex-card, .board-item {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 10px; margin-bottom: 6px; cursor: grab; user-select: none;
}
.ex-card:hover { border-color: var(--brown-soft); box-shadow: var(--shadow); }
.ex-name { flex: 1; font-weight: 600; font-size: 13px; line-height: 1.2; }
.ex-badges { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.badge { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 5px; white-space: nowrap; }
.badge.fn { background: #efe7dd; color: var(--brown-dark); }
.badge.el { color: #fff; }
.ex-count { font-size: 10px; color: var(--muted); min-width: 22px; text-align: right; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ---------- Board ---------- */
.board-meta { padding: 14px 16px 6px; border-bottom: 1px solid var(--line); }
.meta-titel { width: 100%; font-size: 18px; font-weight: 700; color: var(--brown-dark); border: none; border-bottom: 1px dashed var(--line); border-radius: 0; padding: 4px 2px; margin-bottom: 8px; }
.meta-titel:focus { outline: none; border-bottom-color: var(--brown-soft); }
.meta-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.meta-grid label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); }
.meta-grid label.wide { grid-column: span 2; }
.meta-grid input { font-size: 12px; }

.sections { flex: 1; overflow-y: auto; padding: 12px 16px; }
.section {
  border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px; background: #fdfbf8;
}
.section-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.section-title { flex: 1; font-weight: 700; font-size: 13px; color: var(--brown-dark); border: none; background: transparent; }
.section-title:focus { outline: none; }
.section-x { border: none; background: transparent; color: var(--muted); font-size: 15px; padding: 2px 6px; border-radius: 6px; }
.section-x:hover { background: #efe7dd; color: var(--brown-dark); }
.drop {
  min-height: 44px; padding: 8px; list-style: none; margin: 0;
}
.drop.empty::after { content: "Übungen hierher ziehen"; color: #c3b4a4; font-size: 12px; display: block; text-align: center; padding: 10px; }
.board-item { cursor: grab; }
.board-item .ex-name { font-size: 13px; }
.bi-note { font-size: 11px; color: var(--muted); font-style: italic; }
.bi-x { border: none; background: transparent; color: #c3b4a4; font-size: 14px; padding: 0 4px; }
.bi-x:hover { color: var(--el-Feuer); }
.board-foot { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-top: 1px solid var(--line); }

.sortable-ghost { opacity: .4; }
.sortable-chosen { box-shadow: 0 0 0 2px var(--brown-soft); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(42,35,32,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal[hidden] { display: none !important; }
.modal-card { background: #fff; border-radius: 14px; width: 520px; max-width: 100%; max-height: 86vh; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-card.wide { width: 900px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; color: var(--brown-dark); }
.modal-x { border: none; background: transparent; font-size: 18px; color: var(--muted); }
.modal p { padding: 10px 18px 0; margin: 0; }

.boards-list { overflow-y: auto; padding: 10px 18px 18px; }
.board-row { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 9px; margin-bottom: 8px; }
.board-row .br-main { flex: 1; }
.board-row .br-title { font-weight: 700; }
.board-row .br-sub { font-size: 12px; color: var(--muted); }

/* ---------- Lib table ---------- */
.lib-table-wrap { overflow: auto; padding: 8px 18px 18px; }
table.lib { width: 100%; border-collapse: collapse; font-size: 13px; }
table.lib th { text-align: left; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; padding: 6px 8px; position: sticky; top: 0; background: #fff; }
table.lib td { padding: 5px 8px; border-top: 1px solid var(--line); }
table.lib input, table.lib select { width: 100%; }
table.lib .td-name input { font-weight: 600; }
.conf { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 5px; }
.conf-hoch { background: #e3efe1; color: #3f6b3f; }
.conf-mittel { background: #fbf2dc; color: #8a6d1e; }
.conf-niedrig { background: #f7ded7; color: #a2432e; }
.row-x { border: none; background: transparent; color: #c3b4a4; font-size: 15px; }
.row-x:hover { color: var(--el-Feuer); }

/* ---------- Login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 34px 32px; width: 320px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; text-align: center; }
.login-logo { width: 84px; height: 84px; margin: 0 auto 4px; }
.login-card h1 { margin: 0; font-size: 20px; color: var(--brown-dark); }
.login-card p { margin: 0 0 8px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; text-align: left; font-size: 12px; color: var(--muted); }
.login-card button { margin-top: 6px; border: none; background: var(--brown); color: #fff; padding: 10px; border-radius: 9px; font-weight: 700; }
.login-err { color: var(--el-Feuer); font-size: 13px; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--brown-dark); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 13px; z-index: 100; box-shadow: var(--shadow); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .meta-grid { grid-template-columns: repeat(2, 1fr); }
}
