:root {
  --bg: #0a0a0b;
  --bg-secondary: #141416;
  --bg-tertiary: #1c1c1f;
  --bg-hover: #232327;
  --border: #2e2e33;
  --border-light: #3a3a40;

  --text: #f0f0f2;
  --text-muted: #8b8b95;
  --text-dim: #5c5c66;

  --accent: #14b8a6;
  --accent-hover: #2dd4bf;
  --accent-bg: #0d3d38;

  --green: #064e3b;
  --green-text: #34d399;
  --green-bright: #10b981;
  --red: #7f1d1d;
  --red-text: #f87171;
  --red-bright: #ef4444;
  --yellow: #78350f;
  --yellow-text: #fbbf24;
  --yellow-bright: #f59e0b;
  --grey: #1f2024;
  --grey-text: #71717a;

  --type-homework: #3b82f6;
  --type-replacement: #f59e0b;
  --type-exam: #ef4444;

  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 2px 8px rgba(0,0,0,0.4);
  --transition: 0.15s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* Header */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 32px;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  letter-spacing: -0.5px;
}

.nav { display: flex; gap: 8px; }

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: color var(--transition), background var(--transition);
}
.nav-link:hover, .nav-link.active {
  color: var(--text);
  background: var(--bg-tertiary);
}

/* Main */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* Toast */
.toast {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast-item {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
  pointer-events: auto;
}
.toast-item.error { border-color: var(--red-bright); color: var(--red-text); }
.toast-item.success { border-color: var(--green-bright); color: var(--green-text); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-light); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--red-text); }
.btn-danger:hover { background: var(--red); border-color: var(--red-bright); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled, .btn-icon:disabled { opacity: 0.4; pointer-events: none; cursor: default; }
.btn-icon {
  padding: 4px 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.btn-icon:hover { color: var(--text); background: var(--bg-hover); }

/* Forms */
.input, .select, .textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); }
.textarea { resize: vertical; min-height: 60px; }

.form-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

/* Cards */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: border-color var(--transition);
}
.card:hover { border-color: var(--border-light); }
.card-link { text-decoration: none; color: inherit; cursor: pointer; display: block; }

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 16px;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.breadcrumb a { color: var(--accent); text-decoration: none; }
.breadcrumb a:hover { color: var(--accent-hover); }

/* Classes grid */
.classes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.class-card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.class-card-meta {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

.class-card.archived {
  opacity: 0.5;
}

.badge {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.badge-homework { background: rgba(59,130,246,0.15); color: var(--type-homework); }
.badge-replacement { background: rgba(245,158,11,0.15); color: var(--type-replacement); }
.badge-exam { background: rgba(239,68,68,0.15); color: var(--type-exam); }
.badge-archived { background: rgba(113,113,122,0.15); color: var(--grey-text); }
.badge-group { background: rgba(139,92,246,0.15); color: #a78bfa; }

.section-heading {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
  margin-bottom: 12px;
}

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar-separator {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

/* Submission Grid */
.grid-container {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  max-height: calc(100vh - 220px);
  background: var(--bg-secondary);
}

.submission-grid {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  font-size: 13px;
}

.submission-grid th,
.submission-grid td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.submission-grid th {
  background: var(--bg-tertiary);
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 3;
}

.submission-grid th:first-child {
  position: sticky;
  left: 0;
  z-index: 4;
  min-width: 180px;
}

.submission-grid td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--bg-secondary);
  font-weight: 500;
  padding: 6px 12px;
  min-width: 180px;
}

.submission-grid tbody tr:nth-child(even) td:first-child { background: var(--bg-tertiary); }
.submission-grid tbody tr:nth-child(even) { background: var(--bg-tertiary); }
@media (hover: hover) {
  .submission-grid tbody tr:hover td:first-child { background: rgba(251,191,36,0.12); }
  .submission-grid tbody tr:hover { background: rgba(251,191,36,0.12); }
}
.submission-grid tbody tr.active-row { background: rgba(251,191,36,0.12); }
.submission-grid tbody tr.active-row td:first-child { background: rgba(251,191,36,0.12); }

.submission-grid td:first-child.dimmed {
  opacity: 0.3;
}

.task-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.task-header-title { font-size: 12px; }
.task-header-meta {
  display: flex;
  gap: 6px;
  align-items: center;
}
.task-header-deadline {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 400;
}

/* Status cells */
.cell {
  width: 48px;
  height: 36px;
  text-align: center;
  vertical-align: middle;
  cursor: pointer;
  transition: filter var(--transition);
  padding: 0;
  position: relative;
}
.cell:hover { filter: brightness(1.2); }

.cell-fehlt     { background: var(--red);    color: var(--red-text);    }
.cell-abgegeben { background: var(--green);  color: var(--green-text);  }

.cell-icon {
  font-size: 14px;
  line-height: 36px;
  display: block;
}

.cell.dimmed { opacity: 0.15; }
.cell.highlight-col { outline: 2px solid var(--accent); outline-offset: -2px; }

tr.dimmed td:first-child { opacity: 0.3; }
tr.dimmed .cell { opacity: 0.15; }

/* Grid archived state */
.grid-archived .cell {
  cursor: default;
  pointer-events: none;
  opacity: 0.6;
}

/* Popover */
.popover {
  position: fixed;
  z-index: 200;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  min-width: 200px;
}

.popover-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.status-pills {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}

.status-pill {
  flex: 1;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 11px;
  text-align: center;
  cursor: pointer;
  background: transparent;
  color: var(--text-muted);
  transition: all var(--transition);
  font-weight: 500;
}
.status-pill:hover { border-color: var(--border-light); color: var(--text); }
.status-pill.active-fehlt     { background: var(--red);    color: var(--red-text);    border-color: var(--red-bright);    }
.status-pill.active-abgegeben { background: var(--green);  color: var(--green-text);  border-color: var(--green-bright);  }

.popover-note {
  width: 100%;
  margin-bottom: 8px;
}

.popover-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
}
.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 301;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  padding: 20px;
  min-width: 300px;
  max-width: 90vw;
}
.modal-body { font-size: 14px; line-height: 1.6; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.modal-actions .btn-danger { background: var(--red); border-color: var(--red-bright); color: var(--red-text); }
.modal-actions .btn-danger:hover { background: var(--red-bright); color: #fff; }

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 199;
}

/* Panel (slide-in for students/tasks management) */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 400px;
  max-width: 90vw;
  height: 100vh;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  z-index: 150;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.3);
  animation: panel-in 0.2s ease;
}

@keyframes panel-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.panel-title { font-size: 15px; font-weight: 600; }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 149;
}

/* Student/task list items */
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}
.list-item:last-child { border-bottom: none; }
.list-item-name { font-size: 13px; flex: 1; }
.list-item-actions { display: flex; gap: 4px; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 32px; margin-bottom: 12px; }
.empty-state-text { font-size: 14px; }

/* Summary bar */
.summary-bar {
  display: flex;
  gap: 16px;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
}

.summary-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.summary-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.summary-dot.abgegeben { background: var(--green-bright); }
.summary-dot.fehlt     { background: var(--red-bright); }

/* Checkbox */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

/* Utility */
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* Grid touch scroll */
.grid-container {
  -webkit-overflow-scrolling: touch;
}

.submission-grid th {
  position: -webkit-sticky;
  position: sticky;
}
.submission-grid th:first-child {
  position: -webkit-sticky;
  position: sticky;
}
.submission-grid td:first-child {
  position: -webkit-sticky;
  position: sticky;
}

/* Tablet / iPad (max-width: 1100px) */
@media (max-width: 1100px) {
  .main { padding: 16px; }
  .header-inner { padding: 0 16px; }

  .nav { flex: 1; justify-content: flex-end; }

  .page-header { flex-wrap: wrap; }

  .panel { width: 100vw; max-width: 100vw; }

  .toolbar { gap: 6px; }
  .toolbar-separator { display: none; }

  .btn { padding: 8px 16px; min-height: 44px; font-size: 14px; }
  .btn-sm { padding: 6px 12px; min-height: 36px; font-size: 13px; }
  .btn-icon { padding: 8px; min-width: 44px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }

  .input, .select, .textarea { padding: 8px 12px; font-size: 14px; min-height: 44px; }

  .cell {
    width: 56px;
    height: 44px;
  }
  .cell-icon {
    font-size: 16px;
    line-height: 44px;
  }

  .submission-grid th { padding: 10px 12px; }
  .submission-grid td:first-child { min-width: 140px; padding: 8px 10px; }

  .status-pill { padding: 10px 8px; font-size: 13px; min-height: 44px; }

  .list-item { padding: 10px 0; }

  .popover {
    min-width: 260px;
    padding: 16px;
  }

  .classes-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }

  .summary-bar { flex-wrap: wrap; gap: 12px; }
}

/* Portrait tablet (max-width: 768px) */
@media (max-width: 768px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .page-header .flex { width: 100%; }
  .page-header .btn { flex: 1; justify-content: center; }

  .form-row { flex-direction: column; }

  .classes-grid {
    grid-template-columns: 1fr;
  }

  .submission-grid td:first-child { min-width: 100px; font-size: 12px; }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .toolbar .form-group { width: 100%; }
  .toolbar .input { width: 100% !important; }
}
