/* ============================================================
   GPSLogger – gemeinsames Layout / Topbar / responsive Schriften
   ============================================================ */

:root {
  --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* dynamische, aber gedeckelte Schriftgroesse */
  --ui-font-size: clamp(0.80rem, 0.55rem + 1.1vw, 1.05rem);

  --topbar-bg: #2c3e50;
  --topbar-fg: #ffffff;
  --topbar-accent: #34495e;
  --topbar-pad-y: clamp(0.30rem, 1.0vw, 0.55rem);
  --topbar-pad-x: clamp(0.50rem, 2.0vw, 1.00rem);
  --topbar-gap: clamp(0.40rem, 1.5vw, 0.90rem);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: var(--ui-font);
  font-size: var(--ui-font-size);
}

/* Vollbild-Spalte: schlanke Topbar oben, Karte fuellt den Rest */
body {
  display: flex;
  flex-direction: column;
}

#map {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;          /* erlaubt der Karte, im Flex-Layout zu schrumpfen */
  width: 100%;
}

/* ---------- Topbar ---------- */
.topbar {
  position: relative;     /* Anker fuer das aufklappende Menue */
  flex: 0 0 auto;
  display: flex;
  align-items: center;    /* vertikale Zentrierung der Menuezeile */
  gap: var(--topbar-gap);
  padding: var(--topbar-pad-y) var(--topbar-pad-x);
  background: var(--topbar-bg);
  color: var(--topbar-fg);
  z-index: 1000;          /* ueber der Leaflet-Karte */
}

/* Hamburger-Button */
.topbar__burger {
  flex: 0 0 auto;
  width: clamp(2.0rem, 6vw, 2.6rem);
  height: clamp(2.0rem, 6vw, 2.6rem);
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.40em;
  padding: 0.45em;
  background: transparent;
  border: none;
  cursor: pointer;
}
.topbar__burger span {
  display: block;
  width: 1.4em;
  height: 0.15em;
  min-height: 2px;
  background: var(--topbar-fg);
  border-radius: 2px;
  transition: transform .2s ease, opacity .2s ease;
}
/* Hamburger -> X im geoeffneten Zustand (Versatz = Strichhoehe + Abstand) */
.topbar__burger.is-open span:nth-child(1) { transform: translateY(0.55em) rotate(45deg); }
.topbar__burger.is-open span:nth-child(2) { opacity: 0; }
.topbar__burger.is-open span:nth-child(3) { transform: translateY(-0.55em) rotate(-45deg); }

/* ganz links in der Leiste: Fahrzeug-Auswahl (vor dem Inhalt) */
.topbar__lead {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
}

/* Fahrzeug-Dropdown in der Topbar */
.vehicle-select {
  font-family: var(--ui-font);
  font-size: var(--ui-font-size);
  font-weight: 600;
  height: 2em;
  max-width: clamp(6.5rem, 34vw, 12rem);
  padding: 0 1.6em 0 0.5em;
  color: var(--topbar-fg);
  background-color: var(--topbar-accent);
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 6px;
  cursor: pointer;
  /* eigener Pfeil (das Standard-Dropdown-Dreieck ist auf dunklem Grund kaum sichtbar) */
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.4em center;
  background-size: 1em 1em;
}
.vehicle-select:focus {
  outline: none;
  border-color: rgba(255, 255, 255, .7);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, .25);
}
.vehicle-select option { color: #000; background: #fff; }

/* einfache Ueberschrift in der Topbar (z.B. Fahrzeug-Verwaltung) */
.topbar__title { font-weight: 600; white-space: nowrap; }

/* freier Bereich links (immer sichtbar, z.B. "gefahrene Strecke") */
.topbar__content {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--topbar-gap);
}

/* einheitliche Schriften fuer Beschriftungen, Eingaben und Auswahlfelder */
.topbar__content,
.topbar__content span,
.topbar__tools,
.topbar__tools label,
.topbar__tools input,
.topbar__tools select {
  font-family: var(--ui-font);
  font-size: var(--ui-font-size);
  font-weight: 600;
}
.topbar__content span,
.topbar__tools label { white-space: nowrap; }

/* einheitliche Hoehe fuer Datums-/Auswahlfelder
   (sonst rendert iOS type=date hoeher und die Felder sind nicht ausgerichtet) */
.topbar__tools input,
.topbar__tools select {
  height: 2em;
  box-sizing: border-box;
  padding: 0 0.4em;
}

/* einklappbare Bedienelemente (von/bis/Pause) - auf breiten Screens inline rechts */
.topbar__tools {
  display: flex;
  align-items: center;
  gap: var(--topbar-gap);
  margin-left: auto;          /* ans rechte Ende, links vom Toggle/Hamburger */
}
/* Beschriftung + Feld als zusammengehoerige Einheit */
.ui-field {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
}

/* Toggle-Button fuer die Bedienelemente (nur auf schmalen Screens sichtbar) */
.topbar__tools-toggle {
  flex: 0 0 auto;
  display: none;
  align-items: center;
  justify-content: center;
  width: clamp(2.0rem, 6vw, 2.6rem);
  height: clamp(2.0rem, 6vw, 2.6rem);
  padding: 0.3em;
  color: var(--topbar-fg);
  background: transparent;
  border: none;
  cursor: pointer;
}

/* schmale Displays: Bedienelemente hinter den Toggle einklappen */
@media (max-width: 900px) {
  .topbar__tools-toggle { display: inline-flex; }
  .topbar__tools {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 1001;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5em;
    min-width: clamp(12rem, 70vw, 18rem);
    margin-left: 0;
    padding: 0.7em 0.8em;
    background: var(--topbar-bg);
    box-shadow: 0 6px 16px rgba(0, 0, 0, .3);
    border-bottom-left-radius: 6px;
  }
  .topbar__tools.is-open { display: flex; }
  /* feste Label-Breite -> Felder starten gleich und sind gleich breit */
  .topbar__tools .ui-field label { flex: 0 0 5.5em; }
  .topbar__tools .ui-field input,
  .topbar__tools .ui-field select { flex: 1 1 auto; min-width: 0; }
}

/* ---------- aufklappende Navigation ---------- */
.topbar__nav {
  position: absolute;
  top: 100%;
  right: 0;                 /* rechtsbuendig aufklappen, weg von den Zoom-Buttons (oben links) */
  min-width: clamp(9rem, 45vw, 14rem);
  display: none;
  flex-direction: column;
  background: var(--topbar-bg);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .3);
  border-bottom-left-radius: 6px;
  overflow: hidden;
}
.topbar__nav.is-open { display: flex; }
.topbar__nav a {
  color: var(--topbar-fg);
  text-decoration: none;
  padding: 0.75em 1em;
  font-size: var(--ui-font-size);
  border-top: 1px solid rgba(255, 255, 255, .08);
}
.topbar__nav a:first-child { border-top: none; }
.topbar__nav a:hover,
.topbar__nav a:focus { background: var(--topbar-accent); }

/* ---------- Routeninformationen (links, aufklappende Box) ---------- */
/* min-width:0 erlaubt das Schrumpfen im Flex-Content (neben der Fahrzeug-Auswahl);
   die Beschriftung kuerzt dann mit Ellipse statt die Buttons zu ueberlappen.
   Die aufklappende Box ist an der .topbar verankert (nicht am Label) und wird
   davon NICHT beschnitten. */
.routeinfo { cursor: pointer; min-width: 0; }
.routeinfo__label {
  display: block;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.routeinfo__box {
  position: absolute;     /* relativ zur .topbar -> klappt unter der Leiste auf */
  top: 100%;
  left: 0;
  z-index: 1001;
  display: none;
  min-width: clamp(14rem, 60vw, 20rem);
  padding: 0.6em 0.9em;
  background: var(--topbar-bg);
  color: var(--topbar-fg);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .3);
  border-bottom-right-radius: 6px;
  font-size: var(--ui-font-size);
}
.routeinfo__box.is-open { display: block; }
.routeinfo__box table { border-collapse: collapse; width: 100%; }
.routeinfo__box th {
  text-align: left;
  font-weight: 600;
  padding: 0.18em 0.8em 0.18em 0;
  white-space: nowrap;
  vertical-align: top;
}
.routeinfo__box td {
  text-align: right;
  padding: 0.18em 0;
  white-space: nowrap;
}

/* ---------- kombinierte Steuerleiste oben links (Zoom/Layer/Route) ---------- */
/* nutzt Leaflets .leaflet-bar-Optik; hier nur die Icons sauber zentrieren */
.gps-bar a {
  display: flex !important;
  align-items: center;
  justify-content: center;
}
.gps-bar a svg { display: block; }

/* ---------- Hinweis bei zu wenig Daten ---------- */
.map-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 90%;
  text-align: center;
  font-size: clamp(0.95rem, 0.7rem + 1.4vw, 1.5rem);
  font-weight: bold;
}

/* ---------- Auth-/Info-Seiten (Login, Fehler, Logout) ---------- */
.auth-page {
  align-items: center;          /* horizontal zentrieren */
  justify-content: center;      /* vertikal zentrieren */
  min-height: 100%;
  padding: 1rem;
  background: var(--topbar-bg); /* grau wie die Menuezeile */
}
.auth-box {
  width: 100%;
  max-width: 22rem;
  box-sizing: border-box;
  padding: clamp(1.25rem, 4vw, 2rem);
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
  text-align: center;
}
.auth-box h1 {
  margin: 0 0 1rem;
  color: var(--topbar-bg);
  font-size: clamp(1.1rem, 0.9rem + 1.2vw, 1.5rem);
}
.auth-box p { margin: 0 0 1.2rem; color: #333; font-size: var(--ui-font-size); }
.auth-box form { display: flex; flex-direction: column; gap: 0.85rem; text-align: left; }
.auth-field { display: flex; flex-direction: column; gap: 0.3rem; }
.auth-box label { font-weight: 600; font-size: var(--ui-font-size); color: #333; }
.auth-box input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.6em 0.7em;
  font-family: var(--ui-font);
  font-size: var(--ui-font-size);
  border: 1px solid #cbd2d9;
  border-radius: 6px;
}
.auth-box input:focus {
  outline: none;
  border-color: var(--topbar-accent);
  box-shadow: 0 0 0 2px rgba(52, 73, 94, .35);
}
.auth-btn,
.auth-box button {
  display: inline-block;
  margin-top: 0.4rem;
  padding: 0.6em 1.1em;
  font-family: var(--ui-font);
  font-size: var(--ui-font-size);
  font-weight: 600;
  text-decoration: none;
  color: var(--topbar-fg);
  background: var(--topbar-bg);
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.auth-btn:hover,
.auth-box button:hover { background: var(--topbar-accent); }
.auth-error { margin: 0 0 1rem; color: #b71c1c; font-weight: 600; font-size: var(--ui-font-size); }
.auth-box--error h1 { color: #b71c1c; }

/* MFA / Zwei-Faktor */
.auth-check { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; font-size: var(--ui-font-size); color: #333; }
.auth-check input { width: auto; margin: 0; }
.mfa-qr { text-align: center; margin: 0 0 1rem; }
.mfa-qr img { width: 200px; height: 200px; max-width: 100%; }
.mfa-secret { text-align: center; }
.mfa-secret code { font-size: 1.1rem; letter-spacing: 0.05em; word-break: break-all; }
.mfa-codes { list-style: none; padding: 0; margin: 0 0 1.2rem; text-align: center; }
.mfa-codes li { padding: 0.2rem 0; }
.mfa-codes code { font-size: 1.05rem; letter-spacing: 0.08em; }

/* ============================================================
   Verwaltungsseiten (Fahrzeuge / CRUD)
   ============================================================ */
.admin {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;              /* Inhalt scrollt, Topbar bleibt oben */
  background: #eef1f4;
  color: #222;
  padding: clamp(0.8rem, 3vw, 2rem);
}
.admin__inner {
  width: 100%;
  max-width: 60rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: clamp(0.9rem, 2.5vw, 1.5rem);
}

/* Karte / Panel */
.card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .10);
  padding: clamp(1rem, 3vw, 1.6rem);
}
.card h2 { margin: 0 0 1rem; color: var(--topbar-bg); font-size: clamp(1.05rem, 0.9rem + 1vw, 1.35rem); }
.card h3 { margin: 0 0 0.5rem; color: var(--topbar-bg); font-size: clamp(1rem, 0.9rem + 0.6vw, 1.15rem); }
.card hr { border: none; border-top: 1px solid #e2e6ea; margin: 1.4rem 0 1.1rem; }
.card .hint { margin: 0 0 0.9rem; color: #55606b; font-size: var(--ui-font-size); }

/* Flash-Meldungen */
.flash {
  padding: 0.8em 1em;
  border-radius: 8px;
  font-size: var(--ui-font-size);
  font-weight: 600;
}
.flash--ok    { background: #e6f5ea; color: #1b6b34; border: 1px solid #b6e0c2; }
.flash--error { background: #fdecec; color: #b71c1c; border: 1px solid #f5c2c2; }
.flash--token { background: #fff8e1; color: #6b4e00; border: 1px solid #f0d98a; }
.flash--token p { margin: 0 0 0.7rem; }
.token-out { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 0.9rem; }
.token-out dt { font-weight: 600; }
.token-out dd { margin: 0; }
.token-out code { word-break: break-all; font-size: 1.02em; background: rgba(0,0,0,.05); padding: 0.1em 0.35em; border-radius: 4px; }

/* Formulare */
.vform { display: flex; flex-direction: column; gap: 0.9rem; }
.vfield { display: flex; flex-direction: column; gap: 0.3rem; }
.vfield label { font-weight: 600; font-size: var(--ui-font-size); color: #333; }
.vfield small { color: #6b757e; font-size: 0.85em; }
.vform input[type="text"] {
  width: 100%;
  box-sizing: border-box;
  padding: 0.55em 0.7em;
  font-family: var(--ui-font);
  font-size: var(--ui-font-size);
  border: 1px solid #cbd2d9;
  border-radius: 6px;
}
.vform input[type="text"]:focus {
  outline: none;
  border-color: var(--topbar-accent);
  box-shadow: 0 0 0 2px rgba(52, 73, 94, .3);
}
.vform input[disabled] { background: #f2f4f6; color: #6b757e; }
.vcheck { display: flex; align-items: center; gap: 0.5rem; font-size: var(--ui-font-size); color: #333; }
.vcheck input { width: auto; margin: 0; }
.vactions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 0.3rem; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.55em 1.05em;
  font-family: var(--ui-font);
  font-size: var(--ui-font-size);
  font-weight: 600;
  text-decoration: none;
  text-align: center;
  color: var(--topbar-fg);
  background: var(--topbar-bg);
  border: 1px solid var(--topbar-bg);
  border-radius: 6px;
  cursor: pointer;
}
.btn:hover { background: var(--topbar-accent); border-color: var(--topbar-accent); }
.btn--ghost { color: var(--topbar-bg); background: #fff; }
.btn--ghost:hover { background: #eef1f4; color: var(--topbar-bg); }
.btn--danger { color: #fff; background: #c0392b; border-color: #c0392b; }
.btn--danger:hover { background: #a5281c; border-color: #a5281c; }
.btn--sm { padding: 0.35em 0.7em; font-size: 0.9em; }

/* Tabelle */
.table-wrap { overflow-x: auto; }
.vtable { width: 100%; border-collapse: collapse; font-size: var(--ui-font-size); }
.vtable th, .vtable td { text-align: left; padding: 0.6em 0.7em; border-bottom: 1px solid #e6eaee; vertical-align: middle; }
.vtable th { color: #55606b; font-weight: 600; white-space: nowrap; }
.vtable code { font-size: 0.95em; }
.vtable .muted { color: #9aa4ad; }
.vtable .col-actions { white-space: nowrap; }
.vtable .col-actions .btn { margin: 0.15em 0.15em 0.15em 0; }
.vtable form.inline { display: inline; }

.badge { display: inline-block; padding: 0.15em 0.6em; border-radius: 999px; font-size: 0.85em; font-weight: 600; }
.badge--on  { background: #e6f5ea; color: #1b6b34; }
.badge--off { background: #fdecec; color: #b71c1c; }

/* schmale Screens: Tabelle als Karten stapeln */
@media (max-width: 640px) {
  .vtable thead { display: none; }
  .vtable, .vtable tbody, .vtable tr, .vtable td { display: block; width: 100%; }
  .vtable tr { border: 1px solid #e6eaee; border-radius: 8px; margin-bottom: 0.8rem; padding: 0.3rem 0.6rem; }
  .vtable td { border-bottom: 1px solid #f0f2f4; padding: 0.5em 0; }
  .vtable td:last-child { border-bottom: none; }
  .vtable td::before {
    content: attr(data-th);
    display: block;
    font-size: 0.8em;
    font-weight: 600;
    color: #55606b;
    margin-bottom: 0.15em;
  }
  .vtable .col-actions { padding-top: 0.6em; }
}

/* ============================================================
   Bestaetigungs-Dialog (modales Overlay, ersetzt window.confirm)
   ============================================================ */
.modal-open { overflow: hidden; }        /* Hintergrund nicht scrollen, solange offen */

.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;                          /* ueber Topbar (1000/1001) */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .5);
}
.modal__box {
  position: relative;
  width: 100%;
  max-width: 24rem;
  box-sizing: border-box;
  padding: clamp(1.1rem, 4vw, 1.6rem);
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
  text-align: left;
  animation: modal-in .15s ease-out;
}
.modal__title {
  margin: 0 0 0.6rem;
  color: var(--topbar-bg);
  font-size: clamp(1.05rem, 0.9rem + 0.8vw, 1.3rem);
}
.modal__msg {
  margin: 0 0 1.3rem;
  color: #333;
  font-size: var(--ui-font-size);
  line-height: 1.45;
}
.modal__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.6rem;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .modal__box { animation: none; }
}
