:root {
  --primary: #1d5fa8;
  --primary-dark: #164a84;
  --success: #2e8b47;
  --danger: #c0392b;
  --warning-bg: #fff6dc;
  --warning-fg: #7a5a00;
  --bg: #eef1f5;
  --surface: #ffffff;
  --border: #d6dbe2;
  --text: #1f2933;
  --muted: #627080;
  --selected: #e7f0fb;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); }
h1, h2 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.25rem; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace; }
.spacer { flex: 1; }
.offscreen { position: fixed; left: -9999px; }

/* --- Bedienelemente -------------------------------------------------------- */

input, select, button { font: inherit; color: inherit; }
input[type="text"], input[type="password"], input[type="search"], input:not([type]), select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 0.92rem; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: normal; cursor: pointer; }
fieldset { border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; }
legend { font-weight: 600; font-size: 0.92rem; padding: 0 4px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #f3f5f8; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.success:hover:not(:disabled) { filter: brightness(0.92); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { filter: brightness(0.92); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(0, 0, 0, 0.05); }
.link { background: none; border: none; padding: 0; color: var(--primary); cursor: pointer; text-decoration: underline; }
.link.danger { color: var(--danger); }

.stack { display: flex; flex-direction: column; gap: 14px; }
.stack-tight { display: flex; flex-direction: column; gap: 6px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.input-group { display: flex; gap: 6px; }
.notice { background: var(--warning-bg); color: var(--warning-fg); padding: 10px 12px; border-radius: 6px; margin: 0; font-size: 0.92rem; }
.form-error { color: var(--danger); margin: 0; font-weight: 600; }
.form-result { background: #e8f5ec; color: #1d5e30; padding: 10px 12px; border-radius: 6px; margin: 0; }
.import-preview {
  max-height: 220px; overflow-y: auto; margin: 0; padding: 8px 12px 8px 28px;
  border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; line-height: 1.5;
}
.import-preview .warn { color: var(--danger); font-weight: 600; }
.big-value { font-size: 1.3rem; text-align: center; letter-spacing: 0.05em; padding: 12px !important; }

/* --- Bildschirme ----------------------------------------------------------- */

.screen-center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--surface);
  border-radius: 12px;
  padding: 32px;
  box-shadow: 0 6px 30px rgba(20, 40, 70, 0.12);
  text-align: center;
}
.auth-card form { text-align: left; margin-top: 20px; }
.auth-card .link { align-self: center; }
.auth-logo { width: 72px; height: 72px; object-fit: contain; margin-bottom: 10px; }
.auth-card h1 { font-size: 1.4rem; }
.auth-card p { margin: 4px 0 0; }

#screen-app { display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-logo { width: 56px; height: 56px; object-fit: contain; }
.topbar-title h1 { font-size: 1.3rem; }
.topbar-title p { margin: 2px 0 0; color: var(--muted); }
.topbar-actions { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }

.toolbar, .selectionbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 24px;
}
.toolbar #search { flex: 1 1 280px; width: auto; }
.toolbar select { width: auto; }
.selectionbar { background: var(--selected); border-top: 1px solid #c9dbf2; border-bottom: 1px solid #c9dbf2; }

.table-wrap { flex: 1; overflow: auto; margin: 0 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table.students { width: 100%; border-collapse: collapse; }
.students th, .students td { padding: 8px 10px; text-align: left; border-bottom: 1px solid #edf0f3; vertical-align: middle; }
.students thead th { position: sticky; top: 0; background: #f7f9fb; z-index: 1; font-size: 0.88rem; color: var(--muted); user-select: none; }
.students th[data-sort] { cursor: pointer; }
.students th[data-sort]:hover { color: var(--text); }
.students th.sorted { color: var(--text); }
.students th.sorted[data-dir="asc"]::after { content: " ▲"; font-size: 0.75em; }
.students th.sorted[data-dir="desc"]::after { content: " ▼"; font-size: 0.75em; }
.students tbody tr { cursor: default; }
.students tbody tr:hover { background: #f8fafc; }
.students tbody tr.selected { background: var(--selected); }
.col-check { width: 36px; }
.col-actions { white-space: nowrap; text-align: right !important; }
.icon { background: none; border: none; cursor: pointer; padding: 4px 6px; border-radius: 4px; font-size: 1rem; }
.icon:hover { background: rgba(0, 0, 0, 0.07); }
.badge { border: none; border-radius: 12px; padding: 3px 10px; font-size: 0.85rem; cursor: pointer; white-space: nowrap; }
.badge-ok { background: #e3f4e8; color: #1d5e30; }
.badge-open { background: #fdeceb; color: #8e2a20; }
.pw-hidden, .pw-value { background: none; border: none; padding: 2px 4px; cursor: pointer; border-radius: 4px; }
.pw-hidden { color: var(--muted); }
.pw-hidden:hover, .pw-value:hover { background: rgba(0, 0, 0, 0.06); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; margin: 0; }

.statusbar { display: flex; align-items: center; gap: 12px; padding: 10px 24px 16px; color: var(--muted); font-size: 0.9rem; }

/* --- Dialoge & Meldungen --------------------------------------------------- */

dialog {
  width: min(560px, calc(100vw - 32px));
  border: none;
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(20, 30, 45, 0.45); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
details summary { cursor: pointer; }

#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 1000; }
.toast { background: #2b3540; color: #fff; padding: 10px 16px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2); transition: opacity 0.4s; max-width: 380px; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-hide { opacity: 0; }

@media (max-width: 800px) {
  .topbar, .toolbar, .selectionbar { padding-left: 16px; padding-right: 16px; }
  .table-wrap { margin: 0 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .topbar-logo { width: 40px; height: 40px; }
}

/* --- Druck ----------------------------------------------------------------- */

#print-area { display: none; }

@media print {
  @page { size: A4; margin: 15mm; }
  body { background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; font-family: Arial, Helvetica, sans-serif; color: #000; font-size: 11pt; }

  .sheet { break-inside: avoid; }
  .layout-1 .sheet { break-after: page; padding-top: 10mm; }
  .layout-1 .sheet:last-child { break-after: auto; }
  .layout-3 .sheet { height: 87mm; padding: 4mm 0; border-bottom: 1px dashed #888; overflow: hidden; }
  .layout-3 .sheet:nth-child(3n) { border-bottom: none; break-after: page; }
  .layout-3 .sheet:last-child { break-after: auto; }
  .layout-3 .sheet-box { margin: 4mm 0; }
  .layout-3 .sheet-text { margin: 2mm 0; font-size: 9.5pt; }
  .layout-3 .sheet-footer { margin-top: 2mm; }

  /* 8 Kärtchen pro Seite: 2 × 4 im druckbaren Bereich (180 × 267 mm), gestrichelte Schnittlinien */
  .card-page {
    display: grid; grid-template-columns: repeat(2, 90mm); grid-auto-rows: 66.5mm;
    border-top: 0.5pt dashed #888; border-left: 0.5pt dashed #888;
    break-after: page;
  }
  .card-page:last-child { break-after: auto; }
  .card {
    box-sizing: border-box; padding: 4mm 5mm; overflow: hidden;
    border-right: 0.5pt dashed #888; border-bottom: 0.5pt dashed #888;
    display: flex; flex-direction: column; gap: 2.5mm;
  }
  .card-head { display: flex; align-items: center; gap: 3mm; font-size: 9pt; line-height: 1.25; }
  .card-logo { width: 10mm; height: 10mm; object-fit: contain; }
  .card-name { font-weight: bold; font-size: 12.5pt; }
  .card-creds { border-collapse: collapse; }
  .card-creds th { text-align: left; font-size: 10pt; padding: 1mm 4mm 1mm 0; }
  .card-creds td { font-size: 14.5pt; letter-spacing: 0.05em; padding: 1mm 0; }
  .card-text { margin: auto 0 0; font-size: 9pt; line-height: 1.3; color: #222; }

  .sheet-name { font-weight: bold; font-size: 13pt; }
  .sheet-class { font-weight: normal; }
  .sheet-box { border: 1pt solid #000; width: 60%; padding: 4mm; margin: 8mm 0; display: flex; align-items: center; gap: 6mm; }
  .sheet-logo { width: 16mm; height: 16mm; object-fit: contain; }
  .sheet-box-title { font-weight: bold; text-decoration: underline; margin-bottom: 3mm; }
  .sheet-creds { border-collapse: collapse; }
  .sheet-creds th { text-align: left; padding: 1mm 6mm 1mm 0; }
  .sheet-creds td { padding: 1mm 0; font-size: 12pt; letter-spacing: 0.04em; }
  .sheet-text { width: 85%; line-height: 1.4; }
  .sheet-footer { margin-top: 8mm; font-size: 8.5pt; border-top: 0.5pt solid #aaa; padding-top: 1.5mm; color: #333; }
}
