:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --hover: #f3f4f6;
  --selected: #eff6ff;
  --accent: #2563eb;
  --moving: #16a34a;
  --idle: #f59e0b;
  --parked: #64748b;
  --offline: #dc2626;
  --nodata: #9ca3af;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

#sidebar {
  width: 360px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  min-height: 0;
}

#map { flex: 1; min-width: 0; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

h1 { font-size: 18px; margin: 0; }

.conn {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--hover);
  color: var(--muted);
}
.conn.live { background: #dcfce7; color: #166534; }
.conn.down { background: #fee2e2; color: #991b1b; }

.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}
.user-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
button.link { background: none; border: none; color: var(--accent); padding: 2px 0; }

/* Strona logowania */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, .06);
}
.login-card h1 { font-size: 22px; }
.login-hint { color: var(--muted); margin: 6px 0 20px; }
.login-card form { display: grid; gap: 14px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input { padding: 9px 12px; }
.login-card button { padding: 10px; font-weight: 600; }
.login-card button:disabled { opacity: .7; cursor: default; }
.login-error {
  margin: 0;
  padding: 8px 12px;
  border-radius: 6px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 13px;
}

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
}
.summary span { display: inline-flex; align-items: center; gap: 6px; }

.device-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 80px;
}

.device {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.device:hover { background: var(--hover); }
.device.selected { background: var(--selected); }
.device:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.device-main { flex: 1; min-width: 0; }
.device-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-sub, .device-time { color: var(--muted); font-size: 12px; }
.device-time { white-space: nowrap; }
.empty { padding: 16px; color: var(--muted); }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--nodata);
}
.dot.moving { background: var(--moving); }
.dot.idle { background: var(--idle); }
.dot.parked { background: var(--parked); }
.dot.offline { background: var(--offline); }

.details {
  border-top: 2px solid var(--border);
  padding: 12px 16px 16px;
  overflow-y: auto;
  max-height: 60%;
}
.details-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.details h2 { font-size: 16px; margin: 0; }
.details h3 { font-size: 13px; margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

.live {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 10px 0 0;
}
.live dt { color: var(--muted); }
.live dd { margin: 0; font-variant-numeric: tabular-nums; }

.row { display: flex; gap: 6px; flex-wrap: wrap; }

input, button {
  font: inherit;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}
button { background: var(--accent); border-color: var(--accent); color: #fff; cursor: pointer; }
button:hover { filter: brightness(1.08); }
button.secondary { background: #fff; color: var(--text); border-color: var(--border); }
button.close { background: none; border: none; color: var(--muted); font-size: 22px; line-height: 1; padding: 0 4px; }

.history-stats { margin-top: 8px; color: var(--muted); font-size: 13px; }

details.edit-box { margin-top: 14px; }
details.edit-box summary { cursor: pointer; color: var(--accent); }
form.edit { display: grid; gap: 8px; margin-top: 8px; }
form.edit label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
form.edit .msg { font-size: 12px; color: var(--muted); }

/* Znaczniki aut na mapie */
.car-marker {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--nodata);
}
.car-marker.moving { background: var(--moving); }
.car-marker.idle { background: var(--idle); }
.car-marker.parked { background: var(--parked); }
.car-marker.offline { background: var(--offline); }
.car-marker.selected { box-shadow: 0 0 0 4px rgba(37, 99, 235, .45), 0 1px 4px rgba(0, 0, 0, .45); }

.car-arrow {
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 13px solid #fff;
  transform-origin: 50% 55%;
}
.car-marker:not(.moving) .car-arrow {
  border: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #fff;
}

.leaflet-tooltip.car-label { font-weight: 600; }

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  z-index: 1000;
  max-width: calc(100% - 32px);
}

@media (max-width: 760px) {
  body { flex-direction: column-reverse; }
  #sidebar { width: 100%; height: 48%; border-right: none; border-top: 1px solid var(--border); }
  #map { flex: 1; }
}
