/* ============================================================
   KURSPLATTFORM — Mobile-first CSS
   Farben: Lila #7c3aed, Rosa-Akzent #ec4899, Dunkel #1f2937
   ============================================================ */

:root {
  --c-primary:   #7c3aed;
  --c-primary-d: #6d28d9;
  --c-accent:    #ec4899;
  --c-bg:        #f9fafb;
  --c-surface:   #ffffff;
  --c-border:    #e5e7eb;
  --c-text:      #1f2937;
  --c-muted:     #6b7280;
  --c-success:   #059669;
  --c-error:     #dc2626;
  --radius:      12px;
  --shadow:      0 2px 12px rgba(0,0,0,.08);
  --transition:  .2s ease;
}

/* --- Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body { font-family: system-ui, -apple-system, sans-serif; background: var(--c-bg); color: var(--c-text); line-height: 1.6; }
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

/* --- Header --- */
.site-header {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.site-logo { font-weight: 700; font-size: 1.1rem; color: var(--c-primary); }
.site-logo img { height: 36px; width: auto; }
.site-nav { display: none; gap: 20px; }
.site-nav a { color: var(--c-text); font-size: .9rem; }
.site-nav a:hover { color: var(--c-primary); text-decoration: none; }
.nav-toggle { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--c-text); padding: 8px; }

/* Mobil-Nav offen */
.site-nav.open {
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 56px; left: 0; right: 0;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  padding: 12px 16px;
  gap: 12px;
  z-index: 99;
}

@media (min-width: 640px) {
  .site-nav { display: flex; }
  .nav-toggle { display: none; }
}

/* --- Main --- */
.main-content { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }

/* --- Footer --- */
.site-footer { text-align: center; padding: 20px; font-size: .8rem; color: var(--c-muted); border-top: 1px solid var(--c-border); }

/* --- Flash messages --- */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: .9rem; }
.flash--success { background: #d1fae5; color: #065f46; }
.flash--error   { background: #fee2e2; color: #991b1b; }
.flash--info    { background: #dbeafe; color: #1e40af; }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 22px; border-radius: 8px; font-size: .95rem; font-weight: 600;
  cursor: pointer; border: none; transition: background var(--transition), opacity var(--transition);
  min-height: 44px; text-decoration: none;
}
.btn-primary  { background: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-d); text-decoration: none; color: #fff; }
.btn-accent   { background: var(--c-accent); color: #fff; }
.btn-outline  { background: transparent; color: var(--c-primary); border: 2px solid var(--c-primary); }
.btn-danger   { background: var(--c-error); color: #fff; }
.btn-sm       { padding: 7px 14px; font-size: .85rem; min-height: 36px; }
.btn-full     { width: 100%; }

/* --- Cards --- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-body { padding: 16px; }
.card-img { width: 100%; height: 180px; object-fit: cover; }

/* --- Course Grid --- */
.course-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  margin-top: 20px;
}
@media (min-width: 480px) { .course-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .course-grid { grid-template-columns: repeat(3, 1fr); } }

.course-card { display: flex; flex-direction: column; }
.course-card .card-body { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.course-card h3 { font-size: 1rem; line-height: 1.3; }
.course-card p  { font-size: .85rem; color: var(--c-muted); flex: 1; }
.course-card .card-actions { margin-top: auto; padding-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: .75rem; font-weight: 600;
}
.badge-free     { background: #d1fae5; color: #065f46; }
.badge-paid     { background: #ede9fe; color: var(--c-primary); }
.badge-enrolled { background: var(--c-primary); color: #fff; }
.badge-draft    { background: #fef3c7; color: #92400e; }

/* --- Filter Tabs --- */
.filter-tabs { display: flex; gap: 4px; margin-bottom: 4px; border-bottom: 2px solid var(--c-border); }
.filter-tab {
  padding: 10px 18px; cursor: pointer; font-weight: 600; font-size: .9rem;
  color: var(--c-muted); background: none; border: none; border-bottom: 3px solid transparent;
  margin-bottom: -2px; transition: color var(--transition);
}
.filter-tab.active { color: var(--c-primary); border-bottom-color: var(--c-primary); }

/* --- Course Layout (Sidebar + Content) --- */
.course-layout { display: flex; gap: 0; min-height: calc(100vh - 56px); }

.course-sidebar {
  width: 280px; flex-shrink: 0;
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  overflow-y: auto;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
}
.course-sidebar-header { padding: 16px; border-bottom: 1px solid var(--c-border); }
.course-sidebar-header h2 { font-size: .95rem; }

.course-main { flex: 1; padding: 24px 20px; max-width: 820px; }

/* Mobil: Sidebar als Drawer */
.sidebar-toggle {
  display: flex; align-items: center; gap: 8px;
  background: var(--c-primary); color: #fff; border: none;
  padding: 10px 16px; border-radius: 8px; font-size: .9rem;
  cursor: pointer; margin-bottom: 16px; min-height: 44px;
}
@media (min-width: 768px) {
  .sidebar-toggle { display: none; }
  .course-sidebar { display: block !important; }
  .course-layout { margin: 0 -16px -60px; }
  .course-main { padding: 28px 32px; }
}
@media (max-width: 767px) {
  .course-layout { flex-direction: column; }
  .course-sidebar {
    position: fixed; top: 56px; left: 0; bottom: 0; z-index: 200;
    width: 85%; max-width: 320px;
    transform: translateX(-100%); transition: transform var(--transition);
    box-shadow: 4px 0 20px rgba(0,0,0,.15);
  }
  .course-sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    display: none; position: fixed; inset: 56px 0 0 0; background: rgba(0,0,0,.4); z-index: 199;
  }
  .sidebar-overlay.open { display: block; }
}

/* --- Chapter Tree --- */
.chapter-list { list-style: none; padding: 0; }
.chapter-item { border-bottom: 1px solid var(--c-border); }
.chapter-toggle {
  width: 100%; text-align: left; padding: 12px 16px;
  background: none; border: none; cursor: pointer;
  font-weight: 600; font-size: .9rem; display: flex; align-items: center; justify-content: space-between;
}
.chapter-toggle:hover { background: var(--c-bg); }
.chapter-toggle .arrow { transition: transform var(--transition); }
.chapter-toggle.open .arrow { transform: rotate(90deg); }

.lesson-list { list-style: none; padding: 0; background: #fafafa; }
.lesson-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px 10px 28px; font-size: .85rem; color: var(--c-text);
  border-bottom: 1px solid var(--c-border); transition: background var(--transition);
}
.lesson-link:hover { background: #ede9fe; text-decoration: none; }
.lesson-link.active { background: #ede9fe; color: var(--c-primary); font-weight: 600; }
.lesson-link.done::before { content: '✓'; color: var(--c-success); font-weight: 700; }
.lesson-link:not(.done)::before { content: '○'; color: var(--c-border); }

/* --- Progress Bar --- */
.progress-bar-wrap { background: var(--c-border); border-radius: 99px; height: 8px; margin: 8px 0; }
.progress-bar-fill { height: 100%; border-radius: 99px; background: var(--c-primary); transition: width .5s ease; }
.progress-label { font-size: .8rem; color: var(--c-muted); }

/* --- Lesson Content --- */
.lesson-header { margin-bottom: 20px; }
.lesson-header h1 { font-size: 1.4rem; line-height: 1.3; }
.lesson-video { margin-bottom: 20px; }
.lesson-video iframe, .lesson-video video { width: 100%; border-radius: var(--radius); aspect-ratio: 16/9; }
.lesson-audio { margin-bottom: 20px; }
.lesson-audio audio { width: 100%; }
.lesson-body { line-height: 1.8; }
.lesson-body h2 { margin: 20px 0 8px; }
.lesson-body p  { margin-bottom: 12px; }
.lesson-body ul, .lesson-body ol { padding-left: 24px; margin-bottom: 12px; }
.lesson-body img { border-radius: var(--radius); }

/* --- Quiz --- */
.quiz-box { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 20px; margin: 24px 0; }
.quiz-box h3 { margin-bottom: 16px; font-size: 1.1rem; }
.quiz-question { margin-bottom: 20px; }
.quiz-question p { font-weight: 600; margin-bottom: 10px; }
.quiz-option { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 8px; margin-bottom: 6px; cursor: pointer; border: 2px solid var(--c-border); transition: border-color var(--transition), background var(--transition); }
.quiz-option:hover { border-color: var(--c-primary); background: #f5f3ff; }
.quiz-option input { width: 18px; height: 18px; accent-color: var(--c-primary); }
.quiz-option.correct { border-color: var(--c-success); background: #d1fae5; }
.quiz-option.wrong   { border-color: var(--c-error);   background: #fee2e2; }
.quiz-result { padding: 12px 16px; border-radius: 8px; margin-top: 12px; font-weight: 600; }
.quiz-result.pass { background: #d1fae5; color: #065f46; }
.quiz-result.fail { background: #fee2e2; color: #991b1b; }

/* --- Comments --- */
.comments-section { margin-top: 40px; border-top: 1px solid var(--c-border); padding-top: 24px; }
.comment-thread { margin-bottom: 4px; }
.comment { display: flex; gap: 12px; margin-bottom: 8px; }
.comment-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--c-primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; font-size: .9rem; }
.comment-body { flex: 1; background: var(--c-bg); border: 1px solid var(--c-border); border-radius: 10px; padding: 10px 14px; }
.comment-meta { margin-bottom: 4px; }
.comment-text { font-size: .9rem; line-height: 1.6; white-space: pre-wrap; }
.comment-replies { border-left: 2px solid var(--c-border); margin-left: 18px; padding-left: 4px; margin-top: 4px; }
.comment-form textarea, .comment-replies textarea { width: 100%; border: 1px solid var(--c-border); border-radius: 8px; padding: 10px; font-size: .9rem; resize: vertical; min-height: 70px; font-family: inherit; }
.comment-form textarea:focus, .comment-replies textarea:focus { outline: none; border-color: var(--c-primary); }

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .9rem; font-weight: 600; margin-bottom: 6px; }
.form-control {
  width: 100%; padding: 10px 14px; border: 1px solid var(--c-border);
  border-radius: 8px; font-size: 1rem; font-family: inherit;
  transition: border-color var(--transition);
}
.form-control:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(124,58,237,.1); }
.form-hint { font-size: .8rem; color: var(--c-muted); margin-top: 4px; }

/* --- Login Page --- */
.login-wrap { max-width: 380px; margin: 40px auto; }
.login-wrap h1 { text-align: center; font-size: 1.5rem; margin-bottom: 24px; color: var(--c-primary); }

/* --- Admin --- */
.admin-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 640px) { .admin-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .admin-grid { grid-template-columns: repeat(4, 1fr); } }

.stat-card { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 20px; }
.stat-card .stat-value { font-size: 2rem; font-weight: 700; color: var(--c-primary); }
.stat-card .stat-label { font-size: .85rem; color: var(--c-muted); }

.admin-nav { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; }
.admin-nav a {
  padding: 8px 16px; background: var(--c-surface); border: 1px solid var(--c-border);
  border-radius: 8px; font-size: .9rem; color: var(--c-text);
  transition: background var(--transition);
}
.admin-nav a:hover, .admin-nav a.active { background: var(--c-primary); color: #fff; border-color: var(--c-primary); text-decoration: none; }

/* --- Table --- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { background: var(--c-bg); text-align: left; padding: 10px 12px; font-size: .8rem; color: var(--c-muted); text-transform: uppercase; letter-spacing: .05em; border-bottom: 2px solid var(--c-border); }
td { padding: 12px; border-bottom: 1px solid var(--c-border); vertical-align: top; }
tr:hover td { background: #fafafa; }

/* --- Page Heading --- */
.page-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 24px; }
.page-header h1 { font-size: 1.4rem; }

/* --- Toggle Switch --- */
.toggle-wrap { display: flex; align-items: center; gap: 10px; }
.toggle { position: relative; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; background: var(--c-border); border-radius: 24px;
  cursor: pointer; transition: background var(--transition);
}
.toggle-slider::before {
  content: ''; position: absolute; height: 18px; width: 18px; border-radius: 50%;
  left: 3px; top: 3px; background: #fff; transition: transform var(--transition);
}
.toggle input:checked + .toggle-slider { background: var(--c-primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* --- Subcourse tile --- */
.subcourse-tile {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  background: #f5f3ff; border: 1px solid #ddd6fe; border-radius: var(--radius);
  margin: 12px 0;
}
.subcourse-tile .btn { margin-left: auto; flex-shrink: 0; }

/* --- Drag handle (admin tree) --- */
.drag-handle { cursor: grab; color: var(--c-muted); padding: 0 4px; font-size: 1.1rem; }
.drag-handle:active { cursor: grabbing; }

/* --- Enrollment badge --- */
.enroll-active   { color: var(--c-success); font-weight: 600; }
.enroll-inactive { color: var(--c-error); font-weight: 600; }
.enroll-expired  { color: var(--c-muted); }
