:root {
    --bg: #1b1e22;
    --panel: rgba(20, 23, 27, 0.78);
    --text: #e8eaed;
    --muted: #9aa0a6;
    --accent: #f5a623;
    --border: rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#app {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

.panel {
    position: fixed;
    left: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    backdrop-filter: blur(6px);
    z-index: 10;
}
.panel.top { top: 12px; justify-content: space-between; flex-wrap: wrap; }
.panel.bottom { bottom: 12px; justify-content: space-between; font-size: 12px; flex-wrap: wrap; }

.brand { font-weight: 700; letter-spacing: 0.3px; }
.brand span { color: var(--accent); font-weight: 500; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
    appearance: none;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 6px 10px;
    font: inherit;
    cursor: pointer;
}
.btn:hover { background: rgba(255, 255, 255, 0.16); }
select.btn option { background: #22262b; }

.hint { color: var(--muted); }
#status.error { color: #ff6b6b; }

#drop-overlay, #loading {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    z-index: 20;
    pointer-events: none;
}
#drop-overlay {
    background: rgba(245, 166, 35, 0.12);
    border: 3px dashed var(--accent);
    font-size: 20px;
}
#drop-overlay.active, #loading.active { display: flex; }

.spinner {
    width: 42px;
    height: 42px;
    border: 4px solid rgba(255, 255, 255, 0.15);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#pivot {
    position: fixed;
    left: -7px;
    top: -7px;
    width: 14px;
    height: 14px;
    border: 2px solid var(--accent);
    border-radius: 50%;
    background: rgba(245, 166, 35, 0.25);
    pointer-events: none;
    display: none;
    z-index: 5;
}

.speed { display: inline-flex; align-items: center; gap: 6px; cursor: default; }
.speed input { width: 90px; accent-color: var(--accent); }

/* Georeferentie-paneel */
.panel.side {
    top: 76px;
    left: auto;
    right: 12px;
    width: 340px;
    max-height: calc(100% - 150px);
    overflow: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}
.panel.side[hidden] { display: none; }
.side-head { display: flex; justify-content: space-between; align-items: center; }
.panel.side p { margin: 0; }
.muted { color: var(--muted); font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.check { display: inline-flex; gap: 4px; align-items: center; font-size: 12px; }
.btn.small { padding: 2px 6px; font-size: 11px; }
.btn:disabled { opacity: 0.4; cursor: default; }
table.gcp { width: 100%; border-collapse: collapse; font-size: 12px; }
table.gcp th { text-align: left; color: var(--muted); font-weight: 500; }
table.gcp td, table.gcp th { padding: 4px; border-bottom: 1px solid var(--border); }
table.gcp tr[data-i] { cursor: pointer; }
table.gcp tr.active { background: rgba(245, 166, 35, 0.18); }
.good { color: #6fcf97; }
.warn { color: #f2c94c; }
.bad { color: #ff6b6b; }
.result { font-size: 12px; }

.gcp-markers { position: fixed; inset: 0; pointer-events: none; z-index: 4; }
.gcp-marker {
    position: absolute;
    left: -5px;
    top: -5px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4fc3f7;
    border: 2px solid #fff;
    display: none;
}
.gcp-marker.active { background: var(--accent); }
.gcp-marker.measured {
    left: -6px;
    top: -6px;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    background: rgba(0, 230, 118, 0.35);
    border: 2px solid #00e676;
}
.gcp-marker.measured span { transform: rotate(-45deg); transform-origin: 0 0; left: 14px; top: 2px; }
.gcp-marker span {
    position: absolute;
    left: 12px;
    top: -6px;
    white-space: nowrap;
    font-size: 11px;
    background: rgba(0, 0, 0, 0.6);
    padding: 1px 4px;
    border-radius: 4px;
}

.panel.side h4 { margin: 6px 0 0; font-size: 13px; color: var(--accent); }
.panel.side code { font-size: 11px; }
.btn.off { opacity: 0.5; text-decoration: line-through; }

/* Meten */
.panel.measure {
    top: 76px;
    left: 12px;
    right: auto;
    width: 300px;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    font-size: 13px;
}
.panel.measure[hidden] { display: none; }
.panel.measure input { background: rgba(255,255,255,0.08); color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 2px 4px; }
.measure-svg { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 4; }
.measure-svg line, .measure-svg polygon { stroke-width: 2.5; }
.measure-svg circle { stroke: #000; stroke-width: 1; }
.measure-svg .m-shape.sel line, .measure-svg .m-shape.sel polygon { stroke-width: 4; }
.measure-svg text { fill: #fff; font: 600 13px system-ui, sans-serif; paint-order: stroke; stroke: #000; stroke-width: 3px; }

/* Foto-laag */
.panel.photos {
    top: 76px;
    left: auto;
    right: 12px;
    width: 380px;
    max-height: calc(100% - 150px);
    overflow: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    z-index: 11;
}
.panel.photos[hidden] { display: none; }
.ph-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.ph-card { margin: 0; cursor: pointer; font-size: 11px; }
.ph-card:hover .ph-img { outline: 2px solid var(--accent); }
.ph-img { position: relative; border-radius: 6px; overflow: hidden; background: #000; aspect-ratio: 3 / 2; }
.ph-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph-mark, .pv-mark {
    position: absolute;
    width: 14px;
    height: 14px;
    margin: -7px 0 0 -7px;
    border: 2px solid #ff1744;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8);
    pointer-events: none;
}
.pv-osd .pv-mark { position: absolute; left: 0; top: 0; margin: -12px 0 0 -12px; width: 24px; height: 24px; border-width: 3px; z-index: 2; }
.tv-canvas { position: absolute; inset: 0; display: block; cursor: grab; touch-action: none; }
.tv-canvas:active { cursor: grabbing; }
.pv-loading { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 3; }
.pv-loading[hidden] { display: none; }
.ph-card figcaption { margin-top: 3px; line-height: 1.3; word-break: break-all; }
.photo-point {
    position: fixed;
    left: -8px;
    top: -8px;
    width: 16px;
    height: 16px;
    border: 3px solid #ff1744;
    border-radius: 50%;
    pointer-events: none;
    display: none;
    z-index: 5;
}
.photo-viewer { position: fixed; inset: 0; background: #0b0c0e; z-index: 30; }
.photo-viewer[hidden] { display: none; }
.pv-bar { top: 12px; flex-wrap: wrap; }
.pv-spacer { flex: 1; }
.pv-osd { position: absolute; inset: 0; overflow: hidden; }
.pv-bar.panel { z-index: 31; }
a.btn { text-decoration: none; }

@media (max-width: 640px) {
    .panel.side { width: auto; left: 12px; }
    .hint { display: none; }
}

/* Downloads */
.panel.download {
    top: 76px;
    left: auto;
    right: 12px;
    width: 360px;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    font-size: 13px;
}
.panel.download[hidden] { display: none; }
.download-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.download-item a { color: var(--text); text-decoration: none; }
.download-group { display: flex; flex-direction: column; gap: 6px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; }
.download-group .download-item { padding-left: 4px; }
.download-progress { display: flex; align-items: center; gap: 8px; }
.download-progress[hidden] { display: none; }
.download-progress progress { flex: 1; min-width: 0; }
.download-progress span { flex: 2; font-size: 12px; }

/* Presentatie */
.present-panel { width: 380px; }
.vp-list { display: flex; flex-direction: column; gap: 8px; }
.vp-item { display: flex; gap: 8px; padding: 6px; border: 1px solid var(--border); border-radius: 8px; }
.vp-item.active { border-color: var(--accent); }
.vp-thumb { position: relative; flex: 0 0 120px; height: 68px; border-radius: 6px; overflow: hidden; background: #000; cursor: pointer; }
.vp-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.vp-thumb:hover { outline: 2px solid var(--accent); }
.vp-thumb span { position: absolute; left: 4px; top: 2px; font-weight: 700; text-shadow: 0 1px 2px #000; }
.vp-fields { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.vp-fields input, .vp-fields textarea {
    width: 100%; background: rgba(255,255,255,0.06); color: var(--text);
    border: 1px solid var(--border); border-radius: 5px; padding: 3px 5px; font: inherit; font-size: 12px; resize: vertical;
}
.vp-fields input { font-weight: 600; font-size: 13px; }

body.presenting .panel,
body.presenting #pivot,
body.presenting .gcp-markers,
body.presenting .measure-svg { display: none !important; }
.present-bar {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
    width: min(900px, calc(100% - 32px));
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; z-index: 20;
    background: var(--panel); border: 1px solid var(--border); border-radius: 12px; backdrop-filter: blur(6px);
}
.present-bar[hidden] { display: none; }
.present-text { flex: 1; min-width: 0; }
.present-title { font-size: 18px; font-weight: 700; }
.present-note { font-size: 14px; color: var(--text); opacity: 0.9; white-space: pre-wrap; margin-top: 2px; }
.present-note[hidden] { display: none; }
.present-bar .btn.on { background: var(--accent); color: #111; }
@media (max-width: 600px) {
    .present-bar { gap: 6px; padding: 8px; }
    .present-title { font-size: 15px; }
    .present-count { display: none; }
}

/* Video-opname */
.vp-video { display: flex; flex-direction: column; gap: 6px; padding: 6px; border: 1px dashed var(--border); border-radius: 8px; }
.vp-video[hidden] { display: none; }
.vp-video select, .vp-video input[type=number] { background: #22262b; color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 2px 4px; }
body.recording .panel, body.recording #pivot, body.recording .gcp-markers, body.recording .measure-svg,
body.recording .present-bar { display: none !important; }
.rec-overlay { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-start; justify-content: center; padding-top: 16px; background: transparent; cursor: wait; }
.rec-box { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; backdrop-filter: blur(6px); cursor: default; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: #e53935; animation: rec-blink 1s infinite; }
@keyframes rec-blink { 50% { opacity: 0.3; } }

/* ---------- Nieuwe indeling (0.17): bovenbalk, gereedschapsbalk, panelen ---------- */
.panel.top { gap: 10px; }
.spacer { flex: 1; }
.tbtn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 6px; cursor: pointer;
    color: var(--text); background: transparent; border: 0; font: inherit; }
.tbtn:hover { background: rgba(255,255,255,0.08); }
.tbtn:disabled { opacity: 0.4; cursor: default; }
.tbtn svg { width: 17px; height: 17px; }
.tbtn.on { background: rgba(245,166,35,0.2); }

.panel.menu { top: 64px; left: auto; right: 12px; width: 320px; flex-direction: column; align-items: stretch; gap: 2px; padding: 6px; }
.panel.menu[hidden] { display: none; }
.menu-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 6px;
    background: transparent; border: 0; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.menu-item:hover { background: rgba(255,255,255,0.08); }
.menu-item:disabled { opacity: 0.4; cursor: default; }
.menu-item select { background: #22262b; color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 2px 4px; }

.panel.rail { top: 70px; right: auto; flex-direction: column; gap: 4px; padding: 6px; }
.rbtn { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 8px; cursor: pointer;
    color: var(--text); background: transparent; border: 0; }
.rbtn:hover { background: rgba(255,255,255,0.08); }
.rbtn.on { background: var(--accent); color: #111; }
.rbtn svg { width: 22px; height: 22px; }
.rail .sep { height: 1px; align-self: stretch; background: var(--border); margin: 4px 2px; }

.panel.fly { top: 70px; left: 74px; right: auto; width: 330px; max-height: calc(100% - 140px); overflow: auto;
    flex-direction: column; align-items: stretch; gap: 2px; padding: 12px; }
.panel.fly[hidden] { display: none; }
.fly h3 { margin: 0 0 6px; font-size: 15px; }
.fly h4 { margin: 12px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.fly p { margin: 4px 0; }
.lrow { display: flex; align-items: center; gap: 8px; padding: 5px 4px; border-radius: 6px; }
.lrow:hover { background: rgba(255,255,255,0.05); }
.lrow.sub { padding-left: 34px; }
.lrow[hidden] { display: none; }
.lrow .grow { flex: 1; }
.lrow input[type=range] { width: 120px; accent-color: var(--accent); }
.fly select { background: #22262b; color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 2px 4px; font: inherit; font-size: 12px; max-width: 170px; }
.eye { width: 26px; height: 26px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 5px; background: transparent; color: var(--text); cursor: pointer; opacity: 0.35; }
.eye.on { opacity: 1; }
.eye:disabled { opacity: 0.15; cursor: default; }
.eye svg { width: 19px; height: 19px; }
.sw { appearance: none; width: 32px; height: 18px; border-radius: 9px; background: #444; position: relative; cursor: pointer; margin: 0; flex: none; }
.sw::after { content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: #ddd; transition: 0.15s; }
.sw:checked { background: var(--accent); }
.sw:checked::after { left: 16px; background: #111; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { padding: 3px 9px; font: inherit; font-size: 12px; background: transparent; color: var(--text); border: 0; cursor: pointer; }
.seg button.on { background: var(--accent); color: #111; }
.seg button:disabled { opacity: 0.35; cursor: default; }

/* meten */
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; border-radius: 8px;
    border: 1px solid var(--border); background: transparent; color: var(--text); font: inherit; font-size: 11px; cursor: pointer; }
.tool:hover { background: rgba(255,255,255,0.06); }
.tool.on { border-color: var(--accent); background: rgba(245,166,35,0.15); }
.tool svg { width: 22px; height: 22px; }
.m-list { display: flex; flex-direction: column; gap: 2px; }
.m-item { display: flex; align-items: center; gap: 6px; padding: 5px 4px; border-radius: 6px; }
.m-item:hover { background: rgba(255,255,255,0.05); }
.m-item.sel { background: rgba(245,166,35,0.12); }
.m-item.off { opacity: 0.5; }
.m-item .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.m-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.m-name { min-width: 60px; }
.m-val { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 12px; cursor: pointer; white-space: nowrap; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.m-ic { background: transparent; border: 0; color: var(--muted); cursor: pointer; padding: 0 3px; font-size: 13px; }
.m-ic:hover { color: var(--text); }
.m-rename { flex: 1; background: rgba(255,255,255,0.08); color: var(--text); border: 1px solid var(--border); border-radius: 4px; padding: 1px 4px; font: inherit; }

/* weergave-opties */
body.hide-gcp .gcp-markers { display: none; }
body.hide-gcp-names .gcp-marker span { display: none; }
body.hide-pivot #pivot { display: none !important; }
body.presenting .rail, body.presenting .fly, body.recording .rail, body.recording .fly { display: none !important; }

/* ---------- Panorama's (360°) ---------- */
.pano-hud {
    position: fixed; top: 64px; left: 50%; right: auto; width: auto; transform: translateX(-50%);
    display: flex; align-items: center; gap: 10px; padding: 6px 10px; z-index: 20;
}
.pano-hud[hidden] { display: none; }
.pano-hud .pano-name { min-width: 120px; text-align: center; }
.pano-hud .pano-op { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.pano-hud input[type=range] { width: 110px; }
.pano-card {
    position: fixed; left: auto; right: 12px; bottom: 56px; width: 270px; max-height: calc(100vh - 150px);
    display: block;   /* .panel is flex (rij): hier gewoon onder elkaar */
    overflow-y: auto; padding: 8px; z-index: 15;
}
.pano-card[hidden] { display: none; }
.pano-item {
    display: block; width: 100%; margin: 6px 0 0; padding: 0; background: none; color: var(--text);
    border: 1px solid var(--border); border-radius: 6px; overflow: hidden; cursor: pointer; text-align: left;
}
.pano-item canvas { display: block; width: 100%; height: auto; background: #000; }
.pano-item span { display: block; padding: 4px 6px; font-size: 12px; }
.pano-item span span { display: inline; padding: 0; }
.pano-item.first, .pano-item:hover { border-color: var(--accent); }
.pano-dots { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.pano-dots[hidden] { display: none; }
.pano-dot {
    position: absolute; left: 0; top: 0; pointer-events: auto; cursor: pointer; border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.9); background: rgba(245, 166, 35, 0.35);
    box-shadow: 0 0 6px rgba(0, 0, 0, 0.6); padding: 0;
}
.pano-dot:hover { background: rgba(245, 166, 35, 0.8); }
.pano-target {
    position: fixed; left: -9px; top: -9px; width: 18px; height: 18px; border-radius: 50%;
    border: 2px solid var(--accent); box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.5); pointer-events: none; z-index: 6;
}
.pano-target[hidden] { display: none; }
body.in-pano #pivot { display: none !important; }

/* ---------- Binnen lopen ---------- */
.minimap {
    left: 74px; right: auto; bottom: 56px; width: 240px; padding: 6px;
    display: block; z-index: 12;
}
.minimap[hidden] { display: none; }
.minimap canvas { display: block; width: 228px; height: 228px; border-radius: 6px; cursor: crosshair; }
.minimap .mm-label { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); margin-top: 4px; }
body.in-walk #pivot, body.in-pano .minimap { display: none !important; }
.rbtn[hidden] { display: none; }

/* Vloer vastleggen: genummerde punten */
.floor-dot {
    position: fixed; left: -11px; top: -11px; width: 22px; height: 22px; border-radius: 50%;
    background: var(--accent); color: #111; font: 700 12px/22px system-ui, sans-serif; text-align: center;
    border: 2px solid #fff; box-shadow: 0 0 4px rgba(0,0,0,0.6); pointer-events: none; z-index: 8;
}
.lrow[hidden] { display: none; }
