:root {
  --bg: #14161a;
  --panel: #1d2026;
  --panel-2: #24282f;
  --line: #333941;
  --text: #eceef1;
  --muted: #9aa3ae;
  --accent: #ff8a1f;
  --ok: #38b06a;
  --warn: #e5b93c;
  --err: #ef5f5f;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  overscroll-behavior-y: contain;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pad { padding: 1rem 1rem 6rem; }
.pad-sm { padding: .5rem 1rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; margin: .6rem 0; }

h1 { font-size: 1.35rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 .5rem; }
h3 { font-size: .95rem; margin: 1rem 0 .4rem; }

/* ---------------------------------------------------------------- buttons */
button, label.primary, label.ghost {
  font: inherit;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  padding: .7rem 1rem;
  cursor: pointer;
  display: inline-block;
  text-align: center;
}
.primary, label.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #17191d;
  font-weight: 650;
}
.big { padding: 1.1rem 1rem; font-size: 1.1rem; width: 100%; }
.ghost { background: var(--panel-2); }
button.small, .ghost.small { padding: .45rem .7rem; font-size: .85rem; }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; }

/* ---------------------------------------------------------------- login */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-box { width: 100%; max-width: 22rem; text-align: center; }
.login-box form { display: grid; gap: .35rem; text-align: left; margin-top: 1rem; }
.login-box label { font-size: .85rem; color: var(--muted); }
input[type=text], input[type=password] {
  font: inherit;
  padding: .75rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  width: 100%;
}
.login-box button { margin-top: .8rem; }
.error { color: var(--err); min-height: 1.2rem; font-size: .9rem; }

/* ---------------------------------------------------------------- chrome */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem;
  padding: calc(.7rem + var(--safe-top)) 1rem .7rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar-right { display: flex; align-items: center; gap: .5rem; }
.badge {
  font-size: .72rem; padding: .2rem .5rem; border-radius: 999px;
  background: var(--ok); color: #0d1a12; font-weight: 650;
}
.badge.offline { background: var(--err); color: #2a0e0e; }

.queue-bar {
  background: var(--warn); color: #221c05;
  padding: .5rem 1rem; font-size: .85rem; font-weight: 600;
}
.toast {
  position: fixed; left: 1rem; right: 1rem;
  bottom: calc(5.2rem + var(--safe-bottom));
  z-index: 60;
  background: var(--panel-2); border: 1px solid var(--line);
  padding: .7rem 1rem; border-radius: 12px; font-size: .9rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
.toast.ok { border-color: var(--ok); }
.toast.err { border-color: var(--err); }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--panel); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tabbar button {
  border: 0; background: none; border-radius: 0;
  padding: .8rem .2rem; font-size: .8rem; color: var(--muted);
}
.tabbar button.active { color: var(--accent); font-weight: 650; }

/* ---------------------------------------------------------------- capture */
.capture { padding: 1rem 1rem 6rem; display: grid; gap: .8rem; }
.gps-card, .card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: .8rem;
}
.gps-line { display: flex; justify-content: space-between; gap: .8rem; padding: .18rem 0; font-size: .9rem; }
.gps-label { color: var(--muted); flex: 0 0 5.5rem; }
.gps-line span:last-child { text-align: right; }
.gps-card.weak { border-color: var(--warn); }
.gps-card.bad { border-color: var(--err); }

.capture-actions { display: grid; gap: .5rem; }
.note-label { font-size: .8rem; color: var(--muted); }

.live-wrap { position: relative; border-radius: 14px; overflow: hidden; background: #000; }
.live-wrap video { width: 100%; display: block; max-height: 60vh; object-fit: cover; }
.shutter {
  position: absolute; left: 50%; bottom: .9rem; transform: translateX(-50%);
  width: 62px; height: 62px; border-radius: 50%;
  background: #fff; border: 4px solid rgba(0,0,0,.35); padding: 0;
}

.last-shot img { width: 100%; border-radius: 12px; display: block; }

/* ---------------------------------------------------------------- lists */
.site-list { display: grid; gap: .6rem; }
.site-row {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: .8rem; display: flex; justify-content: space-between; align-items: center; gap: .6rem;
  text-align: left; width: 100%;
}
.site-row .name { font-weight: 650; }
.site-row .sub { color: var(--muted); font-size: .8rem; }
.count {
  background: var(--panel-2); border-radius: 999px; padding: .25rem .6rem;
  font-size: .8rem; white-space: nowrap;
}

.photo-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
  gap: .4rem; padding: 0 1rem 6rem;
}
.photo-grid figure { margin: 0; position: relative; }
.photo-grid img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 10px; background: var(--panel-2); display: block;
}
.photo-grid .pill {
  position: absolute; right: .25rem; bottom: .25rem;
  background: rgba(0,0,0,.65); color: #fff;
  font-size: .62rem; padding: .1rem .3rem; border-radius: 6px;
}

/* ---------------------------------------------------------------- map */
/* #map used to be absolute against the initial containing block, i.e. anchored
   to the viewport top -- so it covered the topbar (logout button and the
   online/offline badge were unreachable on the map tab). Nobody noticed while
   the map was grey. #app is a flex column now and the map view is the only
   growing item, so the map fills exactly the gap between topbar and tab bar. */
#app { display: flex; flex-direction: column; min-height: 100dvh; }
#tab-map { position: relative; flex: 1 1 auto; min-height: 0; }
#map {
  position: absolute; inset: 0;
  bottom: calc(3.6rem + var(--safe-bottom));
  background: var(--panel);
}
.leaflet-container { background: #20242a; }
.leaflet-popup-content-wrapper { background: var(--panel); color: var(--text); }
.leaflet-popup-tip { background: var(--panel); }
.leaflet-popup-content a { color: var(--accent); }

/* ---------------------------------------------------------------- overlay */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg); overflow-y: auto;
  padding-bottom: calc(1rem + var(--safe-bottom));
}
.overlay-bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: calc(.7rem + var(--safe-top)) 1rem .7rem;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.viewer-body { padding: 0 0 2rem; }
.viewer-body img { width: 100%; display: block; }

.log {
  background: #0e1013; border: 1px solid var(--line); border-radius: 12px;
  padding: .7rem; font-size: .72rem; line-height: 1.35;
  overflow-x: auto; white-space: pre-wrap; word-break: break-word;
  margin: 0 1rem;
}
.kv { display: flex; justify-content: space-between; gap: .8rem; padding: .15rem 0; font-size: .88rem; }
.kv span:first-child { color: var(--muted); }
.state-ok { color: var(--ok); font-weight: 650; }
.state-warn { color: var(--warn); font-weight: 650; }
.state-err { color: var(--err); font-weight: 650; }

/* ------------------------------------------------------- Baustellen-Sheet */
/* Bottom sheet that asks "Ist das eine von diesen Baustellen?" whenever a
   capture lands outside the automatic radius. Deliberately above the tab bar
   and dismissible, because a dismissed sheet only means "unassigned", never
   "lost". */
.sheet { position: fixed; inset: 0; z-index: 70; display: flex; align-items: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }
.sheet-panel {
  position: relative; width: 100%;
  max-height: 88dvh; overflow-y: auto;
  background: var(--panel); border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: .5rem 1rem calc(1.2rem + var(--safe-bottom));
  box-shadow: 0 -10px 30px rgba(0, 0, 0, .55);
}
.sheet-grab {
  width: 40px; height: 4px; border-radius: 999px; background: var(--line);
  margin: .3rem auto .6rem;
}
.sheet-panel h3 { margin: .2rem 0 .2rem; font-size: 1.05rem; }
.sheet-panel input[type=text] { margin: .5rem 0; }
.sheet-list {
  display: grid; gap: .45rem;
  max-height: 15rem; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: .6rem;
}
.sheet-list .site-row .dist {
  background: var(--panel-2); border-radius: 999px; padding: .25rem .6rem;
  font-size: .8rem; white-space: nowrap; color: var(--muted);
}
.sheet-list .site-row.near .dist { color: var(--ok); font-weight: 650; }
#site-sheet-newbox {
  border: 1px solid var(--line); border-radius: 14px;
  padding: .6rem .8rem; background: var(--panel-2); margin-bottom: .6rem;
}
#site-sheet-newbox summary { cursor: pointer; font-weight: 650; font-size: .92rem; }
#site-sheet-newbox button { width: 100%; margin-top: .5rem; }
#site-sheet-later { width: 100%; }
