:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --text: #1a202c;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #1e3a5f;
  --primary-hover: #2b4e7b;
  --accent: #3b82f6;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 8px 24px rgba(15, 23, 42, 0.12);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--primary); }
code { background: #f1f5f9; padding: 0.1em 0.35em; border-radius: 4px; font-size: 0.95em; }

.container { max-width: 1080px; margin: 0 auto; padding: 0 1.25rem; width: 100%; }

/* Header */
.site-header {
  background: linear-gradient(180deg, var(--primary) 0%, #2a4e7a 100%);
  color: #fff;
  padding: 0.9rem 0;
  box-shadow: var(--shadow);
}
.site-header .nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand {
  color: #fff;
  font-weight: 700;
  font-size: 1.2rem;
  text-decoration: none;
  letter-spacing: 0.02em;
}
.main-nav { display: flex; gap: 1.25rem; }
.main-nav a {
  color: #e6efff;
  text-decoration: none;
  font-weight: 500;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
}
.main-nav a:hover { border-bottom-color: #fff; color: #fff; }
.user-box { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; font-size: 0.92rem; }
.user-name { color: #e6efff; font-weight: 500; }
.streak {
  background: rgba(255, 255, 255, 0.15);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  color: #fff;
  font-weight: 500;
}
.logout-form { margin: 0; }
.logout-link {
  color: #fff;
  text-decoration: none;
  border: 1px solid rgba(255,255,255,0.4);
  padding: 0.25rem 0.7rem;
  border-radius: 6px;
  font-size: 0.9rem;
  background: transparent;
  font: inherit;
  cursor: pointer;
}
.logout-link:hover { background: rgba(255,255,255,0.15); }
.badge {
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  margin-left: 0.25rem;
}
.badge-muted { background: #e2e8f0; color: var(--text-muted); }

/* Main */
.main-content { flex: 1; padding: 2rem 1.25rem 3rem; }
.page-head { margin-bottom: 1.5rem; }
.page-head h1 { margin: 0 0 0.25rem; font-size: 1.75rem; }
.muted { color: var(--text-muted); }

/* Card */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.card h2, .card h1 { margin-top: 0; }
.login-card { max-width: 420px; margin: 3rem auto; }
.empty-state { text-align: center; color: var(--text-muted); }

/* Flash */
.flash-stack { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }
.flash {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-weight: 500;
  border-left: 4px solid;
}
.flash-success { background: var(--success-bg); color: #14532d; border-color: var(--success); }
.flash-error { background: var(--danger-bg); color: #7f1d1d; border-color: var(--danger); }

/* Forms */
.stacked-form label, .inline-form label {
  display: block;
  font-weight: 500;
  margin-bottom: 1rem;
}
.stacked-form input,
.stacked-form textarea,
.stacked-form select,
.inline-form input {
  display: block;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  margin-top: 0.35rem;
  background: #fff;
  color: var(--text);
}
.stacked-form input:focus,
.stacked-form textarea:focus,
.inline-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.15);
}
.hint { display: block; color: var(--text-muted); font-size: 0.85rem; margin-top: 0.25rem; font-weight: 400; }
.form-actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-top: 0.5rem; }
.inline-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.inline-form input { width: auto; flex: 1 1 180px; margin-top: 0; }
.checkbox { display: flex; align-items: center; gap: 0.4rem; font-weight: 500; }
.checkbox input { width: auto; margin: 0; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.55rem 1.1rem;
  border-radius: 6px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, transform 0.05s;
}
.btn:hover { background: var(--primary-hover); color: #fff; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); }
.btn-secondary { background: var(--accent); }
.btn-secondary:hover { background: #2563eb; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--primary); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f8fafc; color: var(--primary); }
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

/* Task-List */
.task-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}
.task-card {
  display: block;
  background: var(--surface);
  padding: 1.15rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
  border-left: 4px solid var(--primary);
  transition: transform 0.1s ease, box-shadow 0.12s ease;
}
.task-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.task-card.card-correct { border-left-color: var(--success); }
.task-card.card-wrong { border-left-color: var(--danger); }
.task-date { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.35rem; display: flex; align-items: center; gap: 0.4rem; }
.task-title { font-weight: 600; font-size: 1.05rem; margin-bottom: 0.6rem; }
.task-status { margin-top: 0.5rem; }

/* Chips & Status */
.chip {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.chip-today { background: var(--warning-bg); color: #92400e; }
.chip-future { background: #e0e7ff; color: #3730a3; }

.status {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
}
.status-correct { background: var(--success-bg); color: #166534; }
.status-wrong { background: var(--danger-bg); color: #991b1b; }
.status-partial { background: var(--warning-bg); color: #92400e; }
.status-open { background: #e2e8f0; color: #475569; }

/* Task-Detail */
.back-link { display: inline-block; margin-bottom: 1rem; color: var(--primary); text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.task-detail .task-head { margin-bottom: 1rem; }
.task-detail h1 { margin: 0.35rem 0 0; font-size: 1.5rem; }
.question {
  background: #f8fafc;
  padding: 1.25rem;
  border-radius: 8px;
  white-space: pre-wrap;
  font-size: 1.05rem;
  border: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.answer-form textarea { resize: vertical; }
.result { background: #f8fafc; border-radius: 8px; padding: 1.25rem; border: 1px solid var(--border); }
.result h2 { margin-top: 0; }
.result-row { display: flex; gap: 1rem; padding: 0.5rem 0; flex-wrap: wrap; }
.result-row .label { width: 180px; color: var(--text-muted); font-weight: 500; flex-shrink: 0; }
.result-row .value { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.result-row .value .status { align-self: flex-start; }
.sentence { white-space: pre-wrap; }
.feedback { color: var(--text-muted); font-style: italic; font-size: 0.92rem; margin-top: 0.25rem; }
.result hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.success-note {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--success-bg);
  color: #14532d;
  border-radius: 8px;
  font-weight: 500;
}
.admin-inline {
  margin-top: 1.5rem;
  padding: 1rem 1.25rem;
  background: #eef2ff;
  border: 1px dashed #c7d2fe;
  border-radius: 8px;
}
.admin-inline h3 { margin: 0 0 0.5rem; }

/* Leaderboard */
.leaderboard, .data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.25rem;
}
.leaderboard th, .leaderboard td,
.data-table th, .data-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.leaderboard th, .data-table th {
  background: #f8fafc;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.num { text-align: right; font-variant-numeric: tabular-nums; }
.strong { font-weight: 600; }
.rank { font-weight: 700; width: 3rem; }
.row-gold { background: linear-gradient(90deg, #fef3c7 0%, transparent 70%); }
.row-silver { background: linear-gradient(90deg, #e5e7eb 0%, transparent 70%); }
.row-bronze { background: linear-gradient(90deg, #fed7aa 0%, transparent 70%); }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.users-table .actions { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.users-table .pw-form { display: flex; gap: 0.3rem; align-items: center; }
.users-table .pw-form input { width: 140px; padding: 0.3rem 0.5rem; font-size: 0.85rem; margin: 0; }

/* AI-Box */
.ai-box {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  padding: 1rem 1.1rem;
  border-radius: 8px;
  margin-bottom: 1.5rem;
}
.ai-box h3 { margin: 0 0 0.35rem; }
.ai-box textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  font: inherit;
  margin-top: 0.5rem;
  background: #fff;
  resize: vertical;
}
.ai-actions { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.5rem; flex-wrap: wrap; }
.ai-box-disabled { background: #f1f5f9; border-color: var(--border); color: var(--text-muted); }

/* Footer */
.site-footer {
  padding: 1rem 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  border-top: 1px solid var(--border);
  background: #fff;
}

/* Teilaufgaben */
.task-context {
  background: #fffbeb;
  border: 1px solid #fde68a;
  padding: 0.9rem 1.1rem;
  border-radius: 8px;
  white-space: pre-wrap;
  margin-bottom: 1.25rem;
  color: #78350f;
}
.task-part {
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  background: #fff;
}
.task-part.part-correct { border-left-color: var(--success); background: #f0fdf4; }
.task-part.part-wrong { border-left-color: var(--danger); background: #fef2f2; }
.task-part h2 {
  font-size: 1.1rem;
  margin: 0 0 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.task-part .question {
  background: #f8fafc;
  padding: 0.9rem 1rem;
  margin-bottom: 1rem;
}
.admin-inline.small {
  font-size: 0.85rem;
  padding: 0.6rem 0.9rem;
  margin-top: 0.75rem;
}

/* Historie-Panel */
.history-panel {
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  margin-bottom: 1.25rem;
}
.history-panel > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--primary);
}
.history-list { margin-top: 0.75rem; display: flex; flex-direction: column; gap: 0.5rem; }
.history-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
}
.history-item > summary { cursor: pointer; font-weight: 500; }
.history-part {
  margin-top: 0.5rem;
  padding: 0.5rem 0.6rem;
  background: #f8fafc;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 0.93rem;
}
.history-part + .history-part { margin-top: 0.4rem; }
.history-part .label { color: var(--text-muted); font-weight: 500; }

/* Chat */
.chat-panel {
  margin-top: 1.5rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}
.chat-panel h2 { margin-top: 0; font-size: 1.1rem; }
.chat-messages {
  max-height: 320px;
  overflow-y: auto;
  padding: 0.5rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.chat-msg {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
}
.chat-msg.own { background: #eff6ff; border-color: #bfdbfe; }
.chat-meta { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.2rem; display: flex; gap: 0.4rem; align-items: center; }
.chat-meta .badge { background: var(--accent); color: #fff; }
.chat-body { white-space: pre-wrap; }
.chat-form { display: flex; gap: 0.5rem; align-items: flex-end; }
.chat-form textarea { flex: 1; padding: 0.5rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; resize: vertical; }

/* Teilaufgaben-Bloecke im Create-Formular */
.part-block {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 0.9rem 1.1rem;
  margin-bottom: 0.75rem;
  background: #f8fafc;
}
.part-block h3 { margin: 0 0 0.5rem; font-size: 1rem; }

/* Zuweisungs-Grid */
.assign-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.35rem 0.75rem;
  margin: 0.35rem 0 1rem;
  padding: 0.6rem 0.8rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.radio { display: flex; align-items: center; gap: 0.4rem; font-weight: 500; margin-bottom: 0.35rem; }
.radio input { width: auto; margin: 0; }

/* Overview-Matrix */
.overview-scroll { overflow-x: auto; }
.overview-table th, .overview-table td { text-align: center; }
.overview-table td:first-child, .overview-table th:first-child { text-align: left; }

/* Punkte & Lernaufgaben */
.points-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.35rem 0 0.75rem;
  padding: 0.5rem 0.75rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
}
.points-row .inline-small,
.inline-small {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin: 0;
}
.inline-small input { width: 70px; padding: 0.25rem 0.4rem; margin: 0; font-size: 0.85rem; }

.part-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.part-practice { font-size: 0.85rem; color: var(--text-muted); }
.task-part.part-practice {
  border-left-color: #8b5cf6;
  background: #faf5ff;
}
.chip-practice { background: #ede9fe; color: #5b21b6; }
.explanation {
  background: #f5f3ff;
  border-left: 3px solid #8b5cf6;
  padding: 0.75rem 0.9rem;
  border-radius: 6px;
  margin-bottom: 0.75rem;
  color: #4c1d95;
}
.path-block {
  background: #f8fafc;
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem;
  white-space: pre-wrap;
  margin: 0;
}
.appeal-box {
  margin-top: 0.5rem;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
}
.appeal-box > summary { cursor: pointer; font-weight: 500; color: #9a3412; }
.appeal-box textarea { width: 100%; padding: 0.4rem; margin-top: 0.4rem; border: 1px solid #fed7aa; border-radius: 4px; font: inherit; }
.appeals-log { margin-top: 0.75rem; font-size: 0.9rem; }
.appeal-item {
  padding: 0.4rem 0.6rem;
  margin-top: 0.3rem;
  background: #f8fafc;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
}

.appeal-card .appeal-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.appeal-block { margin: 0.5rem 0; padding: 0.5rem 0.75rem; background: #f8fafc; border-radius: 6px; }
.appeal-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 0.75rem; }
.appeal-actions form { display: flex; gap: 0.4rem; align-items: center; }
.appeal-actions input[type="text"] { padding: 0.35rem 0.5rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.85rem; min-width: 200px; }

.chip-open { background: #fef3c7; color: #92400e; }
.chip-ai-reviewed { background: #dbeafe; color: #1e40af; }
.chip-admin-granted { background: var(--success-bg); color: #14532d; }
.chip-admin-denied { background: var(--danger-bg); color: #7f1d1d; }

.badge-pending {
  display: inline-block;
  min-width: 1.3em;
  padding: 0.05em 0.5em;
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  margin-left: 0.3rem;
  line-height: 1.3;
}

.overview-table .col-practice {
  background: #faf5ff;
  color: #6b21a8;
}
.part-block.is-practice {
  border-left-color: #8b5cf6;
  background: #faf5ff;
}
.small { font-size: 0.85rem; }

/* Paste-Detection */
.chip-paste { background: #fee2e2; color: #991b1b; }
.paste-notice {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  padding: 0.6rem 0.9rem;
  border-radius: 6px;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}
.paste-hint { color: #b45309; font-weight: 500; margin-top: 0.4rem; }

.paste-card .paste-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.paste-event {
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: #f8fafc;
  border-left: 3px solid var(--danger);
  border-radius: 4px;
}
.paste-meta { margin-bottom: 0.35rem; }
.paste-text {
  background: #fff;
  border: 1px solid var(--border);
  padding: 0.5rem;
  border-radius: 4px;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
  margin: 0;
}
.paste-collapse {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 6px;
}
.paste-collapse > summary { cursor: pointer; color: #9a3412; font-weight: 500; }

.ai-subblock {
  margin-top: 0.75rem;
  padding: 0.75rem 0.9rem;
  background: #fff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
}
.ai-subblock h4 { margin: 0 0 0.35rem; font-size: 0.95rem; }
.ai-subblock input[type="text"],
.ai-subblock > input { width: 100%; padding: 0.4rem 0.6rem; margin-top: 0.35rem; border: 1px solid var(--border); border-radius: 4px; font: inherit; }

/* Responsiv */
@media (max-width: 640px) {
  .site-header .nav { gap: 0.5rem; }
  .user-box { font-size: 0.85rem; }
  .result-row { flex-direction: column; }
  .result-row .label { width: auto; }
  .users-table .pw-form input { width: 110px; }
  .task-grid { grid-template-columns: 1fr; }
}
