:root {
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --text: #1f2421;
  --muted: #69716c;
  --border: #e1dfd6;
  --primary: #2f6f4f;
  --primary-text: #ffffff;
  --accent: #b5651d;
  --ok: #2e7d4f;
  --ok-bg: #e5f3ea;
  --warn: #8a5a00;
  --warn-bg: #fdf3dc;
  --bad: #b3261e;
  --bad-bg: #fbe7e5;
  --highlight: #eef6f1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151816;
    --surface: #1e2220;
    --surface-2: #262b28;
    --text: #e7ebe8;
    --muted: #9aa49e;
    --border: #333a36;
    --primary: #4f9c74;
    --accent: #e09450;
    --ok: #7cc79b;
    --ok-bg: #1e3327;
    --warn: #f0c46b;
    --warn-bg: #3a3020;
    --bad: #f28b82;
    --bad-bg: #3d2322;
    --highlight: #213028;
    --shadow: none;
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

h2 {
  font-size: 1.1rem;
  margin: 0 0 0.75rem;
}
h3 {
  font-size: 0.95rem;
  margin: 1rem 0 0.4rem;
  color: var(--muted);
}
code,
pre {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.85rem;
}
pre {
  white-space: pre-wrap;
  margin: 0.5rem 0;
}

.muted {
  color: var(--muted);
}
.small {
  font-size: 0.85rem;
}
.right {
  text-align: right;
}
.neg {
  color: var(--bad);
}

/* Layout */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}
.grid {
  display: grid;
  gap: 1rem;
  margin-bottom: 1rem;
}
.grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr));
  align-items: start;
}
.stack {
  display: grid;
  gap: 1rem;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
  min-width: 0;
}
.grid > .card,
.stack > .card {
  margin-bottom: 0;
}
.section-title {
  margin: 1.5rem 0 0.75rem;
}

/* Topbar & Tabs */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
}
.brand-lg {
  font-size: 1.5rem;
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 1.8em;
  height: 1.8em;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-text);
}
.topbar-info {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  flex: 1;
}
.pill {
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.85rem;
}
.pill-accent {
  background: var(--accent);
  color: #fff;
}
.logout {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}
.tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tabs button {
  border: 0;
  background: none;
  padding: 0.75rem 0.9rem;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tabs button.active {
  color: var(--text);
  border-bottom-color: var(--primary);
  font-weight: 600;
}
.badge {
  display: inline-block;
  min-width: 1.3em;
  padding: 0 0.35em;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  text-align: center;
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.btn:hover {
  filter: brightness(0.97);
}
.btn:disabled {
  opacity: 0.6;
  cursor: wait;
}
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text);
  font-weight: 600;
}
.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-ghost {
  background: transparent;
}
.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}
.btn-block {
  width: 100%;
}
input {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  width: 100%;
}
input:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}
label {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.9rem;
}
.input-unit {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.input-unit span {
  color: var(--muted);
  min-width: 2rem;
}
.info {
  display: inline-grid;
  place-items: center;
  width: 1.15rem;
  height: 1.15rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--primary);
  background: transparent;
  color: var(--primary);
  font: italic 700 0.7rem/1 Georgia, serif;
  cursor: pointer;
  vertical-align: middle;
}
.info:hover {
  background: var(--primary);
  color: var(--primary-text);
}

/* Key/Value, Stats */
.kv {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.3rem 0;
  border-bottom: 1px dashed var(--border);
}
.kv:last-child {
  border-bottom: 0;
}
.kv .strong-line {
  border-top: 1px solid var(--text);
}
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin: 0.5rem 0 1rem;
}
.stat {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  display: grid;
}
.stat span {
  font-size: 0.8rem;
  color: var(--muted);
}
.stat strong {
  font-size: 1.2rem;
}
.stat small {
  color: var(--muted);
}
.preview {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 0.6rem 0.8rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.result-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.result-head h2 {
  margin: 0;
}
.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.card {
  overflow-x: auto;
}
.table th,
.table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}
.table th {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}
.table .num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.table.compact td,
.table.compact th {
  padding: 0.3rem 0.4rem;
}
.report tr.total td {
  font-weight: 700;
  border-top: 2px solid var(--text);
}
.report tr.sub td {
  color: var(--muted);
  font-size: 0.82rem;
  padding-left: 1.6rem;
}
.sign {
  display: inline-block;
  width: 1.1rem;
  color: var(--muted);
}
tr.highlight td {
  background: var(--highlight);
  font-weight: 600;
}
.span-all {
  grid-column: 1 / -1;
}
.balance {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
  gap: 1rem;
}
.bar {
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
  min-width: 80px;
}
.bar span {
  display: block;
  height: 100%;
  background: var(--primary);
}

/* Chips & Tags */
.chips {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin: 0.75rem 0 1rem;
}
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text);
}
.tag {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.1rem 0.5rem;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
}
.tag-ok {
  background: var(--ok-bg);
  color: var(--ok);
}
.tag-bad {
  background: var(--bad-bg);
  color: var(--bad);
}

/* Alerts */
.alert {
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  margin: 0.5rem 0;
  font-size: 0.9rem;
}
.alert-ok {
  background: var(--ok-bg);
  color: var(--ok);
}
.alert-warn {
  background: var(--warn-bg);
  color: var(--warn);
}
.alert-error {
  background: var(--bad-bg);
  color: var(--bad);
}

/* Lernzentrum */
.task-meta {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}
.question {
  font-size: 1rem;
  margin: 0.6rem 0 0.8rem;
}
.answer-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.answer-row .input-unit {
  flex: 1 1 200px;
  max-width: 280px;
}
.task-done {
  opacity: 0.92;
}
.formula {
  background: var(--surface-2);
  border-left: 3px solid var(--primary);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
}
.solution {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.mc .option {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.4rem;
  cursor: pointer;
}
.mc .option input {
  width: auto;
  margin-top: 0.25rem;
}
.opt-correct {
  background: var(--ok-bg);
  border-color: var(--ok) !important;
}
.opt-wrong {
  background: var(--bad-bg);
  border-color: var(--bad) !important;
}

/* Glossar */
.term h3 {
  color: var(--text);
  margin-top: 0.5rem;
}
.example {
  font-size: 0.9rem;
  background: var(--highlight);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
}

/* Dialog & Toast */
dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  max-width: min(560px, calc(100vw - 2rem));
  padding: 1.25rem;
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 1rem;
}
.dialog-head h3 {
  margin: 0;
  color: var(--text);
  font-size: 1.1rem;
}
.toast {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.7rem 1.1rem;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  z-index: 10;
  max-width: calc(100vw - 2rem);
}
.toast-ok {
  background: var(--ok);
  color: #fff;
}
.toast-error {
  background: var(--bad);
  color: #fff;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}
.login-card form {
  margin-top: 1.25rem;
}
.kv strong {
  white-space: nowrap;
  text-align: right;
}
