:root {
  --bg: #f6f2ec;
  --surface: #ffffff;
  --surface-2: #efe8de;
  --text: #2a2420;
  --muted: #776c62;
  --border: #ded3c5;
  --accent: #8a5528;
  --accent-text: #ffffff;
  --accent-soft: #f1e2d2;
  --plus: #2f7d4a;
  --plus-soft: #e2f1e6;
  --minus: #b0392f;
  --minus-soft: #f8e3e0;
  --plus-fill: #2e7d4b;
  --minus-fill: #c0392b;
  --warn: #9a6400;
  --warn-soft: #fbefd5;
  --radius: 14px;
  --tabbar-h: 58px;
  --gutter: max(16px, env(safe-area-inset-left));
  --gutter-r: max(16px, env(safe-area-inset-right));
  color-scheme: light;
}
/* Dunkel: automatisch nach Systemeinstellung (außer „Hell“ ist erzwungen) oder fest gewählt. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1815;
    --surface: #262220;
    --surface-2: #322c28;
    --text: #f1ebe4;
    --muted: #a99d91;
    --border: #3f3732;
    --accent: #d89a5f;
    --accent-text: #1b1815;
    --accent-soft: #3d2d20;
    --plus: #6cc48a;
    --plus-soft: #1f3527;
    --minus: #ef8378;
    --minus-soft: #3f2220;
    --plus-fill: #2f8a52;
    --minus-fill: #c8463a;
    --warn: #f0b74d;
    --warn-soft: #3b2f15;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1815;
  --surface: #262220;
  --surface-2: #322c28;
  --text: #f1ebe4;
  --muted: #a99d91;
  --border: #3f3732;
  --accent: #d89a5f;
  --accent-text: #1b1815;
  --accent-soft: #3d2d20;
  --plus: #6cc48a;
  --plus-soft: #1f3527;
  --minus: #ef8378;
  --minus-soft: #3f2220;
  --plus-fill: #2f8a52;
  --minus-fill: #c8463a;
  --warn: #f0b74d;
  --warn-soft: #3b2f15;
  color-scheme: dark;
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 12px; }
.seg label { display: flex; align-items: center; min-height: 44px; padding: 0 16px; cursor: pointer; font-weight: 600; border-left: 1px solid var(--border); }
.seg label:first-child { border-left: none; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg label:has(input:checked) { background: var(--accent); color: var(--accent-text); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
main { padding: 8px var(--gutter-r) 0 var(--gutter); max-width: 1200px; margin: 0 auto; }
h1 { font-size: 1.5rem; margin: 4px 0; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
h3 { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 6px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pad { padding: 12px 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.warn-text { color: var(--warn); }
.danger-text { color: var(--minus) !important; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  touch-action: manipulation;
}
.btn.small { min-height: 36px; padding: 0 10px; font-size: .9rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--minus); border-color: var(--minus); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:active:not(:disabled) { transform: scale(.98); }
.file-btn input { display: none; }
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }

/* Formulare */
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
textarea { resize: vertical; }
input[type=checkbox], input[type=radio] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); flex: none; margin: 0; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: .85rem; color: var(--muted); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-bottom: 6px; }
.select-wrap select { width: auto; max-width: 100%; }
.form .btn { margin-top: 4px; }

/* Karten & Listen */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.page-head { margin: 6px 0 10px; }
.back { display: inline-block; text-decoration: none; padding: 6px 0; font-weight: 600; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 6px 0 12px; }
.toolbar select { font-weight: 700; }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list.inset { border-radius: 10px; margin-bottom: 12px; }
.list li + li { border-top: 1px solid var(--border); }
.list li.pad { padding: 14px 16px; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 56px; color: inherit; text-decoration: none; }
.row.static { padding: 10px 12px 10px 16px; }
.row-main { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; color: inherit; text-decoration: none; }
.row-side { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.chev { color: var(--muted); font-size: 1.4rem; }
.tag { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.ok { background: var(--plus-soft); color: var(--plus); }
.empty { text-align: center; padding: 40px 16px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0 0 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.table td.num { white-space: nowrap; }
.table tr.unclear td { background: var(--warn-soft); }

/* Effekt-Symbole */
.eff { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; font-weight: 800; font-size: .9rem; line-height: 1; flex: none; }
.eff.plus { background: var(--plus-soft); color: var(--plus); }
.eff.minus { background: var(--minus-soft); color: var(--minus); }

/* Erfassen: Namensliste + Kompetenzkarten */
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ico-sm { width: 16px; height: 16px; opacity: .85; }
.capture { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 6px; }
.students { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; }
.students-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.students-head select { font-weight: 700; min-height: 40px; padding: 6px 10px; }
.names { display: flex; flex-wrap: wrap; gap: 6px; }
.name {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; font-size: .95rem; cursor: pointer; touch-action: manipulation; text-align: left;
}
.name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name.selected { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.name .badge { min-width: 20px; height: 20px; padding: 0 5px; border-radius: 99px; background: var(--bg); color: var(--muted); font-size: .7rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; margin-left: auto; }
.name.selected .badge { background: rgba(255, 255, 255, .25); color: inherit; }
.board-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; margin-bottom: 8px; font-size: 1.05rem; }
.comp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; align-items: start; }
.comp-card, .card-flat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; }
.comp-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: .95rem; margin-bottom: 8px; }
.comp-title .ico { color: var(--accent); width: 22px; height: 22px; }
.comp-behs { display: flex; flex-direction: column; gap: 6px; }
.beh {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 46px; padding: 6px 12px;
  border-radius: 10px; border: none; font: inherit; font-weight: 600; font-size: .95rem; line-height: 1.2;
  text-align: left; cursor: pointer; touch-action: manipulation;
}
.beh .beh-text { flex: 1; }
.beh.minus { background: var(--minus-fill); color: #fff; }
.beh.plus { background: var(--plus-fill); color: #fff; }
.beh:active { transform: scale(.97); filter: brightness(.92); }
.no-selection .comp-grid { opacity: .5; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip { min-width: 80px; min-height: 54px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-weight: 700; cursor: pointer; }
.duration { max-width: 560px; }

/* Breit (iPad quer): Namensliste links, zweispaltig und eigenständig scrollbar */
@media (min-width: 900px) {
  .capture { grid-template-columns: 250px 1fr; align-items: start; }
  .students { position: sticky; top: calc(env(safe-area-inset-top) + 8px); max-height: calc(100vh - var(--tabbar-h) - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 24px); overflow-y: auto; }
  .names { display: grid; grid-template-columns: 1fr 1fr; }
  .name { width: 100%; padding: 0 8px; }
}

/* Beobachtungen */
.obs-list { list-style: none; margin: 0; padding: 0; }
.obs { display: flex; justify-content: space-between; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.obs:last-child { border-bottom: none; }
.obs-main { display: flex; gap: 10px; align-items: flex-start; flex: 1; min-width: 220px; }
.obs-main .eff { margin-top: 2px; }
.obs.cancelled .obs-main strong { text-decoration: line-through; color: var(--muted); }
.obs-actions { display: flex; gap: 4px; align-items: flex-start; }
.note { font-style: italic; }

/* Zertifikat */
.cert-row { padding: 12px 0; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.cert-row:last-child { border-bottom: none; }
.cert-row.removed .cert-text { text-decoration: line-through; color: var(--muted); }
.cert-row.unclear { background: var(--warn-soft); margin: 0 -16px; padding: 12px 16px; }
.cert-text { font-weight: 600; }
.cert-meta { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: .85rem; color: var(--muted); }
.evidence { margin: 6px 0 0; padding-left: 4px; list-style: none; font-size: .85rem; }
.evidence li { display: flex; gap: 6px; align-items: center; padding: 2px 0; }
details summary { cursor: pointer; color: var(--accent); font-size: .9rem; min-height: 32px; display: flex; align-items: center; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.cert-preview { background: #fff; color: #222; border-radius: 8px; padding: 20px; margin-bottom: 12px; border: 1px solid var(--border); }
.cert-preview h3 { color: #222; text-transform: none; letter-spacing: 0; font-size: 1.15rem; font-weight: 500; margin-top: 18px; }
.cert-preview .kv dt { color: #444; font-weight: 600; }
.cert-preview ul { padding-left: 22px; }
.cert-foot { display: flex; justify-content: space-between; margin-top: 28px; font-size: .9rem; }

/* Katalog bearbeiten */
.beh-edit { list-style: none; margin: 0 0 12px; padding: 0; }
.beh-edit li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.beh-edit li.inactive .beh-label { opacity: .5; }
.beh-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 6px; }
.beh-opts select { width: auto; }
.beh-opts .check { margin: 0; }

/* Tabbar */
.tabbar {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600; }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); }

/* Banner, Toast, Dialog */
#banners { max-width: 1200px; margin: 0 auto; }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 8px var(--gutter-r) 0 var(--gutter); padding: 8px 8px 8px 14px; border-radius: 12px; background: var(--accent-soft); font-weight: 600; font-size: .95rem; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
#toast {
  position: fixed; z-index: 50; left: 50%; transform: translate(-50%, 20px);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px);
  padding: 10px 12px 10px 16px; border-radius: 12px; background: #2a2420; color: #fff;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .25); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast-btn { background: none; border: 1px solid rgba(255, 255, 255, .4); color: #fff; border-radius: 8px; min-height: 36px; padding: 0 12px; font: inherit; font-weight: 700; cursor: pointer; }
dialog {
  border: none; border-radius: 18px; padding: 0; width: min(520px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dlg-form { padding: 20px; max-height: 85vh; overflow-y: auto; }
.dlg-body p { margin-top: 0; }
.dlg-body .check { align-items: flex-start; }
.dlg-body .check input { margin-top: 2px; }
.dlg-error { color: var(--minus); font-weight: 600; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* Symbolwahl im Katalog */
.icon-pick { border: none; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 6px; }
.icon-pick legend { font-size: .85rem; color: var(--muted); margin-bottom: 4px; padding: 0; }
.icon-opt { display: inline-flex; align-items: center; justify-content: center; width: 46px; height: 46px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; }
.icon-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.icon-opt:has(input:checked) { border: 2px solid var(--accent); background: var(--accent-soft); color: var(--accent); }
.icon-opt .ico { width: 24px; height: 24px; }
.with-ico { display: inline-flex; align-items: center; gap: 8px; }
.with-ico .ico { color: var(--accent); }
