:root {
  --bg: #0f1419;
  --panel: #171d24;
  --line: #2a3440;
  --text: #e8eef4;
  --muted: #8b9aab;
  --accent: #3dd6c6;
  --accent-dim: #1f6f67;
  --offline: #6b7380;
  --online: #3dd6c6;
  --danger: #e85d5d;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100%;
}

.sidebar {
  background: linear-gradient(180deg, #1a222b 0%, var(--panel) 40%);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1.25rem;
}

.brand {
  display: flex;
  gap: 0.85rem;
  align-items: center;
  margin-bottom: 1.25rem;
}

.brand-mark {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.55rem;
  background:
    radial-gradient(circle at 30% 30%, #7affef, transparent 55%),
    linear-gradient(135deg, var(--accent), #1a6b8a);
  box-shadow: 0 0 0 1px rgba(61, 214, 198, 0.25);
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.brand p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-family: var(--mono);
}

.actions {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

#btnLocateAll {
  width: 100%;
  border: 0;
  border-radius: 0.55rem;
  padding: 0.75rem 1rem;
  background: var(--accent);
  color: #073b36;
  font: 600 0.95rem var(--font);
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.15s ease;
}

#btnLocateAll:hover {
  filter: brightness(1.05);
}

#btnLocateAll:active {
  transform: translateY(1px);
}

.btn-download {
  display: block;
  width: 100%;
  text-align: center;
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  padding: 0.7rem 1rem;
  color: var(--text);
  font: 600 0.9rem var(--font);
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-download:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-secondary {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  padding: 0.65rem 1rem;
  background: transparent;
  color: var(--muted);
  font: 600 0.85rem var(--font);
  cursor: pointer;
}

.btn-secondary:hover {
  color: var(--text);
  border-color: var(--muted);
}

.hidden { display: none !important; }

.users-panel {
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}

.users-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font: 600 0.75rem var(--font);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
}

.users-toggle:hover {
  color: var(--text);
  border-color: var(--accent-dim);
}

.users-toggle[aria-expanded="true"] .users-toggle-icon {
  transform: rotate(90deg);
}

.users-toggle-icon {
  display: inline-block;
  transition: transform 0.15s ease;
  color: var(--accent);
}

.users-body {
  margin-top: 0.65rem;
}

.users-body.collapsed {
  display: none;
}

.create-user {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.create-user input[type="text"],
.create-user input[type="password"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  padding: 0.45rem 0.55rem;
  font: 0.85rem var(--font);
}

.create-user button {
  border: 0;
  border-radius: 0.4rem;
  background: var(--accent-dim);
  color: var(--text);
  padding: 0.45rem;
  font: 600 0.8rem var(--font);
  cursor: pointer;
}

.check-admin {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.users-msg {
  color: var(--danger);
  font-size: 0.78rem;
  margin: 0 0 0.4rem;
}

.users-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 140px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.users-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.users-list em {
  font-style: normal;
  color: var(--accent);
  font-size: 0.68rem;
  margin-left: 0.25rem;
}

.users-list button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--danger);
  border-radius: 0.3rem;
  padding: 0.15rem 0.4rem;
  font-size: 0.7rem;
  cursor: pointer;
}

/* Login */
.login-page {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse at top, rgba(61, 214, 198, 0.08), transparent 50%),
    var(--bg);
}

.login-card {
  width: min(100%, 380px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  padding: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.login-brand {
  margin-bottom: 0.4rem;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.login-card input {
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  padding: 0.65rem 0.75rem;
  font: 0.95rem var(--font);
}

.login-card button[type="submit"] {
  border: 0;
  border-radius: 0.55rem;
  padding: 0.75rem 1rem;
  background: var(--accent);
  color: #073b36;
  font: 600 0.95rem var(--font);
  cursor: pointer;
}

.login-download {
  margin-top: 0.15rem;
}

.login-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.85rem;
}

.list-head {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
  padding: 0 0.15rem;
}

.device-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.device-item {
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  padding: 0.7rem 0.8rem;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.device-item:hover,
.device-item.active {
  border-color: var(--accent-dim);
  background: rgba(61, 214, 198, 0.06);
}

.device-item .row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
}

.device-item .name {
  font-weight: 600;
  font-size: 0.92rem;
}

.device-item .badge {
  font-family: var(--mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  color: var(--offline);
}

.device-item.online .badge {
  color: var(--online);
}

.device-item .meta {
  margin-top: 0.35rem;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.45;
}

.device-item .item-actions {
  margin-top: 0.55rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.device-item .locate-one,
.device-item .share-maps {
  margin-top: 0;
  width: 100%;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 0.4rem;
  padding: 0.4rem;
  font: 500 0.78rem var(--font);
  cursor: pointer;
}

.device-item .locate-one:hover,
.device-item .share-maps:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.device-item .share-maps:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.map-wrap {
  position: relative;
  min-width: 0;
}

#map {
  height: 100%;
  width: 100%;
  background: #0b1014;
}

.leaflet-container {
  font-family: var(--font);
  background: #0b1014;
}

.leaflet-popup-content-wrapper {
  background: #1a222b;
  color: var(--text);
  border-radius: 0.5rem;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

.leaflet-popup-tip {
  background: #1a222b;
}

.leaflet-popup-content {
  margin: 0.7rem 0.85rem;
  font-size: 0.85rem;
  line-height: 1.45;
}

.leaflet-popup-content strong {
  font-size: 0.95rem;
}

.pin {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 0 0 4px rgba(61, 214, 198, 0.25);
}

.pin.offline {
  background: var(--offline);
  box-shadow: none;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: 42vh 58vh;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
