:root {
  --bg: #f0f4f8;
  --card: #fff;
  --primary: #0066a1;
  --primary-dark: #004d7a;
  --warn: #e65100;
  --lost: #c62828;
  --ok: #2e7d32;
  --muted: #64748b;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  margin: 0;
  background: var(--bg);
  color: #1e293b;
  padding-bottom: 72px;
}

header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  padding: 1rem 1rem 0.75rem;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

#profile {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  opacity: 0.92;
}

#status {
  margin: 0.5rem 1rem 0;
  font-size: 0.78rem;
  color: var(--muted);
}

main { padding: 0.75rem 1rem 1rem; }

.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.device-card {
  border-left: 4px solid var(--primary);
}

.device-card.lost { border-left-color: var(--lost); }
.device-card.sos { border-left-color: var(--warn); }

.device-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.device-head strong { font-size: 1rem; }

.badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  background: #e8f5e9;
  color: var(--ok);
}

.badge.lost { background: #ffebee; color: var(--lost); }
.badge.sos, .badge.warn { background: #fff3e0; color: var(--warn); }

.meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.75rem;
  margin-top: 0.65rem;
  font-size: 0.82rem;
}

.meta dt { color: var(--muted); margin: 0; }
.meta dd { margin: 0; font-weight: 500; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.65rem;
  margin-right: 0.5rem;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-danger { background: var(--lost); color: #fff; }
.btn-ghost { background: #e2e8f0; color: #334155; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

#map {
  height: 52vh;
  min-height: 280px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

.map-legend span::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.35rem;
  vertical-align: middle;
}

.legend-anchor::before { background: #64748b; }
.legend-device::before { background: var(--primary); }
.legend-lost::before { background: var(--lost); }

nav.tabs {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  box-shadow: 0 -2px 10px rgba(15, 23, 42, 0.06);
  z-index: 100;
}

nav.tabs button {
  flex: 1;
  border: none;
  background: none;
  padding: 0.65rem 0.25rem 0.55rem;
  font-size: 0.72rem;
  color: var(--muted);
  cursor: pointer;
}

nav.tabs button.active {
  color: var(--primary);
  font-weight: 700;
}

nav.tabs button .icon { display: block; font-size: 1.15rem; margin-bottom: 0.15rem; }

.field { margin-bottom: 0.85rem; }
.field label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.3rem; }
.field input, .field textarea {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
  font-size: 0.9rem;
}

.hint { font-size: 0.78rem; color: var(--muted); margin-top: 0.35rem; }
.about-body { white-space: pre-line; }

.lang-switch { display: flex; gap: 0.2rem; flex-shrink: 0; }
.lang-btn {
  background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.35);
  color: #fff; padding: 0.25rem 0.45rem; border-radius: 6px; cursor: pointer; font-size: 0.7rem;
}
.lang-btn.active { background: #fff; color: var(--primary); border-color: #fff; }

.badge { text-transform: none; max-width: 45%; text-align: right; font-size: 0.72rem; }

#userid {
  font-family: ui-monospace, monospace;
  font-size: 0.82rem;
  word-break: break-all;
  background: #f8fafc;
  padding: 0.5rem;
  border-radius: 6px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem 1rem;
  font-size: 0.9rem;
}

.toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.toast.show { opacity: 1; }

.leaflet-popup-content { font-size: 0.82rem; margin: 0.5rem 0.65rem; }
