/* Bæ — dark theme, derived from vann.eidsten.tech, trimmed to sheep tracking. */
:root {
  --bg: #0b1220;
  --panel: #101a2e;
  --panel2: #17233b;
  --text: #e9f0ff;
  --muted: #8ea0bf;
  --accent: #38bdf8;
  --green: #22c55e;
  --yellow: #facc15;
  --red: #ef4444;
  --line: rgba(255,255,255,0.12);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }

#app { display: grid; grid-template-columns: 420px 1fr; height: 100vh; overflow: hidden; }
#sidebar { background: linear-gradient(180deg, #101a2e, #0b1220); border-right: 1px solid var(--line); padding: 18px; overflow-y: auto; }

.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.logo { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 16px; background: rgba(56,189,248,0.16); font-size: 28px; box-shadow: 0 12px 30px rgba(0,0,0,0.25); }
h1 { margin: 0; font-size: 23px; letter-spacing: -0.04em; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
h2 { font-size: 17px; margin: 18px 0 12px; }
h3 { font-size: 14px; color: var(--muted); margin: 18px 0 8px; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,0.04); }
.tab, button, select, input { font: inherit; }
button { border: 1px solid var(--line); color: var(--text); background: rgba(255,255,255,0.06); padding: 10px 12px; border-radius: 12px; cursor: pointer; transition: 0.15s ease; }
button:hover { background: rgba(255,255,255,0.11); transform: translateY(-1px); }
button.primary { background: linear-gradient(135deg, #0284c7, #22c55e); border: 0; font-weight: 700; }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.tab { flex: 1 1 auto; padding: 8px 12px; font-size: 12.5px; font-weight: 600; white-space: nowrap; text-align: center; border-radius: 10px; }
.tab.active, .mode.active { background: rgba(56,189,248,0.20); border-color: rgba(56,189,248,0.55); }

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

label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 6px; }
input, select { width: 100%; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,0.06); color: var(--text); outline: none; }
select option { background: #0b1220; }
.buttons { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; }

.hint { margin: 14px 0; padding: 12px; border: 1px solid rgba(56,189,248,0.22); background: rgba(56,189,248,0.08); border-radius: 14px; color: #cdeeff; font-size: 13px; line-height: 1.4; }
.hint code { display: block; white-space: pre-wrap; word-break: break-word; margin-top: 6px; line-height: 1.35; }
code { color: #bae6fd; }

.list { display: grid; gap: 8px; }
.item { padding: 10px 12px; border-radius: 14px; background: rgba(255,255,255,0.055); border: 1px solid var(--line); cursor: pointer; }
.item:hover { background: rgba(255,255,255,0.09); }
.item.active { border-color: rgba(56,189,248,0.55); background: rgba(56,189,248,0.12); }
.item b { display: block; font-size: 14px; }
.item span { color: var(--muted); font-size: 12px; }
.item .row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.item .tag { color: var(--muted); font-size: 11px; font-family: ui-monospace, Menlo, monospace; }

/* firmware download link — styled like a small button */
.fw-dl { display: inline-block; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: rgba(255,255,255,0.06); text-decoration: none; font-size: 12px; }
.fw-dl:hover { background: rgba(255,255,255,0.11); }

.batt-val.low { color: var(--red); }
.batt-val.mid { color: var(--yellow); }
.batt-val.ok  { color: #5eead4; }

main { min-width: 0; position: relative; }
#map { height: 100vh; width: 100%; background: #0e1726; }

.status-card { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: 16px; background: rgba(255,255,255,0.06); border: 1px solid var(--line); }
.status-dot { width: 14px; height: 14px; border-radius: 50%; background: #64748b; box-shadow: 0 0 0 5px rgba(100,116,139,0.15); flex: none; }
.status-dot.live { background: var(--green); box-shadow: 0 0 0 5px rgba(34,197,94,0.18); }
.status-dot.warn { background: var(--yellow); box-shadow: 0 0 0 5px rgba(250,204,21,0.18); }
.status-dot.crit { background: var(--red); box-shadow: 0 0 0 5px rgba(239,68,68,0.18); }
.status-card b { display: block; }
.status-card span { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }

.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.metric-grid div { padding: 12px; border: 1px solid var(--line); background: rgba(255,255,255,0.055); border-radius: 16px; }
.metric-grid span { display: block; color: var(--muted); font-size: 12px; }
.metric-grid b { font-size: 20px; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: 12px; }
.rules { color: #dbeafe; line-height: 1.55; padding-left: 18px; }

/* IoT / raw table */
.iot-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.iot-table th, .iot-table td { border-bottom: 1px solid rgba(255,255,255,.12); padding: 6px 8px; vertical-align: top; }
.iot-table th { text-align: left; color: #bae6fd; position: sticky; top: 0; background: rgba(15,23,42,.95); }
.table-wrap { overflow: auto; max-height: 460px; border: 1px solid rgba(255,255,255,.12); border-radius: 12px; }
.iot-card { border-left: 5px solid #38bdf8; }
.iot-card.stale { border-left-color: #64748b; }

/* Lam — BLE ear-tag overview (web view-only). Reuses .iot-table; a wandered lamb
   (latest sighting by a sheep other than its ewe) gets a clear red row tint, and
   the "Sett av" cell stacks one line per sighting. */
.lamb-table td { vertical-align: top; }
.lamb-table td b { font-size: 12px; color: var(--text); }
/* Whole row opens the lamb's location detail (map). Cursor + hover affordance so it
   reads as clickable; the hover tint sits over any wandered/alert row tint. */
.lamb-table tr.lamb-clickable { cursor: pointer; }
.lamb-table tr.lamb-clickable:hover td { background: rgba(56,189,248,0.12); }
.lamb-table tr.lamb-clickable.wandered:hover td,
.lamb-table tr.lamb-clickable.lamb-alert:hover td { background: rgba(239,120,120,0.24); }
.lamb-table tr.wandered td { background: rgba(239,68,68,0.12); }
.lamb-table .lamb-sight { line-height: 1.5; }
.lamb-table .lamb-sight:not(:last-child) { margin-bottom: 2px; padding-bottom: 2px; border-bottom: 1px solid rgba(255,255,255,.07); }
/* Owner-alert row (assigned ewe hasn't seen the lamb for >12h). Stronger tint + red
   left bar than the plain .wandered row, so a real alert stands out; carries a Godkjenn
   (ack) button. */
.lamb-table tr.lamb-alert td { background: rgba(239,68,68,0.20); }
.lamb-table tr.lamb-alert td:first-child { box-shadow: inset 4px 0 0 var(--red); }
.lamb-alert-box { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.lamb-alert-badge { white-space: normal; line-height: 1.35; }
.lamb-ack { padding: 6px 12px; font-size: 12px; font-weight: 700; border-radius: 10px; border: 0; color: #fff; background: linear-gradient(135deg, #0284c7, #22c55e); }
/* Per-sheep lamb list on the Flokk card */
.lamb-list { border-top: 1px dashed rgba(255,255,255,.12); padding-top: 5px; }

/* health cards + badges */
.hcard { border-left: 5px solid #64748b; }
.hcard.critical { border-left-color: var(--red); }
.hcard.attention { border-left-color: var(--yellow); }
.hcard.ok { border-left-color: var(--green); }
.hbadge { font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.hbadge.critical { background: rgba(239,68,68,0.18); color: #fecaca; border: 1px solid rgba(239,68,68,0.5); }
.hbadge.attention { background: rgba(250,204,21,0.16); color: #fde68a; border: 1px solid rgba(250,204,21,0.45); }
.hbadge.ok { background: rgba(34,197,94,0.18); color: #bbf7d0; border: 1px solid rgba(34,197,94,0.5); }

/* sheep map pins */
.pin { background: var(--green); color: #04210f; border-radius: 50% 50% 50% 0; width: 30px; height: 30px; transform: rotate(-45deg); border: 3px solid var(--green); box-shadow: 0 3px 8px rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; }
.pin.h-att { background: var(--yellow); }   /* helse: følg med */
.pin.h-crit { background: var(--red); }      /* helse: kritisk */
.pin.stale { opacity: .55; }                 /* ingen fersk fiks */
.pin.alarm { background: var(--red); border-color: #fff; animation: pin-pulse 1.1s infinite; }
.pin span { transform: rotate(45deg); font-size: 15px; }
/* Shared farmer's sheep: a star instead of a teardrop — fill = health, ring stays green. */
.pin-star { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; filter: drop-shadow(0 2px 4px rgba(0,0,0,.55)); }
.pin-star svg polygon { fill: var(--green); stroke: var(--green); stroke-width: 2.2; stroke-linejoin: round; }
.pin-star.h-att svg polygon { fill: var(--yellow); }
.pin-star.h-crit svg polygon { fill: var(--red); }
.pin-star.stale { opacity: .55; }
/* Permanent øremerke (ear-tag) label above each sheep marker */
.leaflet-tooltip.sheep-label { background: rgba(11,18,32,.86); color: #eaf1ff; border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: 11px; font-weight: 600; white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,.45); }
.leaflet-tooltip.sheep-label::before { display: none; }   /* hide the tooltip arrow */
@keyframes pin-pulse { 0%{box-shadow:0 0 0 0 rgba(239,68,68,.6)} 70%{box-shadow:0 0 0 12px rgba(239,68,68,0)} 100%{box-shadow:0 0 0 0 rgba(239,68,68,0)} }

/* on-map geofence menu */
.zone-control {
  font-family: Inter, sans-serif;
  background: rgba(16,26,46,0.95);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 11px 12px;
  width: 216px;
  color: var(--text);
  box-shadow: 0 12px 34px rgba(0,0,0,0.45);
  backdrop-filter: blur(8px);
}
.zc-title { font-weight: 800; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.zc-status { color: var(--muted); font-size: 12px; margin: 5px 0 9px; line-height: 1.35; }
.zc-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.zc-row { margin: 0 0 9px; }
.zc-lbl { display: block; color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.zone-control select { padding: 7px 9px; font-size: 12px; border-radius: 10px; }
.zone-control button { padding: 8px 8px; font-size: 12px; border-radius: 10px; }
.zone-control button.wide { grid-column: 1 / -1; }

/* dark Leaflet popups */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: #111827; color: #fff; }
.leaflet-popup-content { font-family: Inter, sans-serif; }
.leaflet-popup-content b { color: #fff; }
.leaflet-popup-content small { color: #9fb4d4; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: #5eead4; display: inline-block; margin-right: 6px; animation: p 2s infinite; }
@keyframes p { 0%{opacity:.4} 50%{opacity:1} 100%{opacity:.4} }

@media (max-width: 900px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 46vh 54vh; }
  #sidebar { order: 2; }
  main { order: 1; }
}

/* --- Virtuelt gjerde (stimulus) ------------------------------------------
   Red, to stay visually distinct from the blue grazing area. They are
   different things: the grazing area alarms on the server, the fence lives on
   the collar and is what the stimulus module acts on. */
#fenceRows td.ok     { color: #4ade80; }
#fenceRows td.warn   { color: #fbbf24; font-weight: 600; }
#fenceRows td.muted  { color: #64748b; }
#fenceRows .muted    { color: #64748b; }

/* --- Tidslinje (timeline playback) --------------------------------------- */
.tl-time {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: #eaf1ff;
  margin: 14px 0 8px;
  line-height: 1.2;
}

.tl-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  padding: 0;
  margin: 4px 0 2px;
  cursor: pointer;
}
.tl-slider:focus { outline: none; }
/* track */
.tl-slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
}
.tl-slider::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,0.14);
}
/* thumb */
.tl-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0b1220;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
  margin-top: -6px; /* center 18px thumb on 6px track */
}
.tl-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #0b1220;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
}
.tl-slider:focus::-webkit-slider-thumb {
  box-shadow: 0 0 0 5px rgba(56,189,248,0.28);
}
.tl-slider:focus::-moz-range-thumb {
  box-shadow: 0 0 0 5px rgba(56,189,248,0.28);
}

.tl-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}

.tl-info {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
