/* ============================================================
   SchulEssen — Design System
   ============================================================ */

:root {
  --accent:       #2563eb;
  --accent-light: #dbeafe;
  --accent-dark:  #1d4ed8;

  --bg:         #f8fafc;
  --surface:    #ffffff;
  --surface2:   #f1f5f9;
  --border:     #e2e8f0;
  --border2:    #cbd5e1;

  --text:       #0f172a;
  --text2:      #475569;
  --text3:      #94a3b8;

  --green:      #16a34a;
  --green-bg:   #dcfce7;
  --orange:     #ea580c;
  --orange-bg:  #ffedd5;
  --red:        #dc2626;
  --red-bg:     #fee2e2;
  --yellow:     #d97706;
  --yellow-bg:  #fef3c7;

  --radius:     10px;
  --radius-lg:  16px;
  --shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:  0 4px 12px rgba(0,0,0,.1);

  --font: 'DM Sans', system-ui, sans-serif;
  --mono: 'DM Mono', monospace;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #0f172a;
    --surface:  #1e293b;
    --surface2: #162032;
    --border:   #334155;
    --border2:  #475569;
    --text:     #f1f5f9;
    --text2:    #94a3b8;
    --text3:    #64748b;
    --accent-light: #1e3a5f;
    --green-bg: #14532d;
    --orange-bg:#431407;
    --red-bg:   #450a0a;
    --yellow-bg:#451a03;
  }
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- Navbar ---- */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 17px;
  color: var(--text);
  text-decoration: none;
  margin-right: 16px;
}

.navbar-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
}

.nav-link {
  padding: 6px 14px;
  border-radius: 7px;
  color: var(--text2);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface2); color: var(--text); }
.nav-link.active { background: var(--accent-light); color: var(--accent); }

.navbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.user-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.role-admin   { background: #ede9fe; color: #6d28d9; }
.role-lehrer  { background: var(--accent-light); color: var(--accent); }
.role-kueche  { background: var(--green-bg); color: var(--green); }
.role-eltern  { background: var(--yellow-bg); color: var(--yellow); }

.user-name { font-size: 14px; color: var(--text2); }

.btn-logout {
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 7px;
  border: 1px solid var(--border2);
  color: var(--text2);
  text-decoration: none;
  transition: all .15s;
}
.btn-logout:hover { background: var(--red-bg); color: var(--red); border-color: var(--red); }

/* ---- Layout ---- */
.main-content { flex: 1; padding: 28px 24px; max-width: 1400px; width: 100%; margin: 0 auto; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title { font-size: 22px; font-weight: 600; }
.page-sub   { font-size: 14px; color: var(--text2); margin-top: 2px; }

.footer {
  text-align: center;
  padding: 16px;
  font-size: 12px;
  color: var(--text3);
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

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

.card-title { font-size: 15px; font-weight: 600; }
.card-body  { padding: 20px; }

/* ---- Grid ---- */
.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.stat-value { font-size: 32px; font-weight: 600; line-height: 1; margin-bottom: 4px; font-family: var(--mono); }
.stat-label { font-size: 13px; color: var(--text2); }
.stat-card.green  { border-left: 3px solid var(--green); }
.stat-card.orange { border-left: 3px solid var(--orange); }
.stat-card.blue   { border-left: 3px solid var(--accent); }
.stat-card.red    { border-left: 3px solid var(--red); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
thead th {
  background: var(--surface2);
  padding: 11px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
tbody tr { border-top: 1px solid var(--border); transition: background .1s; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 11px 16px; vertical-align: middle; }

/* ---- Status badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge-gescannt  { background: var(--green-bg);  color: var(--green); }
.badge-offen     { background: var(--orange-bg); color: var(--orange); }
.badge-abgemeldet{ background: var(--red-bg);    color: var(--red); }
.badge-allergy   { background: var(--yellow-bg); color: var(--yellow); font-size: 14px; padding: 2px 6px; cursor: help; }
.badge-plan      { background: var(--accent-light); color: var(--accent); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all .15s;
  font-family: var(--font);
}
.btn-primary  { background: var(--accent); color: #fff; border-color: var(--accent-dark); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary{ background: var(--surface); color: var(--text); border-color: var(--border2); }
.btn-secondary:hover { background: var(--surface2); }
.btn-danger   { background: var(--red-bg); color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-success  { background: var(--green-bg); color: var(--green); border-color: var(--green); }
.btn-success:hover { background: var(--green); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn-icon { padding: 7px; border-radius: var(--radius); }

/* ---- Forms ---- */
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--text2); }
.form-control {
  display: block;
  width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  font-family: var(--font);
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
select.form-control { cursor: pointer; }

/* Checkboxen für Wochentage */
.day-checks { display: flex; gap: 8px; flex-wrap: wrap; }
.day-check input { display: none; }
.day-check label {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1.5px solid var(--border2);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  user-select: none;
}
.day-check input:checked + label {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---- Flash messages ---- */
.flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 14px;
  font-weight: 500;
}
.flash button { background: none; border: none; cursor: pointer; font-size: 18px; color: inherit; line-height: 1; }
.flash-success { background: var(--green-bg);  color: var(--green); }
.flash-error   { background: var(--red-bg);    color: var(--red); }
.flash-warning { background: var(--yellow-bg); color: var(--yellow); }
.flash-info    { background: var(--accent-light); color: var(--accent); }

/* ---- Login page ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 28px;
  justify-content: center;
}

/* ---- Scanner specific ---- */
.scanner-page {
  background: #0f172a;
  color: #f1f5f9;
  min-height: 100vh;
}
.scanner-viewport {
  position: relative;
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  aspect-ratio: 1;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #000;
}
#scanner-video { width: 100%; height: 100%; object-fit: cover; }
.scanner-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.scanner-frame {
  width: 65%;
  height: 65%;
  border: 2px solid rgba(255,255,255,.6);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.5);
}
.scanner-line {
  position: absolute;
  left: 17.5%;
  right: 17.5%;
  height: 2px;
  background: var(--accent);
  animation: scanline 2s ease-in-out infinite;
  border-radius: 2px;
}
@keyframes scanline {
  0%   { top: 18%; }
  50%  { top: 80%; }
  100% { top: 18%; }
}
.scan-result {
  text-align: center;
  padding: 20px;
  border-radius: var(--radius-lg);
  margin-top: 16px;
}
.scan-result.ok  { background: rgba(22,163,74,.2);  border: 1px solid rgba(22,163,74,.4); }
.scan-result.err { background: rgba(220,38,38,.2);  border: 1px solid rgba(220,38,38,.4); }
.scan-result.warn{ background: rgba(234,88,12,.2);  border: 1px solid rgba(234,88,12,.4); }
.scan-name  { font-size: 24px; font-weight: 600; margin-top: 8px; }
.scan-info  { font-size: 14px; opacity: .7; }

/* ---- Live dashboard ---- */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 900px) { .dashboard-grid { grid-template-columns: 1fr; } }

.live-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--green);
  border-radius: 50%;
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%,100% { opacity: 1; transform: scale(1); }
  50%      { opacity: .5; transform: scale(.8); }
}

/* ---- Schüler-Liste ---- */
.student-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.student-row:last-child { border: none; }
.student-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-light);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}
.student-name { font-weight: 500; font-size: 14px; }
.student-class { font-size: 12px; color: var(--text2); }

/* ---- QR Card ---- */
.qr-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  max-width: 240px;
}
.qr-card img { width: 180px; height: 180px; border-radius: 8px; }

/* ---- Utility ---- */
.flex    { display: flex; }
.flex-col{ display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2   { gap: 8px; }
.gap-3   { gap: 12px; }
.gap-4   { gap: 16px; }
.mt-2    { margin-top: 8px; }
.mt-4    { margin-top: 16px; }
.mb-4    { margin-bottom: 16px; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.text-muted { color: var(--text2); }
.text-right { text-align: right; }
.font-mono { font-family: var(--mono); }
.w-full  { width: 100%; }
.strikethrough { text-decoration: line-through; color: var(--text3); }

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .main-content { padding: 16px; }
  .navbar { padding: 0 16px; }
  .grid-stats { grid-template-columns: repeat(2, 1fr); }
  .navbar-user .user-name { display: none; }
}

/* ---- Print (QR-Ausweise) ---- */
@media print {
  .navbar, .footer, .no-print { display: none !important; }
  .main-content { padding: 0; max-width: 100%; }
  .qr-card { break-inside: avoid; }
}
