:root {
  --bg: #0b1220;
  --panel: #111a2b;
  --panel2: #1a2539;
  --panel3: #223049;
  --line: #2a3850;
  --text: #eef2f8;
  --muted: #93a1b8;
  --brand: #2563eb;
  --brand-hi: #3b82f6;
  --amber: #ffb020;
  --good: #22c55e;
  --bad: #ef4444;
  --radius: 14px;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { display: block; flex: none; }
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 11px 12px; width: 100%; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brand-hi); box-shadow: 0 0 0 3px rgba(59, 130, 246, .25); }
textarea { min-height: 76px; resize: vertical; }
label { display: block; font-size: 12px; font-weight: 600; letter-spacing: .02em; color: var(--muted); margin: 14px 0 6px; }
a { color: var(--brand-hi); }

/* Top bar */
#topbar { position: fixed; top: 0; left: 0; right: 0; z-index: 1000; display: flex; align-items: center; gap: 10px;
  padding: calc(var(--top) + 8px) 12px 10px; background: rgba(11, 18, 32, .94); backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, .06); }
#jobTitle { flex: 1; min-width: 0; }
#jobName { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em; }
#jobStats { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2);
  display: grid; place-items: center; }

/* Map */
#map { position: fixed; inset: 0; background: #0d1422; }
.leaflet-control-attribution { font-size: 9px; background: rgba(0, 0, 0, .45) !important; color: #ccc !important; }
.leaflet-control-attribution a { color: #ddd !important; }
.leaflet-bottom { bottom: calc(var(--bottom) + 80px); }
.pin { background: none; border: 0; }
.imagery-dim { filter: brightness(.8) contrast(1.08) saturate(.85); }
.leaflet-control-scale { margin-left: 12px !important; margin-bottom: 24px !important; }
.leaflet-control-scale-line { background: rgba(11, 18, 32, .78); color: #eef2f8; border: 2px solid #eef2f8; border-top: 0;
  font-size: 11px; font-weight: 600; padding: 1px 6px; }
.legend-row { display: flex; align-items: center; gap: 12px; padding: 8px 2px; border-bottom: 1px solid var(--line); }
.legend-row .main { flex: 1; }
.legend-row .sub { font-size: 12px; color: var(--muted); }
.leaflet-tooltip.line-label { display: none; background: rgba(11, 18, 32, .82); color: #fff; border: 0; box-shadow: none;
  font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px; white-space: nowrap; }
.leaflet-tooltip.line-label::before { display: none; }
.labels-on .leaflet-tooltip.line-label { display: block; }
/* Pin names, Google Earth style: white text with a dark edge, from zoom 16 in. */
.leaflet-tooltip.pin-label { display: none; background: none; border: 0; box-shadow: none; padding: 0 2px; color: #fff;
  font-size: 12px; font-weight: 700; white-space: nowrap;
  text-shadow: 0 0 2px #0b1220, 0 0 2px #0b1220, 0 1px 3px #0b1220; }
.leaflet-tooltip.pin-label::before { display: none; }
.pin-labels-on .leaflet-tooltip.pin-label { display: block; }
.pin-svg { filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .5)); }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--panel3); white-space: nowrap; }
.pill.good { background: rgba(34, 197, 94, .18); color: #86efac; }
.pill.warn { background: rgba(255, 176, 32, .18); color: #ffd27a; }
.pill.bad { background: rgba(239, 68, 68, .2); color: #fca5a5; }
#gpsPill { position: fixed; z-index: 1000; left: 12px; top: calc(var(--top) + 72px); background: rgba(17, 26, 43, .92);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .35); border: 0; flex-direction: column; align-items: flex-start; gap: 1px;
  border-radius: 12px; padding: 6px 10px; text-align: left; }
#gpsPill .coords { font-size: 11px; font-weight: 500; color: #c9d1dc; font-variant-numeric: tabular-nums; }
#gpsPill.good { color: #86efac; } #gpsPill.warn { color: #ffd27a; } #gpsPill.bad { color: #fca5a5; }

#fabs { position: fixed; z-index: 1000; right: 12px; top: calc(var(--top) + 72px); display: flex; flex-direction: column; gap: 10px; }
.fab { width: 46px; height: 46px; border-radius: 14px; border: 1px solid var(--line); background: rgba(17, 26, 43, .94);
  display: grid; place-items: center; box-shadow: 0 2px 12px rgba(0, 0, 0, .45); }
.fab.on { background: var(--brand); border-color: var(--brand); }

/* Bottom toolbar */
#toolbar { position: fixed; z-index: 1000; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 4px; padding: 6px 8px calc(var(--bottom) + 6px); background: rgba(11, 18, 32, .96); backdrop-filter: blur(10px);
  border-top: 1px solid rgba(255, 255, 255, .06); }
#toolbar button { border: 0; background: none; border-radius: 12px; padding: 8px 2px 6px; display: flex;
  flex-direction: column; align-items: center; gap: 4px; min-height: 58px; color: var(--muted); }
#toolbar button:active { background: var(--panel2); color: var(--text); }
#toolbar button[data-act="trace"], #toolbar button[data-act="point"] { color: var(--text); }
#toolbar button[data-act="trace"] svg, #toolbar button[data-act="point"] svg { color: var(--brand-hi); }
#toolbar span { font-size: 11px; font-weight: 600; letter-spacing: .01em; }

/* Trace / edit panel */
#panel { position: fixed; z-index: 1100; left: 0; right: 0; bottom: 0; background: var(--panel);
  border-radius: 20px 20px 0 0; border-top: 1px solid var(--line);
  padding: 14px 14px calc(var(--bottom) + 14px); box-shadow: 0 -8px 30px rgba(0, 0, 0, .5); }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.panel-head .title { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.swatch { width: 16px; height: 16px; border-radius: 4px; border: 1px solid rgba(255, 255, 255, .35); flex: none; display: inline-block; }
.swatch.line { width: 22px; height: 6px; border-radius: 3px; border: 0; }
.badge { display: inline-grid; place-items: center; border-radius: 9px; flex: none; box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .25); }
.stats { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-bottom: 10px; flex-wrap: wrap; }
.stats b { color: var(--text); font-weight: 600; }
.btn-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.btn-row.two { grid-template-columns: 1fr 1fr; }
.btn { border: 1px solid var(--line); border-radius: 12px; padding: 12px 10px; background: var(--panel2); font-weight: 600; font-size: 15px;
  min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center; }
.btn:active { background: var(--panel3); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:active { background: var(--brand-hi); }
.btn.danger { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .35); color: #fca5a5; }
.btn.on { border-color: var(--brand-hi); box-shadow: 0 0 0 1px var(--brand-hi) inset; background: rgba(37, 99, 235, .14); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; }
.toggle-row { display: flex; gap: 6px; margin-bottom: 10px; background: var(--bg); padding: 4px; border-radius: 12px; }
.toggle-row .btn { flex: 1; padding: 8px; min-height: 38px; font-size: 14px; border: 0; background: none; color: var(--muted); }
.toggle-row .btn.on { background: var(--panel3); color: var(--text); box-shadow: none; }

/* Bottom sheet */
#sheetBack { position: fixed; inset: 0; z-index: 1200; background: rgba(3, 7, 15, .55); }
#sheet { position: fixed; z-index: 1300; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto;
  background: var(--panel); border-radius: 20px 20px 0 0; border-top: 1px solid var(--line);
  padding: 6px 16px calc(var(--bottom) + 18px); }
#sheet h2 { font-size: 20px; font-weight: 700; letter-spacing: -.01em; margin: 10px 0 10px; display: flex; align-items: center; gap: 10px; }
#sheet h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 0 8px; font-weight: 700; }
.grab { width: 38px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 4px; }
.sheet-close { margin-left: auto; border: 1px solid var(--line); background: var(--panel2); border-radius: 50%; width: 34px; height: 34px;
  display: grid; place-items: center; color: var(--muted); flex: none; }
.list { display: flex; flex-direction: column; gap: 6px; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; background: var(--panel2);
  border: 1px solid transparent; text-align: left; width: 100%; }
button.item:active { background: var(--panel3); }
.item .main { flex: 1; min-width: 0; }
.item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.item.current { border-color: var(--brand-hi); }
.item.hidden-item { opacity: .55; }
.badge.file-icon { background: var(--panel3); display: inline-grid; place-items: center; flex: none; }
.folder-row { display: flex; align-items: center; gap: 12px; padding: 10px 10px; border-bottom: 1px solid var(--line);
  margin: 0; font-weight: 500; cursor: pointer; }
.folder-row input { width: 22px; height: 22px; flex: none; margin: 0; }
.folder-row .main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-row .sub { font-size: 12px; color: var(--muted); flex: none; }
.types { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.types .btn { justify-content: flex-start; text-align: left; font-weight: 500; font-size: 14px; padding: 10px; min-height: 52px; line-height: 1.2; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.note { font-size: 13px; color: var(--muted); margin: 10px 0; }
.note.warnbox { background: rgba(255, 176, 32, .1); border: 1px solid rgba(255, 176, 32, .3); color: #ffd27a; padding: 10px 12px; border-radius: 10px; }
.style-row { display: grid; grid-template-columns: 44px 1fr 34px; gap: 8px; align-items: center; }
.style-row.asset { grid-template-columns: 44px 1fr 34px; grid-template-areas: "c l b" "f f f"; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.style-row.asset > :nth-child(1) { grid-area: c; } .style-row.asset > :nth-child(2) { grid-area: l; }
.style-row.asset > .badge-slot { grid-area: b; } .style-row.asset > .fields { grid-area: f; font-size: 14px; padding: 8px 10px; }
.style-row input[type=color] { width: 44px; height: 40px; padding: 2px; border-radius: 10px; cursor: pointer; }
.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type=color] { width: 54px; height: 42px; padding: 2px; flex: none; }
.prop-row { display: grid; grid-template-columns: 1fr 1.4fr 34px; gap: 6px; align-items: center; }
.props { font-size: 13px; color: var(--muted); display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; }
.props b { color: var(--text); font-weight: 500; word-break: break-word; }
.spacer { height: 12px; }
.account-card { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(37, 99, 235, .22), rgba(37, 99, 235, .06)); border: 1px solid rgba(59, 130, 246, .35); }
.account-card .avatar { width: 42px; height: 42px; border-radius: 12px; background: var(--brand); display: grid; place-items: center; flex: none; }

#toast { position: fixed; z-index: 3000; left: 50%; transform: translateX(-50%); bottom: calc(var(--bottom) + 96px);
  max-width: 90vw; background: #f8fafc; color: #0b1220; padding: 11px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45); text-align: center; }

/* Welcome screen */
#welcome { position: fixed; inset: 0; z-index: 2500; overflow-y: auto;
  background: radial-gradient(120% 60% at 50% 0%, #17305f 0%, var(--bg) 60%);
  padding: calc(var(--top) + 40px) 22px calc(var(--bottom) + 28px); }
.welcome-inner { max-width: 440px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-name { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.brand-name small { display: block; font-size: 13px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.welcome-inner h1 { font-size: 28px; line-height: 1.15; letter-spacing: -.02em; margin: 34px 0 10px; }
.welcome-inner .lead { color: var(--muted); margin: 0 0 26px; }
.choice { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 16px; margin-bottom: 10px;
  border-radius: var(--radius); background: rgba(17, 26, 43, .85); border: 1px solid var(--line); }
.choice:active { border-color: var(--brand-hi); }
.choice .ic { width: 44px; height: 44px; border-radius: 12px; background: rgba(37, 99, 235, .18); color: var(--brand-hi);
  display: grid; place-items: center; flex: none; }
.choice b { display: block; font-size: 16px; }
.choice span { font-size: 13px; color: var(--muted); }
.welcome-foot { text-align: center; font-size: 12px; color: var(--muted); margin-top: 22px; }

/* Accuracy and safety notice: covers everything until accepted */
#legal { position: fixed; inset: 0; z-index: 2800; overflow-y: auto; background: rgba(3, 7, 15, .92);
  padding: calc(var(--top) + 24px) 18px calc(var(--bottom) + 24px); }
.legal-inner { max-width: 520px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 18px; }
.legal-inner h2 { display: flex; align-items: center; gap: 10px; font-size: 20px; margin: 0 0 10px; color: #ffd27a; }
.legal-inner h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 6px; }
.legal-body p, .legal-body li { font-size: 14px; line-height: 1.5; }
.legal-body ul { padding-left: 18px; margin: 6px 0; }
.legal-body li { margin-bottom: 6px; }

/* Map markers */
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: #3b82f6; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(59, 130, 246, .25), 0 1px 4px rgba(0, 0, 0, .6); }
.crew-dot { width: 30px; height: 30px; border-radius: 50%; background: #16a34a; border: 2.5px solid #fff; color: #fff;
  font-size: 11px; font-weight: 800; display: grid; place-items: center; box-shadow: 0 1px 5px rgba(0, 0, 0, .55); }
.vertex { width: 22px; height: 22px; border-radius: 50%; background: #fff; border: 3px solid var(--brand); }
.vertex.end { background: var(--amber); }

/* Office use on a computer: sheets and panels become a side column */
@media (min-width: 900px) {
  #sheet, #panel { left: 16px; right: auto; width: 440px; bottom: 16px; border-radius: 18px; border: 1px solid var(--line); max-height: calc(100vh - 110px); }
  #sheetBack { background: transparent; pointer-events: none; }
  #toolbar { left: 50%; right: auto; transform: translateX(-50%); bottom: 16px; width: 420px; border-radius: 18px; border: 1px solid var(--line); padding: 6px; }
  .leaflet-bottom { bottom: 0; }
}
