/* Belegsystem DJA - Stylesheet
   Mobile-first. Die App wird fast ausschliesslich am Handy bedient:
   grosse Antippflaechen, 16px Schriftgroesse in Eingabefeldern (darunter
   zoomt iOS beim Antippen ungefragt hinein), Bedienleiste am unteren Rand. */

:root {
  /* Flaechen und Text */
  --bg: #f1f3f7;
  --card: #ffffff;
  --text: #111827;
  --text-soft: #4b5563;
  --muted: #6b7280;
  --border: #e2e6ed;
  --border-strong: #cbd3e0;

  /* Akzent */
  --primary: #1d4ed8;
  --primary-dark: #1a3fb0;
  --primary-soft: #eef2ff;

  /* Signalfarben */
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --warn-border: #fcd34d;
  --success: #15803d;
  --success-bg: #f0fdf4;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --danger-border: #fca5a5;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lift: 0 4px 12px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  /* Platz fuer die fixierte Bedienleiste, inkl. Geste-Leiste am iPhone */
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}

/* Betraege immer mit gleich breiten Ziffern - sonst "wackeln" Spalten
   in der Belegliste, sobald sich eine Zahl aendert. */
.amount, .stat .value, .betrag-check, td.num { font-variant-numeric: tabular-nums; }

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

header.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 20;
}

/* Innerer Container: am Handy schlicht volle Breite, am grossen
   Bildschirm auf Inhaltsbreite begrenzt (siehe unten). */
header.topbar .inner {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header.topbar .brand {
  font-weight: 650;
  font-size: 16px;
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

header.topbar .brand .mark {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0;
}

header.topbar a.logout {
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

header.topbar a.logout:active { background: var(--bg); }

/* ---------- Grundgeruest ---------- */

main {
  max-width: 520px;
  margin: 0 auto;
  padding: 18px 16px 8px;
}

h1 {
  font-size: 21px;
  line-height: 1.25;
  letter-spacing: -.015em;
  margin: 0 0 14px;
}

h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin: 22px 0 8px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.card.flush { padding: 4px 16px; }

/* ---------- Hinweisfelder ---------- */

.notice {
  border-radius: var(--radius);
  padding: 13px 15px;
  margin-bottom: 14px;
  font-size: 14px;
  border: 1px solid;
}

.notice strong { display: block; margin-bottom: 2px; }

.notice-warn { background: var(--warn-bg); border-color: var(--warn-border); color: #78350f; }
.notice-danger { background: var(--danger-bg); border-color: var(--danger-border); color: #7f1d1d; }
.notice-info { background: var(--primary-soft); border-color: #c7d2fe; color: #1e3a8a; }

.notice ul { margin: 8px 0 0; padding-left: 18px; }
.notice li { margin-bottom: 3px; }
.notice a { color: inherit; font-weight: 600; }

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

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 14px 0 5px;
  color: var(--text-soft);
}

label.inline {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 500;
  color: var(--text);
  font-size: 15px;
  padding: 10px 0;
  margin: 6px 0 0;
}

label.inline input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 0;
  flex: none;
  accent-color: var(--primary);
}

input, select, textarea {
  width: 100%;
  padding: 12px 13px;
  font-size: 16px;
  font-family: inherit;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, .12);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.8' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  padding-right: 34px;
}

/* Von der KI unsicher gelesene Felder */
input.unsure, select.unsure {
  border-color: var(--warn-border);
  background-color: var(--warn-bg);
}

.row2 { display: flex; gap: 11px; }
.row2 > div { flex: 1; min-width: 0; }

.feldgruppe {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 13px 14px;
  margin-top: 8px;
}

.feldgruppe > .gruppentitel {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin-top: 12px;
}

/* Live-Gegenrechnung der Betraege */
.betrag-check {
  margin-top: 12px;
  font-size: 13.5px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.betrag-check.ok { background: var(--success-bg); border-color: #bbf7d0; color: #14532d; }
.betrag-check.abweichung { background: var(--warn-bg); border-color: var(--warn-border); color: #78350f; }
.betrag-check .summe { font-weight: 700; white-space: nowrap; }

/* ---------- Schaltflaechen ---------- */

button, .btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-family: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  text-align: center;
  text-decoration: none;
  margin-top: 18px;
  cursor: pointer;
  min-height: 50px;
}

button:active, .btn:active { background: var(--primary-dark); }

button:disabled, button[aria-busy="true"] {
  opacity: .75;
  cursor: default;
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:active { background: var(--bg); }

.btn-danger {
  background: #fff;
  color: var(--danger);
  border-color: var(--danger-border);
}

.btn-danger:active { background: var(--danger-bg); }

/* Wartekringel in der Schaltflaeche */
.spinner {
  width: 17px;
  height: 17px;
  border: 2.5px solid rgba(255, 255, 255, .35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: dreh .7s linear infinite;
  flex: none;
}

@keyframes dreh { to { transform: rotate(360deg); } }

/* Wer Bewegung im System abgeschaltet hat, bekommt einen ruhigen Puls */
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: puls 1.4s ease-in-out infinite; border-top-color: rgba(255,255,255,.9); }
  @keyframes puls { 50% { opacity: .35; } }
}

/* ---------- Foto-Auswahl ---------- */

.upload-photo {
  display: block;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 34px 16px;
  text-align: center;
  color: var(--text-soft);
  cursor: pointer;
  background: #fcfdff;
  transition: border-color .15s, background .15s, color .15s;
}

.upload-photo:active { background: var(--primary-soft); }
.upload-photo .icon { display: block; margin: 0 auto 10px; color: var(--muted); }
.upload-photo .titel { display: block; font-weight: 600; color: var(--text); word-break: break-word; }
.upload-photo .unter { display: block; font-size: 13px; color: var(--muted); margin-top: 3px; }

.upload-photo.gewaehlt {
  border-color: var(--success);
  border-style: solid;
  background: var(--success-bg);
}

.upload-photo.gewaehlt .icon, .upload-photo.gewaehlt .titel { color: var(--success); }

/* Das eigentliche Dateifeld bleibt unsichtbar, aber bedienbar */
.datei-versteckt {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

img.preview {
  width: 100%;
  border-radius: var(--radius);
  margin-bottom: 14px;
  border: 1px solid var(--border);
  background: var(--card);
  display: block;
}

/* ---------- Belegliste ---------- */

.beleg-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
}

.beleg-item:last-child { border-bottom: none; }
.beleg-item:active { background: var(--bg); }
.beleg-item .titel { font-weight: 550; }
.beleg-item .meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.beleg-item .amount { font-weight: 700; white-space: nowrap; }
.beleg-item .amount.einnahme { color: var(--success); }
.beleg-item .amount.ausgabe { color: var(--text); }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: 1px;
  border: 1px solid;
}

.badge-unsicher { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }
.badge-duplikat { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); }

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

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
  margin-bottom: 14px;
}

.summary-grid .stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 14px;
  box-shadow: var(--shadow);
}

.summary-grid .stat .label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: .02em;
}

.summary-grid .stat .value {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.02em;
  margin-top: 3px;
}

.stat .value.einnahme { color: var(--success); }
.stat .value.ausgabe { color: var(--danger); }

.filters { display: flex; gap: 9px; margin-bottom: 13px; }
.filters select { font-size: 14px; padding: 10px 30px 10px 11px; background-position: right 10px center; }

/* ---------- Bedienleiste unten ---------- */

nav.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

nav.bottomnav a {
  flex: 1;
  text-align: center;
  padding: 9px 0 8px;
  text-decoration: none;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 550;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

nav.bottomnav a svg { display: block; }
nav.bottomnav a.active { color: var(--primary); font-weight: 700; }

/* ---------- Kleinkram ---------- */

.error {
  color: var(--danger);
  font-size: 14px;
  margin-top: 10px;
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.empty-state { text-align: center; color: var(--muted); padding: 44px 16px; }
.empty-state .icon { color: var(--border-strong); margin-bottom: 10px; }

.hinweis { font-size: 13px; color: var(--muted); }

/* Anmeldeseite */
.login-wrap { max-width: 400px; margin: 8vh auto 0; }
.login-wrap .logo {
  width: 52px;
  height: 52px;
  border-radius: 15px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  font-weight: 700;
  margin: 0 auto 14px;
  box-shadow: var(--shadow-lift);
}
.login-wrap .titel { text-align: center; font-size: 20px; font-weight: 700; letter-spacing: -.015em; }
.login-wrap .unter { text-align: center; color: var(--muted); font-size: 14px; margin: 3px 0 20px; }

/* ================================================================
   Grosser Bildschirm

   Am Handy ist die Bedienung unten am Daumen richtig. Am PC gehoert
   sie nach oben in die Kopfleiste - eine quer ueber den ganzen
   Monitor gezogene Leiste am unteren Rand wirkt dort verloren.
   ================================================================ */

/* Navigation in der Kopfleiste: am Handy ausgeblendet */
.topnav { display: none; }

@media (min-width: 860px) {

  body { padding-bottom: 32px; }

  /* --- Kopfleiste wird zur Navigationsleiste --- */

  header.topbar { padding: 0 28px; }

  header.topbar .inner {
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 26px;
    padding: 10px 0;
  }

  header.topbar .brand { font-size: 15px; }
  header.topbar .brand .mark { width: 25px; height: 25px; font-size: 12px; }

  .topnav {
    display: flex;
    gap: 4px;
    margin-right: auto;
  }

  .topnav a {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 13px;
    border-radius: 9px;
    text-decoration: none;
    color: var(--text-soft);
    font-size: 14px;
    font-weight: 550;
  }

  .topnav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 650; }
  .topnav a svg { width: 18px; height: 18px; }

  /* Am PC ueberfluessig - die Wege stehen oben */
  nav.bottomnav { display: none; }

  /* --- Breiten je Seite --- */

  main { max-width: 560px; padding: 30px 24px 40px; }
  main.mittel { max-width: 800px; }
  main.breit { max-width: 1060px; }

  h1 { font-size: 25px; margin-bottom: 20px; }

  .login-wrap { margin-top: 11vh; }

  /* --- Pruefmaske zweispaltig ---
     Das Belegfoto bleibt beim Scrollen stehen, waehrend rechts die
     Betraege eingetragen werden. Genau dafuer ist der grosse
     Bildschirm gut - am Handy geht das prinzipbedingt nicht. */

  .review-grid {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    gap: 22px;
    align-items: start;
  }

  .review-grid .foto-spalte { position: sticky; top: 82px; }
  .review-grid img.preview { margin-bottom: 0; }
  .review-grid .card { margin-bottom: 0; }

  /* Die Warnungen laufen ueber beide Spalten */
  .review-grid > .notice { grid-column: 1 / -1; }

  /* --- Kennzahlen duerfen nebeneinander mehr Luft haben --- */

  .summary-grid { gap: 14px; }
  .summary-grid .stat { padding: 15px 17px; }
  .summary-grid .stat .value { font-size: 21px; }

  .beleg-item { padding: 14px 4px; }
  .beleg-item:active { background: transparent; }

  /* Schaltflaechen muessen am PC nicht die volle Breite einnehmen */
  .card form > button[type="submit"] { width: auto; min-width: 220px; }
  .card form > .btn { width: auto; min-width: 180px; display: inline-flex; margin-right: 10px; }
  .login-wrap button { width: 100%; }
}

/* Mauszeiger vorhanden: Rueckmeldung beim Darueberfahren.
   Am Touchscreen wuerde das nur haengenbleibende Zustaende erzeugen. */
@media (hover: hover) {
  button:hover, .btn:hover { background: var(--primary-dark); }
  .btn-secondary:hover { background: var(--bg); }
  .btn-danger:hover { background: var(--danger-bg); }
  .beleg-item:hover { background: var(--primary-soft); }
  .topnav a:hover { background: var(--bg); color: var(--text); }
  header.topbar a.logout:hover { background: var(--bg); color: var(--text); }
  .upload-photo:hover { border-color: var(--primary); background: var(--primary-soft); }
  a:hover { text-decoration: underline; }
  .beleg-item:hover, .topnav a:hover { text-decoration: none; }
}

/* Beleg ohne Foto: keine leere linke Spalte stehen lassen */
@media (min-width: 860px) {
  .review-grid.ohne-foto { grid-template-columns: minmax(0, 1fr); max-width: 620px; }
}

@media (min-width: 860px) {
  /* Belegfotos sind meist hochkant. Ohne Deckel wuerde ein Foto die
     Spalte ueber mehrere Bildschirmhoehen strecken - und weil die
     Spalte beim Scrollen stehen bleibt, waere das Formular daneben
     nicht mehr sinnvoll erreichbar. */
  .review-grid img.preview {
    width: auto;
    max-width: 100%;
    max-height: calc(100vh - 140px);
    margin: 0 auto;
  }
}
