/* BZF Trainer – plain CSS, light + dark */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --border: #d8dee8;
  --text: #17202e;
  --muted: #5d6b80;
  --accent: #1f5fbf;
  --accent-ink: #ffffff;
  --amber: #c27c0e;
  --ok: #1d8a4e;
  --ok-bg: #e3f5ea;
  --bad: #c2362f;
  --bad-bg: #fbe6e4;
  --learn: #e3a21a;
  --new: #c5cdd9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 25, 45, .06), 0 4px 16px rgba(15, 25, 45, .05);
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d131c;
    --surface: #151e2b;
    --surface-2: #1c2737;
    --border: #2a3749;
    --text: #e6ebf2;
    --muted: #93a1b5;
    --accent: #5b9bff;
    --accent-ink: #0b1220;
    --amber: #f0b44c;
    --ok: #3ccf7f;
    --ok-bg: #12301f;
    --bad: #ff6b61;
    --bad-bg: #3a1714;
    --learn: #f0b44c;
    --new: #3a4859;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: 1.55rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-size: 1.05rem; letter-spacing: .02em; }
.brand b { color: var(--accent); font-weight: 700; margin-left: 2px; }
#nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
#nav a, .userbox a {
  text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 8px; white-space: nowrap; font-weight: 500;
}
#nav a:hover, .userbox a:hover { color: var(--text); background: var(--surface-2); }
#nav a.active, .userbox a.active { color: var(--text); background: var(--surface-2); }
.userbox { display: flex; align-items: center; gap: 8px; }

main { max-width: 1060px; margin: 0 auto; padding: 28px 20px 64px; }

/* ---------- generic ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.card + .card, .stack > * + * { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; }

.btn {
  appearance: none; border: 1px solid transparent; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 600; padding: 9px 16px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { filter: brightness(1.07); }
.btn:focus-visible, .opt:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.small { padding: 5px 10px; font-size: .85rem; font-weight: 500; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
input[type=text], input[type=password], input[type=search], select {
  width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
select { width: auto; }
.field { margin-bottom: 14px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.error { color: var(--bad); font-size: .9rem; min-height: 1.2em; margin: 6px 0 0; }

.badge {
  display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.accent { color: var(--accent); }

/* ---------- login ---------- */
.login-wrap { min-height: calc(100vh - 92px); display: grid; place-items: center; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { justify-content: center; font-size: 1.4rem; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 22px; font-size: .9rem; }

/* ---------- KPIs & bars ---------- */
.kpi .v { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: .85rem; }
.kpi.ok .v { color: var(--ok); }
.kpi.learn .v { color: var(--learn); }
.kpi.due .v { color: var(--accent); }

.stackbar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--new); gap: 2px; }
.stackbar.big { height: 16px; }
.stackbar > span { display: block; height: 100%; }
.stackbar .s-ok { background: var(--ok); }
.stackbar .s-learn { background: var(--learn); }
.legend { display: flex; gap: 16px; font-size: .85rem; color: var(--muted); margin-top: 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend .ok { background: var(--ok); }
.legend .learn { background: var(--learn); }
.legend .new { background: var(--new); }

.activity { display: grid; grid-template-columns: repeat(14, 1fr); gap: 6px; align-items: end; height: 110px; }
.activity .col { display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; }
.activity .bar { background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; opacity: .85; }
.activity .bar.zero { background: var(--border); }
.activity-labels { display: grid; grid-template-columns: repeat(14, 1fr); gap: 6px; font-size: .7rem; color: var(--muted); text-align: center; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.sec-name { font-weight: 500; }
.sec-bar { min-width: 140px; }

/* ---------- question card ---------- */
.learn-toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.qcard { padding: 26px; }
.qmeta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; font-size: .85rem; color: var(--muted); }
.qnum { font-family: var(--mono); font-weight: 700; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 8px; }
.qtext { font-size: 1.13rem; font-weight: 600; margin-bottom: 18px; }
.qimg { display: block; margin: 0 0 18px; width: 90px; height: 90px; }
.pips { display: inline-flex; gap: 3px; vertical-align: middle; }
.pips i { width: 8px; height: 8px; border-radius: 2px; background: var(--new); display: inline-block; }
.pips i.on { background: var(--ok); }

.opts { display: grid; gap: 10px; }
.opt {
  display: flex; gap: 14px; align-items: flex-start; text-align: left; width: 100%;
  padding: 13px 16px; border-radius: 9px; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
  transition: border-color .12s, background .12s;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt .key {
  flex: none; width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center;
  font-family: var(--mono); font-weight: 700; font-size: .85rem; background: var(--surface-2); color: var(--muted);
}
.opt.selected { border-color: var(--accent); background: var(--surface-2); }
.opt.selected .key { background: var(--accent); color: var(--accent-ink); }
.opt.correct { border-color: var(--ok); background: var(--ok-bg); }
.opt.correct .key { background: var(--ok); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-bg); }
.opt.wrong .key { background: var(--bad); color: #fff; }
.opt:disabled { cursor: default; }
.feedback { display: flex; align-items: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.feedback .verdict { font-weight: 700; }
.feedback .verdict.ok { color: var(--ok); }
.feedback .verdict.bad { color: var(--bad); }
.hint { font-size: .8rem; color: var(--muted); margin-top: 14px; }
kbd { font-family: var(--mono); font-size: .75rem; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--surface-2); }

/* ---------- exam ---------- */
.exam-bar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.timer { font-family: var(--mono); font-size: 1.25rem; font-weight: 700; padding: 4px 12px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); }
.timer.low { color: var(--bad); border-color: var(--bad); }
.qnav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.qnav button {
  width: 34px; height: 34px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); font: 600 .8rem var(--mono); cursor: pointer;
}
.qnav button.answered { background: var(--surface-2); color: var(--text); border-color: var(--accent); }
.qnav button.current { outline: 2px solid var(--accent); outline-offset: 1px; color: var(--text); }
.qnav button.r-ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.qnav button.r-bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.result-hero { text-align: center; padding: 30px 20px; }
.result-hero .score { font-size: 3rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.result-hero.pass .score { color: var(--ok); }
.result-hero.fail .score { color: var(--bad); }
.review-item + .review-item { margin-top: 12px; }

/* ---------- catalogue ---------- */
.cat-item { padding: 16px 18px; }
.cat-item + .cat-item { margin-top: 10px; }
.cat-item ol { margin: 8px 0 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.cat-item li { padding: 5px 10px; border-radius: 6px; font-size: .93rem; display: flex; gap: 10px; }
.cat-item li .key { font-family: var(--mono); font-weight: 700; color: var(--muted); }
.cat-item li.right { background: var(--ok-bg); }
.cat-item li.right .key { color: var(--ok); }
.cat-item .qtext { font-size: 1rem; margin: 0; }

/* ---------- toast & modal ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px; z-index: 50;
  box-shadow: 0 6px 24px rgba(0,0,0,.2); font-weight: 500;
}
#toast.bad { background: var(--bad); color: #fff; }
dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 22px; max-width: 440px; width: calc(100% - 32px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(10, 15, 25, .5); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.secret {
  font-family: var(--mono); font-size: 1.2rem; padding: 10px 14px; background: var(--surface-2);
  border: 1px dashed var(--border); border-radius: 8px; user-select: all; word-break: break-all; margin: 10px 0;
}

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* touch devices: no hover-only affordances, no keyboard hints */
@media (hover: none) {
  .hint { display: none; }
  .opt:hover:not(:disabled) { border-color: var(--border); }
}
button, a { -webkit-tap-highlight-color: transparent; }
.opt:active:not(:disabled) { background: var(--surface-2); }

@media (max-width: 760px) {
  body { font-size: 16px; }
  .topbar {
    height: auto; padding: 8px 14px; padding-top: calc(8px + env(safe-area-inset-top));
    padding-left: calc(14px + env(safe-area-inset-left)); padding-right: calc(14px + env(safe-area-inset-right));
  }
  .userbox { margin-left: auto; }
  .userbox #nav-user { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; }

  /* bottom tab bar */
  #nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: flex; gap: 0; overflow: visible;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  #nav a {
    flex: 1; text-align: center; padding: 12px 2px; font-size: .8rem; border-radius: 8px;
  }
  #nav a.active { color: var(--accent); background: transparent; font-weight: 700; }

  main { padding: 16px 14px calc(96px + env(safe-area-inset-bottom)); }
  .page-head { margin-bottom: 14px; }
  .page-head h1 { font-size: 1.35rem; }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .grid.kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px; }
  .kpi .v { font-size: 1.35rem; }
  .card { padding: 16px; }
  .qcard { padding: 16px; }
  .qtext { font-size: 1.08rem; }
  .opt { padding: 14px; min-height: 52px; }
  .feedback .btn { flex: 1 1 100%; justify-content: center; padding: 13px; }
  /* keep "Weiter" clear of the bottom tab bar when scrolled into view */
  .feedback { scroll-margin-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .hide-sm { display: none; }

  /* inputs >= 16px prevent iOS zoom on focus */
  input[type=text], input[type=password], input[type=search], select { font-size: 16px; padding: 11px 12px; }
  .learn-toolbar select { flex: 1 1 100%; width: 100%; }

  /* exam: keep timer + submit visible while scrolling */
  .exam-head { position: sticky; top: 52px; z-index: 5; background: var(--bg); padding: 8px 0; margin: -8px 0 6px; }
  .qnav button { width: 38px; height: 38px; }

  /* admin users table -> stacked cards */
  table.users thead { display: none; }
  table.users tr { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding: 12px 0; border-bottom: 1px solid var(--border); }
  table.users tr:last-child { border-bottom: 0; }
  table.users td { border: 0; padding: 0; }
  table.users td.actions-cell, table.users td.mastered-cell { grid-column: 1 / -1; text-align: left; }
  table.users td.mastered-cell { font-size: .85rem; color: var(--muted); }
  table.users td.mastered-cell::after { content: " sicher"; font-family: inherit; }
  table.users .actions { justify-content: flex-start; }
  table.users .actions .btn { padding: 8px 10px; }

  .modal-actions .btn { flex: 1; justify-content: center; }
}
