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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #6a5acd 0, #121212 55%);
  color: #ffffff;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

#app {
  width: 100%;
  max-width: 480px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(160deg, #1b1930 0%, #14131f 100%);
  position: relative;
  overflow: hidden;
}

.screen {
  display: none;
  height: 100%;
}

.screen.active {
  display: flex;
}

#login-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: rgba(15, 14, 30, 0.95);
  border-radius: 20px;
  padding: 24px 20px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(18px);
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 1.8rem;
}

.login-card .subtitle {
  margin: 0 0 16px;
  font-size: 0.9rem;
  color: #b9b6d8;
}

.login-card label {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.login-card input {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #3d3864;
  background: #0b0a18;
  color: #fff;
}

.login-card input:focus {
  outline: none;
  border-color: #8f7bff;
}

button.primary {
  width: 100%;
  margin-top: 8px;
  padding: 11px 14px;
  border-radius: 999px;
  border: none;
  background: radial-gradient(circle at top left, #ff7aa2, #8d7bff);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

button.primary:active {
  transform: translateY(1px);
  opacity: 0.9;
}

.hint {
  margin-top: 12px;
  font-size: 0.8rem;
  color: #a49fd0;
}

.error {
  margin-top: 8px;
  font-size: 0.85rem;
  color: #ff7a7a;
}

.hidden {
  display: none !important;
}

#main-screen {
  flex-direction: column;
  height: calc(100vh - 64px);
}

#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 6px;
  background: linear-gradient(180deg, rgba(17, 16, 32, 0.98), rgba(17, 16, 32, 0.85));
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  z-index: 2;
}

#top-bar h2 {
  margin: 0;
  font-size: 1.1rem;
}

#top-bar p {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: #a2a0c8;
}

#refresh-btn {
  border: none;
  background: rgba(49, 47, 86, 0.9);
  color: #f3f1ff;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  font-size: 1.1rem;
  cursor: pointer;
}

#view-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.tab-view {
  position: absolute;
  inset: 0;
  display: none;
}

.tab-view.active {
  display: block;
}

.tab-inner {
  padding: 12px 16px 80px;
  overflow-y: auto;
}

.tab-inner h3 {
  margin-top: 4px;
  margin-bottom: 8px;
}

.empty-list {
  list-style: none;
  padding-left: 0;
  margin: 8px 0 0;
  font-size: 0.9rem;
  color: #a29fcb;
}

#map-container {
  position: relative;
  width: 100%;
  height: 100%;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

#device-bottom-sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 10px 20px;
  background: linear-gradient(180deg, rgba(11, 10, 24, 0), rgba(11, 10, 24, 0.98));
  z-index: 1;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.sheet-title {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #a5a2ce;
}

.sheet-count {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(79, 73, 142, 0.9);
  font-size: 0.8rem;
}

#device-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  align-items: flex-end;
}

.device-chip {
  min-width: 210px;
  max-width: 260px;
  padding: 10px 12px;
  border-radius: 18px;
  background: rgba(22, 18, 48, 0.96);
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}


.device-chip.active {
  border-color: #9e86ff;
  box-shadow: 0 0 0 1px rgba(158, 134, 255, 0.4), 0 6px 12px rgba(0, 0, 0, 0.6);
}

.device-top-row {
  display: flex;
  justify-content: flex-start;
  gap: 6px;
}

.device-main-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.device-avatar {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(145deg, #ff9a8b, #ff6a88);
  overflow: hidden;
}


.device-avatar-img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
  transform: scale(1.12);
  transform-origin: center center;
}

.device-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.device-name {
  font-size: 0.9rem;
  margin-bottom: 2px;
}

.device-status {
  font-size: 0.78rem;
  color: #b3b0dc;
}

.device-status.online {
  color: #7cf29c;
}

.device-status.offline,
.device-status.unknown {
  color: #8f8cae;
}

.device-details {
  font-size: 0.72rem;
  color: #a9a6d5;
  margin-top: 2px;
}

.device-battery {
  width: 34px;
  height: 16px;
  border-radius: 4px;
  border: 2px solid currentColor;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  flex-shrink: 0;
  font-size: 0.6rem;
  font-weight: 600;
}


.device-battery::after {
  content: "";
  position: absolute;
  right: -5px;
  top: 25%;
  width: 4px;
  height: 50%;
  border-radius: 1px;
  background-color: currentColor;
}

.device-battery-text {
  line-height: 1;
}


.device-battery.high {
  color: #7cf29c;
  
}

.device-battery.medium {
  color: #ffb347;
  
}

.device-battery.low {
  color: #ff6b6b;
  
}

.device-battery.unknown {
  color: #b3b0dc;
  
  opacity: 0.7;
}




.device-history-today {
  border-radius: 999px;
  border: 1px solid rgba(92, 180, 255, 0.7);
  background: rgba(92, 180, 255, 0.15);
  color: #b9e0ff;
  padding: 2px 8px;
  font-size: 0.72rem;
  cursor: pointer;
}

.device-history-custom-toggle {
  border-radius: 999px;
  border: 1px solid rgba(159, 149, 255, 0.7);
  background: rgba(159, 149, 255, 0.1);
  color: #e1dcff;
  padding: 2px 8px;
  font-size: 0.72rem;
  cursor: pointer;
}

.device-custom-panel {
  padding: 4px 6px;
  border-radius: 12px;
  background: rgba(15, 13, 40, 0.95);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.device-custom-range {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.device-custom-from,
.device-custom-to {
  width: 100%;
  padding: 4px 6px;
  border-radius: 8px;
  border: 1px solid #3d3864;
  background: #0b0a18;
  color: #fff;
  font-size: 0.7rem;
}

.device-custom-show {
  align-self: flex-start;
  border-radius: 999px;
  border: 1px solid rgba(126, 243, 162, 0.8);
  background: rgba(126, 243, 162, 0.12);
  color: #bdfcd0;
  padding: 2px 10px;
  font-size: 0.72rem;
  cursor: pointer;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 10px;
  border-radius: 12px;
  background: rgba(25, 23, 52, 0.95);
  margin-bottom: 8px;
}

button.secondary {
  border-radius: 999px;
  border: 1px solid rgba(159, 149, 255, 0.6);
  background: transparent;
  color: #d3d0ff;
  padding: 6px 10px;
  font-size: 0.8rem;
  cursor: pointer;
}

button.secondary.danger {
  border-color: rgba(255, 143, 143, 0.6);
  color: #ffc5c5;
}

button.small {
  padding: 5px 10px;
  font-size: 0.75rem;
}

#bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: 100%;
  max-width: 460px;
  display: flex;
  justify-content: space-around;
  padding: 6px 10px;
  background: rgba(14, 13, 29, 0.96);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
  z-index: 3;
}

.nav-item {
  flex: 1;
  border: none;
  background: transparent;
  color: #a09dc9;
  padding: 4px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.7rem;
  cursor: pointer;
}

.nav-item .icon {
  font-size: 1.1rem;
}

.nav-item.active {
  color: #ffffff;
}

.nav-item.active .icon {
  filter: drop-shadow(0 0 6px rgba(172, 139, 255, 0.8));
}

.leaflet-container {
  background: #0b0a1b;
}

.map-marker-wrapper {
  border: none;
}

.map-marker {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4);
  border: 2px solid rgba(0, 0, 0, 0.6);
  overflow: hidden;
}



.map-marker.online {
  border-color: #6cf09b;
}

.map-marker.offline {
  opacity: 0.5;
  filter: grayscale(0.6);
}

.map-marker-inner {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: #fff;
  font-size: 0.75rem;
}

.map-marker-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.16);
  transform-origin: center center;
}

#fit-devices-btn {
  position: absolute;
  right: 12px;
  bottom: 168px;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: rgba(255, 255, 255, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
  z-index: 2;
  padding: 0;
}

#fit-devices-btn:active {
  transform: translateY(2px);
  opacity: 0.9;
}

.fit-icon {
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translate(0px, 0px);
}

#route-day-legend {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(17, 16, 32, 0.92);
  border-radius: 10px;
  padding: 6px 8px;
  font-size: 0.72rem;
  color: #e4e2ff;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.6);
  z-index: 2;
  max-width: 220px;
}

.route-day-legend-title {
  font-weight: 600;
  margin-bottom: 3px;
  font-size: 0.72rem;
  color: #bcb7ff;
}

.route-day-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
}

.route-day-legend-color {
  width: 18px;
  height: 8px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  flex-shrink: 0;
}

.route-day-legend-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-map {
  display: inline-block;
  width: 18px;
  height: 14px;
  border-radius: 2px;
  border: 1.6px solid currentColor;
  box-sizing: border-box;
  position: relative;
  transform: translateY(1px);
}

.icon-map::before,
.icon-map::after {
  content: "";
  position: absolute;
  top: 1px;
  bottom: 1px;
  border-left: 1.3px solid currentColor;
}

.icon-map::before {
  left: 33%;
}

.icon-map::after {
  left: 66%;
}

.geofences-list {
  list-style: none;
  padding-left: 0;
  margin: 8px 0 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.geofence-item {
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(22, 18, 48, 0.96);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.geofence-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.geofence-name {
  font-size: 0.9rem;
}

.geofence-meta {
  font-size: 0.78rem;
  color: #a5a2ce;
}

.geofence-chip {
  align-self: flex-start;
  margin-top: 2px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: rgba(92, 180, 255, 0.2);
  color: #b9e0ff;
  cursor: pointer;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  z-index: 5;
}


#trip-overlay-content {
  width: 100%;
  max-width: 480px;
  height: 90vh;
  background: radial-gradient(circle at top, #282449 0, #141324 60%);
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

#trip-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(15, 14, 32, 0.95);
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

#trip-overlay-title {
  font-size: 0.95rem;
}

#trip-overlay-close {
  border: none;
  background: transparent;
  color: #e6e4ff;
  font-size: 1.4rem;
  cursor: pointer;
}

#trip-overlay-map {
  flex: 1;
}

.trip-speed-indicator {
  position: absolute;
  top: 52px;
  right: 12px;
  width: 64px;
  height: 64px;
  border-radius: 999px;

  
  background: #ffffff;
  border: 3px solid #8b5cf6;
  

  
  z-index: 999;
  

  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  pointer-events: none;
  text-align: center;
}


#trip-overlay-speed {
  font-size: 0.85rem;
  font-weight: 700;
  color: #000000;
  
  line-height: 1.1;
}



.trip-route-summary {
  padding: 6px 10px;
  font-size: 0.78rem;
  color: #e2e0ff;
  background: rgba(17, 16, 32, 0.9);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#trip-overlay-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px 10px;
  background: rgba(15, 14, 32, 0.96);
  font-size: 0.8rem;
}

.trip-controls-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.trip-controls-right {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #c7c3ff;
}

.trip-btn {
  border-radius: 999px;
  border: 1px solid rgba(160, 150, 255, 0.6);
  background: rgba(160, 150, 255, 0.1);
  color: #e4e0ff;
  padding: 4px 10px;
  font-size: 0.78rem;
  cursor: pointer;
}


.trip-rate-btn {
  border-radius: 999px;
  border: 1px solid rgba(126, 243, 162, 0.85);
  background: rgba(126, 243, 162, 0.14);
  color: #bdfcd0;
  padding: 3px 12px;
  font-size: 0.78rem;
  cursor: pointer;
  font-weight: 600;
}

.trip-rate-btn:active {
  transform: translateY(1px);
  opacity: 0.9;
}

#top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill {
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(20, 18, 38, 0.6);
  color: rgba(255, 255, 255, 0.85);
  user-select: none;
  white-space: nowrap;
}

.pill[data-state="live"] {
  border-color: rgba(38, 255, 52, 0.35);
  background: rgba(20, 60, 30, 0.35);
  color: rgba(220, 255, 230, 0.95);
}

.pill[data-state="sync"] {
  border-color: rgba(10, 246, 255, 0.3);
  background: rgba(10, 50, 60, 0.35);
}

.pill[data-state="idle"] {
  border-color: rgba(186, 167, 167, 0.25);
  background: rgba(60, 55, 55, 0.25);
}

.pill[data-state="offline"] {
  border-color: rgba(255, 20, 20, 0.3);
  background: rgba(60, 20, 20, 0.35);
  color: rgba(255, 230, 230, 0.95);
}

.icon svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(14px);
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(20, 18, 38, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.95);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  max-width: min(560px, calc(100vw - 24px));
  text-align: center;
  z-index: 2000;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

#toast[data-kind="error"] {
  border-color: rgba(255, 20, 20, 0.35);
  background: rgba(60, 20, 20, 0.9);
}

#device-bottom-sheet,
#bottom-nav {
  padding-bottom: env(safe-area-inset-bottom);
}

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