:root {
  --bg: #0a0d0a;
  --panel: rgba(16, 20, 16, 0.82);
  --panel-solid: #121712;
  --stroke: rgba(214, 196, 160, 0.14);
  --stroke-strong: rgba(214, 196, 160, 0.28);
  --text: #f0ebe0;
  --muted: rgba(240, 235, 224, 0.55);
  --copper: #c47a4a;
  --copper-bright: #e8a06a;
  --olive: #7a8f68;
  --danger: #d46555;
  --device: #5b93ff;
  --glow: rgba(196, 122, 74, 0.18);
  --shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  --font-display: "Syne", "Avenir Next", sans-serif;
  --font-body: "Manrope", "Avenir Next", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --side-w: min(400px, calc(100vw - 24px));
  --top-h: 58px;
  --radius: 14px;
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

#admin-app {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(1200px 600px at 12% -10%, rgba(196, 122, 74, 0.12), transparent 55%),
    radial-gradient(900px 500px at 90% 0%, rgba(107, 124, 90, 0.1), transparent 50%),
    var(--bg);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* —— top bar —— */

.admin-top {
  flex: 0 0 auto;
  min-height: var(--top-h);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--stroke);
  background: rgba(10, 13, 10, 0.72);
  backdrop-filter: blur(18px) saturate(1.2);
  z-index: 30;
}

.admin-brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.admin-brand-link {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.03em;
}

.admin-brand-link span {
  color: var(--copper-bright);
  letter-spacing: 0.2em;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  margin-left: 5px;
}

.admin-title {
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  border-left: 1px solid var(--stroke);
  padding-left: 10px;
}

.admin-kpi {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1 1 auto;
  justify-content: center;
}

.kpi-card {
  min-width: 64px;
  padding: 5px 10px;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(0, 0, 0, 0.15));
}

.kpi-label {
  display: block;
  font-size: 0.58rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.kpi-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--copper-bright);
  line-height: 1.15;
}

.admin-top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.conn-pill {
  font-size: 0.64rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--stroke-strong);
  color: var(--muted);
  background: rgba(0, 0, 0, 0.25);
}

.conn-pill[data-state="signalr"] {
  color: #c5d4b5;
  border-color: rgba(122, 143, 104, 0.55);
  box-shadow: 0 0 0 3px rgba(122, 143, 104, 0.12);
}

.conn-pill[data-state="poll"] {
  color: #c4b5fd;
  border-color: rgba(167, 139, 250, 0.35);
}

.conn-pill[data-state="error"] {
  color: var(--danger);
  border-color: rgba(212, 101, 85, 0.45);
}

.admin-btn {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--stroke-strong);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font: 600 0.78rem/1 var(--font-body);
  cursor: pointer;
  text-decoration: none;
  display: inline-grid;
  place-items: center;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease), color 0.2s var(--ease),
    transform 0.2s var(--ease);
}

.admin-btn:hover {
  border-color: var(--copper);
  color: var(--copper-bright);
  background: rgba(196, 122, 74, 0.1);
}

.admin-btn:active {
  transform: scale(0.98);
}

.admin-btn.primary {
  background: linear-gradient(180deg, rgba(232, 160, 106, 0.28), rgba(196, 122, 74, 0.18));
  border-color: rgba(232, 160, 106, 0.55);
  color: #f6d7b8;
  box-shadow: 0 8px 24px rgba(196, 122, 74, 0.15);
}

.admin-btn.primary:hover {
  color: #fff4e8;
  border-color: var(--copper-bright);
}

.admin-btn.ghost {
  color: var(--muted);
}

.admin-btn.block {
  width: 100%;
}

.admin-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* —— auth overlay (never splits layout) —— */

.admin-auth {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-scrim {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(800px 400px at 50% 30%, rgba(196, 122, 74, 0.16), transparent 60%),
    rgba(6, 8, 6, 0.78);
  backdrop-filter: blur(10px);
}

.auth-card {
  position: relative;
  width: min(420px, 100%);
  padding: 28px 26px;
  border-radius: 20px;
  border: 1px solid var(--stroke-strong);
  background: linear-gradient(165deg, rgba(28, 34, 28, 0.96), rgba(14, 18, 14, 0.98));
  box-shadow: var(--shadow), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
  animation: rise 0.45s var(--ease) both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.auth-kicker {
  margin: 0 0 6px;
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--copper-bright);
}

.auth-card h1 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.55rem;
  letter-spacing: -0.03em;
}

.auth-advanced {
  margin-top: 14px;
  border-top: 1px solid var(--stroke);
  padding-top: 10px;
}

.auth-advanced summary {
  cursor: pointer;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  list-style: none;
}

.auth-advanced summary::-webkit-details-marker {
  display: none;
}

.auth-card input[type="text"],
.auth-card input[type="password"] {
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: 500 0.9rem/1.3 var(--font-body);
}


.auth-card textarea {
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: 500 0.84rem/1.4 var(--font-body);
  resize: vertical;
}

.field-label {
  display: block;
  margin-top: 14px;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-label em {
  font-style: normal;
  opacity: 0.7;
  text-transform: none;
  letter-spacing: 0;
}

.auth-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.hint {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--muted);
}

.hint.err {
  color: var(--danger);
  margin-top: 12px;
}

/* —— workspace: map full + floating dock —— */

.admin-body {
  flex: 1;
  min-height: 0;
  position: relative;
  display: block;
}

.admin-map-wrap {
  position: absolute;
  inset: 0;
}

#admin-map {
  position: absolute;
  inset: 0;
  background: #141914;
}

.admin-side {
  position: absolute;
  z-index: 520;
  top: 12px;
  left: 12px;
  bottom: 12px;
  width: var(--side-w);
  display: flex;
  flex-direction: column;
  gap: 0;
  border-radius: 18px;
  border: 1px solid var(--stroke-strong);
  background: var(--panel);
  backdrop-filter: blur(22px) saturate(1.15);
  box-shadow: var(--shadow), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
  overflow: hidden;
  animation: rise 0.5s var(--ease) 0.05s both;
}

.side-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 4px;
  padding: 10px;
  border-bottom: 1px solid var(--stroke);
  background: rgba(0, 0, 0, 0.22);
  flex: 0 0 auto;
}

.side-tab {
  position: relative;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: 600 0.78rem/1 var(--font-body);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}

.side-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.side-tab.is-active {
  color: var(--text);
  background: rgba(196, 122, 74, 0.2);
  box-shadow: 0 0 0 1px rgba(232, 160, 106, 0.25) inset;
}

.tab-badge {
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 5px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-size: 0.65rem;
  background: rgba(212, 101, 85, 0.2);
  border: 1px solid rgba(212, 101, 85, 0.45);
  color: #f0b0a6;
}

.side-panels {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.side-panel {
  flex: 1;
  min-height: 0;
  display: none;
  flex-direction: column;
  overflow: hidden;
}

.side-panel.is-active {
  display: flex;
}

.side-panel[data-panel="setup"].is-active {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  gap: 10px;
  padding: 10px;
}

.side-panel[data-panel="units"].is-active,
.side-panel[data-panel="alarms"].is-active {
  padding: 0;
}

.side-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  min-height: 0;
}

.side-panel[data-panel="setup"] .side-section {
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.22);
  flex: 0 0 auto;
}

.side-section.units,
.side-section.alarms {
  flex: 1;
  height: 100%;
}

.side-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  flex: 0 0 auto;
}

.side-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.badge {
  min-width: 1.5rem;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  font-size: 0.72rem;
  text-align: center;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.25);
}

.badge.danger {
  color: #f0b0a6;
  border-color: rgba(212, 101, 85, 0.45);
}

.side-section input[type="text"],
.side-section input[type="number"],
.side-section input[type="search"],
#unit-search {
  width: 100%;
  height: 40px;
  margin: 0;
  padding: 0 12px;
  border-radius: 11px;
  border: 1px solid var(--stroke);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: 500 0.85rem/1.2 var(--font-body);
  outline: none;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.side-section input:focus,
#unit-search:focus {
  border-color: rgba(232, 160, 106, 0.55);
  box-shadow: 0 0 0 3px var(--glow);
}

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.78rem;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.2s var(--ease), color 0.2s var(--ease), background 0.2s var(--ease);
}

.chip:has(input:checked) {
  color: var(--text);
  border-color: rgba(232, 160, 106, 0.45);
  background: rgba(196, 122, 74, 0.14);
}

.chip input {
  accent-color: var(--copper);
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.inline-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.inline-row .admin-btn {
  height: 40px;
  padding: 0 16px;
}

.unit-list,
.alarm-list,
.geo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
}

.geo-list {
  max-height: 140px;
  border-top: 1px solid var(--stroke);
  padding-top: 8px;
}

.unit-item,
.alarm-item {
  display: grid;
  gap: 3px;
  padding: 11px 12px;
  margin-bottom: 6px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease), transform 0.18s var(--ease);
}

.unit-item:hover,
.alarm-item:hover {
  background: rgba(122, 143, 104, 0.14);
  border-color: var(--stroke);
}

.unit-item[aria-selected="true"] {
  background: rgba(196, 122, 74, 0.16);
  border-color: rgba(232, 160, 106, 0.35);
  box-shadow: 0 0 0 1px rgba(196, 122, 74, 0.12);
}

.unit-item.stale,
.alarm-item {
  border-color: rgba(212, 101, 85, 0.28);
}

.unit-item.noloc {
  opacity: 0.8;
}

.unit-name {
  font-weight: 650;
  font-size: 0.9rem;
  letter-spacing: -0.01em;
}

.unit-meta {
  font-size: 0.72rem;
  color: var(--muted);
}

.unit-meta .tag {
  display: inline-block;
  margin-right: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.6rem;
}

.unit-meta .tag.courier {
  color: var(--olive);
}

.unit-meta .tag.device {
  color: var(--device);
}

.unit-meta .tag.dest {
  color: var(--copper-bright);
}

.unit-meta .tag.phone {
  color: var(--copper);
}

.unit-meta .tag.tracker {
  color: #8eb0ff;
}

.unit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.mini-btn {
  height: 28px;
  padding: 0 9px;
  border-radius: 8px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font: 600 0.68rem/1 var(--font-body);
  cursor: pointer;
}

.mini-btn:hover {
  color: var(--copper-bright);
  border-color: var(--copper);
}

.mini-btn.danger:hover {
  color: var(--danger);
  border-color: rgba(212, 101, 85, 0.5);
}

/* —— map chrome —— */

.map-legend {
  position: absolute;
  z-index: 500;
  right: 12px;
  bottom: 12px;
  left: auto;
  margin: 0;
  padding: 8px 12px;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  max-width: min(420px, calc(100% - 24px));
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(12, 16, 12, 0.78);
  backdrop-filter: blur(12px);
  font-size: 0.7rem;
  color: var(--muted);
  pointer-events: none;
}

.map-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
}

.leg {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.leg.courier {
  background: var(--olive);
}

.leg.phone {
  background: var(--copper);
}

.leg.tracker {
  background: #7aa2ff;
}

.leg.dest {
  background: var(--copper-bright);
}

.leg.device {
  background: var(--device);
}

.leg.geo {
  background: transparent;
  border: 2px solid #7ec8a3;
}

.leg.trail {
  background: #e8c36a;
  border-radius: 2px;
  height: 3px;
  width: 12px;
}

.leg.stale {
  background: var(--danger);
}

.trail-bar {
  position: absolute;
  z-index: 500;
  left: calc(var(--side-w) + 24px);
  right: 12px;
  top: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(12, 16, 12, 0.82);
  backdrop-filter: blur(14px);
  font-size: 0.8rem;
  color: var(--text);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.admin-toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 90;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--stroke-strong);
  background: rgba(18, 23, 18, 0.95);
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  backdrop-filter: blur(12px);
  animation: rise 0.3s var(--ease);
}

.leaflet-container {
  font-family: var(--font-body);
  background: #141914;
}

.leaflet-control-zoom {
  border: none !important;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.4) !important;
}

.leaflet-control-zoom a {
  background: rgba(16, 20, 16, 0.88) !important;
  color: var(--text) !important;
  border-color: var(--stroke) !important;
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
}

@media (max-width: 900px) {
  .admin-body {
    display: grid;
    grid-template-rows: minmax(42vh, 1fr) minmax(280px, 46vh);
  }

  .admin-map-wrap {
    position: relative;
    min-height: 0;
  }

  .admin-side {
    position: relative;
    inset: auto;
    width: 100%;
    top: auto;
    left: auto;
    bottom: auto;
    border-radius: 18px 18px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    animation: none;
  }

  .trail-bar {
    left: 12px;
  }

  .map-legend {
    right: 8px;
    left: 8px;
    max-width: none;
    bottom: 8px;
  }

  .admin-kpi {
    justify-content: flex-start;
    order: 3;
    width: 100%;
  }
}
