:root {
  /* DK Drones / DKD-BBNL colours (as the DK Drones portal and the DKD Field phone app):
     navy top bar, orange main buttons, green focus and accents */
  --dk-navy: #123677;
  --dk-orange: #f56400;
  --dk-green: #54cc08;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #e2e6ea;
  --text: #18212b;
  --muted: #64707d;
  --primary: var(--dk-orange);
  --primary-hover: #d95600;
  --primary-soft: #fff1e6;
  --link: var(--dk-navy);
  --accent: var(--dk-green);
  --danger: #c2410c;
  --danger-soft: #fdeee6;
  --warn: #b45309;
  --info: #1d4ed8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);
  --topbar-h: 56px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1418;
    --panel: #172027;
    --border: #26323c;
    --text: #e6edf3;
    --muted: #94a3b0;
    --primary: #ff7a1f;
    --primary-hover: #ff9447;
    --primary-soft: #3a2010;
    --link: #8fb0f0;
    --accent: var(--dk-green);
    --danger: #fb923c;
    --danger-soft: #3a2116;
    --warn: #fbbf24;
    --info: #60a5fa;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
code, pre { font-family: Consolas, "Cascadia Mono", monospace; }

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 1000; height: var(--topbar-h);
  display: flex; align-items: center; gap: 24px; padding: 0 20px;
  background: var(--dk-navy); color: #fff; border-bottom: 2px solid var(--dk-green);
}
/* DK Drones logo on a white tile: its lettering is navy */
.brand-logo { display: block; height: 38px; padding: 3px 8px; background: #fff; border-radius: 6px; }
.brand-logo img { height: 100%; width: auto; display: block; }
.brand-sub { font-weight: 600; font-size: 13px; letter-spacing: .6px; color: rgba(255, 255, 255, .85); white-space: nowrap; }
@keyframes dk-logo-glow {
  0%, 86%, 100% { filter: drop-shadow(0 0 0 rgba(245, 100, 0, 0)); }
  91% { filter: drop-shadow(0 0 5px rgba(245, 100, 0, .8)) drop-shadow(0 0 14px rgba(245, 100, 0, .4)); }
}
.brand-logo { animation: dk-logo-glow 12s ease-in-out 2s infinite; }
@media (prefers-reduced-motion: reduce) { .brand-logo { animation: none; } }
.topbar .nav a { color: rgba(255, 255, 255, .75); }
.topbar .nav a:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.topbar .nav a.active { color: #fff; background: rgba(255, 255, 255, .14); box-shadow: inset 0 -2px 0 var(--dk-orange); }
.topbar .user { color: rgba(255, 255, 255, .8); }
.topbar .user .btn { background: transparent; color: #fff; border-color: rgba(255, 255, 255, .35); }
.topbar .user .btn:hover { background: rgba(255, 255, 255, .12); }
.topbar .user a { color: #fff; }
.topbar select { background: #fff; color: #18212b; }
.topbar[hidden] { display: none; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text); letter-spacing: .3px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--primary);
  -webkit-mask: none; position: relative; }
.brand-mark::after { content: ""; position: absolute; inset: 6px 5px 6px 5px;
  background: #fff; clip-path: polygon(0 100%, 35% 15%, 60% 65%, 75% 40%, 100% 100%); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.nav a.active { color: var(--primary); background: var(--primary-soft); }
.user { display: flex; align-items: center; gap: 10px; color: var(--muted); }

/* ---- Layout ---- */
main { min-height: calc(100% - var(--topbar-h)); }
.page { max-width: 1180px; margin: 0 auto; padding: 24px 20px 48px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .spacer { flex: 1; }
.crumbs { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.panel-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h2 { color: var(--text); margin-bottom: 6px; }

/* ---- Buttons & forms ---- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--panel); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 600; margin-bottom: 5px; }
input[type=text], input[type=password], input[type=url], input[type=number], select, textarea {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--panel); color: var(--text); font: inherit;
}
textarea { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgb(84 204 8 / .6); outline-offset: -1px; }
.checkbox { display: flex; align-items: center; gap: 8px; }
.form-error { color: var(--danger); margin: 0 0 12px; min-height: 0; }
.form-error:empty { display: none; }

/* ---- Auth ---- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; padding: 28px; }
.auth-card .brand { justify-content: center; font-size: 20px; margin-bottom: 6px; }
.auth-card p.lead { text-align: center; color: var(--muted); margin: 0 0 22px; }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
td.actions { text-align: right; white-space: nowrap; }
.task-row a.task-name { font-weight: 600; color: var(--text); }

/* ---- Status ---- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px;
  font-size: 12px; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.completed { background: #e7f8dd; color: #2f7a07; }
.badge.failed { background: var(--danger-soft); color: var(--danger); }
.badge.running, .badge.downloading, .badge.sending { color: var(--info); }
.badge.queued, .badge.queued_upload, .badge.created { color: var(--warn); }
.badge.online { background: #e7f8dd; color: #2f7a07; }
.badge.offline { background: var(--danger-soft); color: var(--danger); }
.progress { height: 6px; border-radius: 99px; background: var(--bg); overflow: hidden; min-width: 80px; }
.progress > div { height: 100%; background: var(--primary); transition: width .4s; }
.status-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; max-width: 220px; }
.status-cell .progress { width: 100%; }

/* ---- Task page ---- */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.console { margin: 0; height: 420px; overflow: auto; padding: 12px 14px; background: #0d1117; color: #c9d1d9;
  font-size: 12px; line-height: 1.45; border-radius: 0 0 var(--radius) var(--radius); white-space: pre-wrap; word-break: break-all; }
.downloads { list-style: none; margin: 0; padding: 0; }
.downloads li { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); }
.downloads li:last-child { border-bottom: none; }
.error-box { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; white-space: pre-wrap; }

/* ---- Upload ---- */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 36px 16px; text-align: center;
  color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone.over, .dropzone:hover { border-color: var(--primary); background: var(--primary-soft); }
.dropzone strong { color: var(--text); display: block; font-size: 15px; margin-bottom: 4px; }
.file-summary { margin-top: 12px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 16px; }
.preset { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; cursor: pointer; background: var(--panel); text-align: left; font: inherit; color: var(--text); }
.preset:hover { border-color: var(--primary); }
.preset.selected { border-color: var(--primary); background: var(--primary-soft); }
.preset b { display: block; margin-bottom: 2px; }
.preset span { color: var(--muted); font-size: 12px; }
.options-list { max-height: 420px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.option-row { display: grid; grid-template-columns: 200px 1fr; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--border); align-items: center; }
.option-row:last-child { border-bottom: none; }
.option-row.changed { background: var(--primary-soft); }
.option-row .name { font-family: Consolas, monospace; font-size: 12.5px; font-weight: 600; }
.option-row .help { grid-column: 1 / -1; color: var(--muted); font-size: 12px; margin-top: -4px; }
.option-row input, .option-row select { height: 30px; }

/* ---- Map & 3D ---- */
.viewer { position: relative; height: calc(100vh - var(--topbar-h)); }
.viewer #map, .viewer canvas { width: 100%; height: 100%; display: block; }
.viewer-panel { position: absolute; top: 12px; left: 56px; z-index: 900; width: 270px; padding: 12px 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,.18); }
.viewer-panel.right { left: auto; right: 12px; }
.viewer-panel h3 { margin-bottom: 8px; }
.viewer-panel .layer { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.viewer-panel .layer input[type=range] { width: 90px; margin-left: auto; }
.legend-bar { height: 10px; border-radius: 4px; margin-top: 6px;
  background: linear-gradient(90deg, #440154, #3b528b, #21918c, #5ec962, #fde725); }
.legend-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.viewer-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; font-size: 15px; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 10px; }
.seg button { flex: 1; border: none; background: var(--panel); color: var(--text); font: inherit; padding: 6px; cursor: pointer; }
.seg button.active { background: var(--primary); color: #fff; }
.seg button:disabled { color: var(--muted); cursor: not-allowed; }

/* ---- Dialog & toasts ---- */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; width: min(440px, 92vw);
  background: var(--panel); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10, 15, 20, .45); }
dialog form { padding: 20px; }
dialog h2 { margin-bottom: 16px; }
dialog .btn-row { justify-content: flex-end; margin-top: 6px; }
.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 5000; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; animation: pop .2s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---- Ground control ---- */
.gcp-page { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h)); }
.gcp-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px 10px; flex-wrap: wrap; }
.gcp-head .spacer { flex: 1; }
.gcp-info { display: flex; gap: 22px; align-items: center; flex-wrap: wrap; padding: 0 20px 12px; color: var(--muted); }
.gcp-info b { color: var(--text); }
.gcp-info .ok b { color: var(--primary); }
.gcp-info .warn b { color: var(--warn); }
.gcp-info label.inline { display: flex; gap: 8px; align-items: center; }
.gcp-info select { height: 30px; width: auto; }
.gcp-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 260px 210px 1fr; border-top: 1px solid var(--border); }
.gcp-points, .gcp-thumbs { overflow: auto; border-right: 1px solid var(--border); background: var(--panel); }
.gcp-point { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 10px 12px; border: none;
  border-bottom: 1px solid var(--border); background: none; color: var(--text); font: inherit; cursor: pointer; }
.gcp-point > span:last-child { display: flex; flex-direction: column; min-width: 0; }
.gcp-point:hover { background: var(--bg); }
.gcp-point.selected { background: var(--primary-soft); }
.gcp-count { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12px;
  font-weight: 700; background: var(--bg); color: var(--muted); }
.gcp-count.warn { background: #fef3c7; color: #92400e; }
.gcp-count.ok { background: var(--primary); color: #fff; }
.gcp-thumb { position: relative; display: block; width: calc(100% - 16px); margin: 0 8px 8px; padding: 4px; border: 2px solid transparent;
  border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; cursor: pointer; text-align: left; }
.gcp-thumb.selected { border-color: var(--primary); }
.gcp-thumb img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 5px; background: var(--border); image-orientation: none; }
.gcp-thumb span.small { display: block; padding: 3px 2px 0; word-break: break-all; }
.gcp-thumb .tick { position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; border-radius: 50%; background: var(--primary);
  color: #fff; display: grid; place-items: center; font-weight: 700; }
.gcp-viewer { position: relative; min-width: 0; display: flex; flex-direction: column; }
.gcp-viewer #img-map { flex: 1; background: #111; cursor: crosshair; }
.gcp-viewer-bar { display: flex; align-items: center; gap: 12px; justify-content: space-between; padding: 8px 14px;
  background: var(--panel); border-top: 1px solid var(--border); min-height: 44px; }
.gcp-pin { position: relative; }
.gcp-pin span { position: absolute; inset: 0; border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px #000; }
.gcp-pin span::before, .gcp-pin span::after { content: ""; position: absolute; background: #fff; box-shadow: 0 0 0 1px #000; }
.gcp-pin span::before { left: 50%; top: -6px; bottom: -6px; width: 1px; }
.gcp-pin span::after { top: 50%; left: -6px; right: -6px; height: 1px; }
.gcp-pin em { position: absolute; left: 30px; top: 3px; font-style: normal; font-weight: 700; font-size: 12px; color: #fff;
  text-shadow: 0 0 3px #000, 0 0 3px #000; white-space: nowrap; }
.gcp-pin.active span { border-color: #f97316; }
.gcp-pin.active em { color: #fdba74; }
@media (max-width: 900px) { .gcp-body { grid-template-columns: 1fr; grid-auto-rows: minmax(200px, auto); } }

/* ---- Map tools ---- */
.tools-panel { width: 340px; max-height: calc(100% - 24px); overflow: auto; }
.tool-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
.tool-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; font-size: 11.5px; cursor: pointer; }
.tool-btn span { font-size: 17px; line-height: 1; }
.tool-btn:hover { border-color: var(--primary); }
.tool-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.tool-btn:disabled { opacity: .45; cursor: not-allowed; }
.tool-body:empty { display: none; }
.tool-body { border-top: 1px solid var(--border); padding-top: 8px; }
.tool-kv { grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 13px; margin-bottom: 6px; }
.tool-form { display: grid; gap: 6px; margin-bottom: 8px; }
.tool-form label { display: grid; gap: 3px; font-size: 12px; font-weight: 600; }
.tool-form label[hidden] { display: none; }
.tool-form input, .tool-form select, .tools-panel select { height: 30px; }
.leaflet-container.drawing { cursor: crosshair; }
.chart { margin: 6px 0; }
.chart svg { width: 100%; height: 190px; display: block; background: var(--bg); border-radius: 6px; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .tick { font-size: 10px; fill: var(--muted); }
.chart .axis { font-size: 10.5px; fill: var(--muted); }
.chart .cursor { stroke: #1d4ed8; stroke-width: 1; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.chart-legend i { display: inline-block; width: 12px; height: 3px; margin-right: 4px; vertical-align: middle; }
.chart-readout { color: var(--text); width: 100%; min-height: 15px; }

/* ---- Tools panel tabs, features, AI analytics ---- */
.panel-tabs { margin-bottom: 8px; }
.panel-tabs button { font-size: 12.5px; padding: 5px 4px; }
.tool-h { margin: 12px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.tool-form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.feat-add { align-items: center; }
.feat-cats .layer { display: flex; align-items: center; gap: 6px; padding: 2px 0; font-size: 13px; }
.feat-cats .layer span:first-of-type { flex: 1; }
.feat-cats .btn.ghost { height: 22px; padding: 0 6px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.feat-list { max-height: 220px; overflow: auto; }
table.mini { width: 100%; font-size: 12px; }
table.mini th, table.mini td { padding: 4px 6px; }
table.mini tr[data-fid] { cursor: pointer; }
table.mini tr[data-fid]:hover td { background: var(--primary-soft); }
.ch-label { font: 600 11px Arial, sans-serif; color: #1e3a8a; background: rgba(255,255,255,.85); padding: 1px 4px; border-radius: 3px;
  white-space: nowrap; border: 1px solid #93c5fd; }
.feature-popup .kv { margin: 6px 0; }
.ai-card { border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; margin-bottom: 8px; }
.ai-card summary { cursor: pointer; font-weight: 600; padding: 2px 0; }
.ai-card .tool-form { margin-top: 8px; }
.ai-result { border: 1px solid var(--primary); background: var(--primary-soft); border-radius: 8px; padding: 8px 10px; margin: 8px 0; }
.ai-hist { display: flex; gap: 6px; justify-content: space-between; align-items: flex-start; padding: 6px 0; border-bottom: 1px solid var(--border); }
.ai-hist .badge { font-size: 11px; }
.sev { font-weight: 700; } .sev.High { color: #dc2626; } .sev.Medium { color: #ea580c; } .sev.Low { color: #ca8a04; }
.tools-panel .checkbox { font-weight: 400; font-size: 12.5px; }
.tool-form label.checkbox { display: flex; align-items: center; gap: 6px; font-weight: 400; }
.tool-form input[type=checkbox] { height: auto; width: auto; margin: 0; }

/* ---- Corridor dashboard ---- */
:root { --strip-nodata: repeating-linear-gradient(45deg, #d1d5db 0 3px, #f3f4f6 3px 6px); }
.cd { height: calc(100vh - var(--topbar-h)); display: flex; flex-direction: column; overflow: hidden; }
.cd-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.cd-bar .spacer { flex: 1; }
.cd-bar select, .cd-bar input, .cmp-head select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; }
.cd-range { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.cd-range input { width: 80px; }
.cd-bar select, .cmp-head select { width: auto; max-width: 360px; height: auto; }
.cd-bar input, .cd-search input, .cmp-search input { height: auto; }
.cd .panel-tabs { margin-bottom: 8px; }
.cd-title { padding: 6px 14px; font-size: 13px; background: var(--panel); border-bottom: 1px solid var(--border); }
.cd-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--panel); border-bottom: 1px solid var(--border); }
.cd-kpis:empty { display: none; }
.kpi { padding: 8px 12px; border-right: 1px solid var(--border); text-align: center; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-value { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 22px; font-weight: 700; }
.kpi-value .ico { color: var(--primary); }
.cd-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 250px 1fr 420px; }
.cd-left, .cd-right { background: var(--panel); overflow-y: auto; padding: 10px 12px; min-height: 0; }
.cd-left { border-right: 1px solid var(--border); }
.cd-right { border-left: 1px solid var(--border); }
.cd-map { position: relative; min-height: 0; }
.cd-map #cd-map { position: absolute; inset: 0; }
.cd-search { position: absolute; top: 10px; right: 10px; z-index: 500; display: flex; gap: 4px; background: var(--panel); padding: 5px; border-radius: 8px; box-shadow: var(--shadow); }
.cd-search input { width: 190px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
.cd-progress { position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%); z-index: 500; background: var(--panel); padding: 6px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; }
.cd-progress[hidden] { display: none; }
.cd-kv { grid-template-columns: 90px 1fr; font-size: 13px; }
.cd-insps { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.cd-insps a { display: flex; flex-direction: column; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; color: var(--text); }
.cd-insps a.active { border-color: var(--primary); background: var(--primary-soft); }
.cd-insps a:hover { text-decoration: none; border-color: var(--primary); }
.cd-left input[type=search] { width: 100%; padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); margin-bottom: 8px; }
.cd-lgroup { margin-bottom: 10px; }
.cd-layer { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 13px; }
.cd-layer label { flex: 1; }
.cd-layer[hidden] { display: none; }
.cd-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.cd-table { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 12px; overflow: hidden; }
.cd-table header { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: #1f2937; color: #fff; }
.cd-table header h3 { font-size: 14px; }
.cd-table header .spacer { flex: 1; }
.cd-table header .btn { color: #fff; border-color: transparent; background: transparent; }
.cd-table table { width: 100%; border-collapse: collapse; font-size: 13px; }
.cd-table th { text-align: left; background: var(--bg); font-weight: 600; padding: 5px 6px; font-size: 11px; white-space: normal; }
.cd-table td { padding: 5px 6px; border-top: 1px solid var(--border); }
.cd-table td:not(:first-child), .cd-table th:not(:first-child) { text-align: right; }
.cd-table tr.click { cursor: pointer; }
.cd-table tr.click:hover td { background: var(--primary-soft); }
.cd-note { padding: 4px 10px; }
.cd-chart { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.cd-chart[hidden] { display: none; }
.donuts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.donuts figure { margin: 0; text-align: center; }
.donuts figcaption { font-size: 12px; font-weight: 600; }
.donuts i, .strip-legend i { display: inline-block; width: 10px; height: 10px; margin-right: 4px; border: 1px solid #9ca3af; vertical-align: middle; }
.cd-drill-head { display: flex; align-items: center; gap: 8px; }
.cd-cards { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.cd-card { display: grid; grid-template-columns: 150px 1fr; gap: 8px; border: 1px solid var(--border); border-radius: 8px; padding: 6px; font-size: 12px; cursor: pointer; }
.cd-card:hover { border-color: var(--primary); }
.cd-thumb { width: 150px; height: 110px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.cd-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cd-thumb.none { display: none; }
.cd-report { display: flex; flex-direction: column; gap: 8px; }
.cd-rep-head, .cd-rep-item { border: 1px dashed var(--border); border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.cd-rep-head .btn-row, .cd-rep-item .btn-row { justify-content: flex-start; margin: 0; }
.ch-mark { font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 0 3px #000, 0 0 2px #000; white-space: nowrap; transform: translate(6px, -8px); }
.ch-mark.major { color: #fde047; font-size: 12px; }
.ch-pin span { display: inline-block; transform: translate(-50%, -130%); background: #dc2626; color: #fff; font-weight: 700; padding: 2px 8px; border-radius: 10px; white-space: nowrap; box-shadow: 0 1px 4px rgba(0, 0, 0, .4); }
.ico { flex: none; }

/* Strip chart */
.strip-dialog { width: 96vw; max-width: 96vw; height: 92vh; max-height: 92vh; padding: 0; display: flex; flex-direction: column; }
.strip-dialog:not([open]) { display: none; }
.strip-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.strip-head .spacer { flex: 1; }
.strip-scroll { flex: 1; overflow: auto; padding: 10px; }
table.strip { border-collapse: collapse; font-size: 11px; width: auto; }
table.strip td { width: 26px; min-width: 26px; height: 24px; border: 1px solid #d1d5db; text-align: center; font-weight: 700; }
table.strip td.click { cursor: pointer; }
table.strip td.click:hover { outline: 2px solid #0ea5e9; outline-offset: -2px; }
table.strip th { text-transform: none; letter-spacing: 0; font-size: 11px; background: #1f2937; color: #fff; padding: 2px 6px; border: 1px solid #374151; font-weight: 600; white-space: nowrap; }
table.strip th.strip-label { background: #6b7280; }
table.strip tr.strip-ch th { background: var(--panel); color: var(--text); border-color: #d1d5db; font-weight: 500; }
table.strip tr.strip-ch th span { writing-mode: vertical-rl; transform: rotate(180deg); display: inline-block; }
.strip-legend { display: flex; gap: 14px; flex-wrap: wrap; padding: 8px 14px; font-size: 12px; }

/* Photos */
.photo-main { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #111; }
.photo-main img { max-width: 100%; max-height: calc(100% - 26px); object-fit: contain; }
.photo-cap { color: #fff; font-size: 13px; padding: 4px; }
.photo-strip { display: flex; gap: 6px; overflow-x: auto; padding: 8px; border-top: 1px solid var(--border); }
.photo-strip button { flex: none; border: 2px solid transparent; background: none; padding: 0; cursor: pointer; color: var(--text); font-size: 11px; }
.photo-strip button.active { border-color: var(--primary); }
.photo-strip img { width: 150px; height: 100px; object-fit: cover; display: block; }

/* Compare */
.cmp-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: var(--border); }
.cmp-pane { display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.cmp-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px; }
.cmp-map { flex: 1; min-height: 0; }
.cmp-search { display: flex; gap: 4px; }
.cmp-search input { width: 190px; }

@media (max-width: 1100px) {
  .cd { height: auto; overflow: visible; }
  .cd-body { grid-template-columns: 1fr; }
  .cd-map { height: 60vh; }
  .cmp-body { grid-template-columns: 1fr; }
  .cmp-map { height: 45vh; }
}

/* ---- Recent changes popover ---- */
.hist-btn { padding: 4px 7px; line-height: 0; color: var(--muted); }
.hist-btn:hover { color: var(--primary); }
.hist-pop { position: fixed; z-index: 3000; background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 12px 32px rgba(0, 0, 0, .18); display: flex; flex-direction: column; overflow: hidden; }
.hist-head { padding: 10px 14px; font-size: 12px; font-weight: 700; letter-spacing: .4px; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hist-body { overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.hist-item { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--bg); }
.hist-top { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.hist-top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-when { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.hist-act { font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 2px 7px; border-radius: 5px; background: #e0e7ff; color: #3730a3; }
.hist-act.create { background: #dcfce7; color: #166534; }
.hist-act.delete { background: #fee2e2; color: #991b1b; }
.hist-lines { margin-top: 6px; font-family: Consolas, "Cascadia Mono", monospace; font-size: 12px; line-height: 1.6; color: var(--text); word-break: break-word; }
.cd-title .hist-btn { padding: 1px 5px; vertical-align: middle; margin-left: 4px; }

/* ---- Authorisation matrix and audit log ---- */
.perm-dialog { width: min(820px, 96vw); }
.perm-dialog form { max-height: 90vh; display: flex; flex-direction: column; }
.perm-note { background: var(--primary-soft); border-radius: 8px; padding: 8px 12px; margin-bottom: 10px; font-size: 13px; }
.auto-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 3px 0; }
.perm-head { display: flex; align-items: center; gap: 8px; margin: 4px 0 8px; flex-wrap: wrap; }
.perm-head .spacer { flex: 1; }
.perm-scroll { overflow: auto; border: 1px solid var(--border); border-radius: 8px; min-height: 120px; }
.perm-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.perm-table th { position: sticky; top: 0; background: var(--bg); padding: 6px 8px; font-size: 12px; text-align: center; z-index: 1; }
.perm-table th:first-child { text-align: left; }
.perm-table td { padding: 5px 8px; border-top: 1px solid var(--border); vertical-align: middle; }
.perm-table td.c { text-align: center; }
.perm-table tr.perm-group td { background: var(--bg); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.perm-table input[type=radio] { width: 16px; height: 16px; accent-color: var(--primary); }
.al-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.al-filters label { display: flex; flex-direction: column; font-size: 12px; font-weight: 600; color: var(--muted); gap: 3px; }
.al-filters label.grow { flex: 1; min-width: 200px; }
.al-filters input, .al-filters select { height: 34px; padding: 0 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; width: auto; }
.al-filters label.grow input { width: 100%; }
.al-count { padding: 8px 14px; }
.al-table-wrap { overflow-x: auto; }
.al-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.al-table th { text-align: left; padding: 6px 10px; background: var(--bg); font-size: 12px; }
.al-table td { padding: 7px 10px; border-top: 1px solid var(--border); vertical-align: top; }
.al-table td.nowrap { white-space: nowrap; }
.al-changes { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12px; line-height: 1.55; max-width: 520px; word-break: break-word; }
.al-changes summary { cursor: pointer; color: var(--primary); font-family: inherit; }

/* 3D viewer page (the viewer itself lives in a shadow root with its own styles) */
.v3d-page { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h)); }
.v3d-bar { display: flex; align-items: center; gap: 12px; padding: 6px 14px; border-bottom: 1px solid var(--border); background: var(--panel); }
.v3d-bar .spacer { flex: 1; }
.v3d-host { flex: 1; min-height: 0; position: relative; }
.cmp-map { position: relative; }
.cmp-3d { position: absolute; inset: 0; }
.cd-bar .seg { margin-bottom: 0; }
.cd-bar .seg button { padding: 4px 12px; white-space: nowrap; }

/* Client dashboard */
.client { height: calc(100vh - var(--topbar-h)); display: flex; flex-direction: column; overflow: hidden; }
.client-tabs { display: flex; gap: 2px; margin-left: 8px; flex-wrap: wrap; }
.client-tabs a { padding: 5px 12px; border-radius: 6px; color: var(--text); text-decoration: none; }
.client-tabs a:hover { background: var(--bg); }
.client-tabs a.active { background: var(--primary); color: #fff; }
.client-tabs a.off { opacity: .45; }
.client-body { flex: 1; min-height: 0; position: relative; overflow: auto; }
.client-body > .viewer, .client-body > .cd, .client-body > .v3d-page { height: 100%; }
.client-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.client-card { display: block; padding: 16px; color: inherit; text-decoration: none; }
.client-card:hover { border-color: var(--primary); }
.client-card h2 { margin: 0 0 4px; }
.client-stats { display: flex; gap: 10px; align-items: center; margin: 10px 0 6px; }
.client-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.client-kpis .kpi { padding: 12px 14px; margin: 0; }
.client-kpis .kpi b { font-size: 22px; display: block; margin-top: 4px; }
.client-overview td.num, .client-overview th.num { text-align: right; }
.client-overview tr.sel td { background: var(--bg); }
.client-overview .grid-2 { align-items: start; }
.client-overview .grid-2 > .panel { margin-top: 0; }

/* ---- View-only share page ---- */
body.share-page { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.share-bar { position: static; gap: 14px; }
.share-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.share-title b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.share-badge { background: #fef3c7; color: #92400e; }
.share-badge::before { display: none; }
.share-bar select { width: auto; max-width: 360px; height: 34px; }
.share-bar .seg { margin: 0; }
.share-main { flex: 1; min-height: 0; position: relative; }
.share-view, .share-map, .share-3d { position: absolute; inset: 0; }
.share-msg { max-width: 520px; margin: 80px auto; text-align: center; padding: 0 16px; }
.share-msg[hidden] { display: none; }
.share-foot { padding: 4px 14px; border-top: 1px solid var(--border); background: var(--panel); }
.hist-act.viewed { background: #fef3c7; color: #92400e; }
.share-url { display: flex; gap: 6px; }
.share-url input { flex: 1; font-family: Consolas, monospace; font-size: 12px; }
.share-dialog { width: min(560px, 94vw); } .share-dialog .btn-row .spacer { flex: 1; }
.share-bar .seg button { white-space: nowrap; padding: 6px 14px; }

/* ---- Topographic symbols and map legend (topo.js) ---- */
.topo-icon { background: none; border: 0; filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, .55)); }
.topo-icon svg { display: block; }
.topo-sym { display: inline-flex; width: 18px; justify-content: center; }
.topo-legend { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-top: 3px solid var(--dk-orange);
  border-radius: 8px; box-shadow: var(--shadow); font-size: 12px; min-width: 150px; max-width: 230px; max-height: 45vh; overflow: auto; }
.topo-legend-head { all: unset; box-sizing: border-box; display: flex; justify-content: space-between; width: 100%; padding: 6px 10px;
  cursor: pointer; color: var(--primary); }
.topo-legend ul { list-style: none; margin: 0; padding: 0 10px 8px; }
.topo-legend li { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.topo-legend li span { flex: 1; }
.topo-legend li em { font-style: normal; color: var(--muted); }
.auth-card .auth-brand { flex-direction: column; gap: 6px; color: var(--dk-navy); }
.auth-card .auth-brand img { width: 240px; max-width: 100%; height: auto; }
.auth-card .auth-brand span { font-size: 14px; letter-spacing: 1.5px; color: var(--muted); }
.topo-legend-group { padding: 4px 10px 2px; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; color: var(--dk-navy); }
@media (prefers-color-scheme: dark) { .topo-legend-group { color: #8fb0f0; } }

/* Inside the phone app's web view: the app shows its own title bar */
body.in-app .topbar { display: none; }

/* ---- Phones (and the phone app's in-app pages) ---- */
@media (max-width: 720px) {
  :root { --topbar-h: 52px; }
  .topbar { gap: 10px; padding: 0 10px; }
  .brand-sub { display: none; }
  .brand-logo { height: 32px; padding: 2px 6px; }
  .nav { overflow-x: auto; scrollbar-width: none; min-width: 0; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; padding: 6px 9px; }
  .topbar .user > span, .topbar .user [data-act=password] { display: none; }
  .page { padding: 14px 12px 32px; }
  .page-head h1 { font-size: 20px; }
  .panel-head { flex-wrap: wrap; padding: 12px; gap: 8px; }
  .panel-head > div:first-child { flex: 1 1 100%; }
  .panel-head .spacer { display: none; }
  th, td { padding: 8px 10px; }
  /* Dashboard: each task as a small card: name and status, then its buttons */
  section[data-project] thead { display: none; }
  section[data-project] table, section[data-project] tbody { display: block; }
  .task-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
  .task-row td { border: 0; padding: 0; }
  .task-row td.actions { grid-column: 1 / -1; text-align: left; white-space: normal; }
  /* Other wide tables scroll sideways instead of squeezing their columns */
  .panel > table:not(.mini), .panel-body > table:not(.mini) { display: block; overflow-x: auto; }
  /* Map / 3D pages: the panels sit at the top and bottom instead of covering the map */
  .viewer-panel { left: 54px; right: 8px; top: 8px; width: auto; max-height: 34vh; overflow: auto; }
  .viewer-panel.right { left: 8px; top: auto; bottom: 8px; }
  .viewer .leaflet-bottom.leaflet-left { bottom: calc(34vh + 16px); }
}
body.in-app .viewer { height: 100vh; }
.nav a { white-space: nowrap; }
.nav { min-width: 0; overflow-x: auto; scrollbar-width: none; }
.topbar .user { flex-shrink: 0; }
@media (max-width: 1150px) {
  .topbar .user > span, .brand-sub { display: none; }
}

/* GCP / check point role switch (views/gcp.js) */
.gcp-point .gcp-role { margin-left: auto; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 10px;
  background: var(--dk-navy); color: #fff; cursor: pointer; flex-shrink: 0; }
.gcp-point .gcp-role.check { background: var(--dk-orange); }
.gcp-count.check { background: var(--dk-orange); color: #fff; }
/* Check points on the map (views/checkpoints.js) */
.checkpoints .cp-list { margin-top: 6px; max-height: 40vh; overflow: auto; }
.checkpoints .cp-row { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 5px 0; border-top: 1px solid var(--border); }
/* Accuracy report table on the task page */
.small-table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.small-table th, .small-table td { text-align: right; padding: 4px 6px; border-bottom: 1px solid var(--border); white-space: nowrap; }
#accuracy { overflow-x: auto; }
.small-table th:first-child, .small-table td:first-child { text-align: left; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
/* Photo check before upload (photocheck.js) */
.photo-check { margin-top: 10px; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }
.photo-check .pc-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.photo-check .pc-row > span:first-child { width: 18px; height: 18px; border-radius: 50%; display: inline-flex; flex-shrink: 0;
  align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; background: var(--dk-green); }
.photo-check .pc-row.warn > span:first-child { background: var(--dk-orange); }
.photo-check .pc-row > span:nth-child(2) { flex: 1; }
/* Automatic GCP marks (gcpauto.js): orange until checked */
.gcp-pin.auto span { border-color: var(--dk-orange); border-style: dashed; }
.gcp-pin.auto span::before, .gcp-pin.auto span::after { background: var(--dk-orange); }
/* Office PC health alerts (app.js refreshAlerts) */
.alerts-bar .alert { padding: 8px 20px; font-size: 13px; color: #fff; background: #b42318; display: flex; gap: 12px; }
.alerts-bar .alert.warning { background: var(--dk-orange); }
.alerts-bar .alert.info { background: var(--dk-navy); }
.alerts-bar .alert a { color: #fff; text-decoration: underline; margin-left: auto; white-space: nowrap; }
/* Stage-by-stage progress on the task page (ProcessingStages) */
.stages { list-style: none; margin: 12px 0 0; padding: 0; font-size: 13px; }
.stages li { display: flex; align-items: center; gap: 8px; padding: 3px 0; color: var(--muted); }
.stages .dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border); display: inline-flex; flex-shrink: 0;
  align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: #fff; }
.stages li.done { color: var(--text); }
.stages li.done .dot { background: var(--dk-green); border-color: var(--dk-green); }
.stages li.active { color: var(--text); font-weight: 600; }
.stages li.active .dot { border-color: var(--dk-orange); border-top-color: transparent; animation: stage-spin 1s linear infinite; }
.stages li.failed .dot { background: #b42318; border-color: #b42318; }
@keyframes stage-spin { to { transform: rotate(360deg); } }
/* Health alerts on Administration */
.pc-alerts { list-style: none; margin: 0; padding: 10px 20px 0; display: grid; gap: 6px; }
.pc-alerts li { padding: 7px 10px; border-radius: 6px; font-size: 13px; border-left: 4px solid #b42318; background: #fdecea; }
.pc-alerts li.warning { border-color: var(--dk-orange); background: #fff3e8; }
.pc-alerts li.info { border-color: var(--dk-navy); background: var(--primary-soft); }
