:root {
  --bg: #020712;
  --bg-soft: #061428;
  --panel: rgba(8, 22, 42, 0.72);
  --panel-strong: rgba(5, 17, 34, 0.9);
  --line: rgba(127, 232, 255, 0.18);
  --line-strong: rgba(0, 242, 255, 0.5);
  --neon: #00f2ff;
  --neon-soft: rgba(0, 242, 255, 0.22);
  --blue: #2786ff;
  --violet: #6c63ff;
  --text: #eef9ff;
  --muted: #86a3bd;
  --danger: #ff3f6e;
  --warn: #ffd166;
  --ok: #57ffba;
  --radius: 24px;
  --radius-sm: 14px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  --glow: 0 0 18px rgba(0, 242, 255, 0.52), 0 0 48px rgba(39, 134, 255, 0.2);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}

body {
  min-height: 100vh;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

code {
  color: var(--neon);
  font-family: var(--mono);
  font-size: 0.92em;
}

.alpine-backdrop {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(circle at 20% 15%, rgba(0, 116, 255, 0.26), transparent 32%),
    radial-gradient(circle at 80% 10%, rgba(0, 242, 255, 0.16), transparent 28%),
    linear-gradient(145deg, #01040c 0%, #07182e 58%, #020712 100%);
}

.grid-haze {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 242, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 242, 255, 0.05) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.62), transparent 82%);
}

.mountain-layer {
  position: absolute;
  left: 0;
  bottom: -1px;
  width: 100%;
  height: 42vh;
  filter: drop-shadow(0 0 20px rgba(0, 242, 255, 0.22));
}

.mountain-layer path {
  stroke: rgba(0, 242, 255, 0.26);
  stroke-width: 1.6px;
}

.mountain-layer--far {
  opacity: 0.34;
  transform: translateY(-28px);
}

.mountain-layer--far path {
  fill: rgba(4, 26, 54, 0.72);
}

.mountain-layer--near {
  opacity: 0.68;
}

.mountain-layer--near path {
  fill: rgba(2, 11, 25, 0.94);
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px;
  background: rgba(2, 7, 18, 0.74);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(22px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(0, 242, 255, 0.2), rgba(39, 134, 255, 0.07));
  color: var(--neon);
  font-family: var(--mono);
  font-weight: 800;
  box-shadow: var(--glow);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--neon);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 1.35rem;
  letter-spacing: -0.03em;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 4vw, 3rem);
  letter-spacing: -0.055em;
}

.topbar-subtitle {
  margin: 5px 0 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.82rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

h3 {
  margin-bottom: 12px;
  font-size: 1.25rem;
  letter-spacing: -0.03em;
}

.side-nav nav {
  display: grid;
  gap: 10px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
  border-radius: 18px;
  text-align: left;
  transition: 0.2s ease;
}

.nav-item span {
  display: grid;
  place-items: center;
  width: 36px;
  height: 28px;
  color: var(--neon);
  font-family: var(--mono);
  font-size: 0.68rem;
}

.nav-item.active,
.nav-item:hover {
  color: var(--text);
  border-color: var(--line-strong);
  background: rgba(0, 242, 255, 0.08);
  box-shadow: 0 0 18px rgba(0, 242, 255, 0.12);
}

.nav-footer {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: auto;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 14px rgba(255, 63, 110, 0.7);
}

.pulse-dot.online {
  background: var(--ok);
  box-shadow: 0 0 14px rgba(87, 255, 186, 0.7);
}

.workspace {
  min-width: 0;
  overflow-y: auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px;
  width: min(720px, 100%);
  margin-left: auto;
}

.glass-card,
.status-card {
  border: 1px solid var(--line);
  background: linear-gradient(160deg, rgba(8, 22, 42, 0.78), rgba(2, 8, 20, 0.64));
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.status-card {
  min-height: 88px;
  padding: 14px;
  border-radius: 20px;
}

.status-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.status-card strong {
  font-family: var(--mono);
  font-size: 0.9rem;
}

.weather-card small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.signal-stack {
  display: inline-flex;
  align-items: flex-end;
  gap: 4px;
  min-height: 24px;
  margin-right: 10px;
}

.signal-stack span {
  width: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

.signal-stack span:nth-child(1) { height: 8px; }
.signal-stack span:nth-child(2) { height: 12px; }
.signal-stack span:nth-child(3) { height: 16px; }
.signal-stack span:nth-child(4) { height: 20px; }
.signal-stack span:nth-child(5) { height: 24px; }

.signal-stack span.active {
  background: var(--neon);
  box-shadow: 0 0 12px rgba(0, 242, 255, 0.8);
}

.battery-shell {
  position: relative;
  width: 100%;
  height: 13px;
  margin: 4px 0 10px;
  border: 1px solid rgba(0, 242, 255, 0.34);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
}

.battery-shell::after {
  content: "";
  position: absolute;
  top: 3px;
  right: -5px;
  width: 3px;
  height: 5px;
  border-radius: 0 4px 4px 0;
  background: rgba(0, 242, 255, 0.5);
}

.battery-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--neon), var(--ok));
  box-shadow: var(--glow);
  transition: width 0.4s ease;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.map-stage {
  position: relative;
  height: min(62vh, 680px);
  min-height: 440px;
  overflow: hidden;
  border-radius: var(--radius);
}

#map {
  position: absolute;
  inset: 0;
  background: #061428;
}

.leaflet-container {
  background: #061428;
  font-family: var(--font);
}

.leaflet-tile {
  filter: saturate(0.65) hue-rotate(165deg) brightness(0.64) contrast(1.22);
}

.map-tools,
.map-hud {
  position: absolute;
  z-index: 500;
  display: flex;
  gap: 10px;
}

.map-tools {
  top: 16px;
  left: 16px;
  right: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.history-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(2, 7, 18, 0.72);
  backdrop-filter: blur(18px);
}

.history-toggle.inline {
  background: rgba(255, 255, 255, 0.04);
}

.history-toggle button {
  min-height: 30px;
  padding: 0 10px;
  color: var(--muted);
  font-family: var(--mono);
  font-weight: 800;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
}

.history-toggle button.active {
  color: #001016;
  border-color: var(--line-strong);
  background: var(--neon);
  box-shadow: 0 0 15px rgba(0, 242, 255, 0.34);
}

.map-hud {
  right: 16px;
  bottom: 16px;
  left: 16px;
  align-items: stretch;
}

.search-box {
  display: grid;
  gap: 4px;
  min-width: min(360px, 100%);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(2, 7, 18, 0.72);
  backdrop-filter: blur(18px);
}

.search-box span {
  color: var(--neon);
  font-family: var(--mono);
  font-size: 0.64rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.search-box input,
.settings-form input,
.settings-form select,
select {
  width: 100%;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  outline: none;
}

.search-box input {
  padding: 2px 0;
  background: transparent;
  border: 0;
}

.neon-button,
.danger-button,
.interval-grid button {
  min-height: 42px;
  padding: 0 16px;
  color: #001016;
  font-weight: 800;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: linear-gradient(135deg, var(--neon), #5effff);
  box-shadow: 0 0 15px rgba(0, 242, 255, 0.34);
  transition: 0.18s ease;
}

.neon-button:hover,
.danger-button:hover,
.interval-grid button:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 24px rgba(0, 242, 255, 0.5);
}

.neon-button.ghost {
  color: var(--text);
  background: rgba(2, 7, 18, 0.68);
}

.danger-button {
  width: 100%;
  min-height: 54px;
  color: #fff;
  border-color: rgba(255, 63, 110, 0.7);
  background: linear-gradient(135deg, rgba(255, 63, 110, 0.24), rgba(255, 63, 110, 0.72));
  box-shadow: 0 0 22px rgba(255, 63, 110, 0.34);
}

.hud-card {
  flex: 1;
  min-width: 160px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(2, 7, 18, 0.76);
  backdrop-filter: blur(18px);
}

.hud-card span,
.metric-card p {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hud-card strong,
.metric-card strong {
  display: block;
  font-size: 1.18rem;
}

.hud-card small,
.metric-card small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.dashboard-grid,
.control-grid,
.settings-grid,
.split-layout {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.dashboard-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric-card {
  min-height: 150px;
  padding: 18px;
  border-radius: var(--radius);
}

.metric-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  margin-bottom: 14px;
  color: var(--neon);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(0, 242, 255, 0.08);
  box-shadow: 0 0 14px rgba(0, 242, 255, 0.2);
}

.muted-copy {
  color: var(--muted);
  line-height: 1.55;
}

.history-summary,
.sheep-profile {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.history-summary {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.history-summary div,
.sheep-profile div {
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.history-summary span,
.sheep-profile span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.history-summary strong,
.sheep-profile strong {
  display: block;
  overflow-wrap: anywhere;
}

.vital-card strong {
  display: block;
  margin: 18px 0 8px;
  color: var(--neon);
  font-family: var(--mono);
  font-size: clamp(2rem, 6vw, 4rem);
  text-shadow: 0 0 20px rgba(0, 242, 255, 0.36);
}

.split-layout {
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
}

.panel-large,
.control-grid > article,
.settings-grid > article,
.settings-grid > form {
  padding: 22px;
  border-radius: var(--radius);
}

.panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.panel-header select,
#device-select {
  max-width: 220px;
  padding: 10px;
}

.health-chart {
  display: grid;
  grid-template-columns: repeat(7, minmax(34px, 1fr));
  align-items: end;
  gap: 14px;
  height: 300px;
  padding: 16px 4px 0;
}

.bar-wrap {
  display: grid;
  grid-template-rows: 1fr auto auto;
  gap: 10px;
  height: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: center;
}

.bar-track {
  display: flex;
  align-items: end;
  min-height: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  overflow: hidden;
}

.bar-fill {
  width: 100%;
  min-height: 8%;
  border-radius: inherit;
  background: linear-gradient(to top, var(--blue), var(--neon));
  box-shadow: var(--glow);
  transition: height 0.35s ease;
}

.bar-value {
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.72rem;
}

.bar-label {
  color: var(--muted);
  font-size: 0.75rem;
}

.chart-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 18px;
  color: var(--muted);
  font-family: var(--mono);
}

.log-stream {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  padding-right: 6px;
}

.log-row {
  display: grid;
  grid-template-columns: 76px 100px minmax(0, 1fr);
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.75rem;
}

.log-row strong {
  color: var(--neon);
}

.control-grid {
  grid-template-columns: 1fr 1fr 1fr;
}

.danger-panel {
  border-color: rgba(255, 63, 110, 0.35);
}

.toggle-list {
  display: grid;
  gap: 12px;
  margin: 16px 0 20px;
}

.toggle-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.toggle-list input {
  accent-color: var(--neon);
}

.interval-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.interval-grid button.active {
  color: #fff;
  border-color: rgba(255, 63, 110, 0.8);
  background: linear-gradient(135deg, rgba(255, 63, 110, 0.45), rgba(255, 63, 110, 0.95));
  box-shadow: 0 0 20px rgba(255, 63, 110, 0.44);
}

.range-control {
  display: grid;
  gap: 14px;
  margin: 18px 0;
}

.range-control span {
  color: var(--neon);
  font-family: var(--mono);
  font-weight: 800;
}

.range-control input {
  width: 100%;
  accent-color: var(--danger);
}

.settings-grid {
  grid-template-columns: minmax(0, 0.95fr) minmax(360px, 1.05fr);
}

.flow-list {
  display: grid;
  gap: 12px;
  margin: 16px 0 0;
  padding-left: 22px;
  color: var(--muted);
  line-height: 1.55;
}

.settings-form {
  display: grid;
  gap: 12px;
}

.settings-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.settings-form input {
  padding: 12px;
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
}

#settings-status,
#interval-status {
  color: var(--muted);
  font-family: var(--mono);
}

.leaflet-div-icon.neon-marker {
  border: 0;
  background: transparent;
}

.neon-marker-core {
  position: relative;
  width: 24px;
  height: 24px;
  border: 2px solid var(--neon);
  border-radius: 50%;
  background: rgba(0, 242, 255, 0.22);
  box-shadow: var(--glow);
}

.neon-marker-core::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: inherit;
  background: var(--neon);
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-nav {
    position: fixed;
    right: 16px;
    bottom: 16px;
    left: 16px;
    z-index: 1000;
    display: grid;
    grid-template-columns: 1fr;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 24px;
  }

  .brand,
  .nav-footer {
    display: none;
  }

  .side-nav nav {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
  }

  .nav-item {
    justify-content: center;
    padding: 10px 6px;
  }

  .nav-item strong {
    display: none;
  }

  .workspace {
    padding-bottom: 96px;
  }
}

@media (max-width: 960px) {
  .topbar,
  .form-actions {
    flex-direction: column;
  }

  .status-strip,
  .dashboard-grid,
  .split-layout,
  .control-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .map-stage {
    display: grid;
    grid-template-rows: minmax(420px, 62vh) auto auto;
    height: auto;
    min-height: 0;
    overflow: visible;
    background: linear-gradient(160deg, rgba(8, 22, 42, 0.78), rgba(2, 8, 20, 0.64));
  }

  #map {
    position: relative;
    inset: auto;
    height: 62vh;
    min-height: 420px;
    border-radius: var(--radius) var(--radius) 18px 18px;
    overflow: hidden;
  }

  .map-tools,
  .map-hud {
    position: relative;
    inset: auto;
    z-index: 2;
    margin: 12px;
  }

  .map-tools {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
  }

  .map-tools .search-box,
  .map-tools .history-toggle {
    grid-column: 1 / -1;
    min-width: 0;
  }

  .map-tools .neon-button {
    width: 100%;
    min-height: 40px;
    padding: 0 10px;
    font-size: 0.82rem;
  }

  .map-hud {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .history-summary {
    grid-template-columns: 1fr;
  }

  .interval-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .hud-card {
    min-width: 0;
  }
}

@media (max-width: 640px) {
  .workspace {
    padding: 14px;
    padding-bottom: 92px;
  }

  .status-strip {
    grid-template-columns: 1fr;
  }

  .map-stage {
    grid-template-rows: minmax(360px, 56vh) auto auto;
  }

  #map {
    height: 56vh;
    min-height: 360px;
  }

  .map-tools {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 10px;
  }

  .map-tools .neon-button {
    min-height: 38px;
    font-size: 0.74rem;
  }

  .map-hud {
    grid-template-columns: 1fr;
    gap: 8px;
    margin: 10px;
  }

  .hud-card {
    padding: 11px 12px;
  }

  .health-chart {
    gap: 8px;
  }

  .log-row {
    grid-template-columns: 1fr;
  }

  .interval-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
