/* ═══════════════════════════════════════════════════════════════════════════
   Lektions-Bot — Design-System (mobile first)
   Alle Abstände/Farben laufen über Tokens, damit sich das Erscheinungsbild
   einer anderen Feuerwehr über die Akzentfarbe anpassen lässt.
   ═══════════════════════════════════════════════════════════════════════════ */

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

:root {
  /* --brand / --brand-dark / --brand-tint kommen aus index.html (Branding) */
  --brand: #CC2200;
  --brand-dark: #991A00;
  --brand-tint: #FDEEEB;

  --bg:          #F3F2EF;
  --surface:     #FFFFFF;
  --surface-2:   #F7F6F3;
  --surface-3:   #EFEEEA;
  --border:      #E1DFD9;
  --border-str:  #CFCCC4;
  --text:        #23231F;
  --text-2:      #4A4944;
  --muted:       #77756E;

  --ok:      #147D5A;
  --ok-bg:   #E3F5ED;
  --warn:    #8A5A00;
  --warn-bg: #FFF4DE;
  --err:     #C0281A;
  --err-bg:  #FDEBE8;

  --r-sm: 8px;
  --r:    12px;
  --r-lg: 18px;

  --sh-1: 0 1px 2px rgba(25,22,18,.05), 0 1px 3px rgba(25,22,18,.04);
  --sh-2: 0 4px 12px rgba(25,22,18,.08), 0 2px 4px rgba(25,22,18,.04);
  --sh-3: 0 16px 48px rgba(25,22,18,.18);

  --header-h: 56px;
  --nav-h: 58px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --gutter: 14px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:         #171614;
    --surface:    #201F1C;
    --surface-2:  #262522;
    --surface-3:  #2E2D29;
    --border:     #35332E;
    --border-str: #474540;
    --text:       #EFEDE8;
    --text-2:     #C9C6BF;
    --muted:      #96938B;

    --ok-bg:   #12302A;
    --warn-bg: #33280F;
    --err-bg:  #3A1C18;
    --ok:      #57C79E;
    --warn:    #E0AE5A;
    --err:     #F0796A;

    --sh-1: 0 1px 2px rgba(0,0,0,.4);
    --sh-2: 0 4px 14px rgba(0,0,0,.45);
    --sh-3: 0 16px 48px rgba(0,0,0,.6);
  }
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

[hidden] { display: none !important; }

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

::selection { background: var(--brand); color: #fff; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

/* ── LOGIN ─────────────────────────────────────────────────────────────── */

.login-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-t)) var(--gutter) calc(24px + var(--safe-b));
  background:
    radial-gradient(1000px 520px at 50% -10%,
                    color-mix(in srgb, var(--brand) 14%, transparent), transparent 70%),
    var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-2);
  padding: 30px 22px 26px;
  width: 100%; max-width: 390px;
  display: flex; flex-direction: column;
}
.login-logo { height: 46px; width: auto; max-width: 70%; object-fit: contain; align-self: center; margin-bottom: 16px; }
.login-org  { font-size: 1.05rem; font-weight: 700; text-align: center; line-height: 1.3; }
.login-app  { font-size: .88rem; color: var(--muted); text-align: center; }
.login-sub  { font-size: .8rem; color: var(--muted); text-align: center; margin: 8px 0 22px; line-height: 1.45; }
.login-sub:empty { margin: 0 0 22px; }
/* Passwort-setzen-Karte hat keinen .login-sub – Abstand hier setzen */
#setpw-fields { margin-top: 20px; }
.login-card .field { margin-bottom: 12px; }
.login-card .btn { margin-top: 8px; }
.login-err  { font-size: .85rem; color: var(--err); text-align: center; margin-top: 12px; min-height: 1.2em; }

/* ── HEADER ────────────────────────────────────────────────────────────── */

.app-header {
  position: sticky; top: 0; z-index: 60;
  display: flex; align-items: center; gap: 10px;
  height: calc(var(--header-h) + var(--safe-t));
  padding: var(--safe-t) var(--gutter) 0;
  background: var(--brand);
  color: #fff;
}
.app-logo { height: 30px; width: auto; max-width: 96px; object-fit: contain; flex-shrink: 0; }
@media (max-width: 400px) { .app-logo { max-width: 72px; } }
.app-titles { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; flex: 1; }
.app-org  { font-size: .93rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-name { font-size: .72rem; opacity: .82; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.status-badge {
  font-size: .68rem; font-weight: 600; padding: 3px 9px; border-radius: 99px;
  white-space: nowrap; flex-shrink: 0;
}
.status-badge.is-ok      { background: rgba(255,255,255,.2); color: #fff; }
.status-badge.is-error   { background: #fff; color: var(--err); }
.status-badge.is-loading { background: rgba(255,255,255,.16); color: rgba(255,255,255,.85); }

/* Auf schmalen Displays ist im Header kein Platz für den Text:
   alles in Ordnung → ausblenden, Problem → roter Punkt (Details im title). */
@media (max-width: 639px) {
  /* Auf dem Handy bricht der Import-Knopf sonst den Kartentitel um */
  #input-card .card-head h2 { flex: 1 0 100%; }
  #input-card .card-head .btn { width: 100%; }
  .status-badge.is-ok, .status-badge.is-loading { display: none; }
  .status-badge.is-error {
    width: 9px; height: 9px; padding: 0; border-radius: 50%;
    font-size: 0; overflow: hidden; background: #FFD4CE;
    box-shadow: 0 0 0 2px rgba(255,255,255,.35);
  }
}

.user-btn {
  display: flex; align-items: center; gap: 7px; flex-shrink: 0;
  background: rgba(255,255,255,.14); color: #fff;
  border: 0; border-radius: 99px; padding: 5px 9px 5px 5px;
  font: inherit; font-size: .8rem; cursor: pointer;
  min-height: 36px;
}
.user-btn:hover { background: rgba(255,255,255,.24); }
.user-initials {
  width: 26px; height: 26px; border-radius: 50%; background: rgba(255,255,255,.9);
  color: var(--brand-dark); font-weight: 800; font-size: .72rem;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.user-btn .user-name { display: none; }
.user-btn .chev { opacity: .8; }

.user-menu {
  position: absolute; top: calc(var(--header-h) + var(--safe-t) - 4px); right: var(--gutter);
  z-index: 70; min-width: 210px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--sh-3);
  padding: 6px; display: flex; flex-direction: column;
}
.user-menu button {
  text-align: left; background: none; border: 0; font: inherit; font-size: .9rem;
  color: var(--text); padding: 11px 12px; border-radius: var(--r-sm); cursor: pointer;
}
.user-menu button:hover { background: var(--surface-2); }
.user-menu button.danger { color: var(--err); }
.user-menu hr { border: 0; border-top: 1px solid var(--border); margin: 5px 8px; }

/* ── NAVIGATION ────────────────────────────────────────────────────────── */

.top-nav { display: none; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}
.bottom-nav button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; min-height: var(--nav-h); padding: 6px 2px;
  background: none; border: 0; font: inherit; font-size: .66rem; font-weight: 600;
  color: var(--muted); cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.bottom-nav button svg { width: 21px; height: 21px; }
.bottom-nav button.active { color: var(--brand); }
.bottom-nav button.is-cta .nav-icon {
  background: var(--brand); color: #fff; border-radius: 12px;
  width: 38px; height: 26px; display: flex; align-items: center; justify-content: center;
  box-shadow: var(--sh-1);
}
.bottom-nav button.is-cta.active .nav-icon { background: var(--brand-dark); }

/* ── LAYOUT ────────────────────────────────────────────────────────────── */

main {
  max-width: 1120px; margin: 0 auto;
  padding: 16px var(--gutter) calc(var(--nav-h) + var(--safe-b) + 28px);
}
.view { display: none; }
.view.active { display: block; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.view-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.view-head h2 { font-size: 1.35rem; font-weight: 700; letter-spacing: -.01em; flex: 1; }
.view-head-actions { display: flex; gap: 8px; align-items: center; }

/* ── KARTEN ────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  margin-bottom: 16px;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.card-head h2 { font-size: .98rem; font-weight: 700; flex: 1; }
.card-head-note { font-size: .78rem; color: var(--muted); }
.card-body { padding: 16px; }
.card-body-sep { border-top: 1px solid var(--border); }

.group-label {
  font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); margin: 18px 0 10px;
}
.card-body > .group-label:first-child { margin-top: 0; }

.hint { font-size: .8rem; color: var(--muted); line-height: 1.5; }

.banner {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 13px; border-radius: var(--r); font-size: .84rem;
  margin-bottom: 12px;
}
.banner svg { flex-shrink: 0; }
.banner-info { background: var(--warn-bg); color: var(--warn); }

.empty-state {
  text-align: center; padding: 42px 20px; color: var(--muted); font-size: .9rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg);
}

/* ── FORMULARE ─────────────────────────────────────────────────────────── */

.form-grid { display: grid; grid-template-columns: 1fr; gap: 13px; }
.col-full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
label {
  font-size: .79rem; font-weight: 600; color: var(--text-2);
}
.label-hint { font-weight: 400; color: var(--muted); }

input[type=text], input[type=password], input[type=number], input[type=search],
input[type=email], input[type=date], select, textarea {
  width: 100%;
  /* 16px verhindert das automatische Zoomen von iOS Safari beim Fokus */
  font: inherit; font-size: 16px;
  padding: 11px 12px;
  border: 1px solid var(--border-str); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  min-height: 44px;
  -webkit-appearance: none; appearance: none;
}
textarea { resize: vertical; min-height: 84px; line-height: 1.55; }
/* Datumsfelder behalten ihr Bedienelement zum Auswählen */
input[type=date] { appearance: auto; -webkit-appearance: none; }
input[type=date]::-webkit-calendar-picker-indicator { cursor: pointer; opacity: .6; }
input[type=date]::-webkit-calendar-picker-indicator:hover { opacity: 1; }

/* Datumszeilen: auswählen oder tippen, bei Bedarf mehrere */
.date-rows { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.date-row { display: flex; align-items: center; gap: 6px; }
.date-row input { flex: 1; min-width: 0; }
.date-row input.is-freitext { font-style: italic; }
.date-rows .add-item-btn { order: 99; align-self: flex-start; }
select {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2377756E' stroke-width='2.5' stroke-linecap='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; background-size: 16px;
  padding-right: 36px;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .75; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
input[type=color] {
  padding: 4px; height: 44px; width: 100%; max-width: 110px; cursor: pointer;
  border: 1px solid var(--border-str); border-radius: var(--r-sm); background: var(--surface);
}

.check, .switch {
  display: flex; align-items: center; gap: 9px;
  font-size: .88rem; color: var(--text-2); cursor: pointer;
  min-height: 40px; user-select: none;
}
.check input[type=checkbox], .switch input[type=checkbox] {
  width: 20px; height: 20px; flex-shrink: 0; accent-color: var(--brand); cursor: pointer;
}
.check-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 14px; margin-bottom: 14px; }

.btn-row { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 16px; }
.btn-row .btn { flex: 1; min-width: 140px; }

.form-msg { font-size: .84rem; margin-top: 10px; min-height: 1.2em; }
.form-msg.ok  { color: var(--ok); }
.form-msg.err { color: var(--err); }

/* ── BUTTONS ───────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-size: .88rem; font-weight: 600;
  padding: 10px 16px; min-height: 44px;
  border: 1px solid transparent; border-radius: var(--r-sm);
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-brand { background: var(--brand); color: #fff; }
.btn-brand:hover:not(:disabled) { background: var(--brand-dark); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-str); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost.danger { color: var(--err); }
.btn-block { width: 100%; }
.btn-sm { font-size: .82rem; padding: 8px 12px; min-height: 38px; }
.btn-icon { padding: 0; width: 44px; min-width: 44px; }
.btn-icon.btn-sm { width: 38px; min-width: 38px; }

/* ── MODUS-AUSWAHL ─────────────────────────────────────────────────────── */

.mode-choice { display: grid; grid-template-columns: 1fr; gap: 11px; margin-top: 14px; }
.mode-card {
  display: flex; flex-direction: column; gap: 5px; text-align: left;
  border: 1.5px solid var(--border-str); border-radius: var(--r);
  background: var(--surface); color: var(--text);
  padding: 15px 16px; font: inherit; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.mode-card:hover, .mode-card.selected { border-color: var(--brand); background: var(--brand-tint); }
@media (prefers-color-scheme: dark) {
  .mode-card:hover, .mode-card.selected { background: color-mix(in srgb, var(--brand) 16%, var(--surface)); }
}
.mode-icon  { font-size: 1.4rem; line-height: 1; color: var(--brand); }
.mode-title { font-size: .95rem; font-weight: 700; }
.mode-desc  { font-size: .82rem; color: var(--muted); line-height: 1.5; }

/* ── SPINNER ───────────────────────────────────────────────────────────── */

.spinner {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 26px; color: var(--muted); font-size: .9rem;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); margin-bottom: 16px;
}
.spinner-dot {
  width: 17px; height: 17px; border-radius: 50%;
  border: 2px solid var(--border-str); border-top-color: var(--brand);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── PILLS / CHIPS ─────────────────────────────────────────────────────── */

.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: .7rem; font-weight: 600; padding: 3px 9px; border-radius: 99px;
  background: var(--surface-3); color: var(--muted); white-space: nowrap;
}
.pill-ok   { background: var(--ok-bg);   color: var(--ok); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }

.chip {
  display: inline-flex; align-items: center;
  font-size: .73rem; font-weight: 600; padding: 3px 9px; border-radius: 99px;
  background: var(--ok-bg); color: var(--ok); white-space: nowrap;
}
.chip.empty { background: var(--surface-3); color: var(--muted); font-weight: 500; }
.chip.link  { cursor: pointer; }
.chip.neutral { background: var(--surface-3); color: var(--text-2); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }

/* ── TOOLBAR / SUCHE ───────────────────────────────────────────────────── */

.toolbar {
  display: flex; flex-wrap: wrap; gap: 9px; align-items: center;
  margin-bottom: 14px;
}
.search { position: relative; flex: 1 1 100%; min-width: 0; }
.search svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}
.search input { padding-left: 37px; }
.search input[type=search]::-webkit-search-cancel-button { -webkit-appearance: none; }
.sort-select { flex: 1 1 auto; min-width: 165px; }
.sort-select select { min-height: 42px; }

/* ── DATEN-LISTEN (Tabelle → Karten auf Mobile) ────────────────────────── */

.data-table {
  /* display:block ist entscheidend: als echte Tabelle würde sie sich nach
     ihrem breitesten Inhalt richten (lange Dateinamen) und aus der Karte
     laufen — die Werte rechts wären dann abgeschnitten und unsichtbar. */
  display: block;
  width: 100%; border-collapse: collapse; font-size: .88rem;
}
.data-table thead { display: none; }
.data-table tbody { display: flex; flex-direction: column; gap: 10px; }
.data-table tr {
  display: block;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--sh-1);
  padding: 12px 14px;
}
.data-table td {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 5px 0; border: 0; min-width: 0;
}
.data-table td::before {
  content: attr(data-label);
  font-size: .73rem; font-weight: 600; color: var(--muted);
  flex-shrink: 0;
}
.data-table td > * { min-width: 0; }
.data-table .cell-title {
  display: block; padding: 0 0 8px; margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-size: 1rem; font-weight: 700; color: var(--text); cursor: pointer;
}
.data-table .cell-title::before { content: none; }
.data-table .cell-title:hover { color: var(--brand); }
.data-table .cell-actions {
  display: block; padding-top: 10px; margin-top: 4px;
  border-top: 1px solid var(--border);
}
.data-table .cell-actions::before { content: none; }
.data-table .cell-value { text-align: right; color: var(--text-2); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.row-actions .btn { flex: 1; }

/* Wissensbasis: unterhalb 900px ersetzt .cell-meta diese drei Spalten */
.data-table td.col-wide { display: none; }

/* Tabelle innerhalb einer Karte: keine doppelte Karten-Umrandung */
.in-card { padding: 0 14px 14px; }
.in-card .empty-state { border: 0; padding: 26px 0; }

/* ── LEKTIONSPLAN (Sheet) ──────────────────────────────────────────────── */

.editor-bar {
  position: sticky; top: calc(var(--header-h) + var(--safe-t)); z-index: 40;
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  padding: 10px var(--gutter);
  margin: -16px calc(-1 * var(--gutter)) 14px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.editor-bar-title {
  display: flex; align-items: center; gap: 7px; flex: 1; min-width: 0;
  font-size: .95rem; font-weight: 700;
}
.editor-bar-title > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.editor-bar-primary { flex-shrink: 0; }
.editor-bar-actions {
  display: flex; gap: 7px; flex: 1 1 100%;
  overflow-x: auto; scrollbar-width: none; padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}
.editor-bar-actions::-webkit-scrollbar { display: none; }
.editor-bar-actions .btn { flex-shrink: 0; }

.sheet {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--sh-1);
  margin-bottom: 16px;
}
.sheet-head {
  display: flex; align-items: center; gap: 10px;
  background: var(--brand); color: #fff; padding: 11px 14px;
  font-weight: 700; font-size: .95rem;
}
.sheet-logo { height: 26px; width: auto; max-width: 84px; object-fit: contain; }

.sheet-meta { border-bottom: 1px solid var(--border); }
.sheet-meta-main { padding: 12px 14px; }
.sheet-meta-side {
  padding: 10px 14px 12px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px; background: var(--surface-2);
}
.sheet-label {
  display: block; font-size: .68rem; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 3px;
}
.sheet-thema { font-size: 1.1rem; font-weight: 700; line-height: 1.35; }
.meta-row { font-size: .88rem; }
.meta-row textarea { margin-top: 5px; font-size: 16px; }

.sheet-fields { border-bottom: 1px solid var(--border); }
.sheet-row { border-bottom: 1px solid var(--border); }
.sheet-row:last-child { border-bottom: 0; }
.sheet-row-label {
  background: var(--surface-2); padding: 7px 14px;
  font-size: .7rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--text-2);
}
.sheet-row-body { padding: 10px 14px; font-size: .9rem; line-height: 1.6; min-height: 40px; }
.sheet-sublabel { font-size: .8rem; color: var(--muted); margin-bottom: 3px; }

/* Herkunft einer importierten Lektion */
.quelle-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--brand); font-weight: 600; text-decoration: none;
}
.quelle-link:hover { text-decoration: underline; }
.quelle-note { display: block; margin-top: 3px; font-size: .78rem; color: var(--muted); }

/* Wartemeldung im Import-Dialog */
.modal .spinner { margin: 4px 0 0; }

.dash-list { list-style: none; padding: 0; }
.dash-list li { display: flex; align-items: baseline; gap: 6px; padding: 2px 0; }
.dash-list li::before { content: "–"; color: var(--muted); flex-shrink: 0; }
.dash-list li > span[contenteditable] { flex: 1; min-width: 0; }
.li-del {
  background: none; border: 0; cursor: pointer; color: var(--muted);
  padding: 4px; line-height: 0; flex-shrink: 0; border-radius: 5px;
}
.li-del:hover { color: var(--err); background: var(--err-bg); }

.sheet-notes { padding: 14px; }
.sheet-notes-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 12px;
}
.sheet-notes-head strong { font-size: .95rem; }
.sheet-notes-head span { font-size: .84rem; color: var(--muted); }
.sheet-section {
  font-size: .8rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-2); margin: 16px 0 6px;
}
.sheet-section:first-of-type { margin-top: 0; }

.phase { margin-bottom: 10px; }
.phase-head {
  display: flex; align-items: center; gap: 7px;
  background: var(--brand-tint); color: var(--text);
  border-radius: var(--r-sm); padding: 7px 10px; margin-bottom: 5px;
  font-size: .88rem; font-weight: 700;
}
@media (prefers-color-scheme: dark) {
  .phase-head { background: color-mix(in srgb, var(--brand) 20%, var(--surface)); }
}
.phase-head > [data-field=phase] { flex: 1; min-width: 0; }
.phase-head .dur { font-weight: 500; color: var(--text-2); white-space: nowrap; }
.phase-btns { display: flex; gap: 2px; flex-shrink: 0; }
.phase-btn {
  background: none; border: 0; cursor: pointer; color: var(--text-2);
  padding: 6px; line-height: 0; border-radius: 5px;
}
.phase-btn:hover { background: rgba(0,0,0,.08); }
.phase-btn.danger:hover { color: var(--err); }
.phase-body { padding-left: 8px; font-size: .88rem; }

.add-item-btn, .add-phase-btn {
  display: flex; align-items: center; gap: 5px;
  background: none; border: 0; color: var(--muted);
  font: inherit; font-size: .82rem; font-weight: 600;
  padding: 8px 4px; cursor: pointer; border-radius: var(--r-sm);
}
.add-item-btn:hover, .add-phase-btn:hover { color: var(--brand); }
.add-phase-btn {
  width: 100%; justify-content: center;
  border: 1px dashed var(--border-str); padding: 11px; margin-top: 6px;
}
.add-phase-btn:hover { border-color: var(--brand); }

[contenteditable=true] {
  outline: none; border-radius: 4px; min-width: 24px;
  transition: background .12s, box-shadow .12s;
}
[contenteditable=true]:hover  { background: color-mix(in srgb, var(--brand) 8%, transparent); }
[contenteditable=true]:focus  {
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  box-shadow: 0 0 0 1.5px var(--brand);
}
[contenteditable=false]:hover { background: none; }

/* ── PLAKAT-EDITOR ─────────────────────────────────────────────────────── */

.plakat-layout { display: flex; flex-direction: column; gap: 0; }

.module-strip { padding: 12px 0 12px 14px; border-bottom: 1px solid var(--border); }
.module-strip-label {
  font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 8px;
}
.module-strip-items {
  display: flex; gap: 7px; overflow-x: auto; padding: 2px 14px 6px 0;
  scrollbar-width: thin; -webkit-overflow-scrolling: touch;
}
.mod {
  flex-shrink: 0; font: inherit; font-size: .76rem; font-weight: 700; color: #fff;
  background: var(--mod, #555); border: 2px solid transparent; border-radius: 99px;
  padding: 8px 14px; cursor: pointer; min-height: 38px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.22);
  -webkit-tap-highlight-color: transparent;
}
.mod.selected { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }

.plakat-stage {
  padding: 14px; display: flex; justify-content: center;
  background: var(--surface-2); overflow-x: auto;
}
#plakat-poster {
  background: #fff; border: 3px solid #222; border-radius: 5px;
  position: relative; flex-shrink: 0;
}
#plakat-grid { position: relative; }
.pg-cell {
  position: absolute; box-sizing: border-box;
  background: #f4f4f2; border: 1px dashed #dcdcd6; border-radius: 3px;
  transition: background .1s;
}
.pg-cell.pg-hl  { background: #DBEAFE !important; border-color: #93C5FD !important; }
.pg-cell.pg-inv { background: #FEE2E2 !important; border-color: #FCA5A5 !important; }

.pg-block {
  position: absolute; box-sizing: border-box; border-radius: 5px; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  cursor: grab; user-select: none; -webkit-user-select: none; touch-action: none;
}
.pg-block.dragging { opacity: .5; cursor: grabbing; }
.pg-label {
  position: relative; z-index: 1; font-size: 10px; font-weight: 800; color: #fff;
  letter-spacing: .04em; text-align: center; padding: 0 4px;
  text-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.pg-del {
  position: absolute; top: 2px; right: 2px; z-index: 2;
  width: 17px; height: 17px; border: 0; padding: 0; border-radius: 50%;
  background: rgba(0,0,0,.35); cursor: pointer; opacity: .75;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .12s, background .12s;
}
.pg-block:hover .pg-del { opacity: 1; }
.pg-del:hover { background: rgba(0,0,0,.75); opacity: 1; }
.pg-resize {
  position: absolute; bottom: 0; right: 0; z-index: 2;
  width: 22px; height: 22px; cursor: se-resize; touch-action: none;
  display: flex; align-items: flex-end; justify-content: flex-end; padding: 4px;
}
.pg-resize::after {
  content: ""; width: 9px; height: 9px; border-radius: 2px;
  background: rgba(255,255,255,.55); box-shadow: 0 0 0 1px rgba(0,0,0,.2);
}

.acc { border-top: 1px solid var(--border); padding: 12px 0; }
.acc:first-child { border-top: 0; padding-top: 0; }
.acc > summary {
  font-size: .8rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--muted); cursor: pointer; list-style: none; padding: 6px 0;
  display: flex; align-items: center; gap: 7px;
}
.acc > summary::-webkit-details-marker { display: none; }
.acc > summary::before {
  content: ""; width: 7px; height: 7px; flex-shrink: 0;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform .15s;
}
.acc[open] > summary::before { transform: rotate(45deg); }
.acc > *:not(summary) { margin-top: 10px; }

.gallery-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 6px; max-height: 260px; overflow-y: auto; margin-top: 9px;
  -webkit-overflow-scrolling: touch;
}
.gallery-grid button {
  border: 2px solid transparent; border-radius: var(--r-sm); overflow: hidden;
  padding: 0; background: var(--surface-3); cursor: pointer; aspect-ratio: 4 / 3;
}
.gallery-grid button.selected { border-color: var(--brand); }
.gallery-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }

.bild-slot {
  display: flex; align-items: center; gap: 9px; padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.bild-slot:last-child { border-bottom: 0; }
.bild-slot-name { font-size: .8rem; font-weight: 600; color: var(--text-2); flex-shrink: 0; }
.bild-slot img { width: 34px; height: 34px; object-fit: cover; border-radius: 5px; flex-shrink: 0; }
.bild-slot .btn { margin-left: auto; }

/* ── BRANDING ──────────────────────────────────────────────────────────── */

.brand-logo-row {
  display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap;
  padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--border);
}
.brand-logo-preview {
  width: 128px; height: 74px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--r);
  padding: 9px;
}
.brand-logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.brand-logo-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; flex: 1; min-width: 180px; }
.brand-logo-actions .hint { flex: 1 1 100%; }
/* App-Symbol: quadratische Vorschau, so wie es auf dem Home-Bildschirm wirkt */
.brand-logo-preview.is-icon { width: 74px; height: 74px; }
.brand-logo-preview.is-icon img { border-radius: 14px; }
.hint.warn { color: var(--warn); }

/* ── MODALS ────────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(16,14,12,.5);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
  animation: fade .15s ease-out;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.modal {
  width: 100%; max-width: 440px;
  background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--sh-3);
  padding: 20px 18px calc(20px + var(--safe-b));
  max-height: 88vh; overflow-y: auto;
  animation: sheet-up .22s cubic-bezier(.32,.72,0,1);
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: none; } }
.modal h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: 4px; }
.modal > p { font-size: .85rem; color: var(--muted); margin-bottom: 14px; }
.modal .field { margin-bottom: 12px; }
.modal-actions { display: flex; gap: 9px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }
.modal-err { font-size: .83rem; color: var(--err); margin-top: 8px; min-height: 1.1em; }
.modal-list {
  display: flex; flex-direction: column; gap: 2px;
  max-height: 44vh; overflow-y: auto; margin: 10px 0;
  -webkit-overflow-scrolling: touch;
}
.modal-list label {
  display: flex; align-items: center; gap: 10px;
  font-size: .93rem; font-weight: 500; color: var(--text);
  padding: 10px 10px; border-radius: var(--r-sm); cursor: pointer; min-height: 46px;
}
.modal-list label:hover { background: var(--surface-2); }
.modal-list input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--brand); }

/* ── TOAST ─────────────────────────────────────────────────────────────── */

.toast-wrap {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-b) + 14px); z-index: 120;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: min(420px, calc(100vw - 28px)); pointer-events: none;
}
.toast {
  background: var(--text); color: var(--bg);
  padding: 11px 16px; border-radius: 99px; box-shadow: var(--sh-3);
  font-size: .86rem; font-weight: 600; text-align: center;
  animation: toast-in .2s ease-out;
}
.toast.err { background: var(--err); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }


/* ── UNTERNAVIGATION (Verwaltung) ──────────────────────────────────────── */

.segmented {
  display: flex; gap: 6px; margin-bottom: 16px;
  overflow-x: auto; padding-bottom: 4px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented button {
  flex-shrink: 0; font: inherit; font-size: .85rem; font-weight: 600;
  padding: 9px 15px; min-height: 40px; cursor: pointer;
  border: 1px solid var(--border-str); border-radius: 99px;
  background: var(--surface); color: var(--text-2);
  transition: background .15s, color .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.segmented button:hover { background: var(--surface-2); }
.segmented button.active {
  background: var(--brand); border-color: var(--brand); color: #fff;
}

/* ── LINK-KNOPF (Passwort vergessen o. Ä.) ─────────────────────────────── */

.link-btn {
  background: none; border: 0; padding: 10px 4px; margin-top: 4px;
  font: inherit; font-size: .85rem; font-weight: 600; color: var(--brand);
  cursor: pointer; align-self: center; border-radius: var(--r-sm);
}
.link-btn:hover { text-decoration: underline; }

/* ── INDEXIERUNGS-FORTSCHRITT ──────────────────────────────────────────── */

.index-job {
  padding: 14px 16px; border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.index-job-head {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 10px;
}
.index-job-head strong { font-size: .9rem; }
.index-job .spinner-dot { width: 15px; height: 15px; flex-shrink: 0; }
.index-job.is-done .spinner-dot { display: none; }
.index-job .hint { margin-top: 7px; }

.progress {
  height: 7px; border-radius: 99px; background: var(--surface-3); overflow: hidden;
}
.progress-bar {
  height: 100%; width: 0; border-radius: 99px; background: var(--brand);
  transition: width .3s ease;
}
.progress-bar.indeterminate {
  width: 35%; animation: slide 1.2s ease-in-out infinite;
}
@keyframes slide {
  0%   { margin-left: -35%; }
  100% { margin-left: 100%; }
}

/* ── WISSENSBASIS ──────────────────────────────────────────────────────── */

.kb-name { display: flex; align-items: flex-start; gap: 7px; min-width: 0; }
.kb-name svg { flex-shrink: 0; color: var(--muted); margin-top: 3px; }
.kb-name span {
  /* Reglementsnamen sind lang und unterscheiden sich oft erst am Ende
     ("..._14-Kantonale-Ergaenzungen_DE"). Umbrechen statt kürzen. */
  min-width: 0; overflow-wrap: anywhere; line-height: 1.35;
}

/* Kompakte Kennzahlen-Zeile der Wissensbasis (nur schmale Displays) */
.cell-meta {
  /* justify-content überschreibt das space-between der generischen
     Zellenregel – sonst werden die Trennpunkte auseinandergezogen. */
  display: flex !important; justify-content: flex-start;
  flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 7px 0 0 !important; font-size: .82rem; color: var(--muted);
}
.cell-meta .pill { margin-left: auto; }
.cell-meta::before { content: none !important; }
.cell-meta .sep { opacity: .5; }

.chunk-list {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 52vh; overflow-y: auto; margin: 10px 0;
  -webkit-overflow-scrolling: touch;
}
.chunk {
  border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 10px 12px; background: var(--surface-2);
}
.chunk-head {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  font-size: .72rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px;
}
.chunk-text {
  font-size: .82rem; line-height: 1.55; color: var(--text-2);
  white-space: pre-wrap; word-break: break-word;
  max-height: 8.5em; overflow: hidden; position: relative;
}
.chunk-text.open { max-height: none; }
.chunk-more {
  background: none; border: 0; padding: 5px 0 0; cursor: pointer;
  font: inherit; font-size: .76rem; font-weight: 600; color: var(--brand);
}
.pager {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-top: 10px;
}
.pager span { font-size: .8rem; color: var(--muted); }

.pill-danger { background: var(--err-bg); color: var(--err); }

/* ═══════════════════════════════════════════════════════════════════════
   TABLET  ≥ 640px
   ═══════════════════════════════════════════════════════════════════════ */

@media (min-width: 640px) {
  :root { --gutter: 22px; }

  .form-grid { grid-template-columns: 1fr 1fr; gap: 14px; }
  .mode-choice { grid-template-columns: 1fr 1fr; }
  .check-grid { grid-template-columns: repeat(3, 1fr); }

  .search { flex: 1 1 260px; }
  .btn-row .btn { flex: 0 1 auto; }

  .modal-backdrop { align-items: center; padding: 22px; }
  .modal { border-radius: var(--r-lg); animation: fade .18s ease-out; }

  .brand-logo-preview { width: 168px; height: 92px; }
}

/* ═══════════════════════════════════════════════════════════════════════
   DESKTOP  ≥ 900px
   ═══════════════════════════════════════════════════════════════════════ */

@media (min-width: 900px) {
  :root { --gutter: 28px; --header-h: 60px; }

  body { font-size: 15px; }

  .app-logo { height: 34px; max-width: 150px; }
  .app-org  { font-size: 1rem; }
  .app-name { font-size: .76rem; }
  .user-btn .user-name { display: inline; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Top-Navigation statt Bottom-Bar */
  .top-nav {
    position: sticky; top: calc(var(--header-h) + var(--safe-t)); z-index: 50;
    display: flex; gap: 2px;
    padding: 0 var(--gutter);
    background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .top-nav button {
    display: flex; align-items: center; gap: 7px;
    background: none; border: 0; border-bottom: 2.5px solid transparent;
    margin-bottom: -1px; padding: 13px 15px;
    font: inherit; font-size: .89rem; font-weight: 600; color: var(--muted);
    cursor: pointer; transition: color .15s, border-color .15s;
  }
  .top-nav button svg { width: 17px; height: 17px; }
  .top-nav button:hover { color: var(--text); }
  .top-nav button.active { color: var(--brand); border-bottom-color: var(--brand); }
  .top-nav .nav-spacer { flex: 1; }
  .bottom-nav { display: none; }

  main { padding: 24px var(--gutter) 56px; }
  .editor-bar { top: calc(var(--header-h) + var(--safe-t) + 49px); margin-top: -24px; }
  .editor-bar-actions { flex: 0 0 auto; overflow: visible; }
  .editor-bar-primary { order: 2; }

  .view-head h2 { font-size: 1.55rem; }

  /* Tabellen als echte Tabellen */
  .data-table {
    display: table;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-lg); box-shadow: var(--sh-1); overflow: hidden;
  }
  .data-table thead { display: table-header-group; }
  .data-table tbody { display: table-row-group; }
  .data-table tr { display: table-row; background: none; border: 0; border-radius: 0; box-shadow: none; padding: 0; }
  .data-table th {
    text-align: left; padding: 11px 14px;
    background: var(--surface-2); border-bottom: 1px solid var(--border);
    font-size: .74rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
    color: var(--muted); white-space: nowrap; user-select: none;
  }
  .data-table th.sortable { cursor: pointer; }
  .data-table th.sortable:hover { color: var(--text); }
  .data-table th .sort-icon { margin-left: 4px; opacity: .45; }
  .data-table th.sort-asc  .sort-icon::after { content: "▲"; }
  .data-table th.sort-desc .sort-icon::after { content: "▼"; }
  .data-table th:not(.sort-asc):not(.sort-desc) .sort-icon::after { content: "⇅"; }
  .data-table td {
    display: table-cell; vertical-align: middle;
    padding: 11px 14px; border-bottom: 1px solid var(--border);
  }
  .data-table td.col-wide { display: table-cell; }
  .data-table td::before { content: none; }
  .data-table tbody tr:last-child td { border-bottom: 0; }
  .data-table tbody tr:hover td { background: var(--surface-2); }
  .data-table .cell-title {
    display: table-cell; padding: 11px 14px; margin: 0; font-size: .92rem;
    border-bottom: 1px solid var(--border); border-radius: 0;
  }
  .data-table .cell-actions {
    display: table-cell; padding: 8px 14px; margin: 0;
    border-top: 0; border-bottom: 1px solid var(--border); white-space: nowrap;
  }
  .data-table .cell-value { text-align: left; white-space: nowrap; }
  .row-actions { flex-wrap: nowrap; }
  .row-actions .btn { flex: 0 0 auto; }
  .sort-select { display: none; }
  .in-card { padding: 0; }
  .in-card .data-table { border: 0; border-radius: 0; box-shadow: none; }
  .kb-name { align-items: center; }
  .kb-name svg { margin-top: 0; }
  .cell-meta { display: none !important; }

  /* Lektionsplan zweispaltig */
  .sheet-meta { display: grid; grid-template-columns: 1fr minmax(210px, auto); }
  .sheet-meta-side { border-top: 0; border-left: 1px solid var(--border); }
  .sheet-row { display: grid; grid-template-columns: 148px 1fr; }
  .sheet-row-label {
    border-right: 1px solid var(--border); display: flex; align-items: flex-start;
    padding-top: 11px;
  }

  /* Plakat-Editor zweispaltig */
  .plakat-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
  .plakat-fields-card { position: sticky; top: calc(var(--header-h) + var(--safe-t) + 116px); max-height: calc(100vh - var(--header-h) - 150px); overflow-y: auto; }
  .module-strip { padding-left: 16px; }
  .module-strip-items { flex-wrap: wrap; overflow: visible; padding-right: 16px; }
}

@media (min-width: 1100px) {
  .plakat-layout { grid-template-columns: minmax(0, 1fr) 380px; }
}

/* ── Druck ─────────────────────────────────────────────────────────────── */

@media print {
  .app-header, .top-nav, .bottom-nav, .editor-bar, .toolbar, .view-head-actions,
  .add-item-btn, .add-phase-btn, .li-del, .phase-btns, .banner, .hint { display: none !important; }
  body { background: #fff; }
  main { padding: 0; max-width: none; }
  .sheet { border: 0; box-shadow: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
