:root {
  --night: #071d14;
  --night-soft: #103428;
  --primary: #08783f;
  --primary-hover: #045f31;
  --accent: #b7ef3a;
  --ink: #092419;
  --body: #29483b;
  --muted: #61786d;
  --paper: #ffffff;
  --paper-deep: #edf7f1;
  --canvas: #f3f8f5;
  --rule: #c9ded2;
  --rule-subtle: #e1eee7;
  --radius: 14px;
  --radius-sm: 8px;

  --st-located: #19c25a;
  --st-suggest: #ffd23f;
  --st-new: #36b3ff;
  --c-replace: #e2483d;
  --c-repair: #f5a524;
  --c-ok: #20b15a;
  --c-monitor: #8e7cf0;
  --c-landlord: #2f7ff0;
  --c-tenant: #ec7a31;
  --c-unknown: #a3a9a6;

  --topbar-h: 52px;
  --sheet-peek: 72px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--night); overscroll-behavior: none; }
body.plain { background: var(--canvas); }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ top bar -- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 1000;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 10px 0 4px;
  display: flex; align-items: center; gap: 8px;
  background: var(--night); color: #fff;
}
.topbar .title { flex: 1; min-width: 0; line-height: 1.15; }
.topbar .site { font-weight: 700; font-size: 16px; }
.topbar .addr { font-size: 12px; color: #a9c4b6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; padding: 10px; color: #fff; cursor: pointer; border-radius: 10px; }
.icon-btn:active { background: var(--night-soft); }
.progress {
  font-size: 14px; padding: 5px 10px; border-radius: 999px;
  background: var(--night-soft); color: #d6e8de; font-variant-numeric: tabular-nums;
}
.progress b { color: var(--accent); }
.sync { font-size: 12px; padding: 4px 8px; border-radius: 999px; background: #6b4b00; color: #ffe7a3; }

/* ---------------------------------------------------------------- map -- */
#map {
  position: fixed; left: 0; right: 0; bottom: 0;
  top: calc(var(--topbar-h) + env(safe-area-inset-top));
  background: #2a2f2c;
}
.leaflet-container { font: inherit; }
.leaflet-container .leaflet-control-attribution { font-size: 9px; background: rgba(255,255,255,.6); padding: 0 4px; }

.fabs {
  position: fixed; right: 10px; z-index: 900;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 10px);
  display: flex; flex-direction: column; gap: 10px;
}
.fab {
  width: 46px; height: 46px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--paper); color: var(--ink); box-shadow: 0 2px 10px rgba(0,0,0,.35);
  display: grid; place-items: center;
}
.fab.on { background: var(--primary); color: #fff; }

/* unit markers */
.um { position: relative; }
.um .dot {
  position: absolute; left: -9px; top: -9px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--c); border: 2.5px solid #fff; box-shadow: 0 0 0 1.5px rgba(0,0,0,.55), 0 1px 4px rgba(0,0,0,.5);
}
.um.suggest .dot {
  background: rgba(0,0,0,.25); border: 2.5px dashed var(--st-suggest); box-shadow: 0 0 0 1px rgba(0,0,0,.6);
}
.um.selected .dot { transform: scale(1.35); box-shadow: 0 0 0 3px var(--accent), 0 1px 6px rgba(0,0,0,.6); }
.um .lbl {
  position: absolute; left: 12px; top: -10px; white-space: nowrap;
  font-size: 12px; font-weight: 700; color: #fff; padding: 1px 5px; border-radius: 5px;
  background: rgba(7, 29, 20, .78); pointer-events: none;
}
.um.suggest .lbl { color: #ffe68a; background: rgba(0,0,0,.6); font-weight: 600; }
.hide-labels .um .lbl, .zoom-lo .um .lbl { display: none; }
.zoom-lo .um .dot { width: 12px; height: 12px; left: -6px; top: -6px; border-width: 2px; }

.reflbl {
  font-size: 10px; font-weight: 600; color: #fff; white-space: nowrap; pointer-events: none;
  text-shadow: 0 0 2px #000, 0 0 3px #000;
}
.hide-reflabels .reflbl, .zoom-mid .reflbl, .zoom-lo .reflbl { display: none; }

.pin-temp {
  width: 26px; height: 26px; margin: -26px 0 0 -13px; position: relative;
}
.pin-temp::before {
  content: ""; position: absolute; inset: 0; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: var(--accent); border: 2px solid var(--night); box-shadow: 0 2px 6px rgba(0,0,0,.5);
}
.gps-dot {
  width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%;
  background: #2f8bff; border: 3px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.4), 0 0 10px rgba(47,139,255,.8);
}

/* ------------------------------------------------------ placing banner -- */
.placing-banner {
  position: fixed; left: 10px; right: 66px; z-index: 950;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 10px);
  background: var(--primary); color: #fff; border-radius: 12px; padding: 10px 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
.pb-text { font-size: 15px; }
.pb-actions { display: flex; gap: 8px; margin-top: 8px; }

/* -------------------------------------------------------------- sheet -- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 980;
  background: var(--paper); border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,.35);
  padding: 0 14px calc(10px + env(safe-area-inset-bottom));
  max-height: 72vh; display: flex; flex-direction: column;
  transition: max-height .18s ease;
}
.sheet.tall { max-height: 88vh; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--rule); margin: 8px auto 6px; cursor: grab; }
.searchrow { display: flex; gap: 8px; align-items: center; }
#search {
  flex: 1; min-width: 0; height: 46px; border-radius: 12px; border: 1.5px solid var(--rule);
  padding: 0 14px; font-size: 17px; background: var(--canvas); color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .02em;
}
#search::placeholder { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; letter-spacing: 0; color: var(--muted); }
#search:focus { outline: none; border-color: var(--primary); background: #fff; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; margin-top: 8px; }
.sheet-body:empty, .sheet.collapsed .sheet-body { display: none; }

@media (min-width: 900px) {
  .sheet {
    top: calc(var(--topbar-h) + 12px); bottom: 12px; left: 12px; right: auto; width: 400px;
    max-height: none; border-radius: 16px; padding-bottom: 14px;
  }
  .sheet .grab { display: none; }
  .sheet .searchrow { margin-top: 14px; }
  .sheet.tall { max-height: none; }
  .placing-banner { left: 424px; right: auto; width: 420px; }
}

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 16px; border-radius: 12px; border: 0; cursor: pointer;
  background: var(--primary); color: #fff; font-weight: 650; font-size: 16px; text-decoration: none;
}
.btn:active { background: var(--primary-hover); }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.wide { width: 100%; }
.btn.ghost { background: var(--paper-deep); color: var(--ink); }
.btn.ghost:active { background: var(--rule-subtle); }
.btn.ghost-light { background: rgba(255,255,255,.18); color: #fff; }
.btn.danger { background: #fbecec; color: #b42323; }
.btn.confirm { background: var(--st-located); color: #052b14; }
.btn[disabled] { opacity: .5; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 4px; }
.btn-row .btn { flex: 1 1 auto; }

/* results / list */
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 8px; }
.chip {
  flex: none; border: 1.5px solid var(--rule); background: var(--paper); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.row {
  display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--rule-subtle);
  cursor: pointer;
}
.row:active { background: var(--canvas); }
.row .swatch { width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--c); }
.row .swatch.hollow { background: transparent; border: 2px dashed #b48a00; }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 700; font-size: 16px; }
.row .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .serial { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--body); }
.row mark { background: #fff1a8; color: inherit; border-radius: 3px; }
.row .side { font-size: 12px; color: var(--muted); text-align: right; flex: none; }
.empty { color: var(--muted); padding: 14px 4px; font-size: 15px; }
.section-h { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 2px; font-weight: 700; }

/* unit card */
.card-h { display: flex; align-items: flex-start; gap: 10px; }
.card-h .tag { font-size: 22px; font-weight: 800; line-height: 1.15; }
.card-h .sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.card-h .x { margin-left: auto; background: var(--paper-deep); border: 0; width: 36px; height: 36px; border-radius: 50%; font-size: 20px; cursor: pointer; flex: none; }
.serial-big {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 22px; font-weight: 700;
  letter-spacing: .08em; background: var(--canvas); border-radius: 10px; padding: 8px 12px; margin: 10px 0 6px;
  word-break: break-all;
}
.serial-big small { display: block; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.status {
  border-radius: 10px; padding: 9px 12px; font-size: 14px; margin: 8px 0; line-height: 1.35;
}
.status.located { background: #e3f8eb; color: #0d5a2c; }
.status.suggest { background: #fff6d3; color: #6b5200; }
.status.missing { background: var(--paper-deep); color: var(--body); }
.status.warn { background: #fdece3; color: #8a3b10; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; margin: 8px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.photos { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0; }
.photos img { height: 84px; width: 84px; object-fit: cover; border-radius: 8px; flex: none; cursor: pointer; background: var(--canvas); }
.field { display: block; margin: 10px 0; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 10px 12px; border-radius: 10px;
  border: 1.5px solid var(--rule); background: #fff; color: var(--ink);
}
.field textarea { min-height: 64px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  border: 1.5px solid var(--rule); background: var(--paper); border-radius: 10px; padding: 8px 12px;
  font-size: 14px; cursor: pointer;
}
.seg button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.pill { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--paper-deep); color: var(--body); }
.pill.replace { background: #fde4e2; color: #a3241b; }
.pill.repair { background: #fdf0d8; color: #865200; }
.pill.ok { background: #e3f8eb; color: #0d5a2c; }
.pill.monitor { background: #ece8fd; color: #4a3aa8; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ------------------------------------------------------------- drawer -- */
.drawer-scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1100; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(330px, 86vw); z-index: 1101;
  background: var(--night); color: #e5f1ea; overflow-y: auto;
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(18px + env(safe-area-inset-bottom));
}
.drawer .logo { width: 170px; display: block; margin-bottom: 10px; }
.drawer .who { font-size: 13px; color: #a9c4b6; margin-bottom: 18px; word-break: break-all; }
.drawer-section { border-top: 1px solid var(--night-soft); padding: 14px 0; }
.drawer .label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: #8fb3a1; margin-bottom: 8px; font-weight: 700; }
.drawer .seg button { background: var(--night-soft); color: #e5f1ea; border-color: #1d4a39; }
.drawer .seg button.on { background: var(--accent); color: var(--night); border-color: var(--accent); }
.drawer a.dl, .drawer .linkish {
  display: block; color: #fff; text-decoration: none; padding: 9px 0; font-size: 15px; background: none; border: 0;
  cursor: pointer; text-align: left; width: 100%;
}
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 3px 0; }
.legend-item i { width: 14px; height: 14px; border-radius: 50%; background: var(--c); border: 2px solid #fff; flex: none; }
.legend-item i.hollow { background: transparent; border: 2px dashed var(--st-suggest); }
.legend-item .n { margin-left: auto; color: #a9c4b6; font-variant-numeric: tabular-nums; }
.stat-line { display: flex; justify-content: space-between; font-size: 14px; padding: 3px 0; }
.stat-line b { color: var(--accent); font-variant-numeric: tabular-nums; }

.layers-pop {
  position: fixed; right: 64px; z-index: 990; top: calc(var(--topbar-h) + env(safe-area-inset-top) + 10px);
  background: var(--paper); border-radius: 12px; padding: 8px 12px; box-shadow: 0 4px 18px rgba(0,0,0,.4);
}
.layers-pop label { display: flex; gap: 10px; align-items: center; padding: 8px 0; font-size: 15px; }
.layers-pop input { width: 20px; height: 20px; accent-color: var(--primary); }

/* -------------------------------------------------------- viewer/toast -- */
.viewer { position: fixed; inset: 0; z-index: 1200; background: rgba(0,0,0,.92); display: grid; place-items: center; }
.viewer img { max-width: 100vw; max-height: 100vh; object-fit: contain; }
.viewer-x { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 12px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.2); color: #fff; font-size: 26px; cursor: pointer; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 1300;
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 12px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px;
  box-shadow: 0 4px 18px rgba(0,0,0,.4); max-width: calc(100vw - 32px);
}

/* -------------------------------------------------------------- login -- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--paper); border-radius: var(--radius); padding: 28px 24px; width: min(380px, 100%); text-align: center; box-shadow: 0 8px 24px rgba(9,36,25,.08); }
.login-card .logo { width: 210px; max-width: 100%; margin-bottom: 14px; }
.login-card .eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.login-card h1 { margin: 4px 0 18px; font-size: 26px; }
.login-card .hint { color: var(--muted); font-size: 13px; margin-top: 14px; }
.site-link { display: block; text-align: left; padding: 12px 14px; border: 1.5px solid var(--rule); border-radius: 12px; margin: 8px 0; color: var(--ink); text-decoration: none; }
.site-link span { display: block; font-size: 13px; color: var(--muted); }
