:root {
  --bg: #0f1115;
  --panel: rgba(23, 26, 33, 0.96);
  --card: #1e222b;
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --line: #2a2f3a;
  --ok: #3ccf6a;
  --warn: #ffb020;
  --bad: #ff4d4f;
  --accent: #4da3ff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
#map { position: fixed; inset: 0; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }

/* ---- status card over the map ---- */
.status-card {
  position: fixed; top: calc(10px + var(--safe-top)); left: 60px; right: 60px; z-index: 900;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  backdrop-filter: blur(6px); max-width: 420px; margin: 0 auto;
}
.status-line { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.status-line #statusText { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: #555; flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.warning { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.dot.outside { background: var(--bad); box-shadow: 0 0 8px var(--bad); }
.dot.stale { background: #777; }
.grid { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 4px 10px; margin-top: 6px; }
.grid label { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.grid b { font-size: 14px; white-space: nowrap; }
.pill { font-size: 10px; padding: 2px 7px; border-radius: 999px; background: #333; color: var(--muted); flex: none; }
.pill.on { background: #123d25; color: var(--ok); }
.pill.off { background: #3d1212; color: var(--bad); }

/* ---- alert banner ---- */
.banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 2000;
  padding: calc(14px + var(--safe-top)) 16px 14px; font-size: 20px; font-weight: 800; text-align: center; color: #111;
}
.banner.warning { background: var(--warn); }
.banner.outside { background: var(--bad); color: #fff; }
.banner.critical { background: #b1000b; color: #fff; animation: flash .6s infinite alternate; font-size: 22px; }
@keyframes flash { from { background: #b1000b; } to { background: #ff2a33; } }
.dot.critical { background: #ff2a33; box-shadow: 0 0 14px #ff2a33; animation: flash-dot .5s infinite alternate; }
@keyframes flash-dot { from { opacity: 1; } to { opacity: .3; } }
.banner.stale { background: #666; color: #fff; }
.banner ~ .status-card { top: calc(70px + var(--safe-top)); }
.banner.hidden ~ .status-card { top: calc(10px + var(--safe-top)); }
.hidden { display: none !important; }

/* ---- floating buttons ---- */
.fabs { position: fixed; right: 12px; bottom: calc(24px + var(--safe-bottom)); z-index: 950; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.fab {
  width: 52px; height: 52px; border-radius: 50%; border: 1px solid #3a4356; background: var(--panel); color: var(--text);
  font-size: 22px; cursor: pointer; box-shadow: 0 4px 14px rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center;
}
.fab.wide { width: auto; border-radius: 26px; padding: 0 16px; font-size: 15px; font-weight: 600; }
.fab.toggle.on { background: #1f3b5c; border-color: var(--accent); }
.fab:active { transform: scale(.95); }

/* ---- drawer ---- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: 100%; max-width: 400px; z-index: 1500;
  background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: calc(12px + var(--safe-top)) 12px calc(12px + var(--safe-bottom));
  box-shadow: -6px 0 24px rgba(0,0,0,.5);
}
.drawer header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.icon-btn { background: transparent; border: 1px solid #3a4356; color: var(--text); border-radius: 8px; width: 40px; height: 40px; font-size: 18px; cursor: pointer; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.row label { color: var(--muted); }
button {
  background: #2a3140; color: var(--text); border: 1px solid #3a4356; border-radius: 8px;
  padding: 9px 12px; cursor: pointer; font: inherit; min-height: 40px;
}
button:hover { background: #343c4e; }
button:disabled { opacity: .5; cursor: default; }
button.toggle.on { background: #1f3b5c; border-color: var(--accent); }
input[type=number], input[type=text], select {
  background: #11141a; color: var(--text); border: 1px solid #3a4356; border-radius: 8px; padding: 8px 10px; font: inherit; min-height: 40px;
}
input[type=number] { width: 80px; }
input[type=text] { width: 100%; }
input[type=checkbox] { width: 20px; height: 20px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 8px; }
code { background: #11141a; padding: 1px 4px; border-radius: 4px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: none; }
.list.small li { font-size: 13px; padding: 4px 0; }
.list .meta { color: var(--muted); font-size: 12px; }
.list input[type=text] { width: auto; flex: 1; min-width: 0; }
details { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
summary { cursor: pointer; color: var(--accent); padding: 4px 0; }
.log { background: #0b0d11; color: #b8c0cc; font: 11px/1.4 ui-monospace, Consolas, monospace; padding: 8px; border-radius: 6px; max-height: 200px; overflow: auto; white-space: pre-wrap; word-break: break-all; margin: 6px 0; }

/* ---- markers ---- */
.dog-marker { display: flex; flex-direction: column; align-items: center; width: 90px; margin-left: -30px; }
.dog-icon { font-size: 28px; line-height: 1; filter: drop-shadow(0 2px 3px rgba(0,0,0,.7)); }
.dog-icon.warning { animation: pulse .8s infinite alternate; }
.dog-icon.outside { animation: pulse .4s infinite alternate; }
.dog-label {
  margin-top: 2px; background: rgba(15,17,21,.85); color: #fff; font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 999px;
  white-space: nowrap; border: 1px solid rgba(255,255,255,.2);
}
.dog-label.old { color: var(--warn); }
.dog-label.stale { color: var(--bad); }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.35); } }
.handheld-icon { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; box-shadow: 0 0 6px #000; }
.leaflet-container { background: #222; font: inherit; }
.leaflet-top.leaflet-left { top: calc(var(--safe-top) + 4px); }
.leaflet-touch .leaflet-bar a { width: 40px; height: 40px; line-height: 40px; }
.leaflet-touch .leaflet-draw-toolbar a { background-size: 300px 40px; }

@media (max-width: 600px) {
  .status-card { left: 56px; right: 8px; padding: 8px 10px; }
  .grid { grid-template-columns: 1fr 1fr; }
  .status-line { font-size: 15px; }
  .drawer { max-width: 100%; }
}
.kennel-icon { font-size: 26px; line-height: 1; filter: drop-shadow(0 2px 3px rgba(0,0,0,.7)); }
.paused-cover { position: fixed; inset: 0; z-index: 1200; background: rgba(15,17,21,.82); display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; }
.paused-cover p { color: var(--muted); max-width: 360px; }
/* No focus rectangle when a fence or pin is clicked */
.leaflet-interactive:focus, path.leaflet-interactive, .leaflet-marker-icon:focus, .leaflet-container:focus { outline: none !important; }
/* Kennel tool button shows a house instead of the generic map-pin sprite */
.leaflet-draw-toolbar a.leaflet-draw-draw-marker { background-image: none !important; }
.leaflet-draw-toolbar a.leaflet-draw-draw-marker::after { content: '🏠'; display: block; text-align: center; font-size: 20px; line-height: 30px; }
.leaflet-touch .leaflet-draw-toolbar a.leaflet-draw-draw-marker::after { line-height: 40px; font-size: 22px; }
/* Drawing toolbar and its action links ("Finish", "Save", "Cancel") sit above the status card */
.leaflet-top.leaflet-left { z-index: 960; }
.leaflet-draw-actions a { color: #fff !important; background: #2a3140 !important; font-size: 13px; white-space: nowrap; }
/* Hide the status card while drawing or editing so the map hints at top-left are visible */
body.drawing .status-card { display: none; }
.leaflet-draw-tooltip { z-index: 970; }

/* Troubleshooting box shown while updates have stopped */
.trouble { position: fixed; left: 50%; transform: translateX(-50%); top: calc(150px + var(--safe-top)); z-index: 905; width: min(520px, calc(100% - 24px)); background: var(--panel); border: 1px solid var(--warn); border-radius: 12px; padding: 12px 44px 12px 14px; font-size: 14px; }
.trouble b { display: block; margin-bottom: 6px; color: var(--warn); }
.trouble ul { margin: 0; padding-left: 18px; color: var(--muted); }
.trouble li { margin: 4px 0; }
.trouble .icon-btn { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; font-size: 14px; }
@media (max-width: 600px) { .trouble { top: calc(200px + var(--safe-top)); } }
