/* Grundlayout und Komponenten.
   Keine Inline-Styles irgendwo im Projekt: die Content-Security-Policy verbietet
   'unsafe-inline'. Alles Sichtbare wird ueber Klassen gesteuert. */

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p, figure { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Sichtbarer Fokus fuer Tastaturbedienung — nie entfernen. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-s);
}
:focus:not(:focus-visible) { outline: none; }

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

.hidden { display: none !important; }

/* Nur fuer Screenreader sichtbar. */
.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;
}

/* ---------------------------------------------------------------- Layout */

.shell { min-height: 100%; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: -.01em; }

/* Die Logos stecken in <picture>, damit im Dunkelmodus die helle Fassung
   geladen wird — das Grau der Marke haette dort nur 2.25:1 Kontrast.
   `display: contents` sorgt dafuer, dass fuer das Layout weiterhin das
   <img> zaehlt und nicht der Container darum. */
picture { display: contents; }

/* Bildmarke (Kreis mit "IT") — oben links in der Kopfzeile. */
.brand-mark {
  width: 32px; height: 28px; flex: none;
  display: block;
  object-fit: contain;
}
.brand-name { font-size: 15px; }
.brand-sub { color: var(--muted); font-weight: 400; }

/* Vollstaendiges Logo rechts in der Kopfzeile. Bewusst zurueckhaltend:
   die Bildmarke links traegt bereits die Wiedererkennung. */
.brand-full {
  /* Seitenverhaeltnis der Datei fest vorgeben (653.2 : 136.5), damit das
     Logo in keinem Layout gestaucht werden kann. */
  height: 28px;
  aspect-ratio: 653.2 / 136.5;
  width: auto;
  flex: none;
  display: block;
  opacity: .9;
}
@media (max-width: 640px) {
  /* Auf schmalen Geraeten wuerde beides nebeneinander gedraengt wirken. */
  .brand-full { display: none; }
}

.topbar-spacer { flex: 1; }

.main { flex: 1; width: 100%; max-width: 1060px; margin: 0 auto; padding: 22px 20px 64px; }

.page-head {
  display: flex; align-items: flex-start; gap: 16px;
  flex-wrap: wrap; margin-bottom: 20px;
}
.page-title { font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.page-desc { color: var(--muted); font-size: 14px; margin-top: 3px; max-width: 60ch; }

.section { margin-top: 34px; }
.section-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 12px; }

/* ---------------------------------------------------------------- Buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 17px; min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: var(--fill);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: background var(--speed) var(--ease), border-color var(--speed) var(--ease), opacity var(--speed);
  text-decoration: none;
}
.btn:hover:not(:disabled) { background: var(--fill-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-outline { background: transparent; border-color: var(--border-strong); }
.btn-outline:hover:not(:disabled) { background: var(--fill); }

.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

.btn-ghost { background: transparent; padding: 7px 12px; min-height: 36px; }
.btn-ghost:hover:not(:disabled) { background: var(--fill); }

.btn-sm { padding: 6px 13px; min-height: 34px; font-size: 13px; }
.btn-block { width: 100%; }

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

.field { margin-bottom: 16px; }
.label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

.input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input[aria-invalid="true"] { border-color: var(--danger); }
textarea.input { resize: vertical; min-height: 84px; }

/* Eingabe fuer den Einmalcode: gross, mittig, gut abtippbar. */
.input-code {
  font-family: var(--font-mono);
  font-size: 26px; font-weight: 600;
  letter-spacing: .34em; text-align: center;
  padding: 14px 10px 14px 24px;
}

/* ---------------------------------------------------------------- Karten */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-s);
}
.card-pad { padding: 20px; }

.auth-wrap {
  flex: 1;
  display: grid; place-items: center;
  padding: 28px 20px 64px;
  position: relative;
  overflow: hidden; /* haelt das angeschnittene Ausrufezeichen im Rahmen */
}

/* Ausrufezeichen der Wortmarke als grossflaechiges Hintergrundmotiv.
   Vertikal immer vollstaendig sichtbar, am linken Rand um rund ein Drittel
   seiner Breite angeschnitten. Die Verschiebung erfolgt ueber `transform`,
   weil sich Prozente dort auf die Breite des Motivs beziehen — bei `left`
   waeren es Prozente der Seitenbreite und der Anschnitt wuerde je nach
   Fenstergroesse voellig unterschiedlich ausfallen.
   Liegt hinter der Anmeldekarte und wird nie zum Lesehindernis. */
.auth-wrap::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  transform: translate(-34%, -50%);
  height: 96%;
  aspect-ratio: 30.6 / 49.5; /* Seitenverhaeltnis der Originaldatei */
  background: url('/img/logo-bang.svg') center / contain no-repeat;
  opacity: .18;
  pointer-events: none;
  z-index: 0;
}

/* Schmale Geraete: kleiner und weiter aus dem Bild, damit das Motiv der
   Anmeldekarte nicht in die Quere kommt. */
@media (max-width: 620px) {
  .auth-wrap::before {
    height: 78%;
    transform: translate(-42%, -50%);
    opacity: .12;
  }
}

.auth-card { width: 100%; max-width: 420px; position: relative; z-index: 1; }
.auth-head { text-align: center; margin-bottom: 22px; }

/* Grosse Bildmarke ueber der Anmeldung — der erste Eindruck der Seite.
   Breite statt Hoehe vorgeben, weil die Marke leicht querformatig ist. */
.auth-logo {
  display: block;
  width: 132px; height: auto;
  margin: 4px auto 20px;
}

/* Begruessung: bewusst kraeftig gesetzt, sie traegt die Marke. */
.auth-welcome {
  font-size: 15.5px;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: -.01em;
  margin-bottom: 18px;
  text-wrap: balance;
}

.auth-title { font-size: 20px; font-weight: 600; letter-spacing: -.02em; }
.auth-sub { color: var(--muted); font-size: 14px; margin-top: 5px; }

/* Auf kleinen Bildschirmen etwas kompakter, damit die Eingabefelder
   ohne Scrollen erreichbar bleiben. */
@media (max-height: 640px), (max-width: 420px) {
  .auth-logo { width: 96px; margin-bottom: 14px; }
  .auth-welcome { font-size: 14.5px; margin-bottom: 14px; }
}

/* ---------------------------------------------------------------- Dateiliste */

.toolbar {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; margin-bottom: 16px;
}

.crumbs { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; font-size: 14px; min-height: 34px; }
.crumb {
  background: none; border: 0; padding: 5px 9px;
  border-radius: var(--radius-s); color: var(--muted);
  cursor: pointer; font-weight: 500;
}
.crumb:hover { background: var(--fill); color: var(--text); }
.crumb[aria-current="page"] { color: var(--text); font-weight: 600; cursor: default; }
.crumb[aria-current="page"]:hover { background: none; }
.crumb-sep { color: var(--muted); opacity: .6; user-select: none; }

.list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }

.row {
  display: flex; align-items: center; gap: 13px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: background var(--speed) var(--ease);
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }

.row-icon {
  width: 36px; height: 36px; flex: none;
  border-radius: var(--radius-s);
  background: var(--fill);
  display: grid; place-items: center;
  color: var(--muted);
}
.row-icon.is-folder { background: var(--accent-soft); color: var(--accent); }

.row-main { flex: 1; min-width: 0; }
.row-name {
  display: block; width: 100%; text-align: left;
  background: none; border: 0; padding: 0;
  font-size: 14.5px; font-weight: 500; color: inherit;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
button.row-name { cursor: pointer; }
button.row-name:hover { color: var(--accent); }
.row-meta { font-size: 12.5px; color: var(--muted); margin-top: 1px; }

.row-actions { display: flex; align-items: center; gap: 4px; flex: none; }

.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 0; border-radius: var(--radius-s);
  background: transparent; color: var(--muted);
  cursor: pointer;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.icon-btn:hover { background: var(--fill-2); color: var(--text); }
.icon-btn.is-danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn svg { width: 17px; height: 17px; display: block; }

/* Auf schmalen Geraeten sind Aktionen immer sichtbar (kein Hover auf Touch). */
@media (max-width: 640px) {
  .row { padding: 12px 12px; gap: 10px; }
  .row-actions { gap: 0; }
}

/* Touch-Bedienung: Fingerkuppen brauchen groessere Ziele als ein Mauszeiger.
   Gemessen auf 375 px Breite waren Pfad- und Symbolknoepfe mit 32-34 px zu
   klein; 44 px entspricht der gaengigen Empfehlung.
   Auch an die Breite gekoppelt: ein schmaler Bildschirm wird in aller Regel
   mit dem Finger bedient, und `pointer: coarse` allein greift auf einem
   Desktop-Browser mit verkleinertem Fenster nicht. */
@media (pointer: coarse), (max-width: 640px) {
  .icon-btn { width: 44px; height: 44px; }
  .crumb { padding: 10px 11px; }
  .btn-sm { min-height: 40px; }
  .btn-ghost { min-height: 40px; }

  /* Der Datei- bzw. Ordnername ist das wichtigste Ziel in jeder Zeile —
     zum Oeffnen und zum Herunterladen. Als reine Textzeile war er nur
     22 px hoch und damit mit dem Finger kaum zu treffen. */
  .row-name { min-height: 40px; display: flex; align-items: center; }
}

/* ---------------------------------------------------------------- Zustaende */

.state { padding: 52px 24px; text-align: center; color: var(--muted); }
.state-title { font-weight: 600; color: var(--text); margin-bottom: 5px; }
.state-text { font-size: 14px; max-width: 44ch; margin: 0 auto; }
.state-action { margin-top: 18px; }

.spinner {
  width: 22px; height: 22px; margin: 0 auto 14px;
  border: 2.5px solid var(--fill-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 15px;
  border-radius: var(--radius-s);
  font-size: 14px;
  margin-bottom: 16px;
}
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }

/* ---------------------------------------------------------------- Upload */

.uploads { position: fixed; right: 18px; bottom: calc(18px + var(--safe-b)); z-index: 40; width: min(340px, calc(100vw - 36px)); }
.uploads:empty { display: none; }

.upload {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-top: 9px;
}
.upload-head { display: flex; align-items: center; gap: 10px; }
.upload-name { flex: 1; min-width: 0; font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-pct { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.progress { height: 5px; border-radius: 999px; background: var(--fill-2); overflow: hidden; margin-top: 9px; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 999px; transition: width .2s var(--ease); }
.upload.is-error .progress-bar { background: var(--danger); }
.upload-status { font-size: 12.5px; color: var(--muted); margin-top: 7px; }
.upload.is-error .upload-status { color: var(--danger); }

/* Ablagebereich fuer Dateien */
.dropzone { position: relative; }
.dropzone.is-over::after {
  content: '';
  position: absolute; inset: -3px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  pointer-events: none;
}

/* ---------------------------------------------------------------- Dialoge */

.dialog {
  border: 0; padding: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  width: min(460px, calc(100vw - 32px));
}
.dialog::backdrop { background: rgba(8, 22, 24, .5); }
.dialog-pad { padding: 22px; }
.dialog-title { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.dialog-text { font-size: 14px; color: var(--muted); margin-bottom: 18px; }
.dialog-actions { display: flex; gap: 9px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- Zugangsdaten */

/* Wird genau einmal angezeigt — deshalb optisch deutlich hervorgehoben. */
.secret {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 11px 13px;
  margin-top: 7px;
}
.secret-value {
  flex: 1; min-width: 0;
  font-family: var(--font-mono); font-size: 13.5px;
  word-break: break-all;
}

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 600;
  background: var(--fill); color: var(--muted);
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-off { background: var(--warn-soft); color: var(--warn); }
.badge-revoked { background: var(--danger-soft); color: var(--danger); }

/* ---------------------------------------------------------------- Protokoll */

.kennzahlen {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.kennzahlen .card-pad { padding: 14px 16px; }
.kennzahlen .page-title { font-size: 26px; }

.filterleiste {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.filterleiste .field { margin-bottom: 0; }

/* Zeitstempel schmal und einheitlich, damit die Spalte ruhig wirkt. */
.protokoll-zeit {
  flex: none;
  width: 150px;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Fehlversuche und Sperren sollen ins Auge fallen. */
.row.ist-auffaellig { background: var(--danger-soft); }
.row.ist-auffaellig .row-name { color: var(--danger); }

@media (max-width: 640px) {
  /* Auf schmalen Geraeten unter den Text statt daneben. */
  .row .protokoll-zeit { width: auto; }
  .list .row:has(.protokoll-zeit) { flex-wrap: wrap; }
}

/* ---------------------------------------------------------------- Meldungen */

.toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + var(--safe-b)); z-index: 60;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--text); color: var(--bg);
  padding: 10px 17px; border-radius: var(--radius-pill);
  font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow);
  max-width: min(90vw, 440px);
}
.toast.is-error { background: var(--danger); color: #fff; }

/* ---------------------------------------------------------------- QR-Code */

/* Immer heller Grund: ein dunkles Design wuerde den Code sonst unlesbar
   machen.
   Zur Groesse: Der Code hat mit Rand rund 61 Module. Bei 264px entfallen
   damit gut 4px auf ein Modul — genug, damit eine Telefonkamera ihn aus
   normalem Abstand sicher erfasst. Deutlich kleiner wird es unzuverlaessig. */
.qr {
  display: block;
  width: min(264px, 70vw);
  height: auto;
  margin: 4px auto 16px;
  border-radius: var(--radius-s);
  background: #fff;
  padding: 10px;
  border: 1px solid var(--border);
}

.qr-fallback { margin-bottom: 16px; }
.qr-fallback summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
}
.qr-fallback summary:hover { color: var(--accent); }

/* Der Schluessel zum Abtippen. Umbruch erlaubt, damit nichts abgeschnitten
   wird — auch nicht auf schmalen Bildschirmen. */
.code-block {
  display: block;
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--fill);
  border-radius: var(--radius-s);
  font-family: var(--font-mono);
  font-size: 14px;
  letter-spacing: .08em;
  word-break: break-all;
  user-select: all;
}

/* Hinweiszeile ueber einer Liste — etwas Luft, damit sie nicht wie eine
   Bildunterschrift der Werkzeugleiste wirkt. */
.hint-block { margin: 2px 0 12px; }

/* Leerzeile innerhalb eines mehrzeiligen Hinweises. */
.hint-luecke { height: 8px; }
