:root {
  color-scheme: dark;
  --bg: #06110e;
  --panel: #0d1d18;
  --panel-2: #122720;
  --line: rgba(222, 244, 232, .12);
  --text: #f1f7f3;
  --muted: #9eb4a9;
  --lime: #b9f56e;
  --green: #56dc8c;
  --amber: #ffca68;
  --red: #ff7f78;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 16px; line-height: 1.45; }
button, input { font: inherit; }
button { cursor: pointer; }

/* Lokal Leaflet-bas. Den externa CDN-stilen kan blockeras av SRI/CSP eller
   innehållsblockerare; kartan måste ändå kunna placera plattor och kontroller. */
.leaflet-container { overflow: hidden; outline: 0; -webkit-tap-highlight-color: transparent; }
.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer { position: absolute; left: 0; top: 0; }
.leaflet-tile { visibility: hidden; user-select: none; -webkit-user-drag: none; }
.leaflet-tile-loaded { visibility: inherit; }
.leaflet-container img.leaflet-image-layer,
.leaflet-container .leaflet-tile { max-width: none !important; max-height: none !important; }
.leaflet-pane { z-index: 400; }
.leaflet-tile-pane { z-index: 200; }
.leaflet-overlay-pane { z-index: 400; }
.leaflet-shadow-pane { z-index: 500; }
.leaflet-marker-pane { z-index: 600; }
.leaflet-tooltip-pane { z-index: 650; }
.leaflet-popup-pane { z-index: 700; }
.leaflet-map-pane canvas { z-index: 100; }
.leaflet-map-pane svg { z-index: 200; }
.leaflet-control { position: relative; z-index: 800; pointer-events: auto; }
.leaflet-top, .leaflet-bottom { position: absolute; z-index: 1000; pointer-events: none; }
.leaflet-top { top: 0; }
.leaflet-right { right: 0; }
.leaflet-bottom { bottom: 0; }
.leaflet-left { left: 0; }
.leaflet-control { margin: 10px; }
.leaflet-bar { border-radius: 4px; box-shadow: 0 1px 5px rgba(0,0,0,.35); }
.leaflet-bar a { display: block; width: 30px; height: 30px; border-bottom: 1px solid #ccc; background: #fff; color: #222; text-align: center; text-decoration: none; font: 700 18px/30px Arial,sans-serif; }
.leaflet-bar a:first-child { border-radius: 4px 4px 0 0; }
.leaflet-bar a:last-child { border-bottom: 0; border-radius: 0 0 4px 4px; }
.leaflet-control-attribution { margin: 0 !important; padding: 0 5px; background: rgba(255,255,255,.8); color: #333; font-size: 11px; }
.leaflet-control-attribution a { color: #075b94; }
.leaflet-interactive { cursor: pointer; }

.app-page { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
#app { width: min(100%, 980px); margin: 0 auto; padding: 0 16px 28px; }
.topbar { min-height: 84px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.topbar h1, .login-card h1 { margin: 1px 0 0; font-size: clamp(1.55rem, 4vw, 2rem); letter-spacing: -.04em; }
.eyebrow { margin: 0; color: var(--lime); font-size: .72rem; font-weight: 800; letter-spacing: .15em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-actions form { margin: 0; }
.demo-badge { padding: 6px 9px; border: 1px solid rgba(185,245,110,.35); border-radius: 999px; color: var(--lime); font-size: .68rem; font-weight: 800; letter-spacing: .08em; }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; background: var(--panel); color: var(--muted); }

.status-strip { display: flex; align-items: center; gap: 12px; margin: 4px 0 12px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
.status-strip div { display: flex; flex-direction: column; min-width: 0; }
.status-strip strong { font-size: .9rem; letter-spacing: .04em; }
.status-strip span:last-child { color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; box-shadow: 0 0 0 5px rgba(158,180,169,.1); }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 5px rgba(86,220,140,.12); }
.status-dot.stale { background: var(--amber); box-shadow: 0 0 0 5px rgba(255,202,104,.12); }
.status-dot.offline { background: var(--red); box-shadow: 0 0 0 5px rgba(255,127,120,.12); }
.status-dot.loading { animation: pulse 1.3s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.map-card { position: relative; overflow: hidden; height: min(52vh, 510px); min-height: 340px; border: 1px solid var(--line); border-radius: 24px; background: #d7e1db; box-shadow: 0 18px 50px rgba(0,0,0,.25); }
#map { height: 100%; width: 100%; z-index: 1; }
.leaflet-control-attribution { font-size: 10px !important; }
.leaflet-bar a { color: #13231d; }
.map-action { position: absolute; z-index: 500; top: 12px; right: 12px; padding: 9px 12px; border: 0; border-radius: 999px; background: rgba(7,20,16,.9); color: var(--text); font-weight: 700; box-shadow: 0 4px 18px rgba(0,0,0,.22); }
.distance-card { position: absolute; z-index: 500; left: 12px; bottom: 28px; padding: 10px 14px; border-radius: 14px; background: rgba(7,20,16,.9); box-shadow: 0 4px 18px rgba(0,0,0,.22); }
.distance-card span { display: block; color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; }
.distance-card strong { font-size: 1.15rem; }
.dog-marker { display: grid; place-items: center; width: 48px !important; height: 48px !important; margin-left: -24px !important; margin-top: -24px !important; border: 3px solid white; border-radius: 50%; background: #172b23; color: var(--lime); font-size: 22px; box-shadow: 0 5px 18px rgba(0,0,0,.35); }

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 12px; }
.metrics article { min-width: 0; min-height: 106px; padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); }
.metrics span { display: block; color: var(--muted); font-size: .76rem; }
.metrics strong { display: block; margin-top: 9px; font-size: clamp(1.1rem, 3vw, 1.55rem); letter-spacing: -.03em; }
.metrics small { display: block; margin-top: 2px; color: var(--muted); font-size: .7rem; }
.meter { height: 3px; margin-top: 12px; border-radius: 9px; background: rgba(255,255,255,.1); overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; background: var(--lime); transition: width .4s ease; }

.mode-card { margin-top: 12px; padding: 18px; border: 1px solid var(--line); border-radius: 20px; background: var(--panel); }
.mode-card h2 { margin: 2px 0 14px; font-size: 1.2rem; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 5px; border-radius: 15px; background: #071511; }
.segmented button { padding: 12px; border: 1px solid transparent; border-radius: 11px; background: transparent; color: var(--muted); }
.segmented button strong, .segmented button span { display: block; }
.segmented button span { margin-top: 2px; font-size: .7rem; }
.segmented button.active { border-color: rgba(185,245,110,.22); background: var(--panel-2); color: var(--text); box-shadow: 0 2px 12px rgba(0,0,0,.2); }
.segmented button.active strong { color: var(--lime); }
.segmented button:disabled { opacity: .55; cursor: wait; }
.mode-feedback { min-height: 20px; margin: 9px 2px -3px; color: var(--muted); font-size: .78rem; }
.last-position { margin: 14px 3px 0; color: var(--muted); font-size: .78rem; }
.routes-card { margin-top: 12px; padding: 18px; border: 1px solid var(--line); border-radius: 20px; background: var(--panel); }
.routes-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.routes-heading h2 { margin: 2px 0 0; font-size: 1.2rem; }
.routes-heading button { padding: 9px 12px; border: 1px solid rgba(185,245,110,.3); border-radius: 10px; background: var(--panel-2); color: var(--lime); font-weight: 700; }
.route-detail { min-height: 20px; margin: 9px 0 13px; color: var(--muted); font-size: .8rem; }
.routes-list { display: grid; gap: 8px; }
.routes-list > p { margin: 0; color: var(--muted); font-size: .85rem; }
.route-row { width: 100%; padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 12px; background: #071511; color: var(--text); text-align: left; }
.route-row span { min-width: 0; }
.route-row strong, .route-row small { display: block; }
.route-row small { margin-top: 2px; color: var(--muted); font-size: .72rem; }
.route-row em { flex: none; color: var(--lime); font-style: normal; font-weight: 750; }
.route-row.active { border-color: var(--lime); background: var(--panel-2); }

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; background: radial-gradient(circle at 50% 20%, #17382b 0, var(--bg) 55%); }
.login-card { width: min(100%, 410px); padding: 30px; border: 1px solid var(--line); border-radius: 26px; background: rgba(13,29,24,.92); box-shadow: 0 30px 90px rgba(0,0,0,.35); }
.brand-mark { display: grid; place-items: center; width: 50px; height: 50px; margin-bottom: 24px; border-radius: 15px; background: var(--lime); color: #102015; font-size: 1.45rem; font-weight: 900; }
.login-copy { margin: 7px 0 25px; color: var(--muted); }
.login-card label { display: block; margin-bottom: 7px; color: var(--muted); font-size: .82rem; }
.login-card input { width: 100%; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; outline: none; background: #071511; color: var(--text); }
.login-card input:focus { border-color: var(--lime); box-shadow: 0 0 0 3px rgba(185,245,110,.12); }
.primary-button { width: 100%; margin-top: 12px; padding: 13px; border: 0; border-radius: 12px; background: var(--lime); color: #102015; font-weight: 850; }
.login-error { padding: 10px 12px; border-radius: 10px; background: rgba(255,127,120,.12); color: #ffaaa5; font-size: .85rem; }

@media (max-width: 640px) {
  .metrics { grid-template-columns: 1fr 1fr; }
  .metrics article { min-height: 98px; }
  .map-card { height: 46vh; min-height: 310px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
