/* ═══════════════════════════════════════════════════════════════════════
   Base: Reset + wiederverwendbare Komponenten (shell-unabhängig)
   ═══════════════════════════════════════════════════════════════════════ */

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

html { height: 100%; }
body {
  height: 100dvh;
  font-family: var(--font);
  font-size: var(--fs-md);
  background: var(--bg0);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select { font: inherit; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; }
svg { display: block; flex-shrink: 0; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: var(--r-full); }
::-webkit-scrollbar-track { background: transparent; }

/* Telemetrie-Zahlen laufen nicht (Tachometer, Koordinaten) */
.num { font-variant-numeric: tabular-nums; }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  padding: 10px var(--s4);
  border-radius: var(--r-md);
  font-size: var(--fs-sm); font-weight: 600;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast), opacity var(--t-fast);
  white-space: nowrap;
  min-height: 40px;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover:not(:disabled) { background: var(--accent-strong); }

.btn--ghost { background: var(--bg2); color: var(--text-dim); border: 1px solid var(--border); }
.btn--ghost:hover:not(:disabled) { background: var(--bg3); color: var(--text); }

.btn--danger { background: var(--err-dim); color: var(--err); }
.btn--danger:hover:not(:disabled) { background: rgba(248, 113, 113, .25); }

.btn--icon {
  padding: 0; width: 40px; min-width: 40px;
  border-radius: var(--r-md);
  color: var(--text-muted);
}
.btn--icon:hover { background: var(--bg2); color: var(--text); }

.btn--sm { min-height: 32px; padding: 6px var(--s3); font-size: var(--fs-xs); }

/* ── Formfelder ──────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label {
  font-size: var(--fs-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: .7px;
  color: var(--text-muted);
}
.field input, .field select {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  padding: 10px var(--s3);
  min-height: 42px;
  outline: none;
  transition: border-color var(--t-fast);
  width: 100%;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field input::placeholder { color: var(--text-muted); }
.field select {
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237e93ac' stroke-width='1.8' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 34px;
}
/* Native Date/Time-Picker-Icons auf Dunkel invertieren */
input[type=date]::-webkit-calendar-picker-indicator,
input[type=time]::-webkit-calendar-picker-indicator { filter: invert(.7); }

/* ── Karten & Panels ─────────────────────────────────────────────────── */
.card {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--e1);
}
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--e2);
}

.section-label {
  font-size: var(--fs-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-muted);
}

/* ── Badges & Status ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs); font-weight: 700;
}
.badge--ok   { background: var(--ok-dim);   color: var(--ok); }
.badge--warn { background: var(--warn-dim); color: var(--warn); }
.badge--err  { background: var(--err-dim);  color: var(--err); }
.badge--idle { background: var(--idle-dim); color: var(--text-dim); }

.dot { width: 9px; height: 9px; border-radius: var(--r-full); flex-shrink: 0; }
.dot--online  { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot--offline { background: var(--idle); }
.dot--unknown { background: var(--warn); }

/* Live-Verbindungsanzeige */
.live-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted);
}
.live-chip .dot { width: 7px; height: 7px; }
.live-chip.is-live { color: var(--ok); }
.live-chip.is-live .dot { background: var(--ok); animation: livePulse 2s ease infinite; }
.live-chip:not(.is-live) .dot { background: var(--warn); }
@keyframes livePulse { 50% { opacity: .4; } }

/* ── Fahrzeug-Marker (Mapbox) ────────────────────────────────────────── */
/* WICHTIG: Das Root-Element (.vmark-wrap) wird von Mapbox per transform
   positioniert — es darf selbst NIE transform/transition tragen.
   Alle Effekte liegen auf dem inneren Kreis (.vmark). */
/* KEIN position hier — .mapboxgl-marker (position:absolute) muss gelten,
   sonst landen die Marker im Layout-Fluss statt an der Koordinate. */
.vmark-wrap {
  width: 38px; height: 38px;
  cursor: pointer;
  border: none; background: none; padding: 0;
}
.vmark {
  position: relative;
  width: 100%; height: 100%;
  border-radius: var(--r-full);
  border: 3px solid #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--e2);
  color: #fff;
  transition: transform var(--t-fast), border-color var(--t-fast);
}
.vmark-wrap:hover .vmark { transform: scale(1.12); }
.vmark--online  { background: var(--accent-strong); }
.vmark--offline { background: var(--idle); }
.vmark--unknown { background: var(--warn); }
.vmark--selected { transform: scale(1.15); border-color: var(--accent); }
.vmark--moving::after {
  content: ''; position: absolute; inset: -8px;
  border-radius: var(--r-full);
  border: 2px solid var(--accent);
  animation: markPulse 1.6s ease-out infinite;
}
@keyframes markPulse {
  from { transform: scale(.7); opacity: .8; }
  to   { transform: scale(1.2); opacity: 0; }
}

/* Label über dem Marker: Name (+ Geschwindigkeit wenn online).
   Passt beides nicht in eine Zeile, bricht das Label um (max-width). */
.vmark-label {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; justify-content: center;
  flex-wrap: wrap;
  column-gap: 6px; row-gap: 1px;
  width: max-content;
  max-width: 150px;
  text-align: center;
  line-height: 1.3;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 3px 10px;
  font-size: var(--fs-xs); font-weight: 700;
  color: var(--text);
  pointer-events: none;
  box-shadow: var(--e1);
}
.vmark-label__name { white-space: normal; overflow-wrap: break-word; max-width: 130px; }
.vmark-label__speed { color: var(--ok); white-space: nowrap; }
.vmark-label__speed:empty { display: none; }

/* Cluster-Marker: fasst nahe Fahrzeuge beim Rauszoomen zusammen */
.vcluster {
  width: 46px; height: 46px;
  border-radius: var(--r-full);
  background: var(--accent-strong);
  border: 3px solid #fff;
  color: #fff;
  font-size: 16px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--e2);
  cursor: pointer;
  padding: 0;
}
.vcluster:hover { background: var(--accent); color: var(--accent-ink); }

/* ── Fahrzeugliste (Desktop-Panel + Mobile-Sheet identisch) ─────────── */
.vlist { overflow-y: auto; overscroll-behavior: contain; }
.vitem {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%; text-align: left;
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--border);
  transition: background var(--t-fast);
  min-height: 60px;
}
.vitem:hover, .vitem.is-selected { background: var(--bg2); }
.vitem.is-selected { box-shadow: inset 3px 0 0 var(--accent); }
.vitem__body { flex: 1; min-width: 0; }
.vitem__name {
  font-size: var(--fs-md); font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.vitem__ign {
  display: inline-flex; vertical-align: -2px;
  margin-left: 5px; color: var(--ok);
}
.vitem__meta { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 2px; }
.vitem__speed { font-size: var(--fs-sm); font-weight: 700; color: var(--ok); white-space: nowrap; }
.vitem__speed.is-idle { color: var(--text-muted); font-weight: 500; }

/* ── Detail-Statistiken ──────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.stat {
  background: var(--bg2);
  border-radius: var(--r-md);
  padding: var(--s3);
}
.stat__label { font-size: var(--fs-xs); color: var(--text-muted); margin-bottom: 4px; }
.stat__value { font-size: var(--fs-lg); font-weight: 700; }
.stat__value small { font-size: var(--fs-xs); font-weight: 500; color: var(--text-muted); }

/* ── Tabellen ────────────────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  text-align: left; padding: var(--s3) var(--s4);
  font-size: var(--fs-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: .6px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.table td { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); }
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--bg2); }

/* ── Fortschrittsbalken ──────────────────────────────────────────────── */
.bar { background: var(--bg3); border-radius: var(--r-full); height: 7px; overflow: hidden; }
.bar__fill { height: 100%; border-radius: var(--r-full); transition: width .5s ease; }
.bar__fill--ok   { background: var(--ok); }
.bar__fill--warn { background: var(--warn); }
.bar__fill--err  { background: var(--err); }

/* ── Zustände: Laden / Leer / Fehler ─────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--bg3);
  border-top-color: var(--accent);
  border-radius: var(--r-full);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s3); padding: var(--s7) var(--s4);
  color: var(--text-muted); font-size: var(--fs-sm);
  text-align: center;
}
.state svg { color: var(--bg3); }
.state--error { color: var(--err); }

.skeleton {
  background: linear-gradient(90deg, var(--bg2) 25%, var(--bg3) 50%, var(--bg2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-md);
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Toast ───────────────────────────────────────────────────────────── */
#toasts {
  position: fixed; bottom: calc(var(--s5) + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: var(--s2);
  z-index: var(--z-toast);
  pointer-events: none;
}
.toast {
  background: var(--bg3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: var(--s3) var(--s5);
  font-size: var(--fs-sm); font-weight: 600;
  box-shadow: var(--e3);
  animation: toastIn var(--t-med) both;
  display: flex; align-items: center; gap: var(--s2);
}
.toast--err { border-color: var(--err); color: var(--err); }
.toast--ok  { border-color: var(--ok); color: var(--ok); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* ── Dialog (ersetzt confirm()) ──────────────────────────────────────── */
.dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(4, 8, 16, .7);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  z-index: var(--z-modal);
  display: flex; align-items: center; justify-content: center;
  padding: var(--s5);
  animation: fadeIn var(--t-fast) both;
}
.dialog {
  background: var(--bg1);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  padding: var(--s6);
  max-width: 380px; width: 100%;
  box-shadow: var(--e3);
}
.dialog__title { font-size: var(--fs-lg); font-weight: 700; margin-bottom: var(--s2); }
.dialog__text  { font-size: var(--fs-sm); color: var(--text-dim); margin-bottom: var(--s5); }
.dialog__actions { display: flex; gap: var(--s2); justify-content: flex-end; }
@keyframes fadeIn { from { opacity: 0; } }

/* ── Wochentags-Auswahl (Geofence-Kalender) ──────────────────────────── */
.daypick { display: flex; gap: var(--s1); }
.daypick button {
  flex: 1; min-height: 36px;
  background: var(--bg2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  font-size: var(--fs-xs); font-weight: 600;
  color: var(--text-muted);
  transition: all var(--t-fast);
}
.daypick button.is-on {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-ink); font-weight: 700;
}

/* ── SIM-Karten ──────────────────────────────────────────────────────── */
.sim-card { padding: var(--s5); display: flex; flex-direction: column; gap: var(--s4); }
.sim-card__head { display: flex; align-items: center; gap: var(--s2); font-weight: 600; }
.sim-card__head svg { color: var(--text-muted); }
.sim-block { border-top: 1px solid var(--border); padding-top: var(--s4); }
.sim-row { display: flex; justify-content: space-between; align-items: baseline; font-size: var(--fs-sm); padding: 3px 0; }
.sim-row > span:first-child { color: var(--text-muted); }
.sim-big { display: flex; justify-content: space-between; align-items: baseline; }
.sim-big strong { font-size: var(--fs-2xl); font-weight: 800; }
.sim-big span { font-size: var(--fs-sm); color: var(--text-muted); }

/* ── Mapbox-Anpassungen ──────────────────────────────────────────────── */
.mapboxgl-ctrl-group {
  background: var(--glass-bg) !important;
  -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border) !important;
  border-radius: var(--r-md) !important;
  overflow: hidden;
}
.mapboxgl-ctrl-group button { background: transparent !important; }
.mapboxgl-ctrl-group button + button { border-top: 1px solid var(--border) !important; }
.mapboxgl-ctrl-icon { filter: invert(.85); }
.mapboxgl-ctrl-attrib { background: rgba(10, 15, 26, .6) !important; }
.mapboxgl-ctrl-attrib a { color: var(--text-muted) !important; }

/* ── Druck (PDF-Export für Berichte) ─────────────────────────────────── */
@media print {
  body { background: #fff; color: #000; overflow: visible; height: auto; }
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; inset: 0 auto auto 0; width: 100%; padding: 20px; }
  .print-area .table th, .print-area .table td { color: #000; border-color: #ccc; }
  .no-print { display: none !important; }
}
