/* SaqrVision — sharp, flat, minimal. Square corners, 1px hairlines, no glow, short precise motion. */
:root {
  --bg: #0a0b0c;
  --panel: #111315;
  --panel-2: #171a1c;
  --line: #24292c;
  --line-2: #3a4145;
  --text: #eceeee;
  --muted: #7f898d;
  --accent: #19c2a8;        /* teal */
  --accent-ink: #001a16;
  --mark: #12d6b9;          /* bright teal for marks drawn over photos and maps */
  --danger: #ff5a4e;
  --ok: #3ddc84;
  --ease: cubic-bezier(.2, 0, 0, 1);
  --font: Inter, ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  /* Space taken by the phone's status bar / gesture bar and, in a full-screen Telegram Mini App,
     by Telegram's own Close/menu buttons (telegram-web-app.js sets the --tg-* variables). */
  --inset-top: max(env(safe-area-inset-top, 0px),
                   calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)));
  --inset-bottom: max(env(safe-area-inset-bottom, 0px),
                      calc(var(--tg-safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px)));
}

* { box-sizing: border-box; border-radius: 0; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); }
body { min-height: 100vh; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
::selection { background: var(--accent); color: var(--accent-ink); }

/* small caps label used across the app */
.stat .k, .dev-zone h3, .danger-zone h3 {
  font-size: 11px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
}

/* ---------------- brand ---------------- */
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; letter-spacing: .02em; font-size: 16px; text-decoration: none; text-transform: uppercase; }
.brand .logo { width: 30px; height: 30px; flex: none; display: block; }
.brand b { color: var(--accent); font-weight: 700; }

/* ---------------- buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border: 1px solid var(--line-2); background: transparent;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  transition: background-color .12s linear, border-color .12s linear, color .12s linear;
}
.btn:hover { border-color: var(--text); }
.btn:active { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #2ee0c4; border-color: #2ee0c4; }
.btn.primary:active { background: var(--text); border-color: var(--text); }
.btn.ghost { border-color: transparent; }
.btn.ghost:hover { border-color: var(--line-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:disabled:hover { border-color: var(--line-2); }
.icon-btn { width: 38px; padding: 0; }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------------- top bar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 20px;
  height: calc(60px + var(--inset-top)); padding: var(--inset-top) 28px 0; background: rgba(10, 11, 12, .92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar .spacer { flex: 1; }
.live { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; }
.live .dot { width: 7px; height: 7px; background: var(--muted); }
.live.on .dot { background: var(--ok); animation: blink 1.6s steps(1) infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* ---------------- feed ---------------- */
main { padding: 32px 28px calc(32px + var(--inset-bottom)); }
.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.card {
  position: relative; background: var(--panel); display: flex; flex-direction: column;
  animation: card-in .28s var(--ease) both; border: 1px solid var(--line); transition: background-color .12s linear;
}
.card::before {   /* accent rule that draws across the top on hover */
  content: ""; position: absolute; z-index: 3; left: -1px; top: -1px; height: 2px; width: calc(100% + 2px);
  background: var(--accent); transform: scaleX(0); transform-origin: left; transition: transform .22s var(--ease);
}
@keyframes card-in { from { opacity: 0; transform: translateY(8px); } }
@media (hover: hover) {   /* touch screens would keep the hover state after a tap */
  .card:hover::before { transform: scaleX(1); }
  .card:hover { background: var(--panel-2); }
  .card:hover .shot::after { inset: 8px; opacity: 1; --c: var(--mark); }
}
.card.fresh::before { animation: sweep 1.2s var(--ease) 2; }
.card.fresh { animation: card-in .28s var(--ease) both, flash 1.6s linear; }
@keyframes sweep { from { transform: scaleX(0); } 60%, to { transform: scaleX(1); } }
@keyframes flash { 0%, 30% { background: #10302b; } }

.shot { position: relative; aspect-ratio: 1; background: #050606; cursor: zoom-in; overflow: hidden; }
.shot img { width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; display: block; }   /* bird is centred in the crop */
.shot::after {   /* corner brackets — a viewfinder, not a frame */
  content: ""; position: absolute; inset: 12px; pointer-events: none; opacity: .75;
  transition: inset .22s var(--ease), opacity .22s linear;
  --c: rgba(255, 255, 255, .85); --l: 16px;
  background:
    linear-gradient(var(--c), var(--c)) left top / var(--l) 1px no-repeat,
    linear-gradient(var(--c), var(--c)) left top / 1px var(--l) no-repeat,
    linear-gradient(var(--c), var(--c)) right top / var(--l) 1px no-repeat,
    linear-gradient(var(--c), var(--c)) right top / 1px var(--l) no-repeat,
    linear-gradient(var(--c), var(--c)) left bottom / var(--l) 1px no-repeat,
    linear-gradient(var(--c), var(--c)) left bottom / 1px var(--l) no-repeat,
    linear-gradient(var(--c), var(--c)) right bottom / var(--l) 1px no-repeat,
    linear-gradient(var(--c), var(--c)) right bottom / 1px var(--l) no-repeat;
}
.tag {
  position: absolute; z-index: 1; left: 0; bottom: 0; padding: 6px 12px;
  background: rgba(5, 6, 6, .82); color: #fff; backdrop-filter: blur(8px);
  font-size: 12px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
}
.tag .pct { color: var(--mark); margin-left: 8px; font-family: var(--mono); letter-spacing: 0; }
.body { padding: 16px 18px 4px; display: grid; gap: 4px; }
.when { font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.sub { color: var(--muted); font-size: 13px; }
.coords { font-family: var(--mono); font-size: 12.5px; color: #aeb7ba; margin-top: 6px; }
.actions { display: flex; gap: 8px; padding: 16px 18px 18px; margin-top: auto; }
.actions .btn { flex: 1; height: 40px; }
.nogps { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; padding: 12px 0; }

.empty { text-align: center; color: var(--muted); padding: 100px 20px; font-size: 14px; }
.empty .logo { width: 56px; height: 56px; opacity: .4; margin-bottom: 18px; }
.more { display: flex; justify-content: center; padding: 28px 0 8px; }

/* ---------------- viewer ---------------- */
.viewer {
  position: fixed; inset: 0; z-index: 50; background: rgba(5, 6, 6, .96);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(20px + var(--inset-top)) 20px calc(20px + var(--inset-bottom));
  animation: fade .16s linear;
}
@keyframes fade { from { opacity: 0; } }
.viewer .stage { position: relative; line-height: 0; max-width: 100%; animation: card-in .24s var(--ease); }
.viewer img { max-width: calc(100vw - 40px); max-height: calc(100vh - 140px); border: 1px solid var(--line); }
.viewer .box { position: absolute; border: 2px solid var(--mark); box-shadow: 0 0 0 1px rgba(0, 0, 0, .6); pointer-events: none; }
.viewer .bar { display: flex; gap: 8px; align-items: center; margin-top: 16px; flex-wrap: wrap; justify-content: center; }
.viewer .note { color: #c3cad3; }

/* ---------------- login ---------------- */
.center { min-height: 100vh; display: grid; place-items: center; padding: calc(24px + var(--inset-top)) 24px calc(24px + var(--inset-bottom)); }
.login {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-top: 2px solid var(--accent); padding: 36px 28px 28px; display: grid; gap: 18px;
  animation: card-in .3s var(--ease);
}
.login .brand { flex-direction: column; justify-content: center; gap: 18px; font-size: 20px; }
.login .brand .logo { width: 84px; height: 84px; }
.login p { margin: 0; color: var(--muted); text-align: center; font-size: 11px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; }
input[type=password] {
  width: 100%; height: 44px; border: 1px solid var(--line-2); background: var(--bg);
  color: var(--text); padding: 0 14px; font: inherit; outline: none; transition: border-color .12s linear;
}
input[type=password]:focus { border-color: var(--accent); }
.login .btn { height: 44px; width: 100%; }
.error { color: var(--danger); font-size: 13px; text-align: center; min-height: 18px; }

/* ---------------- route ---------------- */
.route-page { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
#map { flex: 1; background: #050606; }
.sheet {
  position: absolute; z-index: 500; left: 16px; top: calc(16px + var(--inset-top)); width: 360px; max-width: calc(100vw - 32px);
  background: rgba(10, 11, 12, .94); backdrop-filter: blur(12px); border: 1px solid var(--line);
  border-top: 2px solid var(--accent); padding: 16px; display: grid; gap: 14px;
  animation: card-in .28s var(--ease);
}
.sheet > * { min-width: 0; }
.sheet .head { display: flex; align-items: center; gap: 12px; }
.sheet .head .btn { height: 34px; width: 34px; padding: 0; flex: none; }
.sheet .title { font-weight: 700; font-size: 16px; min-width: 0; }
.sheet .title small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stats { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); }
.stat { padding: 10px 12px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat .v { font-size: 22px; font-weight: 700; font-family: var(--mono); letter-spacing: -.02em; white-space: nowrap; }
.stat .v small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 4px; font-family: var(--font); letter-spacing: .04em; }
.gps-status { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.gps-status .dot { width: 7px; height: 7px; background: var(--muted); flex: none; }
.gps-status.ok .dot { background: var(--ok); animation: blink 1.6s steps(1) infinite; }
.gps-status.bad { color: var(--danger); cursor: pointer; }
.gps-status.bad .dot { background: var(--danger); }
.sheet .row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.sheet .row .btn { min-width: 0; white-space: normal; text-align: center; line-height: 1.2; height: auto; min-height: 38px; padding: 6px 12px; font-size: 11.5px; }
.sheet .btn.primary { height: 44px; }
/* navigation mode: the panel turns into a turn-by-turn display */
.nav { display: none; gap: 12px; }
.sheet.navigating > .stats, .sheet.navigating > .gps-status, .sheet.navigating > .row,
.sheet.navigating > #start, .sheet.navigating > #navigate { display: none; }
.sheet.navigating .nav { display: grid; }
.nav-main { display: grid; grid-template-columns: 72px 1fr; gap: 14px; align-items: center; }
.nav-arrow { width: 72px; height: 72px; fill: var(--accent); stroke: #fff; stroke-width: 1.5; stroke-linejoin: miter; transition: transform .2s var(--ease); }
.nav-arrow.north { fill: var(--muted); }
.nav-step { font-family: var(--mono); font-size: 30px; font-weight: 700; line-height: 1.05; letter-spacing: -.02em; }
.nav-step small { font-family: var(--font); font-size: 14px; color: var(--muted); margin-left: 4px; }
.nav-instr { font-size: 15px; font-weight: 600; margin-top: 4px; }
.nav-sub { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; }
.nav-sub b { color: var(--text); font-family: var(--mono); }
.nav .row { grid-template-columns: 1fr 1fr; }
.nav .row .btn { height: 44px; font-size: 12.5px; }
.nav .row .btn.hidden + .btn { grid-column: 1 / -1; }
.arrow { display: inline-block; transition: transform .3s var(--ease); color: var(--accent); font-weight: 700; }

.leaflet-container { font: inherit; }
.leaflet-top { top: var(--inset-top); }
.leaflet-bar, .leaflet-control-layers { border: 1px solid var(--line-2) !important; box-shadow: none !important; border-radius: 0 !important; }
.leaflet-bar a, .leaflet-control-layers { background: rgba(10, 11, 12, .92) !important; color: var(--text) !important; }
.leaflet-bar a { border-radius: 0 !important; border-bottom-color: var(--line-2) !important; transition: background-color .12s linear; }
.leaflet-bar a:hover { background: var(--text) !important; color: var(--bg) !important; }
.leaflet-control-layers-toggle { filter: invert(1); background-color: transparent !important; }
.leaflet-control-layers-expanded { color: var(--text); padding: 8px 12px; }
.leaflet-control-attribution { background: rgba(10, 11, 12, .75) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: #aeb7ba !important; }
.leaflet-tooltip { border-radius: 0; background: var(--bg); color: var(--text); border: 1px solid var(--line-2); box-shadow: none; font-family: var(--mono); font-size: 12px; }
.leaflet-tooltip-top::before { border-top-color: var(--line-2); }
.pin-me { position: relative; width: 64px; height: 64px; pointer-events: none; }
.pin-me .dot { position: absolute; left: 25px; top: 25px; width: 14px; height: 14px; border-radius: 50%; background: #4aa3ff; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .5); pointer-events: auto; }
.pin-me .cone {   /* where the phone points */
  position: absolute; inset: 0; display: none; transition: transform .12s linear;
  background: conic-gradient(from -28deg, rgba(74, 163, 255, .95) 0deg 56deg, transparent 56deg);
  -webkit-mask: radial-gradient(circle, #000 25%, rgba(0, 0, 0, .7) 50%, transparent 71%);
          mask: radial-gradient(circle, #000 25%, rgba(0, 0, 0, .7) 50%, transparent 71%);
}
.pin-target { width: 22px; height: 22px; position: relative; }   /* diamond with a reticle ring */
.pin-target::before {
  content: ""; position: absolute; inset: 4px; background: var(--mark); border: 2px solid #fff; transform: rotate(45deg);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .5);
}
.pin-target::after {
  content: ""; position: absolute; inset: -6px; border: 1px solid var(--mark); animation: reticle 2s var(--ease) infinite;
}
@keyframes reticle { from { transform: scale(.6); opacity: 1; } to { transform: scale(1.3); opacity: 0; } }

/* bird marker: the crop as a thumbnail on a stem, the tip marks the exact spot */
.pin-bird { position: relative; width: 60px; height: 76px; cursor: pointer; }
.pin-bird img {
  position: absolute; left: 0; top: 0; width: 60px; height: 60px; object-fit: cover; image-rendering: pixelated;
  border: 2px solid var(--mark); background: #050606; box-shadow: 0 0 0 1px rgba(0, 0, 0, .55);
  transition: transform .16s var(--ease); transform-origin: 50% 100%;
}
.pin-bird:hover img { transform: scale(1.08); }
.pin-bird .stem { position: absolute; left: 29px; top: 60px; width: 2px; height: 12px; background: var(--mark); }
.pin-bird .tip {
  position: absolute; left: 25px; top: 68px; width: 10px; height: 10px; background: var(--mark);
  border: 2px solid #fff; transform: rotate(45deg); box-shadow: 0 0 0 1px rgba(0, 0, 0, .5);
}
.pin-bird .tip::after {
  content: ""; position: absolute; inset: -9px; border: 1px solid var(--mark); animation: reticle 2s var(--ease) infinite;
}

/* detection card in the map popup */
.det-popup .leaflet-popup-content-wrapper {
  border-radius: 0; padding: 0; background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-top: 2px solid var(--accent); box-shadow: 0 12px 32px rgba(0, 0, 0, .6);
}
.det-popup .leaflet-popup-content { margin: 0; width: 320px !important; font: 13px/1.4 var(--font); }
.det-popup .leaflet-popup-tip { background: var(--panel); border: 1px solid var(--line); box-shadow: none; }
.det-popup a.leaflet-popup-close-button { color: var(--text); background: rgba(5, 6, 6, .8); width: 28px; height: 28px; font: 18px/28px var(--font); top: 0; right: 0; z-index: 2; }
.det-popup a.leaflet-popup-close-button:hover { background: var(--text); color: var(--bg); }
.det { display: grid; grid-template-columns: 112px 1fr; }
.det-shot { position: relative; width: 112px; height: 112px; background: #050606; cursor: zoom-in; overflow: hidden; }
.det-shot::after { content: "⤢"; position: absolute; right: 0; bottom: 0; width: 22px; height: 22px; display: grid; place-items: center; font-size: 13px; color: #fff; background: rgba(5, 6, 6, .8); }
.det-shot img { width: 100%; height: 100%; object-fit: cover; image-rendering: pixelated; display: block; }
.det-info { padding: 10px 34px 8px 14px; min-width: 0; }
.det-head { font-weight: 700; font-size: 14px; letter-spacing: .1em; text-transform: uppercase; }
.det dl { margin: 6px 0 0; display: grid; gap: 1px; }
.det dt { font-size: 10px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-top: 5px; }
.det dd { margin: 0; font-size: 13px; }
.det dd.pct { color: var(--mark); font-family: var(--mono); font-size: 18px; font-weight: 700; line-height: 1.1; }
.det dd small { display: block; color: var(--muted); font-size: 11.5px; }
.det-foot {
  grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 10px; padding: 8px 14px;
  border-top: 1px solid var(--line); color: var(--muted); font-size: 11.5px;
}
.det-foot .mono { font-family: var(--mono); }
.det .btn { grid-column: 1 / -1; margin: 0 14px 14px; height: 36px; font-size: 11.5px; }
.route-page ~ .viewer { z-index: 2000; }   /* above Leaflet's panes and controls */

/* ---------------- developer mode ---------------- */
.dev-badge {
  display: inline-flex; align-items: center; gap: 8px; padding: 0 0 0 10px; height: 26px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .14em;
  color: var(--danger); border: 1px solid var(--danger);
}
.dev-badge button {
  cursor: pointer; border: 0; height: 100%; padding: 0 10px; font: 700 10.5px var(--font); letter-spacing: .14em; text-transform: uppercase;
  background: var(--danger); color: #1b0705; transition: background-color .12s linear;
}
.dev-badge button:hover { background: #fff; }
.dev-zone { border: 1px solid var(--line); padding: 16px; display: grid; gap: 10px; margin-bottom: 14px; }
.dev-zone h3, .danger-zone h3 { margin: 0; }
.dev-zone p { margin: 0; color: var(--muted); font-size: 13.5px; }
.del {
  position: absolute; z-index: 2; right: 0; top: 0; height: 30px; padding: 0 12px; cursor: pointer; border: 0;
  font: 700 11px var(--font); letter-spacing: .12em; text-transform: uppercase; color: #fff;
  background: rgba(5, 6, 6, .82); border-left: 2px solid var(--danger); backdrop-filter: blur(8px);
  transition: background-color .12s linear, color .12s linear;
}
.del:hover { background: var(--danger); color: #1b0705; }
.del.armed { background: var(--danger); color: #1b0705; }

/* ---------------- settings / danger zone ---------------- */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(5, 6, 6, .8); display: grid; place-items: center; padding: calc(20px + var(--inset-top)) 20px calc(20px + var(--inset-bottom)); animation: fade .14s linear; }
.modal-box {
  width: 100%; max-width: 440px; background: var(--panel); border: 1px solid var(--line);
  border-top: 2px solid var(--accent); padding: 24px; display: grid; gap: 14px; animation: card-in .24s var(--ease);
}
.modal-box h2 { margin: 0; font-size: 13px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.danger-zone { border: 1px solid var(--danger); padding: 16px; display: grid; gap: 10px; }
.danger-zone h3 { color: var(--danger); }
.danger-zone p { margin: 0; color: var(--muted); font-size: 13.5px; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #1b0705; }
.btn.danger.armed { background: var(--danger); color: #1b0705; }
.dev-form { display: grid; gap: 10px; }
.dev-form p { margin: 0; color: var(--muted); font-size: 13.5px; }
.dev-form .error { text-align: left; }
.modal-msg { font-size: 13px; color: var(--ok); min-height: 18px; }

@media (max-width: 640px) {
  .topbar { height: calc(54px + var(--inset-top)); padding: var(--inset-top) 14px 0; gap: 12px; }
  .brand { font-size: 14px; gap: 10px; }
  .brand .logo { width: 26px; height: 26px; }
  .live .label { display: none; }
  main { padding: 10px 10px calc(10px + var(--inset-bottom)); }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .shot::after { inset: 8px; --l: 10px; }
  .tag { padding: 4px 8px; font-size: 10.5px; }
  .tag .pct { margin-left: 5px; }
  .del { height: 26px; padding: 0 9px; font-size: 10px; }
  .body { padding: 10px 12px 2px; }
  .when { font-size: 15px; }
  .sub { font-size: 12px; }
  .coords { font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .actions { flex-direction: column; gap: 6px; padding: 10px 12px 12px; }
  .actions .btn { height: 36px; flex: none; font-size: 11.5px; }
  .dev-badge { font-size: 9.5px; }
  .sheet { left: 0; right: 0; bottom: 0; top: auto; width: auto; max-width: none; border-left: 0; border-right: 0; border-bottom: 0;
           padding: 14px 14px calc(14px + var(--inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
