/* ===========================================================================
   Mastprüfung Hamburg — Oberfläche.

   Leitlinien aus dem Übergabepapier §11: nüchtern, funktional, hoher Kontrast.
   Die App wird bei Sonnenlicht draußen bedient, teils mit Handschuhen. Deshalb
   bewusst helle Grundfläche mit dunkler Schrift statt Dunkelmodus, große
   Trefferflächen (mindestens 44 px) und keine grauen Feinheiten, die im
   Gegenlicht verschwinden.
   =========================================================================== */

:root {
  --grund: #f4f6f8;
  --blatt: #ffffff;
  --linie: #d3dae1;
  --linie-stark: #b3bec9;
  --text: #14202b;
  --text-still: #56636f;
  --marke: #0f2436;
  --haupt: #0a6ed1;
  --haupt-dunkel: #085aa8;
  --ok: #1a7f37;
  --warnung: #9a6700;
  --fehler: #c9341a;
  --gefahr-grund: #fff4e5;
  --schatten: 0 1px 2px rgba(20, 32, 43, 0.08), 0 2px 8px rgba(20, 32, 43, 0.06);
  --radius: 10px;
  --kopf-hoehe: 52px;
  --nav-hoehe: 60px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--grund);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#huelle {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
}

/* --- Kopfleiste ---------------------------------------------------------- */

#kopfleiste {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  padding-top: env(safe-area-inset-top);
  height: calc(var(--kopf-hoehe) + env(safe-area-inset-top));
  background: var(--marke);
  color: #fff;
}

.kopf-titel { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.kopf-marke { font-weight: 800; letter-spacing: 0.06em; font-size: 14px; color: #6fb4f0; }
.kopf-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.netzanzeige {
  flex: none;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.netzanzeige.online { background: rgba(26, 127, 55, 0.22); color: #7ee2a0; }
.netzanzeige.offline { background: rgba(201, 52, 26, 0.28); color: #ffb4a5; }

/* --- Ansicht ------------------------------------------------------------- */

#ansicht {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#ansicht:focus { outline: none; }

.seitenkopf h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.unterzeile { margin: 4px 0 0; color: var(--text-still); font-size: 14px; }

.blatt {
  background: var(--blatt);
  border: 1px solid var(--linie);
  border-radius: var(--radius);
  box-shadow: var(--schatten);
  padding: 16px;
}
.blatt h2 { margin: 0 0 4px; font-size: 17px; }
.blatt h3 { margin: 18px 0 6px; font-size: 15px; }
.blatt-kopf { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.blatt-fuss { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }
.blatt.leer { text-align: center; padding: 40px 20px; }
.blatt.leer .stufe {
  display: inline-block; margin: 0 0 8px; padding: 3px 10px; border-radius: 999px;
  background: #e8f0f8; color: var(--haupt-dunkel); font-size: 12px; font-weight: 700;
}
.leer-hinweis { color: var(--text-still); font-style: italic; }

/* --- Navigation ---------------------------------------------------------- */

#navigation {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--blatt);
  border-top: 1px solid var(--linie);
  padding-bottom: env(safe-area-inset-bottom);
}

.navknopf {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: var(--nav-hoehe);
  text-decoration: none;
  color: var(--text-still);
  font-size: 11px;
  font-weight: 600;
  border-top: 3px solid transparent;
}
.navknopf.aktiv { color: var(--haupt); border-top-color: var(--haupt); background: #f2f7fc; }
.navsymbol { font-size: 19px; line-height: 1; }

/* --- Knöpfe -------------------------------------------------------------- */

.knopf {
  appearance: none;
  border: 1px solid var(--linie-stark);
  background: var(--blatt);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 11px 16px;
  min-height: 44px;
  border-radius: 8px;
  cursor: pointer;
}
.knopf:active { transform: translateY(1px); }
.knopf:disabled { opacity: 0.45; cursor: not-allowed; }
.knopf.haupt { background: var(--haupt); border-color: var(--haupt); color: #fff; }
.knopf.haupt:not(:disabled):hover { background: var(--haupt-dunkel); }
.knopf.warnung { background: var(--fehler); border-color: var(--fehler); color: #fff; }
.knopf.still { background: transparent; color: var(--text-still); }
.knopf.klein { min-height: 34px; padding: 6px 11px; font-size: 13px; }
.knopf.gross { min-height: 54px; font-size: 17px; width: 100%; }
.knopf.zurueck { background: none; border: none; color: var(--haupt); padding: 0 0 6px; min-height: 0; font-size: 15px; }

.aktionen { display: flex; flex-direction: column; gap: 10px; }

/* --- Hinweise ------------------------------------------------------------ */

.hinweis {
  padding: 11px 14px;
  border-radius: 8px;
  border-left: 4px solid var(--linie-stark);
  background: #f0f3f6;
  font-size: 14px;
  margin: 12px 0;
}
.hinweis.ok { background: #e9f6ed; border-left-color: var(--ok); }
.hinweis.warnung { background: #fdf5e3; border-left-color: var(--warnung); }
.hinweis.fehler { background: #fdecea; border-left-color: var(--fehler); }
.hinweis p { margin: 6px 0 0; font-size: 13px; color: var(--text-still); }

.gefahrenband {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 15px;
  background: var(--gefahr-grund);
  border: 2px solid var(--warnung);
  border-radius: var(--radius);
  font-weight: 700;
  color: #6b4700;
}
.gefahr-symbol { font-size: 22px; line-height: 1; }

/* --- Ablagezone ---------------------------------------------------------- */

.ablagezone {
  border: 2px dashed var(--linie-stark);
  border-radius: var(--radius);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.ablagezone:hover, .ablagezone.aktiv { border-color: var(--haupt); background: #f2f7fc; }
.ablage-symbol { font-size: 34px; color: var(--haupt); line-height: 1; }
.ablage-titel { margin: 10px 0 4px; font-size: 17px; font-weight: 700; }
.ablage-hinweis { margin: 0; color: var(--text-still); font-size: 14px; }

/* --- Tabellen ------------------------------------------------------------ */

.tabellenrahmen {
  overflow-x: auto;
  border: 1px solid var(--linie);
  border-radius: 8px;
  -webkit-overflow-scrolling: touch;
}
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--linie); vertical-align: top; }
th { background: #eef2f5; font-weight: 700; font-size: 13px; white-space: nowrap; position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: none; }
.rechts { text-align: right; }
td code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; background: #eef2f5; padding: 2px 5px; border-radius: 4px; }
.beispiel { color: var(--text-still); font-size: 13px; max-width: 220px; }
.zuordnung tr.pflicht td { background: #f6faff; }
.zielfeld { width: 100%; min-height: 38px; font: inherit; font-size: 14px; padding: 6px 8px; border: 1px solid var(--linie-stark); border-radius: 6px; background: #fff; }
.feldhinweis { margin: 5px 0 0; font-size: 12px; color: var(--text-still); }
.vorschau td.abgeleitet { background: #fdf7e6; font-style: italic; }
.attribute th { width: 40%; background: #f7f9fb; position: static; white-space: normal; }

/* --- Problemprotokoll ---------------------------------------------------- */

.probleme { margin: 12px 0; border: 1px solid var(--linie); border-radius: 8px; padding: 10px 14px; background: #fffdf7; }
.probleme summary { cursor: pointer; font-weight: 700; color: var(--warnung); }
.problemgruppe h4 { margin: 12px 0 4px; font-size: 14px; }
.probleme ul { margin: 0; padding-left: 18px; font-size: 13px; }
.probleme li { margin-bottom: 3px; }
.zeilennr { font-weight: 700; color: var(--text-still); }

/* --- Filter -------------------------------------------------------------- */

.filterleiste {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  background: var(--blatt);
  border: 1px solid var(--linie);
  border-radius: var(--radius);
  padding: 12px;
}
.filterfeld { display: flex; flex-direction: column; gap: 3px; min-width: 130px; flex: 1 1 130px; }
.filterfeld.weit { flex: 2 1 220px; }
.filterfeld > span { font-size: 12px; font-weight: 700; color: var(--text-still); text-transform: uppercase; letter-spacing: 0.03em; }
.filterfeld select, .suchfeld {
  font: inherit; font-size: 15px; min-height: 42px; padding: 8px 10px;
  border: 1px solid var(--linie-stark); border-radius: 8px; background: #fff; width: 100%;
}
.filterschalter { display: flex; align-items: center; gap: 7px; font-size: 14px; min-height: 42px; }
.filterschalter input { width: 20px; height: 20px; }

/* --- Kennzahlen ---------------------------------------------------------- */

.kennzahlen { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kachel {
  background: var(--blatt); border: 1px solid var(--linie); border-radius: var(--radius);
  padding: 11px 13px; display: flex; flex-direction: column; gap: 3px;
}
.kachel.breit { grid-column: 1 / -1; }
.kachel.warnung { border-color: var(--warnung); background: #fdf9ef; }
.kachel-titel { font-size: 12px; font-weight: 700; color: var(--text-still); text-transform: uppercase; letter-spacing: 0.03em; }
.kachel-wert { font-size: 19px; font-weight: 700; }
.kachel.breit .kachel-wert { font-size: 14px; font-weight: 500; line-height: 1.5; }

/* --- Bestandsliste (virtualisiert) --------------------------------------- */

.bestandsliste { flex: 1 1 auto; min-height: 340px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.vl-innen { position: relative; }
.vl-hoehe { width: 1px; }
.vl-fenster { position: absolute; top: 0; left: 0; right: 0; display: flex; flex-direction: column; gap: 6px; }

.mastzeile {
  height: 72px;
  background: var(--blatt);
  border: 1px solid var(--linie);
  border-radius: 8px;
  padding: 9px 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  overflow: hidden;
}
.mastzeile:hover { border-color: var(--haupt); }
.mastzeile:focus-visible { outline: 3px solid var(--haupt); outline-offset: 1px; }
.mastzeile-kopf { display: flex; align-items: center; gap: 7px; min-width: 0; }
.mastzeile-fuss { display: flex; gap: 12px; font-size: 12.5px; color: var(--text-still); min-width: 0; white-space: nowrap; overflow: hidden; }
.mast-strasse { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mast-zusatz { font-size: 13px; color: var(--text-still); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mast-id { font-variant-numeric: tabular-nums; }
.merkmale { overflow: hidden; text-overflow: ellipsis; }

.statuspunkt { flex: none; width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.statuszeile { display: flex; align-items: center; gap: 7px; margin-top: 8px; font-size: 14px; color: var(--text-still); }

.marke { flex: none; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.marke.grau { background: #eef2f5; color: var(--text-still); }
.marke.gefahr { background: var(--gefahr-grund); color: #6b4700; border: 1px solid var(--warnung); }

/* --- Mast-Detailseite ---------------------------------------------------- */

.merkmale-gitter { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.merkmal { display: flex; flex-direction: column; gap: 2px; }
.merkmal-titel { font-size: 12px; font-weight: 700; color: var(--text-still); text-transform: uppercase; letter-spacing: 0.03em; }
.merkmal-wert { font-size: 17px; font-weight: 600; }
.merkmal-quelle { font-size: 11px; color: var(--warnung); font-style: italic; }

.historie { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.historie-eintrag { display: flex; gap: 12px; align-items: flex-start; padding-bottom: 10px; border-bottom: 1px solid var(--linie); }
.historie-eintrag p { margin: 2px 0 0; font-size: 14px; color: var(--text-still); }
.historie-text { font-size: 13px !important; }
.historie-ergebnis {
  flex: none; min-width: 42px; text-align: center; font-weight: 800; font-size: 13px;
  padding: 5px 8px; border-radius: 6px; background: #eef2f5; color: var(--text-still);
}
.historie-ergebnis.ok { background: #e9f6ed; color: var(--ok); }
.historie-ergebnis.befund { background: #fdecea; color: var(--fehler); }
.historie-ergebnis.hinweis { background: #fdf5e3; color: var(--warnung); }

/* --- Fortschritt --------------------------------------------------------- */

.fortschritt { width: 100%; }
.fortschritt h3 { margin: 0 0 8px; }
.fortschritt-huelle { height: 8px; background: #e3e9ee; border-radius: 999px; overflow: hidden; }
.fortschritt-balken { height: 100%; width: 0; background: var(--haupt); transition: width 0.25s ease-out; }
.fortschritt-text { margin: 7px 0 0; font-size: 14px; color: var(--text-still); }

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

.meldungen {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-hoehe) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%);
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(560px, calc(100vw - 24px));
  pointer-events: none;
}
.meldung {
  background: var(--marke);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14.5px;
  box-shadow: 0 4px 16px rgba(20, 32, 43, 0.25);
  animation: einblenden 0.2s ease-out;
}
.meldung.ok { background: var(--ok); }
.meldung.warnung { background: var(--warnung); }
.meldung.fehler { background: var(--fehler); }
.meldung.geht { opacity: 0; transition: opacity 0.3s; }
@keyframes einblenden { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* --- Dialog -------------------------------------------------------------- */

.dialog-huelle {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(20, 32, 43, 0.5);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.dialog {
  background: var(--blatt); border-radius: 12px; padding: 22px;
  width: min(440px, 100%); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}
.dialog h3 { margin: 0 0 8px; font-size: 18px; }
.dialog p { margin: 0; color: var(--text-still); font-size: 14.5px; }
.dialog-knoepfe { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

/* --- Breiter Bildschirm -------------------------------------------------- */

@media (min-width: 860px) {
  #huelle { grid-template-columns: 190px 1fr; grid-template-rows: auto 1fr; }
  #kopfleiste { grid-column: 1 / -1; }
  #navigation {
    grid-row: 2; grid-column: 1;
    grid-auto-flow: row; grid-auto-columns: auto; grid-auto-rows: min-content;
    border-top: none; border-right: 1px solid var(--linie); padding-top: 10px;
  }
  .navknopf {
    flex-direction: row; justify-content: flex-start; gap: 11px;
    height: 46px; padding: 0 16px; font-size: 15px;
    border-top: none; border-left: 3px solid transparent;
  }
  .navknopf.aktiv { border-top: none; border-left-color: var(--haupt); }
  #ansicht { grid-row: 2; grid-column: 2; padding: 20px 24px 32px; }
  .seitenkopf h1 { font-size: 26px; }
  .meldungen { bottom: 20px; left: calc(50% + 95px); }
}
