/* Gemeinsames Fundament von wertima.
   EINZIGE Quelle fuer Farben, Radien, Komponenten – die Seiten-Stylesheets
   (styles.css, photos.css) enthalten nur noch Seitenspezifisches.
   Liegt VOR der Anmeldeschranke, damit auch Login/Passwortwechsel es nutzen. */

:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1c2530;
  --muted: #5b6b7a;
  --line: #d7dde3;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --accent-weich: #e4f0ea;   /* Akzent-Hintergrund (aktive Nav, Pillen, Haken) */
  --error: #b23b3b;
  --ok: #2f6f4f;
  --warn: #8a6116;
  --warn-bg: #fdf1dc;
  --warn-line: #ecd9ae;
  --flaeche: #eef1f4;        /* neutrale Knopf-/Zeilenflaeche */
  --flaeche-aktiv: #e2e7ec;
  --eingabe-bg: #ffffff;
  --gefahr-bg: #f1e3e3;
  --gefahr-line: #e3cccc;
  --gefahr-hover: #f9eeee;
  --pill-blau-bg: #e8eef4;
  --pill-blau-ink: #3a5c7a;
  --pill-lila-bg: #ece6f5;
  --pill-lila-ink: #5a4a86;
  --pill-grau-bg: #eef2f7;
  --pill-grau-ink: #4a5a6a;
  --zeile-hover: #f7f9fa;
  --zeile-aktiv: #eef4f1;
  --radius: 12px;
  --radius-klein: 8px;
  --schatten: 0 6px 24px rgba(28, 37, 48, 0.06);
}

/* Dark Mode folgt automatisch der Geraeteeinstellung. EINZIGE Stelle fuer
   dunkle Farbwerte - die Seiten-Stylesheets definieren KEINE Farben mehr
   (sie wuerden diesen Block sonst wieder ueberschreiben, genau das war der
   "falsche Schriftfarben"-Fehler auf dem Telefon). */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #12171d;
    --card: #1b222b;
    --ink: #e7edf3;
    --muted: #9aa8b6;
    --line: #2b343f;
    --accent: #3f9b6c;
    --accent-ink: #0d1a13;
    --accent-weich: #21362b;
    --error: #e08e8e;
    --ok: #5cb98a;
    --warn: #d9b36a;
    --warn-bg: #332915;
    --warn-line: #57482a;
    --flaeche: #242d36;
    --flaeche-aktiv: #2b3540;
    --eingabe-bg: #141a21;
    --gefahr-bg: #3a2626;
    --gefahr-line: #573a3a;
    --gefahr-hover: #2e2020;
    --pill-blau-bg: #243040;
    --pill-blau-ink: #9fc0dd;
    --pill-lila-bg: #322a44;
    --pill-lila-ink: #b7a6e0;
    --pill-grau-bg: #262e37;
    --pill-grau-ink: #a9b6c3;
    --zeile-hover: #202932;
    --zeile-aktiv: #21362b;
    --schatten: 0 6px 24px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

/* --- Kopfzeile (App-Shell, gerendert von shell.js) ------------------------- */
.shell-kopf {
  /* volle Breite auf ALLEN Seiten: die generischen header-Regeln der
     Daten-/Fotoseite (styles.css/photos.css: max-width 760px, zentriert)
     duerfen die Shell-Topbar nicht einengen */
  max-width: none;
  margin: 0;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 50;
}
.shell-marke {
  font-weight: 800;
  font-size: 1rem;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.shell-marke span { color: var(--accent); }
.shell-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.shell-nav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 8px 12px;
  border-radius: 999px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.shell-nav a.aktiv { background: var(--accent-weich); color: var(--accent); }
.shell-nav a:hover { color: var(--accent); }
.shell-kontext {
  background: var(--accent-weich);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 5px 12px;
  border-radius: 999px;
  white-space: nowrap;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.shell-rechts {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}
.shell-nutzer { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shell-abmelden {
  color: var(--error);
  text-decoration: none;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: var(--radius-klein);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.shell-abmelden:hover { background: var(--gefahr-hover); }
@media (max-width: 560px) {
  .shell-nutzer { display: none; }
  /* Auf dem Telefon: Marke + Abmelden in Zeile 1, Navigation als eigene,
     seitlich rollbare Zeile 2. So passt die Kopfzeile auch bei
     iOS-Textvergroesserung (grosser dynamischer Text) - eine einzelne Zeile
     lief dort rechts aus dem Bild. min-width: 0 laesst die Marke notfalls
     mit Auslassungspunkten schrumpfen. */
  .shell-kopf { flex-wrap: wrap; gap: 4px 8px; padding: 8px 10px; }
  .shell-marke { font-size: 0.9rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .shell-rechts { flex-shrink: 0; }
  .shell-nav {
    order: 10; flex: 1 1 100%; min-width: 0;
    flex-wrap: nowrap; overflow-x: auto;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .shell-nav::-webkit-scrollbar { display: none; }
  .shell-nav a { padding: 6px 9px; font-size: 0.86rem; min-height: 38px; }
  .shell-abmelden { padding: 8px 6px; font-size: 0.86rem; }
  .shell-kontext { max-width: 34vw; }
}

/* --- Akten-Reiterleiste (unter der Kopfzeile, auf allen Akte-Seiten) -------- */
.akten-reiter {
  position: sticky;
  top: 0;
  z-index: 49;
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 6px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.akten-reiter::-webkit-scrollbar { display: none; }
.akten-reiter a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 8px 14px;
  border-radius: 999px;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}
.akten-reiter a.aktiv { background: var(--accent-weich); color: var(--accent); }
.akten-reiter a.akten-zurueck { color: var(--accent); flex: 0 0 auto; }

/* Aktionen der Akte am Ende der Reiterleiste (statt frueherem "..."-Menue,
   das auf dem Telefon unhandlich war - die Leiste scrollt horizontal) */
.akten-trenner { flex: 0 0 1px; align-self: stretch; margin: 8px 6px; background: var(--line); }
.akten-aktion {
  background: none; border: none; cursor: pointer; font-family: inherit;
  color: var(--muted); font-weight: 600; font-size: 0.92rem;
  padding: 8px 14px; border-radius: 999px; min-height: 40px;
  display: inline-flex; align-items: center; white-space: nowrap; flex: 0 0 auto;
}
.akten-aktion[hidden] { display: none; } /* display:inline-flex wuerde hidden sonst uebersteuern */
.akten-aktion:hover { background: var(--flaeche); }
.akten-aktion.gefahr { color: var(--error); }
.akten-aktion:disabled { opacity: 0.5; cursor: not-allowed; }

/* --- Bausteine -------------------------------------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--schatten);
}

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}
.pill.on, .pill.eingetragen, .pill.freigegeben { background: var(--accent-weich); color: var(--ok); }
.pill.off, .pill.fehler { background: var(--gefahr-bg); color: var(--error); }
.pill.offen { background: var(--pill-blau-bg); color: var(--pill-blau-ink); }
.pill.uebernommen { background: var(--warn-bg); color: var(--warn); }
.pill.demo { background: var(--pill-lila-bg); color: var(--pill-lila-ink); }
.pill.punkte { background: var(--warn-bg); color: var(--warn); }

button, .knopf {
  padding: 10px 14px;
  font-size: 0.92rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-klein);
  cursor: pointer;
  min-height: 44px;
}
button.primary, .knopf.primary { color: var(--accent-ink); background: var(--accent); }
button.secondary, .knopf.secondary { background: var(--flaeche); color: var(--ink); border: 1px solid var(--line); }
button.gefahr, .knopf.gefahr { background: var(--gefahr-bg); color: var(--error); border: 1px solid var(--gefahr-line); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--eingabe-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-klein);
  padding: 10px 12px;
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--flaeche);
  color: var(--muted);
  opacity: 0.75;
  cursor: not-allowed;
}
.field.gesperrt .field-label, .field.gesperrt label { color: var(--muted); }

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.msg { font-size: 0.9rem; min-height: 1.2em; }
.msg.err, .status.err { color: var(--error); }
.msg.ok, .status.ok { color: var(--ok); }
.muted { color: var(--muted); }

.warnung {
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  color: var(--warn);
  border-radius: var(--radius-klein);
  padding: 10px 12px;
  font-size: 0.88rem;
}

/* --- Toast (kurze Rueckmeldung unten) ---------------------------------------- */
.toast {
  /* Rein informativ - darf NIE Tipper abfangen: er bleibt nach dem Ausblenden
     (opacity 0) im DOM und lag mit z-index 200 unsichtbar UEBER der Mitte der
     Sheet-Knoepfe ("Abbrechen ging nur am Rand", 2026-07-23). */
  pointer-events: none;
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 8px 28px rgba(28, 37, 48, 0.25);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 200;
  max-width: min(92vw, 480px);
  text-align: center;
}
.toast.sichtbar { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--error); }

/* --- Bottom-Sheet (Eingaben statt prompt()) ---------------------------------- */
.sheet-hintergrund {
  position: fixed;
  inset: 0;
  background: rgba(28, 37, 48, 0.4);
  z-index: 150;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  background: var(--card);
  border-radius: 16px 16px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 560px;
  box-shadow: 0 -8px 30px rgba(28, 37, 48, 0.2);
}
.sheet h3 { margin: 0 0 4px; font-size: 1.02rem; }
.sheet .sheet-hinweis { color: var(--muted); font-size: 0.86rem; margin: 0 0 12px; }
.sheet input, .sheet textarea { width: 100%; }
.sheet .sheet-knoepfe { display: flex; gap: 10px; margin-top: 14px; }
.sheet .sheet-knoepfe button { flex: 1; }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}

/* --- Erfolgsdialog (mittig, z. B. nach dem Speichern) ------------------------ */
.dialog-hintergrund {
  position: fixed;
  inset: 0;
  background: rgba(28, 37, 48, 0.45);
  z-index: 160;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.dialog {
  background: var(--card);
  border-radius: 16px;
  padding: 26px 22px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 16px 48px rgba(28, 37, 48, 0.3);
}
.dialog-haken {
  width: 56px; height: 56px; margin: 0 auto 12px;
  border-radius: 999px; background: var(--accent-weich); color: var(--ok);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; font-weight: 800;
}
.dialog h3 { margin: 0 0 6px; font-size: 1.1rem; }
.dialog .dialog-az {
  font-size: 1.35rem; font-weight: 800; color: var(--accent);
  font-variant-numeric: tabular-nums; margin: 2px 0 4px;
}
.dialog .dialog-hinweis { color: var(--muted); font-size: 0.9rem; margin: 0 0 18px; }
.dialog .dialog-knoepfe { display: flex; flex-direction: column; gap: 10px; }
.dialog .dialog-knoepfe .knopf, .dialog .dialog-knoepfe button { width: 100%; }

/* --- Seriengutachten -------------------------------------------------------- */
.pill.serie { background: var(--pill-blau-bg); color: var(--pill-blau-ink); }
/* Gewerbeakte: eigener Feldsatz - in der Liste sofort erkennbar. */
.pill.gewerbe { background: var(--warn-bg); color: var(--warn); }
.einheit-bez { margin-left: 6px; color: var(--muted); font-size: 0.85em; white-space: nowrap; }

/* Einheiten-Wechsler unter der Akten-Reiterleiste (alle Reiter der Akte) */
.einheiten-chips {
  display: flex; gap: 6px; align-items: center;
  padding: 6px 10px;
  background: var(--card); border-bottom: 1px solid var(--line);
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.einheiten-chips::-webkit-scrollbar { display: none; }
.einheiten-chips .einheiten-label { color: var(--muted); font-size: 0.85rem; font-weight: 600; flex: 0 0 auto; }
.einheiten-chips a {
  color: var(--ink); text-decoration: none; font-weight: 600; font-size: 0.9rem;
  padding: 8px 14px; border-radius: 999px; background: var(--flaeche);
  min-height: 40px; display: inline-flex; align-items: center; white-space: nowrap; flex: 0 0 auto;
}
.einheiten-chips a.aktiv { background: var(--accent); color: var(--accent-ink); }

/* Umschalter "Nur Wohnung | Alle Abschnitte" im Formular einer Serienakte */
.serien-toggle {
  display: inline-flex; margin: 8px 0 4px;
  border: 1px solid var(--line); border-radius: 999px; overflow: hidden;
}
.serien-toggle button {
  background: var(--card); border: none; color: var(--muted);
  font-weight: 600; font-size: 0.9rem; padding: 9px 16px; min-height: 40px; cursor: pointer;
}
.serien-toggle button.aktiv { background: var(--accent-weich); color: var(--accent); }

/* Kennzeichnung der Geltung (Modus "Alle Abschnitte") */
.geltung-banner {
  margin: 6px 0 12px; padding: 9px 12px;
  background: var(--pill-blau-bg); color: var(--pill-blau-ink);
  border-radius: var(--radius-klein); font-size: 0.86rem;
}
.geltung-banner.einheit { background: var(--accent-weich); color: var(--accent); }
.geltung-banner.vorbelegt { background: var(--pill-grau-bg); color: var(--pill-grau-ink); }
.geltung-badge {
  margin-left: 8px; padding: 2px 8px; border-radius: 999px;
  background: var(--accent-weich); color: var(--accent);
  font-size: 0.72rem; font-weight: 700; white-space: nowrap; flex: 0 0 auto;
  align-self: center;
}
.geltung-badge.objekt { background: var(--pill-blau-bg); color: var(--pill-blau-ink); }
.geltung-badge.vorbelegt { background: var(--pill-grau-bg); color: var(--pill-grau-ink); }

/* Modus "Nur Wohnung": objektbezogene/vorbelegte Felder ausblenden;
   die Geltungs-Banner sind dann irrelevant und wuerden nur verwirren */
form.nur-wohnung .field[data-geltung="objekt"],
form.nur-wohnung .field[data-geltung="vorbelegt"],
form.nur-wohnung .geltung-banner { display: none; }

/* Auswahl-Sheet (grosse Wahl-Knoepfe, z. B. Standard- oder Seriengutachten) */
.sheet-auswahl { display: flex; flex-direction: column; gap: 10px; }
.sheet-auswahl button {
  text-align: left; background: var(--flaeche); border: 1px solid var(--line);
  border-radius: var(--radius-klein); padding: 12px 14px; cursor: pointer; color: var(--ink);
}
.sheet-auswahl button:hover { background: var(--flaeche-aktiv); }
.sheet-auswahl .auswahl-titel { display: block; font-weight: 700; font-size: 0.98rem; }
.sheet-auswahl .auswahl-text { display: block; color: var(--muted); font-size: 0.86rem; margin-top: 2px; }

/* Hinweis auf der Fotoseite einer Serienakte (Objektfotos uebernehmen) */
.serien-foto-banner {
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  margin: 0 0 14px; padding: 10px 12px;
  background: var(--pill-blau-bg); color: var(--pill-blau-ink);
  border-radius: var(--radius-klein); font-size: 0.9rem;
}
.serien-foto-banner button { flex: 0 0 auto; }

/* Kopf-/Fusszeilen-Felder des Anlagen-Word-Exports (Unterlagen-Reiter) */
.feld-zeile { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.feld-zeile label { flex: 0 0 80px; font-size: 0.9rem; color: #555; }
.feld-zeile input {
  flex: 1; padding: 8px 10px; font-size: 0.95rem;
  border: 1px solid #ccc; border-radius: 6px;
}

/* PLZ-Automatik: Hinweis + aufklappende Vorschlagsliste unter dem PLZ-Feld
   (Akte, CRM, Verwaltung; assets/plz-automatik.js) */
.plz-wrap { position: relative; }
.plz-wrap.plz-offen { z-index: 30; }
.plz-hinweis { margin: 6px 0 0; font-size: 0.9rem; color: var(--muted); }
.plz-wrap.plz-mit-knopf input { padding-right: 44px; }
.plz-aufklappen {
  position: absolute; right: 6px; top: 30px; width: 36px; height: 36px; padding: 0;
  background: transparent; border: 0; color: var(--muted); font-size: 1.1rem; line-height: 36px;
}
.plz-liste {
  position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; z-index: 30;
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); overflow: hidden;
}
.plz-liste-kopf { padding: 8px 12px; font-size: 0.85rem; color: var(--muted); border-bottom: 1px solid var(--line); }
.plz-liste-eintraege { list-style: none; margin: 0; padding: 0; max-height: 270px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.plz-liste-eintraege li.muted { padding: 8px 12px; font-size: 0.85rem; }
.plz-eintrag {
  width: 100%; text-align: left; min-height: 44px; padding: 10px 12px; display: flex; gap: 10px; align-items: baseline;
  background: transparent; color: var(--ink); border: 0; border-bottom: 1px solid var(--line); border-radius: 0;
}
.plz-liste-eintraege li:last-child .plz-eintrag { border-bottom: 0; }
.plz-eintrag:active { background: var(--flaeche); }
.plz-eintrag-ort { font-size: 0.9rem; color: var(--muted); }
