:root {
  --bg: #12161a;
  --panel: #1b2127;
  --panel-2: #232b33;
  --line: #2e3841;
  --text: #e8edf2;
  --dim: #93a1ad;
  --accent: #7ec27a;
  --warn: #e6a94a;
  --bad: #e2574c;
  --safe-b: env(safe-area-inset-bottom, 0px);
  /* The panels sit directly under the topbar, so both have to agree on
     how tall it is. One number, declared once. */
  --topbar-h: 46px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden;
  font: 15px/1.4 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; }
.hidden { display: none !important; }

/* login */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px 24px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; font-size: 30px; letter-spacing: .08em; }
.login-card .sub { margin: -8px 0 10px; color: var(--dim); font-size: 13px; }
input, button, select { font: inherit; }
input { background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; padding: 12px; }
button { background: var(--accent); color: #10201a; border: 0; border-radius: 9px;
  padding: 12px; font-weight: 600; cursor: pointer; }
.error { color: var(--bad); font-size: 13px; min-height: 18px; }

/* chrome */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
#topbar { display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  height: var(--topbar-h);
  background: var(--panel); border-bottom: 1px solid var(--line); z-index: 500; }
.brand { font-weight: 700; letter-spacing: .1em; }
.mesh { flex: 1; font-size: 13px; color: var(--dim); }
.mesh b { color: var(--text); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.dot.up { background: var(--accent); } .dot.down { background: var(--bad); }
.icon-btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; position: relative; }
/* Kielinapissa lukee se kieli johon vaihtaa, kahdella kirjaimella. */
.icon-btn.lang-btn { font-size: 12px; font-weight: 700; letter-spacing: .04em;
  padding: 8px 8px; min-width: 34px; }
.badge { position: absolute; top: -6px; right: -6px; background: var(--bad); color: #fff;
  border-radius: 9px; font-size: 11px; padding: 1px 5px; }
#map { flex: 1; background: #0c0f12; }
.menu { position: absolute; top: 54px; right: 10px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 6px; z-index: 900;
  display: flex; flex-direction: column; min-width: 190px; }
.menu button { background: transparent; color: var(--text); text-align: left;
  padding: 9px 10px; border-radius: 7px; font-weight: 400; }
.menu button.on { background: var(--panel-2); font-weight: 600; }

/* device sheet */
.sheet { background: var(--panel); border-top: 1px solid var(--line); z-index: 600;
  max-height: 46vh; display: flex; flex-direction: column;
  padding-bottom: var(--safe-b); transition: max-height .18s ease; }
.sheet.collapsed { max-height: 54px; }
.handle { display: grid; place-items: center; height: 22px; cursor: pointer; flex: none; }
.handle span { width: 42px; height: 4px; border-radius: 2px; background: var(--line); }
.devices { overflow-y: auto; padding: 0 8px 10px; }
.device { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center;
  padding: 9px 8px; border-radius: 10px; cursor: pointer; }
.device + .device { border-top: 1px solid var(--line); border-radius: 0; }
.device.sel { background: var(--panel-2); }
.pin { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; color: #0d1114; font-size: 13px; }
.d-name { font-weight: 600; }
.d-meta { font-size: 12px; color: var(--dim); }
.d-right { text-align: right; font-size: 12px; color: var(--dim); white-space: nowrap; }
.d-dist { font-size: 16px; font-weight: 700; color: var(--text); }
.stale .d-name, .stale .d-dist { color: var(--warn); }
.dead .pin { opacity: .35; } .dead .d-name { color: var(--dim); }

/* tracker parameters — a pending change is amber, a confirmed one green.
   Buttons are 44 px tall because this gets pressed with a glove on. */
.cfg { grid-column: 1 / -1; margin-top: 8px; padding-top: 9px;
  border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.cfg-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; }
.cfg-label { font-size: 12px; font-weight: 600; color: var(--dim);
  text-transform: uppercase; letter-spacing: .06em; }
.cfg-state { font-size: 12px; color: var(--dim); }
.cfg-state.ok { color: var(--accent); }
.cfg-state.wait { color: var(--warn); }
.cfg-state.bad { color: var(--bad); }
.cfg-buttons { display: flex; flex-wrap: wrap; gap: 6px; }
.cfg-buttons button { min-width: 62px; height: 44px; padding: 0 12px; border-radius: 10px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line); cursor: pointer; }
.cfg-buttons button.on { background: var(--accent); border-color: var(--accent); color: #0d1114;
  font-weight: 700; }
/* Chosen but not yet acknowledged by the collar: the same slot, a different
   colour, so nobody reads a queued change as a done one. */
.cfg-buttons button.on.pending { background: var(--warn); border-color: var(--warn); }
.cfg-buttons.busy { opacity: .5; pointer-events: none; }
.cfg-err { font-size: 12px; color: var(--bad); }

/* messages */
.panel { position: absolute; inset: var(--topbar-h) 0 0; background: var(--bg); z-index: 950;
  display: flex; flex-direction: column; }
.panel-head { display: flex; align-items: center; padding: 10px 12px;
  border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 16px; flex: 1; }
.messages { flex: 1; overflow-y: auto; padding: 10px 12px; }
.msg { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px; margin-bottom: 8px; }
.msg .who { font-size: 12px; color: var(--dim); margin-bottom: 3px; }
.hint { color: var(--dim); font-size: 12px; padding: 0 12px 14px; margin: 0; }

/* käyttöönottolomake */
.form { padding: 12px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.form label { font-size: 13px; color: var(--dim); }
.form .hint { padding: 0; }
.form select { background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 9px; padding: 12px; }
#adopt-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 18px; letter-spacing: .08em; text-transform: uppercase; }
.ok-note { color: var(--accent); font-size: 13px; }
/* An opt-in that has to survive being pressed with a glove: the whole row is
   the target, not the 13 px box. */
.toggle-row { display: flex; align-items: center; gap: 10px; min-height: 44px;
  padding: 0 12px; cursor: pointer; font-size: 14px; }
.toggle-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.d-badge { font-size: 11px; padding: 1px 6px; border-radius: 6px; margin-left: 6px;
  border: 1px solid var(--line); color: var(--dim); }
.d-remove { background: none; border: none; color: var(--dim); font-size: 18px;
  width: 34px; height: 34px; cursor: pointer; }

/* map markers */
.marker { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.85); color: #0d1114; font-weight: 700; font-size: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,.55); }
.marker.stale { opacity: .55; border-style: dashed; }
/* Masts are terrain, not animals: square, muted, and behind everything the
   user actually came to look at. */
.marker.infra { border-radius: 7px; width: 26px; height: 26px; font-size: 11px;
  background: #6b7a86; border-color: rgba(255,255,255,.5); opacity: .85; }
.marker.infra.down { background: var(--bad); }
.marker-label { position: absolute; top: 33px; left: 50%; transform: translateX(-50%);
  background: rgba(18,22,26,.85); border: 1px solid var(--line); color: var(--text);
  font-size: 11px; padding: 1px 5px; border-radius: 5px; white-space: nowrap; }
.course { position: absolute; top: -9px; left: 50%; width: 0; height: 0;
  border-left: 5px solid transparent; border-right: 5px solid transparent;
  border-bottom: 9px solid #fff; transform-origin: 50% 25px; }
.me-dot { width: 16px; height: 16px; border-radius: 50%; background: #4a9cf5;
  border: 3px solid #fff; box-shadow: 0 0 0 3px rgba(74,156,245,.35); }
.leaflet-container { background: #0c0f12; }
.leaflet-control-attribution { background: rgba(18,22,26,.8) !important; color: var(--dim) !important; }
.leaflet-control-attribution a { color: var(--dim) !important; }

/* Network health, in the one place a glance lands: green when every mast we
   run has been heard, amber when some are missing, red when none answer. */
.net.ok { color:#7ec27a; }
.net.part { color:#e6a94a; }
.net.none { color:#e2574c; }

/* Puhelin: verkkotilanne omalle rivilleen.
 *
 * The topbar is brand + summary + five buttons on one row. On a 390 px phone
 * the brand and buttons take ~320 px of it, which leaves ~70 px for a string
 * that wants ~210 ("Verkko 3/4 · 2 seurainta · 5 min sitten"), so it wrapped
 * to three lines and the topbar grew to twice its height -- straight out of
 * the map, which is the one thing the screen is for.
 *
 * Giving the summary its own full-width row costs 20 px and saves 40, and it
 * is deterministic: one line whatever the language does to the wording.
 * Finnish is the longer of the two and is what this has to survive.
 */
@media (max-width: 560px) {
  :root { --topbar-h: 68px; }
  #topbar { flex-wrap: wrap; align-content: center; row-gap: 2px;
    gap: 8px; padding: 6px 10px; }
  /* Pushes the buttons right now that the summary no longer does it. */
  .brand { flex: 1; }
  #topbar .icon-btn { padding: 6px 9px; }
  /* order pulls it below the buttons; the 100 % basis keeps it there. Ellipsis
     rather than wrap: a truncated line still reads, a third row does not fit. */
  #mesh-summary { order: 10; flex: 1 0 100%; font-size: 12px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* Kapea puhelin (SE, mini): tuotenimi saa väistyä. Sovellus on jo auki, joten
   se kertoo nimensä turhaan -- napit eivät. */
@media (max-width: 380px) {
  .brand { display: none; }
  #topbar { gap: 6px; }
  #topbar .icon-btn { padding: 6px 8px; }
}
