@font-face {
  font-family: "Husqvarna Gothic";
  src: url("/fonts/husqvarna-gothic-light.woff2") format("woff2");
  font-display: swap;
  font-style: normal;
  font-weight: 300;
}

@font-face {
  font-family: "Husqvarna Gothic";
  src: url("/fonts/husqvarna-gothic-regular.woff2") format("woff2");
  font-display: swap;
  font-style: normal;
  font-weight: 400;
}

@font-face {
  font-family: "Husqvarna Gothic";
  src: url("/fonts/husqvarna-gothic-bold.woff2") format("woff2");
  font-display: swap;
  font-style: normal;
  font-weight: 700;
}

:root {
  --surface: #e4e6e6;
  --panel: #ffffff;
  --ink: #080a0b;
  --ink-soft: #1c2022;
  --muted: #5d6669;
  --line: #d2d7d7;
  --line-strong: #aeb8bb;
  --accent: #104834;
  --accent-strong: #137752;
  --accent-live: #19a974;
  --warning: #b6462e;
  --shadow: 0 18px 44px rgba(8, 10, 11, 0.15);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: "Husqvarna Gothic", Arial, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 400;
  -webkit-text-size-adjust: 100%;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  height: 100svh;
  min-height: 100svh;
  overflow: hidden;
}

.sidebar {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 32px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 5;
}

.sidebar::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--accent);
  content: "";
}

.brand-block {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 8px;
}

.eyebrow,
.label {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 7vw, 3.25rem);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: 0;
}

.menu-toggle {
  display: none;
  width: auto;
  min-width: 72px;
  min-height: 40px;
  padding: 0 13px;
  border-color: var(--line-strong);
  background: var(--panel);
  color: var(--ink);
}

.menu-toggle:hover {
  border-color: var(--accent);
  background: var(--surface);
  transform: none;
}

.status-strip,
.metrics {
  display: grid;
  gap: 14px;
}

.status-strip {
  grid-template-columns: 1fr 88px;
  align-items: stretch;
}

.status-strip > div,
.metrics > div {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.status-strip strong,
.metrics strong {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 1.05rem;
  font-weight: 700;
}

.metrics {
  grid-template-columns: 1fr 1fr;
}

.metrics > div:last-child {
  grid-column: 1 / -1;
}

.controls {
  display: grid;
  gap: 12px;
  margin-top: auto;
}

select,
input,
button {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}

select,
input {
  border-color: var(--line-strong);
  padding: 0 12px;
}

input[hidden],
label[hidden] {
  display: none;
}

button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}

button:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.refresh-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-color: var(--line-strong);
  background: var(--panel);
  color: var(--accent);
}

.refresh-button:hover {
  border-color: var(--accent);
  background: var(--surface);
  color: var(--accent);
  transform: none;
}

.refresh-button-icon {
  font-size: 1.18rem;
  line-height: 1;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  color: var(--ink);
  cursor: pointer;
}

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

.auto-enabled-toggle {
  display: none;
}

.map-style-switch,
.display-mode-switch,
.route-render-switch {
  display: grid;
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
}

.map-style-switch {
  grid-template-columns: 1fr 1fr;
}

.route-render-switch {
  grid-template-columns: 1fr 1fr;
}

.display-mode-switch {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.route-render-debug {
  display: grid;
  gap: 12px;
}

.route-render-debug[hidden] {
  display: none;
}

.fence-editor {
  display: grid;
  gap: 10px;
}

.fence-editor[hidden] {
  display: none;
}

.fence-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.fence-button {
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--panel);
  color: var(--ink);
  font-size: 0.86rem;
  transform: none;
}

.fence-button:hover {
  background: var(--surface);
  transform: none;
}

.fence-button.active,
.fence-button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.fence-button.danger {
  color: var(--warning);
}

.fence-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.fence-status {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
}

.fence-drawing {
  cursor: crosshair;
}

.style-option,
.display-option,
.route-render-option {
  min-height: 44px;
  border: 0;
  border-radius: 0;
  background: var(--panel);
  color: var(--ink);
  transform: none;
}

.style-option + .style-option,
.display-option + .display-option,
.route-render-option + .route-render-option {
  border-left: 1px solid var(--line-strong);
}

.style-option:hover,
.display-option:hover,
.route-render-option:hover {
  border-color: transparent;
  background: var(--surface);
  transform: none;
}

.style-option.active,
.style-option.active:hover,
.display-option.active,
.display-option.active:hover,
.route-render-option.active,
.route-render-option.active:hover {
  background: var(--accent);
  color: #ffffff;
}

.legend-label {
  margin-bottom: -4px;
}

.weekday-legend,
.activity-legend {
  display: grid;
  gap: 6px;
  align-items: center;
}

.weekday-legend {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.activity-legend {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.weekday-item,
.activity-item {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.1;
}

.weekday-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--day-color);
  box-shadow: 0 0 0 1px rgba(8, 10, 11, 0.16);
}

.activity-line {
  display: inline-block;
  width: 16px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--activity-color);
  box-shadow: 0 0 0 1px rgba(8, 10, 11, 0.14);
}

.latest {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.latest p {
  margin: 0 0 14px;
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.map-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: #dfe4e4;
}

.heatmap-canvas {
  pointer-events: none;
  opacity: 0.9;
}

.playback-marker {
  background: transparent;
  border: 0;
}

.playback-marker span {
  position: relative;
  display: block;
  width: 24px;
  height: 24px;
  border: 3px solid #ffffff;
  border-radius: 999px;
  background: var(--marker-color, var(--accent-live));
  box-shadow: 0 0 0 2px rgba(8, 10, 11, 0.78), 0 10px 22px rgba(8, 10, 11, 0.32);
}

.playback-marker span::after {
  position: absolute;
  inset: -7px;
  border: 1px solid rgba(25, 169, 116, 0.65);
  border-radius: inherit;
  content: "";
  animation: playback-pulse 1.6s ease-out infinite;
}

@keyframes playback-pulse {
  0% {
    opacity: 0.75;
    transform: scale(0.72);
  }

  100% {
    opacity: 0;
    transform: scale(1.45);
  }
}

.playback-panel {
  position: absolute;
  right: 96px;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 24px;
  z-index: 700;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 15px;
  border: 1px solid rgba(8, 10, 11, 0.16);
  border-left: 5px solid var(--accent-live);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.playback-button {
  width: auto;
  min-width: 76px;
  min-height: 42px;
  padding: 0 14px;
  flex: 0 0 auto;
}

.playback-main {
  display: grid;
  min-width: 0;
  flex: 1 1 auto;
  gap: 7px;
}

.playback-slider {
  width: 100%;
  min-height: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--accent-live);
}

.playback-slider:disabled {
  opacity: 0.55;
}

.playback-meta {
  display: flex;
  min-width: 0;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink-soft);
  font-size: 0.78rem;
  line-height: 1.2;
}

.playback-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaflet-control-zoom a {
  color: var(--ink);
}

.leaflet-bottom.leaflet-right {
  margin-bottom: 94px;
}

.leaflet-touch .leaflet-control-zoom a {
  width: 44px;
  height: 44px;
  line-height: 44px;
}

.empty-state {
  position: absolute;
  left: 50%;
  top: 50%;
  display: none;
  width: min(420px, calc(100% - 40px));
  transform: translate(-50%, -50%);
  padding: 20px 22px;
  border: 1px solid rgba(8, 10, 11, 0.14);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  text-align: center;
}

.empty-state strong,
.empty-state span {
  display: block;
}

.empty-state span {
  margin-top: 6px;
  color: var(--muted);
}

.empty .empty-state {
  display: block;
}

.login-page {
  min-height: 100%;
  background: var(--ink);
  overflow: auto;
}

.login-shell {
  display: grid;
  min-height: 100svh;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}

.login-panel {
  width: min(420px, 100%);
  padding: 32px;
  border-left: 5px solid var(--accent-live);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin-bottom: 28px;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-message {
  min-height: 1.35em;
  margin: 0;
  color: var(--warning);
  font-size: 0.92rem;
  line-height: 1.35;
}

@media (min-width: 781px) and (max-width: 1180px) and (orientation: landscape) {
  .app-shell {
    grid-template-columns: minmax(292px, 340px) minmax(0, 1fr);
  }

  .sidebar {
    gap: 18px;
    padding: 24px 22px;
  }

  h1 {
    font-size: 2.35rem;
  }

  .status-strip,
  .metrics {
    gap: 10px;
  }

  .status-strip > div,
  .metrics > div {
    padding-top: 11px;
  }

  .controls {
    gap: 10px;
  }

  .latest {
    padding-top: 12px;
  }
}

@media (max-width: 780px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .sidebar {
    gap: 14px;
    padding: max(18px, env(safe-area-inset-top)) 16px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow: visible;
  }

  .sidebar::before {
    inset: 0 0 auto;
    width: auto;
    height: 5px;
  }

  .brand-block {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding-bottom: 0;
  }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  h1 {
    max-width: none;
    font-size: 1.65rem;
    line-height: 1;
    text-align: right;
  }

  .status-strip,
  .metrics {
    gap: 8px;
  }

  .status-strip {
    grid-template-columns: minmax(0, 1fr) 78px;
  }

  .metrics {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .metrics > div:last-child {
    grid-column: auto;
  }

  .status-strip > div,
  .metrics > div {
    padding-top: 10px;
  }

  .status-strip strong,
  .metrics strong {
    font-size: 0.98rem;
  }

  .controls {
    grid-template-columns: 1fr 1fr;
    gap: 8px 10px;
    margin-top: 0;
  }

  .controls > label[for="rangeSelect"],
  #rangeSelect,
  .date-control,
  .map-style-switch,
  .display-mode-switch,
  .legend-label,
  .weekday-legend,
  .activity-legend {
    grid-column: 1 / -1;
  }

  .toggle {
    min-height: 44px;
  }

  #refreshButton {
    grid-column: 1 / -1;
  }

  .latest {
    display: none;
  }

  .map-stage {
    min-height: 0;
  }

  .playback-panel {
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 12px;
    gap: 10px;
    padding: 10px 11px;
  }

  .playback-button {
    min-width: 66px;
    min-height: 40px;
    padding: 0 10px;
  }

  .playback-meta {
    font-size: 0.72rem;
  }

  .leaflet-bottom.leaflet-right {
    margin-bottom: 104px;
  }

  .menu-collapsed .sidebar {
    gap: 0;
    padding-bottom: 12px;
  }

  .menu-collapsed .status-strip,
  .menu-collapsed .metrics,
  .menu-collapsed .controls,
  .menu-collapsed .latest {
    display: none;
  }
}

@media (max-width: 480px) and (orientation: portrait) {
  .sidebar {
    gap: 10px;
    padding-right: 12px;
    padding-left: 12px;
  }

  h1 {
    font-size: 1.28rem;
  }

  .label {
    font-size: 0.66rem;
  }

  .status-strip strong,
  .metrics strong {
    font-size: 0.9rem;
  }

  .controls > label[for="rangeSelect"] {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  select,
  input,
  button {
    min-height: 46px;
  }

  .toggle {
    min-height: 38px;
    font-size: 0.9rem;
  }

  .display-option,
  .route-render-option {
    min-height: 42px;
    font-size: 0.86rem;
  }

  .activity-legend {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .empty-state {
    top: 46%;
    width: min(360px, calc(100% - 28px));
  }
}

@media (max-width: 420px) and (max-height: 760px) and (orientation: portrait) {
  .metrics {
    display: none;
  }

  .sidebar {
    gap: 9px;
  }
}

@media (max-width: 780px) and (orientation: landscape) {
  html,
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100svh;
    height: auto;
  }

  .map-stage {
    min-height: 460px;
  }
}

@media (max-width: 480px) {
  .login-panel {
    padding: 26px 22px;
    border-left: 0;
    border-top: 5px solid var(--accent-live);
  }

  .login-panel h1 {
    font-size: 2rem;
  }
}
