:root {
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; /* charts: categorical slots, light */
  --bg: #f4f6f2; --panel: #ffffff; --ink: #1d2a21; --muted: #5d6b61; --line: #dfe5dc;
  --brand: #1f3a2a; --go: #2e8b3e; --go-ink: #fff; --warn: #c98a00; --alarm: #c62828;
  --chip: #eef2ec; --shadow: 0 2px 10px rgba(0,0,0,.12);
  --field: #4caf50; --nogo: #e53935; --boundary: #1e88e5;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111612; --panel: #1a211c; --ink: #e8efe8; --muted: #9db0a2; --line: #2c372f;
    --chip: #243027; --shadow: 0 2px 10px rgba(0,0,0,.5);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  }
}
:root[data-theme="dark"] {
  --bg: #111612; --panel: #1a211c; --ink: #e8efe8; --muted: #9db0a2; --line: #2c372f;
  --chip: #243027; --shadow: 0 2px 10px rgba(0,0,0,.5);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
header { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; background: var(--brand); color: #fff; z-index: 1000; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; white-space: nowrap; }
.brand img { width: 30px; height: 30px; }
.head-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn { position: relative; width: 42px; height: 42px; border: 0; border-radius: 10px;
  background: rgba(255,255,255,.1); cursor: pointer; display: grid; place-items: center; }
.icon-btn svg { width: 22px; height: 22px; fill: #fff; }
.badge { position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; background: var(--alarm); color: #fff; font-size: 12px; font-weight: 700;
  display: grid; place-items: center; }
.link { width: 10px; height: 10px; border-radius: 50%; background: #9e9e9e; margin-right: 4px; }
.link.ok { background: #7ddc6f; }
.stop-all { border: 0; border-radius: 10px; background: var(--alarm); color: #fff; font-weight: 800;
  letter-spacing: .5px; padding: 0 16px; height: 42px; cursor: pointer; box-shadow: 0 0 0 2px rgba(255,255,255,.35); }
.stop-all:active { transform: scale(.97); }

main { position: relative; flex: 1; display: flex; min-height: 0; }
#map { flex: 1; min-width: 0; background: #cfd8cc; }
#panel { width: 400px; max-width: 42vw; background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; z-index: 900; }
.grip { display: none; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; padding: 12px 6px; border: 0; background: none; cursor: pointer; font-weight: 600;
  color: var(--muted); border-bottom: 3px solid transparent; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--go); }
.tab { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }

@media (max-width: 760px) {
  main { flex-direction: column; }
  #panel { width: 100%; max-width: none; height: 46vh; border-left: 0; border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0; box-shadow: var(--shadow); transition: height .2s; }
  #panel.small { height: 132px; }
  #panel.tall { height: 78vh; }
  .grip { display: block; width: 44px; height: 5px; border-radius: 3px; background: var(--line);
    margin: 7px auto 0; cursor: pointer; }
  .brand span { display: none; }
  .stop-all { padding: 0 12px; }
}

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--chip); cursor: pointer;
  font-weight: 600; text-decoration: none; color: var(--ink); min-height: 42px; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary, .btn.go { background: var(--go); border-color: var(--go); color: var(--go-ink); }
.btn.danger { background: var(--alarm); border-color: var(--alarm); color: #fff; }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.big { width: 100%; min-height: 54px; font-size: 18px; }
.btn.small { min-height: 34px; padding: 5px 10px; font-size: 14px; }
.add-row { display: flex; gap: 6px; flex-wrap: wrap; }
.add-row .btn { flex: 1 1 auto; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
h3 { margin: 6px 0 2px; font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
input, select { font: inherit; padding: 9px 10px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); min-height: 42px; width: 100%; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }

/* ---------- cards ---------- */
.card { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--panel);
  display: flex; flex-direction: column; gap: 6px; cursor: pointer; }
.card.selected { outline: 3px solid var(--go); }
.card.disabled { opacity: .5; cursor: default; }
.card .title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(0,0,0,.08); }
.status { font-weight: 600; }
.status.ok { color: var(--go); } .status.warn { color: var(--warn); } .status.alarm { color: var(--alarm); }
.status.off { color: var(--muted); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--chip); border-radius: 8px; padding: 3px 8px; font-size: 13px; white-space: nowrap; }
.chip.good { color: var(--go); } .chip.bad { color: var(--alarm); } .chip.meh { color: var(--warn); }
.bar { height: 8px; border-radius: 4px; background: var(--chip); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--go); }
.actions { display: flex; gap: 6px; }
.actions .btn { flex: 1; white-space: nowrap; padding: 9px 8px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.wtile { border: 1px solid var(--line); border-radius: 12px; padding: 12px 6px; background: var(--panel);
  display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; font-weight: 600; }
.wtile svg { width: 40px; height: 40px; stroke: var(--go); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.wtile.selected { outline: 3px solid var(--go); }
.steps { display: flex; gap: 6px; font-size: 13px; color: var(--muted); }
.steps b { color: var(--ink); }
.summary { font-size: 20px; font-weight: 700; }
.warnbox { background: #fff4d6; color: #6b4b00; border-radius: 10px; padding: 8px 10px; font-size: 14px; }
details summary { cursor: pointer; color: var(--muted); padding: 4px 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- map ---------- */
.leaflet-container .leaflet-tile-container img.leaflet-tile { width: 256.5px !important; height: 256.5px !important; mix-blend-mode: normal; } /* hide tile seams on scaled displays */
.far .robot-label { display: none; }
.robot-icon { width: 34px; height: 34px; }
.robot-icon svg { width: 34px; height: 34px; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.robot-label { background: rgba(0,0,0,.65); color: #fff; border: 0; border-radius: 6px; padding: 1px 6px;
  font-weight: 700; box-shadow: none; }
.robot-label::before { display: none; }
.area-label { background: rgba(255,255,255,.85); border: 0; border-radius: 6px; font-weight: 600;
  color: #1d2a21; box-shadow: none; padding: 1px 6px; }
.area-label::before { display: none; }
.obs-icon { display: grid; place-items: center; }
.obs-icon span { width: 22px; height: 22px; display: grid; place-items: center; font-weight: 900; font-size: 14px;
  color: #000; background: #ffb300; clip-path: polygon(50% 0, 100% 100%, 0 100%); padding-top: 6px; }
.obs-icon.bumper span { background: #ff5252; color: #fff; }
.live-icon span { display: block; width: 18px; height: 18px; border-radius: 50%; background: #8d6e63;
  border: 2px solid #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(141,110,99,.7); } 100% { box-shadow: 0 0 0 14px rgba(141,110,99,0); } }
.leaflet-popup-content { margin: 10px 12px; font-size: 14px; }
.leaflet-popup-content .actions { margin-top: 8px; flex-direction: column; }
.draw-bar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 950;
  background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); padding: 8px 10px;
  display: flex; align-items: center; gap: 8px; max-width: calc(100% - 32px); }
.draw-bar span { font-weight: 600; }

/* ---------- modal & toasts ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 2000; display: grid; place-items: center; padding: 16px; }
.modal-box { background: var(--panel); border-radius: 16px; padding: 18px; width: 100%; max-width: 520px;
  max-height: 88vh; overflow: auto; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.modal-box h2 { margin: 0; font-size: 20px; }
.modal-box .actions { justify-content: flex-end; }
#toasts { position: fixed; top: 66px; left: 50%; transform: translateX(-50%); z-index: 2100;
  display: flex; flex-direction: column; gap: 8px; width: min(520px, calc(100% - 32px)); pointer-events: none; }
.toast { pointer-events: auto; background: var(--panel); color: var(--ink); border-left: 6px solid var(--go);
  border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); font-weight: 600; cursor: pointer; }
.toast.warn { border-left-color: var(--warn); }
.toast.alarm { border-left-color: var(--alarm); background: #ffebee; color: #7f1010; }
.event { display: flex; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.event .when { color: var(--muted); font-size: 13px; white-space: nowrap; min-width: 52px; }
.event.alarm .msg { color: var(--alarm); font-weight: 600; }
.event.warn .msg { color: var(--warn); font-weight: 600; }
.mono { font-family: ui-monospace, monospace; font-size: 13px; word-break: break-all; background: var(--chip);
  padding: 6px 8px; border-radius: 8px; }

/* ---------- weather, plans, help ---------- */
.wx { border: 0; border-radius: 10px; background: rgba(255,255,255,.1); color: #fff; height: 42px; padding: 0 10px;
  cursor: pointer; font-size: 14px; white-space: nowrap; }
@media (max-width: 760px) { .wx { font-size: 12px; padding: 0 6px; } }
.days { display: flex; gap: 4px; flex-wrap: wrap; }
.days label { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; height: 36px;
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-size: 14px; background: var(--chip); }
.days input { display: none; }
.days label.on { background: var(--go); border-color: var(--go); color: #fff; }
.help-photo { width: 100%; border-radius: 12px; background: #000; aspect-ratio: 4 / 3; object-fit: cover; }
.help-actions { display: grid; grid-template-columns: 1fr; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; min-height: 0; }
.station-icon span { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: #0277bd; color: #fff; border: 2px solid #fff; font-size: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.5); }
.vine-line { pointer-events: none; }
.section { display: flex; flex-direction: column; gap: 8px; }

/* ---------- on-site camera view ---------- */
.ar { position: fixed; inset: 0; z-index: 3000; background: #000; color: #fff; overflow: hidden; }
.ar video, .ar canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.ar video { object-fit: cover; }
.ar-top { position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px; background: linear-gradient(rgba(0,0,0,.6), transparent); }
.ar-top .btn, .ar-actions .btn { background: rgba(0,0,0,.55); color: #fff; border-color: rgba(255,255,255,.3); }
.ar-chip { background: rgba(0,0,0,.55); border-radius: 8px; padding: 4px 8px; font-size: 13px; }
.ar-top #ar-set { margin-left: auto; }
.ar-cross { position: absolute; left: 50%; top: 50%; width: 34px; height: 34px; transform: translate(-50%, -50%); pointer-events: none;
  background: linear-gradient(#fff, #fff) center/2px 100% no-repeat, linear-gradient(#fff, #fff) center/100% 2px no-repeat;
  filter: drop-shadow(0 0 2px #000); }
.ar-msg { position: absolute; left: 16px; right: 16px; top: 30%; background: rgba(0,0,0,.8); border-radius: 12px; padding: 14px;
  font-size: 16px; line-height: 1.5; text-align: center; }
.ar-bottom { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 10px max(10px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.7)); display: flex; flex-direction: column; gap: 6px; }
.ar-near { font-size: 15px; text-shadow: 0 1px 2px #000; }
.ar-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ar-settings { display: grid; gap: 6px; background: rgba(0,0,0,.6); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.ar-settings input { width: 100%; min-height: 0; padding: 0; }

/* ---------- login ---------- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; background: var(--brand); padding: 16px; }
.login-box { background: var(--panel); border-radius: 18px; padding: 24px; width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 14px; align-items: stretch; text-align: center; }
.login-box img { width: 56px; height: 56px; margin: 0 auto; }
.pin-dots { display: flex; justify-content: center; gap: 12px; min-height: 22px; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); }
.pin-dots i.on { background: var(--ink); border-color: var(--ink); }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pad button { height: 60px; border-radius: 14px; border: 1px solid var(--line); background: var(--chip);
  font-size: 24px; font-weight: 700; cursor: pointer; }
.err { color: var(--alarm); min-height: 20px; font-weight: 600; }
/* the product name, kept out of the page text so the translations leave it alone */
.brand-name::before { content: 'KopterMax '; }
.brand-name b::before { content: 'Field'; }
.follow-ctl a { display: flex; align-items: center; justify-content: center; color: #333; }
.follow-ctl a.on { background: #2e7d32; color: #fff; }
button.chip { border: 0; font: inherit; cursor: pointer; }

/* ---------- robot list and robot page ---------- */
.heard { font-weight: 600; white-space: nowrap; }
.heard.on { color: var(--go); } .heard.off { color: var(--muted); }
.card.kv { cursor: default; gap: 0; padding: 4px 12px; }
.kv-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 6px 0;
  border-bottom: 1px solid var(--line); font-size: 14px; }
.kv-row > span:last-child { text-align: right; min-width: 0; overflow-wrap: anywhere; }
.kv-block { display: flex; flex-direction: column; gap: 4px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.card.kv > :last-child { border-bottom: 0; }
#tab-robot [data-f=head] > div:empty { display: none; }

/* ---------- charts (robot health, incidents) ---------- */
.chart-card { gap: 4px; }
.chart { display: flex; gap: 6px; align-items: stretch; }
.chart-y { display: flex; flex-direction: column; justify-content: space-between; text-align: right; min-width: 34px; font-size: 11px; }
.chart-plot { flex: 1; min-width: 0; height: 96px; touch-action: pan-y; }
.chart-plot svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart-read { text-align: right; font-variant-numeric: tabular-nums; }
.chart-legend { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); }
.chart-legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
#tab-robot details summary { font-size: 14px; }

/* ---------- the service page: every autopilot parameter (params.js) ---------- */
#panel.wide { width: min(920px, 72vw); max-width: none; }
@media (max-width: 760px) { #panel.wide { width: 100%; height: 78vh; } }
#tab-params details.pgroup { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
#tab-params details.pgroup > summary { padding: 8px 10px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.prows { display: flex; flex-direction: column; }
.prow { padding: 6px 10px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.prow.pending { background: #fff4d6; box-shadow: inset 4px 0 0 var(--warn); }
:root[data-theme="dark"] .prow.pending { background: #3a3013; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .prow.pending { background: #3a3013; } }
.pname { font-family: ui-monospace, monospace; font-size: 13px; }
.peditor input, .peditor select { width: 190px; max-width: 46vw; min-height: 32px; padding: 3px 6px; }
.pdesc { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.pdesc.full { display: block; }
.pbits { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0 10px; }
.params-bar { position: sticky; bottom: -12px; margin: 0 -12px -12px; padding: 8px 12px; display: flex; gap: 8px;
  align-items: center; background: var(--panel); border-top: 1px solid var(--line); box-shadow: var(--shadow); }
.plist { max-height: 50vh; overflow: auto; }
#tab-params details.pgroup > summary::before { content: '▸'; color: var(--muted); transition: transform .15s; }
#tab-params details.pgroup[open] > summary::before { transform: rotate(90deg); }
