/* Grundgerüst der Oberfläche. Maße und Aufbau aus docs/design/Main.html (Rechner) und
   docs/design/Anlegen.html (iPhone). Keine Inline-Styles: die CSP erlaubt nur style-src 'self'. */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
}

a { color: var(--accent); }
a:hover { color: var(--text); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- Rahmen: Navigation links, Inhalt rechts -------------------------------------------- */

.shell { min-height: 100vh; display: flex; align-items: stretch; }

.nav {
  flex: 0 0 240px;
  padding: 28px 20px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand:hover { color: var(--text); }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: var(--on-accent);
  display: flex; align-items: center; justify-content: center; font-weight: 600;
}
.brand-name { font-weight: 600; font-size: 17px; }

.nav-links { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
  display: flex; align-items: center; min-height: 44px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--muted); text-decoration: none;
}
.nav-link:hover { color: var(--text); background: var(--surface2); }
.nav-link[aria-current="page"] { color: var(--text); background: var(--accent-soft); font-weight: 600; }

.nav-short { display: none; }
.nav-foot { margin-top: auto; font-size: 13px; color: var(--muted); line-height: 1.5; }
.nav-account { display: flex; flex-direction: column; gap: 8px; }
.nav-session { margin: 0; }
.nav-server { margin-top: 8px; }
/* Nach einer Anmeldung mit Wiederherstellungscode: Hinweis auf einen neuen Passkey */
.nav-hint { margin: 8px 0; padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); }
.nav-hint a { color: inherit; font-weight: 600; text-decoration: underline; }

.main {
  flex: 1 1 auto;
  min-width: 0;
  padding: 40px 48px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* iPhone und schmale Fenster: Navigation wird zur Leiste oben */
@media (max-width: 720px) {
  body { font-size: 16px; }
  .shell { flex-direction: column; }
  .nav {
    flex: none;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  /* Nur das Zeichen, damit Marke und Links in eine Zeile passen */
  .brand-name {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  .nav-links { flex-direction: row; gap: 4px; margin-left: auto; }
  .nav-link { padding: 0 10px; }
  /* Kurzform sichtbar, volle Bezeichnung bleibt für Bildschirmleser (enthält die Kurzform) */
  .nav-short { display: inline; }
  .nav-link .nav-full:not(:only-child) {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
  /* Kompakte Fußzeile als eigene Zeile: Anmeldeart und Abmelden nebeneinander */
  .nav-foot { flex: 1 0 100%; margin-top: 0; }
  .nav-account { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
  .nav-logout .link-button { min-height: 44px; padding: 0 4px; }
  .nav-server { display: none; }
  .main { padding: 20px 16px calc(24px + env(safe-area-inset-bottom)); gap: 20px; }
}

/* --- Seitenkopf ------------------------------------------------------------------------- */

.page-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px;
}
.page-title { margin: 0; font-size: 28px; font-weight: 600; }
.page-sub { margin: 6px 0 0; color: var(--muted); }

@media (max-width: 720px) {
  .page-title { font-size: 22px; }
}

/* --- Flächen ---------------------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 24px;
}
.card-title { margin: 0 0 6px; font-size: 18px; font-weight: 600; }
.card-text { margin: 0; color: var(--muted); }

.empty { text-align: center; padding: 48px 24px; }

/* --- Schaltflächen ---------------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px; border-radius: 10px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { color: var(--on-accent); filter: brightness(1.08); }
.btn-secondary { background: transparent; border-color: var(--accent); color: var(--accent); }
.btn-secondary:hover { color: var(--text); border-color: var(--text); }

/* --- Statuskennzeichen ------------------------------------------------------------------ */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 500;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-err { background: var(--err-soft); color: var(--err); }

/* --- Formulare -------------------------------------------------------------------------- */

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

.fieldset { border: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.legend, .label { padding: 0; font-size: 14px; color: var(--muted); font-weight: 500; }
.hint { font-size: 13px; color: var(--muted); }

.input {
  min-height: 48px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit;
}

/* Umschalter mit gleich breiten Segmenten (Anlegen.html: Fach) */
.segmented {
  display: grid; grid-auto-columns: minmax(0, 1fr); grid-auto-flow: column;
  gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface2);
  max-width: 420px;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
  min-height: 44px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); cursor: pointer;
}
.segmented input:checked + label { background: var(--surface); color: var(--text); font-weight: 600; }
.segmented input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }

.form-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.card-text + .form, .card-text + .alert { margin-top: 16px; }

/* --- htmx ------------------------------------------------------------------------------- */
/* htmx fügt seine Indikator-Styles nicht selbst ein (CSP), deshalb hier */

.htmx-indicator { opacity: 0; transition: opacity 200ms ease-in; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* --- Hilfsklassen ---------------------------------------------------------------------- */

[hidden] { display: none !important; }

.field { display: flex; flex-direction: column; gap: 6px; }
.input { width: 100%; }
.input-code { font-size: 18px; letter-spacing: 0.06em; text-transform: uppercase; }
.input-code::placeholder { text-transform: none; letter-spacing: 0.04em; }

.btn-block { width: 100%; min-height: 52px; border-radius: 12px; }
.btn-quiet { background: transparent; color: var(--muted); border-color: var(--border); font-weight: 500; }
.btn-quiet:hover { color: var(--err); border-color: var(--err); }
.btn:disabled { opacity: 0.6; cursor: progress; }

.link-button {
  padding: 0; border: none; background: none; font: inherit; color: var(--accent);
  text-decoration: underline; cursor: pointer;
}

.alert { margin: 0; padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.alert-err { background: var(--err-soft); color: var(--err); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-ok { background: var(--ok-soft); color: var(--ok); }

.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.section-head .card-title { margin: 0; }

.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px;
  padding: 12px 0; border-top: 1px solid var(--border);
}
.row:first-child { border-top: none; }
.row-title { font-weight: 600; }
.row-meta { font-size: 13px; color: var(--muted); }

/* --- Anmeldeseiten (ohne Navigation) --------------------------------------------------- */

.auth {
  min-height: 100vh;
  max-width: 440px;
  margin: 0 auto;
  padding: calc(40px + env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.auth-brand { display: flex; align-items: center; gap: 10px; }
/* Ohne Navigation ist Platz für den Namen, auch am iPhone */
.auth-brand .brand-name { position: static; width: auto; height: auto; overflow: visible; clip: auto; }
.auth-card { display: flex; flex-direction: column; gap: 16px; }
.auth-title { margin: 0; font-size: 22px; font-weight: 600; }

.disclosure { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 12px; }
.disclosure summary { cursor: pointer; color: var(--accent); min-height: 44px; display: flex; align-items: center; }
.disclosure[open] summary { margin-bottom: 8px; }
.disclosure .form { margin-bottom: 12px; }

.code-list {
  margin: 0; padding: 0 0 0 28px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px 20px;
}
.code-list code, .code-big { font-family: var(--font-sans); font-weight: 600; letter-spacing: 0.06em; }
.code-big { margin: 4px 0; font-size: 32px; }

.device-code { display: flex; flex-wrap: wrap; gap: 24px; align-items: center; }
.device-code-qr { flex: 0 0 220px; }
.device-code-text { flex: 1 1 260px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
/* QR-Code immer dunkel auf hell, auch im Dunkelmodus, damit Kameras ihn lesen */
.qr { width: 100%; height: auto; display: block; border-radius: 8px; }
.qr-bg { fill: #FFFFFF; }
.qr-fg { fill: #000000; }

/* --- Bewertungsprofile ------------------------------------------------------------------- */

.profile-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 16px; }
.profile-card { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.breadcrumb { margin: 0 0 6px; font-size: 14px; }
.alert-title { margin: 0 0 4px; font-weight: 600; }
.alert ul { margin: 0; padding-left: 20px; }
.key-table { border-collapse: collapse; margin-top: 12px; }
.key-table th, .key-table td { padding: 6px 12px 6px 0; text-align: left; font-weight: 400; }
.key-table thead th { font-size: 13px; color: var(--muted); }
.key-table td { display: flex; align-items: center; gap: 6px; }
.input-percent { width: 6em; text-align: right; }
.rule { border: none; border-top: 1px solid var(--border); margin: 16px 0 0; padding: 16px 0 0; display: flex; flex-direction: column; gap: 12px; }
.textarea { min-height: 80px; resize: vertical; font: inherit; }
.check { display: flex; align-items: center; gap: 8px; min-height: 44px; font-size: 14px; color: var(--muted); }

/* --- Klassenarbeiten --------------------------------------------------------------------- */

.exam-form { max-width: 640px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.optional { font-weight: 400; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chips label {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.chips input:checked + label { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.chips input:checked + label::before { content: "✓"; margin-right: 6px; }
.chips input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
.check-card { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; }
.check-card input { width: 20px; height: 20px; margin-top: 2px; flex: none; }
.check-card label { display: flex; flex-direction: column; gap: 2px; }
.check-title { font-weight: 600; }
.exam-row-facts { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 12px 0 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
@media (max-width: 720px) {
  .exam-form { max-width: none; }
}
.pre-line { white-space: pre-line; }
.btn-danger { background: var(--err); border-color: var(--err); color: var(--surface); }
.confirm-actions { margin-top: 16px; }

/* --- Aufgabenblatt ----------------------------------------------------------------------- */

.sheet-pages { list-style: none; margin: 12px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 180px)); gap: 16px; }
.sheet-page { display: flex; flex-direction: column; gap: 8px; }
.sheet-page img { width: 100%; height: auto; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.sheet-page-bar { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.sheet-page-label { font-weight: 600; font-size: 14px; }
.sheet-page-actions { display: flex; gap: 2px; }
.icon-button {
  min-width: 44px; min-height: 44px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.icon-button:disabled { color: var(--muted); cursor: default; opacity: 0.6; }
[data-upload-error]:focus { outline: none; }

/* --- Hilfsmittel -------------------------------------------------------------------------- */

.aid-row { border: none; border-top: 1px solid var(--border); margin: 12px 0 0; padding: 12px 0 0; display: flex; flex-direction: column; gap: 8px; }
.aid-row:first-of-type { border-top: none; margin-top: 4px; padding-top: 0; }
.aid-row-options { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; }
.aid-subjects { display: flex; flex-wrap: wrap; gap: 0 16px; }
.facts dd { overflow-wrap: anywhere; }
@media (max-width: 720px) {
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 8px; }
}
.aid-remove { border-top: 1px dashed var(--border); margin-top: 2px; }

/* --- Erwartungshorizont ------------------------------------------------------------------ */

.draft-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.stat-label { margin: 0; font-size: 13px; color: var(--muted); }
.stat-value { margin: 4px 0 0; font-size: 20px; font-weight: 600; }
.findings { margin: 8px 0 0; padding-left: 20px; }
.table-scroll { overflow-x: auto; }
.points-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.points-table th, .points-table td { padding: 8px 8px 8px 0; text-align: left; border-top: 1px solid var(--border); font-weight: 400; }
.points-table thead th { font-size: 13px; color: var(--muted); border-top: none; }
.points-table tfoot th, .points-table tfoot td { font-weight: 600; }
.points-table .num { text-align: right; }
.subtask h3.label { margin: 12px 0 4px; }
.draft-running { border-color: var(--accent); }
.run-inputs { margin: 8px 0 0; padding-left: 20px; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }

/* --- Erwartungshorizont: Aufgabenblatt neben dem Entwurf, Formeln, Staffeln, offene Fragen --------------- */
.scheme-layout { display: grid; grid-template-columns: minmax(260px, 2fr) 3fr; gap: 24px; align-items: start; }
.scheme-layout > :only-child { grid-column: 1 / -1; }
.scheme-main { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.sheet-panel { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; }
.sheet-panel summary { cursor: pointer; }
.sheet-panel-pages { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.sheet-panel-pages img { width: 100%; height: auto; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
@media (max-width: 960px) {
  .scheme-layout { grid-template-columns: 1fr; }
  .sheet-panel { position: static; max-height: none; }
}
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 4px 0; padding-left: 22px; }
.md-table, .steps-table { border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.md-table th, .md-table td, .steps-table th, .steps-table td { padding: 4px 10px 4px 0; border-top: 1px solid var(--border); text-align: left; font-weight: 400; }
.md-table thead th, .steps-table thead th { color: var(--muted); font-size: 13px; border-top: none; }
.steps-table .num { text-align: right; }
.md, .criterion-text { max-width: 100%; }
.md .md-table { display: block; overflow-x: auto; }
.math-display { display: block; margin: 6px 0; overflow-x: auto; }
.criteria { list-style: none; margin: 0; padding: 0; }
.criterion { padding: 8px 0; border-top: 1px solid var(--border); }
.criterion:first-child { border-top: none; }
.criterion-line { display: flex; justify-content: space-between; gap: 12px; }
.criterion-points { font-weight: 600; white-space: nowrap; }
.criterion-zero .criterion-points { color: var(--warn); }
.criterion .badge { margin: 4px 0 0; }
.question { margin: 12px 0; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.question-open { border-color: var(--warn); }
.question-title { margin: 0; }
.question .section-head { margin-bottom: 4px; }
.question-answer { margin-top: 6px; }
.question-actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px 12px; margin-top: 10px; }
.question-answer-form { flex: 1 1 260px; }
.question-answer-form summary { cursor: pointer; padding: 10px 0; color: var(--accent); font-weight: 500; }
.subtask-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px 12px; margin-top: 16px; }
.subtask-reviewed { border-color: var(--ok); }

/* --- Editor einer Teilaufgabe -------------------------------------------------------------------------- */
.subtask-form .card { display: flex; flex-direction: column; gap: 16px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.field.check { flex-direction: row; align-items: center; gap: 8px; flex-wrap: wrap; }
.input-short { max-width: 110px; }
.criterion-edit { margin: 0; padding: 16px; border: 1px solid var(--border); border-radius: 10px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.criterion-edit legend { padding: 0 4px; }
.staffel { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.steps-edit td { padding-right: 8px; }
.criterion-actions { display: flex; justify-content: flex-end; }
.ai-hint { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 4px; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.changed-note { margin-top: 8px; }
.regenerate { margin-top: 12px; } .regenerate summary { cursor: pointer; padding: 10px 0; color: var(--accent); font-weight: 500; }
