/* KD Tracking – gemeinsame Gestaltung für Büro-Ansicht und Empfänger-Link.
   Farben und Schrift wie auf der neuen KD-Website, Schrift selbst gehostet. */

@font-face {
  font-family: "Instrument Sans";
  src: url("/assets/fonts/instrument-sans-latin-var.woff2") format("woff2-variations"),
       url("/assets/fonts/instrument-sans-latin-var.woff2") format("woff2");
  font-weight: 400 700;
  font-stretch: 75% 100%;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Instrument Sans Fallback";
  src: local("Arial"), local("Helvetica Neue"), local("Helvetica");
  size-adjust: 103.9%;
  ascent-override: 93.4%;
  descent-override: 24.1%;
  line-gap-override: 0%;
}

:root {
  --forest-950: #0f1812;
  --forest-900: #18281e;
  --forest-800: #263e2f;
  --forest-700: #304f3c;
  --ivory: #f3f0e6;
  --paper: #e9e4d6;
  --white: #fffef9;
  --ink: #152019;
  --brown: #80592f;
  --amber: #d49a37;
  --sand: #ead5aa;
  --muted: #4c5852;
  --line: rgba(21, 32, 25, .16);
  --line-strong: rgba(21, 32, 25, .34);
  --live: #2c7a47;
  --stale: #a86b12;
  --ended: #7b857f;
  --danger: #8a2c1d;
  --font-sans: "Instrument Sans", "Instrument Sans Fallback", system-ui, sans-serif;
  --radius: 10px;
  color-scheme: light;
}

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

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

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.45;
  color: var(--ink);
  background: var(--ivory);
}

h1, h2, p, dl, dd, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
a { color: inherit; }
button { font: inherit; }

:focus-visible { outline: 3px solid var(--forest-700); outline-offset: 2px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  padding: .45rem .9rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--white);
  color: var(--ink);
  font-weight: 600;
  font-size: .9375rem;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--paper); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn-danger { color: var(--danger); border-color: rgba(138, 44, 29, .45); }

.dot {
  display: inline-block;
  flex: none;
  width: .625rem;
  height: .625rem;
  border-radius: 50%;
  background: var(--ended);
}
.dot-live { background: var(--live); }
.dot-stale { background: var(--stale); }
.dot-waiting { background: var(--sand); box-shadow: inset 0 0 0 1px var(--line-strong); }
.dot-ended { background: var(--ended); }

/* Fahrzeug auf der Karte */
.vehicle {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 3px solid var(--white);
  border-radius: 50%;
  background: var(--forest-800);
  box-shadow: 0 1px 4px rgba(15, 24, 18, .4);
}
.vehicle-arrow {
  display: none;
  width: 0;
  height: 0;
  border-right: 5px solid transparent;
  border-bottom: 9px solid var(--amber);
  border-left: 5px solid transparent;
}
.vehicle.has-heading .vehicle-arrow { display: block; }
.vehicle.is-old { background: var(--ended); }

.maplibregl-ctrl-attrib { font-family: var(--font-sans); }

/* ------------------------------------------------------------------ Büro */

.page-admin {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .625rem 1rem;
  background: var(--forest-900);
  color: var(--ivory);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .625rem;
  font-weight: 650;
  text-decoration: none;
}
.brand img { display: block; width: 49px; height: 24px; }
.topbar-note {
  padding: .1rem .5rem;
  border: 1px solid rgba(243, 240, 230, .35);
  border-radius: 999px;
  font-size: .8125rem;
}
.topbar-state { margin-left: auto; font-size: .875rem; color: rgba(243, 240, 230, .8); }

.admin {
  display: grid;
  grid-template-columns: minmax(16rem, 22rem) 1fr;
  min-height: 0;
}

.side {
  overflow: auto;
  padding: 1rem;
  border-right: 1px solid var(--line);
  background: var(--white);
}
.side section + section { margin-top: 1.75rem; }
.side h2, .detail h2 {
  margin-bottom: .5rem;
  font-size: .8125rem;
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}

.tour-list { display: grid; gap: .25rem; }
.tour {
  display: flex;
  align-items: flex-start;
  gap: .625rem;
  width: 100%;
  padding: .625rem .75rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.tour:hover { background: var(--ivory); }
.tour.is-selected { border-color: var(--line-strong); background: var(--ivory); }
.tour .dot { margin-top: .4rem; }
.tour-main { display: grid; min-width: 0; }
.tour-title { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.tour-meta { font-size: .8125rem; color: var(--muted); }

.device-list { display: grid; gap: .5rem; }
.device {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  font-size: .875rem;
}
.device-meta { color: var(--muted); }
.device.is-revoked { opacity: .55; }

.empty, .placeholder { color: var(--muted); font-size: .9375rem; }

.main {
  display: grid;
  grid-template-rows: minmax(18rem, 55vh) auto;
  min-height: 0;
  overflow: auto;
}
.admin-map { min-height: 18rem; }
.placeholder { padding: 1.5rem; }

.detail { padding: 1.25rem 1.5rem 2rem; }
.detail-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.detail-head h1 { font-size: 1.375rem; line-height: 1.2; }
.meta { margin-top: .25rem; color: var(--muted); font-size: .9375rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 1.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}
.stat { padding: .75rem .875rem; background: var(--white); }
.stat dt { font-size: .8125rem; color: var(--muted); }
.stat dd { font-weight: 600; font-variant-numeric: tabular-nums; }

.battery { margin-bottom: 1.5rem; }
.battery svg { display: block; width: 100%; height: 7.5rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--white); }

.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); gap: 1.5rem; }
.rows { display: grid; gap: 1px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--line); }
.rows li { padding: .5rem .75rem; background: var(--white); font-size: .875rem; font-variant-numeric: tabular-nums; }
.rows .row-time { display: inline-block; min-width: 3.25rem; color: var(--muted); }
.rows li.is-warning { box-shadow: inset 3px 0 0 var(--amber); }
.rows li.is-empty { color: var(--muted); }

@media (max-width: 860px) {
  .page-admin { height: auto; min-height: 100dvh; }
  .admin { grid-template-columns: 1fr; }
  .side { max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .main { overflow: visible; }
  .admin-map { height: 55vh; }
  .detail { padding: 1rem; }
}

/* ------------------------------------------------------------------ Empfänger-Link */

.page-public { height: 100dvh; overflow: hidden; background: var(--paper); }

/* Google Maps setzt am Container position: relative – darum mit Vorrang fixieren. */
.public-map { position: fixed !important; inset: 0; }

.sheet {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  left: 1rem;
  display: grid;
  gap: .375rem;
  max-width: 25rem;
  padding: 1rem 1.25rem 1.125rem;
  border-radius: 14px;
  background: var(--white);
  box-shadow: 0 8px 28px rgba(15, 24, 18, .2);
}
.sheet-brand {
  display: flex;
  align-items: center;
  gap: .625rem;
  margin-bottom: .25rem;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--muted);
}
.sheet-brand img { display: block; width: 49px; height: 24px; }
.sheet h1 { font-size: 1.375rem; line-height: 1.2; }
.sheet-label { color: var(--muted); }
.sheet-status { display: flex; align-items: center; gap: .5rem; margin-top: .25rem; font-size: 1.0625rem; font-weight: 650; }
.sheet-updated { color: var(--muted); font-size: .9375rem; font-variant-numeric: tabular-nums; }

.contact {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-top: .5rem;
  padding: .625rem 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-decoration: none;
}
.contact svg { flex: none; width: 1.25rem; height: 1.25rem; color: var(--forest-700); }
.contact-text { display: grid; }
.contact-label { font-size: .8125rem; color: var(--muted); }
.contact-value { font-weight: 600; }
.contact:hover .contact-value { text-decoration: underline; }

.sheet-note { margin-top: .25rem; font-size: .8125rem; color: var(--muted); }

@media (min-width: 720px) {
  .sheet { right: auto; bottom: 1.5rem; left: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

/* ------------------------------------------------------------------ Gemeinsam: Formulare */

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.btn-primary { border-color: var(--forest-700); background: var(--forest-700); color: var(--white); }
.btn-primary:hover { background: var(--forest-800); }
.btn-quiet { border-color: transparent; background: none; color: var(--muted); }
.btn-quiet:hover { background: var(--paper); color: var(--ink); }

input:not([type="checkbox"]) {
  width: 100%;
  min-height: 2.875rem;
  padding: .625rem .875rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--white);
  color: var(--ink);
  font: inherit;
}
input:focus-visible { outline: 3px solid var(--forest-700); outline-offset: 1px; }
label { font-size: .875rem; font-weight: 600; color: var(--muted); }

/* ------------------------------------------------------------------ Login */

.page-login { display: grid; place-items: center; min-height: 100dvh; padding: 1.5rem; }
.login { display: grid; gap: .25rem; width: min(100%, 22rem); }
.login-logo { width: 98px; height: 48px; margin-bottom: 1rem; }
.login h1 { font-size: 2rem; line-height: 1.1; }
.login-lead { margin-bottom: 1.5rem; color: var(--muted); }
.login-form { display: grid; gap: .5rem; }
.login-form label:not(.check) { margin-top: .5rem; }
.check { display: flex; align-items: center; gap: .5rem; margin: .75rem 0 .5rem; color: var(--ink); font-weight: 500; }
.check input { width: 1.125rem; height: 1.125rem; accent-color: var(--forest-700); }
.form-error { color: var(--danger); font-size: .9375rem; }
.login .btn { min-height: 3rem; margin-top: .5rem; font-size: 1rem; }

/* ------------------------------------------------------------------ Dashboard */

.page-dash { display: grid; grid-template-rows: auto 1fr; min-height: 100dvh; }
.topbar-btn {
  margin-left: auto;
  padding: .375rem .625rem;
  border: 0;
  border-radius: 6px;
  background: none;
  color: rgba(243, 240, 230, .85);
  font-size: .9375rem;
  cursor: pointer;
}
.topbar-btn:hover { background: rgba(243, 240, 230, .1); color: var(--ivory); }

.dash { display: grid; grid-template-rows: 42vh auto; }
.dash-map { min-height: 16rem; }
.dash-panel { padding: 1rem 1rem calc(2rem + env(safe-area-inset-bottom)); background: var(--ivory); }

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .25rem;
  margin-bottom: 1rem;
  padding: .25rem;
  border-radius: 10px;
  background: var(--paper);
}
.tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .375rem;
  min-height: 2.5rem;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--white); color: var(--ink); box-shadow: 0 1px 2px rgba(15, 24, 18, .12); }
.count:empty { display: none; }
.count { min-width: 1.375rem; padding: 0 .375rem; border-radius: 999px; background: var(--forest-700); color: var(--white); font-size: .75rem; line-height: 1.375rem; }

.tours { display: grid; gap: .5rem; }
.tour-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  width: 100%;
  padding: .875rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.tour-row:hover { border-color: var(--line-strong); }
.tour-row-main { display: grid; flex: 1; min-width: 0; gap: .125rem; }
.tour-row-title { overflow: hidden; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.tour-row-meta { color: var(--muted); font-size: .875rem; }
.tour-row-go { color: var(--muted); font-size: 1.5rem; line-height: 1; }

.plan {
  display: grid;
  gap: .375rem;
  margin-bottom: 1.25rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--white);
}
.plan .btn { margin-top: .5rem; }

.planned { display: grid; gap: .75rem; padding: 1rem; border: 1px solid var(--line); border-radius: 10px; background: var(--white); }
.planned-main { display: grid; gap: .125rem; }
.planned-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.search { margin-bottom: 1rem; }
.month + .month { margin-top: 1.25rem; }
.month h2 { margin-bottom: .5rem; font-size: .875rem; font-weight: 650; color: var(--muted); }

.back { margin: 0 0 .75rem -.5rem; padding: .375rem .5rem; border: 0; border-radius: 6px; background: none; color: var(--muted); font-size: .9375rem; cursor: pointer; }
.back:hover { background: var(--paper); color: var(--ink); }
.detail-view h1 { font-size: 1.5rem; line-height: 1.2; }
.d-status { display: flex; align-items: center; gap: .5rem; margin: .375rem 0 1.25rem; font-weight: 600; }
.facts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1px;
  overflow: hidden;
  margin-bottom: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--line);
}
.fact { padding: .75rem .875rem; background: var(--white); }
.fact dt { color: var(--muted); font-size: .8125rem; }
.fact dd { font-weight: 650; font-variant-numeric: tabular-nums; }
.d-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

@media (min-width: 900px) {
  .page-dash { height: 100dvh; }
  .dash { grid-template-columns: minmax(22rem, 27rem) 1fr; grid-template-rows: none; min-height: 0; }
  .dash-map { order: 2; height: 100%; }
  .dash-panel { order: 1; overflow: auto; padding: 1.25rem; border-right: 1px solid var(--line); }
}

/* ------------------------------------------------------------------ Ziel und Adresssuche */

.dest-pin {
  width: 20px;
  height: 20px;
  border: 4px solid var(--amber);
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 4px rgba(15, 24, 18, .4);
}

.place { position: relative; }
.place-list {
  position: absolute;
  z-index: 20;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--white);
  box-shadow: 0 8px 24px rgba(15, 24, 18, .16);
}
.place-option {
  display: grid;
  width: 100%;
  padding: .625rem .875rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}
.place-option:last-child { border-bottom: 0; }
.place-option:hover, .place-option[aria-selected="true"] { background: var(--ivory); }
.place-main { font-weight: 600; }
.place-secondary { color: var(--muted); font-size: .875rem; }
.place-chosen { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .625rem .875rem; border: 1px solid var(--forest-700); border-radius: 8px; background: var(--white); }
.place-chosen-text { display: grid; }
.eta { font-weight: 650; }

.optional { font-weight: 400; }
.sheet-eta { font-size: 1rem; }
