:root {
  color-scheme: light;
  --background: #f7f1e7;
  --surface: #fffdf8;
  --text: #2f261d;
  --muted: #6f6255;
  --accent: #8a6a3e;
  --accent-dark: #654a29;
  --border: #d8c9b5;
  --focus: #315c8a;
  --field-bg: #fff;
  --tint: #f8f1e7;
  --header-bg: rgba(255, 253, 248, 0.92);
  --button-bg: #654a29;
  --on-button: #fff;
  --error-text: #9d2d2d;
  --success-text: #27663c;
  --warning-border: #b77b32;
  --danger-text: #7f312c;
  --danger-border: #a65a54;
  --glow: rgba(184, 153, 105, 0.18);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --background: #1d1714;
  --surface: #2a211b;
  --text: #f4eadc;
  --muted: #cdbba6;
  --accent: #c99b62;
  --accent-dark: #e2b878;
  --border: rgba(231, 198, 156, 0.26);
  --focus: #8db8e6;
  --field-bg: #211915;
  --tint: #3a2c23;
  --header-bg: rgba(33, 25, 21, 0.92);
  --button-bg: #c99b62;
  --on-button: #21150f;
  --error-text: #ffaaa2;
  --success-text: #8fd19b;
  --warning-border: #d4a15c;
  --danger-text: #ffaaa2;
  --danger-border: #c77a73;
  --glow: rgba(201, 155, 98, 0.1);
}

.admin-theme-button {
  min-width: 2.8rem;
  padding-inline: 0.8rem;
  font-size: 1.1rem;
  line-height: 1;
}

.text-button {
  min-height: auto;
  padding: 0;
  color: var(--accent-dark);
  background: transparent;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.form-switch {
  margin: 1.25rem 0 0;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top left, var(--glow), transparent 34rem),
    var(--background);
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 3vw, 3rem);
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
}

.back-link {
  color: var(--accent-dark);
  font-weight: 600;
}

.admin-header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.admin-language-button {
  min-width: 2.8rem;
  padding-inline: 0.8rem;
}

.admin-main {
  display: grid;
  place-items: start center;
  padding: clamp(2rem, 7vw, 5rem) 1rem;
}

.admin-card {
  width: min(100%, 38rem);
  padding: clamp(1.5rem, 5vw, 3rem);
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--surface);
  box-shadow: 0 1.5rem 4rem rgba(60, 43, 25, 0.1);
}

.eyebrow {
  margin: 0 0 0.5rem;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2rem, 7vw, 3rem);
  font-weight: 500;
}

.intro {
  margin: 1rem 0 2rem;
  color: var(--muted);
  line-height: 1.6;
}

form,
label {
  display: grid;
  gap: 0.6rem;
}

form {
  gap: 1.25rem;
}

label {
  font-weight: 650;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  padding: 0.85rem 0.95rem;
  color: var(--text);
  background: var(--field-bg);
  font: inherit;
}

textarea {
  resize: vertical;
}

/* Auswahlfelder im selben Stil wie die Eingabefelder, mit eigenem Pfeil (passt sich dem Dunkelmodus an). */
select {
  width: 100%;
  min-height: 3rem;
  border: 1px solid var(--border);
  border-radius: 0.55rem;
  padding: 0.75rem 2.6rem 0.75rem 0.95rem;
  color: var(--text);
  background-color: var(--field-bg);
  background-image:
    linear-gradient(45deg, transparent 50%, var(--accent) 50%),
    linear-gradient(135deg, var(--accent) 50%, transparent 50%);
  background-position:
    calc(100% - 1.25rem) 50%,
    calc(100% - 0.9rem) 50%;
  background-size: 0.35rem 0.35rem;
  background-repeat: no-repeat;
  font: inherit;
  appearance: none;
  cursor: pointer;
}

select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 40%, transparent);
  outline-offset: 2px;
}

input:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 40%, transparent);
  outline-offset: 2px;
}

button {
  min-height: 2.8rem;
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 1.25rem;
  color: var(--on-button);
  background: var(--button-bg);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.button-link {
  display: inline-flex;
  min-height: 2.8rem;
  align-items: center;
  border-radius: 999px;
  padding: 0.7rem 1.25rem;
  color: var(--on-button);
  background: var(--button-bg);
  font-weight: 700;
  text-decoration: none;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.secondary-button {
  color: var(--accent-dark);
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--border);
}

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 2rem;
}

#accountLabel {
  margin: 0;
  overflow-wrap: anywhere;
}

.status {
  min-height: 1.5rem;
  margin: 1rem 0 0;
  color: var(--muted);
}

.status.error {
  color: var(--error-text);
}

.status.success {
  color: var(--success-text);
}

[hidden] {
  display: none !important;
}

@media (max-width: 36rem) {
  .admin-header,
  .account-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .admin-header-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 0.6rem 1rem;
  }
}

/* Kachelübersicht: kompakte Einstiege, ein Klick öffnet den ganzen Bereich. */
.section-tiles {
  display: grid;
  /* auto-fill: wenige Kacheln bleiben klein, statt die ganze Breite zu füllen. */
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.85rem;
  margin-top: 1.5rem;
}

.section-tile {
  position: relative;
  display: grid;
  align-content: start;
  gap: 0.25rem;
  min-height: 0;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1rem 3rem rgba(60, 43, 25, 0.07);
  text-decoration: none;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.section-tile:hover,
.section-tile:focus-visible {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.section-tile-icon {
  display: grid;
  place-items: center;
  width: 2.1rem;
  height: 2.1rem;
  margin-bottom: 0.25rem;
  border-radius: 50%;
  color: var(--accent-dark);
  background: var(--tint);
  font-size: 1.1rem;
}

.section-tile strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.1rem;
  font-weight: 500;
}

.section-tile small {
  color: var(--muted);
  line-height: 1.4;
}

.section-tile-count {
  position: absolute;
  top: 1rem;
  right: 1rem;
  min-width: 2rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  color: var(--accent-dark);
  background: var(--tint);
  font-weight: 600;
  text-align: center;
}

.section-tile-count:empty {
  display: none;
}

.section-back {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--accent-dark);
  font-weight: 600;
  text-decoration: none;
}

.section-back:hover,
.section-back:focus-visible {
  text-decoration: underline;
}

.section-tiles[hidden],
[data-section][hidden],
[data-section-container][hidden] {
  display: none !important;
}

.section-tile-thumb {
  width: 100%;
  height: 5.5rem;
  margin-bottom: 0.25rem;
  border-radius: 0.6rem;
  object-fit: cover;
  background: var(--tint);
}

/* Auf dem Handy (auch als App) zwei kompakte Spalten, damit alles auf einen Blick passt. */
@media (max-width: 36rem) {
  .section-tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .section-tile {
    min-height: 0;
    padding: 0.9rem;
  }

  .section-tile strong {
    font-size: 1.05rem;
  }

  .section-tile small {
    display: none;
  }

  .section-tile-count {
    top: 0.9rem;
    right: 0.9rem;
  }

  .section-tile-thumb {
    height: 5rem;
  }
}

/* Nach der Anmeldung nutzt die Lehrerübersicht die volle Breite statt einer schmalen Spalte. */
.admin-card:has(#teacherPanel:not([hidden])) {
  width: min(100%, 72rem);
}

#teacherPanel .section-tiles {
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
}

@media (max-width: 36rem) {
  #teacherPanel .section-tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Leere Statuszeilen belegen keinen Platz, bleiben aber für Vorleseprogramme erhalten. */
main > .status:empty {
  min-height: 0;
  margin: 0;
}

/* Kompakter Seitenkopf auf allen Lehrerseiten, damit der Inhalt ohne Scrollen sichtbar ist. */
body :is(.materials-main, .media-main, .operations-main) {
  padding-top: 1.25rem;
}

:is(.materials-heading, .media-heading, .operations-heading) h1 {
  margin-block: 0;
  font-size: clamp(1.5rem, 2.4vw, 2rem);
}

:is(.materials-heading, .media-heading, .operations-heading) .eyebrow {
  margin-bottom: 0.2rem;
}

:is(.materials-heading, .media-heading, .operations-heading) .intro {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
}

/* Ist ein Bereich offen, entfällt zusätzlich der Einleitungstext. */
html[data-section-open] :is(.materials-heading, .media-heading, .operations-heading) .intro {
  display: none;
}

:is(.materials-main, .media-main, .operations-main) > :is(.section-tiles, .media-section, .materials-card, .operations-card) {
  margin-top: 1rem;
}

/* Navigation der Lehrerbereiche in der Kopfzeile, rechts neben den Einstellungen. */
.teacher-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.15rem;
  margin-right: 0.5rem;
  order: -1;
}

.teacher-nav[hidden] {
  display: none;
}

.teacher-nav a {
  padding: 0.3rem 0.7rem;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.teacher-nav a:hover,
.teacher-nav a:focus-visible {
  border-color: var(--border);
  background: var(--tint);
}

.teacher-nav a[aria-current="page"] {
  border-color: var(--accent);
  color: var(--accent-dark);
  background: var(--tint);
}

/* Breite Bildschirme: Leiste fest links neben dem Logo verankert, Einstellungen rechts.
   So steht sie auf jeder Seite an derselben Stelle, egal was rechts daneben steht. */
@media (min-width: 60.01rem) {
  .admin-header-actions:has(.teacher-nav:not([hidden])) {
    flex: 1;
  }

  .teacher-nav {
    margin: 0 auto 0 1.5rem;
  }
}

/* Auf schmalen Bildschirmen eine wischbare Zeile über die volle Breite. */
@media (max-width: 60rem) {
  .admin-header-actions:has(.teacher-nav:not([hidden])) {
    flex-wrap: wrap;
    justify-content: flex-end;
    row-gap: 0.5rem;
  }

  .teacher-nav {
    order: 10;
    flex: 1 0 100%;
    flex-wrap: nowrap;
    margin-right: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .teacher-nav a {
    flex: none;
  }
}

/* Lehrerbereich nach der Anmeldung kompakter. */
.admin-main:has(#teacherPanel:not([hidden])) {
  padding-top: 1.25rem;
}

.admin-card:has(#teacherPanel:not([hidden])) {
  padding: clamp(1rem, 2.5vw, 1.75rem);
}

#teacherPanel > h1 {
  margin: 0.5rem 0 0;
  font-size: clamp(1.5rem, 2.4vw, 2rem);
}

#teacherPanel > .intro {
  margin: 0.25rem 0 0;
}

/* Website-Text: ohne Überschriftenblock, Formular direkt sichtbar. */
html[data-section-open] #teacherPanel > :is(h1, .intro) {
  display: none;
}

#teacherPanel [data-section="text"] {
  margin-top: 0.75rem;
}

#teacherPanel [data-section="text"] h2 {
  margin: 0.25rem 0;
  font-size: 1.4rem;
}

#teacherPanel [data-section="text"] .intro {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
}

#contentForm button[type="submit"] {
  justify-self: start;
  width: auto;
}

/* Website-Texte: Abschnittsleiste, darunter je Text eine Zeile mit Bezeichnung, Deutsch, Russisch. */
.site-text-sections {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.9rem;
}

.site-text-sections button {
  min-height: 0;
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--border);
  color: var(--text);
  background: transparent;
  font-size: 0.9rem;
}

.site-text-sections button[aria-current="true"] {
  border-color: var(--accent);
  color: var(--accent-dark);
  background: var(--tint);
}

.site-text-badge {
  margin-left: 0.4rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  color: var(--on-button);
  background: var(--accent);
  font-size: 0.75rem;
}

.site-text-form {
  display: grid;
  gap: 0.5rem;
}

#siteTextFields {
  display: grid;
  gap: 0.5rem;
}

.site-text-row {
  display: grid;
  grid-template-columns: minmax(9rem, 13rem) minmax(0, 1fr) minmax(0, 1fr);
  gap: 0.75rem;
  align-items: start;
}

.site-text-head {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.site-text-label {
  padding-top: 0.55rem;
  font-size: 0.9rem;
  font-weight: 700;
}

.site-text-field {
  position: relative;
}

.site-text-field textarea {
  padding: 0.5rem 0.7rem;
  line-height: 1.4;
}

.site-text-field.is-changed textarea {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--field-bg) 88%, var(--accent) 12%);
}

.site-text-reset {
  position: absolute;
  top: 0.25rem;
  right: 0.35rem;
  min-height: 0;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--border);
  color: var(--accent-dark);
  background: var(--surface);
  font-size: 0.72rem;
}

.site-text-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-top: 0.25rem;
}

.site-text-actions .status {
  margin: 0;
}

@media (max-width: 48rem) {
  .site-text-row {
    grid-template-columns: 1fr;
    gap: 0.3rem;
  }

  .site-text-head {
    display: none;
  }

}

/* Zusätzliche Fragen unter den festen Fragen. */
.site-text-extra {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.site-text-extra h3 {
  margin: 0;
  font-size: 1.1rem;
}

.site-text-extra-hint {
  margin: 0 0 0.25rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.site-text-label .site-text-remove {
  position: static;
  margin-top: 0.35rem;
  color: var(--error-text);
}

.site-text-add {
  justify-self: start;
}

/* Bestätigung nach dem Speichern, unten mittig. */
.teacher-toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  z-index: 100;
  max-width: calc(100vw - 2rem);
  padding: 0.8rem 1.4rem;
  border-radius: 999px;
  color: #fff;
  background: #2f6b3a;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 1rem);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.teacher-toast[data-type="error"] {
  background: #8b2a22;
}

.teacher-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Ungespeicherte Änderungen: Speichern-Button hervorheben. */
button.has-unsaved {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent);
}

.unsaved-note {
  color: var(--accent-dark);
  font-size: 0.85rem;
  font-weight: 700;
}
