/* Fernwork One — viewer frame of the geo / 3D viewers (DXF Drawing, Shapefile, Point Cloud, IFC Model, STL / OBJ).
   Markup comes from tools/js/viewers/geo-frame.js; everything is scoped to .gv so the document viewers on the same
   page are untouched. Kit components (fw-framebar, fw-seg, fw-zoom, fw-inspector …) provide the base look. */

.gv { position: relative; --gv-hl: #ffd400; }
.gv .hidden { display: none !important; }

/* ───────── empty state (dropzone) ───────── */
.gv-empty { display: grid; min-height: min(62vh, 520px); }
.gv-empty .dropzone {
  display: grid; place-content: center; justify-items: center; gap: 6px; min-height: inherit;
  border-radius: var(--radius-md); background: var(--surface-1);
}
.gv-empty .dropzone-icon { width: 36px; height: 36px; color: var(--text-3); }
.gv-empty .dropzone-text { font-size: var(--text-md); color: var(--text-1); }
.gv-empty .dropzone-hint { color: var(--text-3); font-size: var(--text-sm); }
/* Phones: a compact card instead of a box that filled the screen (there is nothing to drag onto it there). */
@media (max-width: 767px) {
  .gv-empty { min-height: 0; }
  .gv-empty .dropzone { min-height: 0; padding: var(--space-6) var(--space-4); }
  .gv-empty .dropzone-icon { width: 28px; height: 28px; }
}
.gv-empty .fw-touch-copy .dropzone-browse { font-weight: 600; }
.gv-empty-note { margin-top: var(--space-2); font-size: var(--text-sm); color: var(--text-3); text-align: center; }

/* ───────── frame ───────── */
.gv .gv-frame.fw-workbench {
  display: grid; margin: 0; background: var(--bg);
  height: calc(100dvh - var(--appbar-h) - 120px); min-height: 440px;
  border: 1px solid var(--border-subtle); border-radius: var(--radius-md); overflow: hidden;
  grid-template-rows: var(--framebar-h) minmax(0, 1fr) var(--statusbar-h);
  position: relative;
}
.gv-frame.is-dragover::after {
  content: "Drop to open"; position: absolute; inset: 0; z-index: 5; display: grid; place-items: center;
  border: 2px dashed var(--accent-fill); border-radius: inherit; background: color-mix(in srgb, var(--bg) 70%, transparent);
  font-weight: 600; color: var(--accent-text); pointer-events: none;
}

.gv-bar { gap: var(--space-2); container: gvbar / inline-size; overflow: hidden; }
.gv-bar__tools, .gv-bar__end { display: flex; align-items: center; gap: 6px; min-width: 0; flex: none; }
.gv-bar__sep { width: 1px; height: 20px; background: var(--border-subtle); flex: none; }
.gv-file { max-width: 220px; }
.gv-btn { color: var(--text-2); }
.gv-btn[aria-expanded="true"] { background: var(--surface-active); color: var(--text-1); }
.gv .gv-btn[aria-pressed="true"], .gv .gv-btn.active { background: var(--accent-subtle-bg); color: var(--accent-text); border-color: transparent; }
.gv .gv-btn[aria-pressed="true"] .fw-icon { color: var(--accent-text); }
.gv .fw-bottombar__btn[aria-pressed="true"] { color: var(--accent-text); }
.gv-btn[disabled], .gv .fw-seg__opt[disabled] { opacity: .45; cursor: not-allowed; }
.gv-btn--icon .gv-btn__label { display: none; }
.gv-export { color: var(--text-1); }
.gv-seg .fw-seg__opt { padding: 0 10px; }
.gv-seg .fw-seg__opt .fw-icon { flex: none; }
@container gvbar (max-width: 1000px) { .gv-bar .gv-btn:has(.fw-icon) .gv-btn__label { display: none; } .gv-bar .gv-btn { padding: 0 8px; } }
@container gvbar (max-width: 760px) { .gv-bar .fw-seg__opt:has(.fw-icon) .gv-seg__label { display: none; } .gv-bar .gv-seg .fw-seg__opt { padding: 0 8px; } .gv-file { max-width: 140px; } }

.gv-main { min-height: 0; }
.gv-stage { background: var(--stage); overflow: hidden; }
.gv-canvas-wrap { position: absolute; inset: 0; }
.gv-canvas-wrap canvas, .gv-3d-wrap { width: 100%; height: 100%; display: block; }
.gv-3d-wrap { position: absolute; inset: 0; }
.gv-3d-wrap canvas { display: block; }

/* Stage overlays (bottom right: zoom; bottom left: map opacity / hints) */
.gv-zoom { bottom: var(--space-3); right: var(--space-3); }
.gv-zoom__value { display: inline-grid; place-items: center; }
.gv-opacity {
  position: absolute; left: var(--space-3); bottom: var(--space-3); z-index: 2; display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; border-radius: 10px; background: var(--surface-1); border: 1px solid var(--border-subtle); box-shadow: var(--shadow-2);
  font-size: var(--text-xs); color: var(--text-2);
}
.gv-opacity input[type="range"] { width: 120px; accent-color: var(--accent-fill); }
.gv-opacity__busy { display: inline-flex; align-items: center; gap: 6px; color: var(--text-3); }
.gv-opacity__busy .fw-spinner { width: 12px; height: 12px; }
.gv-hud {
  position: absolute; left: var(--space-3); bottom: var(--space-3); z-index: 2; padding: 4px 10px; border-radius: 8px;
  background: color-mix(in srgb, var(--surface-1) 88%, transparent); border: 1px solid var(--border-subtle);
  font-size: var(--text-xs); color: var(--text-3); pointer-events: none;
}

/* ───────── panels (list + inspector) ───────── */
.gv-panel { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.gv-panel__head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 6px 14px; }
.gv-panel__title { margin: 0; font-size: var(--text-xs); font-weight: 600; color: var(--text-2); letter-spacing: .01em; }
.gv-panel__close { display: none; margin-left: auto; }
.gv-panel__body { flex: 1; min-height: 0; overflow: auto; }
.gv-list .gv-panel__body { padding: 0 6px 8px; }
.gv-section { gap: var(--space-2); }
.gv-section__head { justify-content: space-between; min-height: 24px; }
.gv-section__title { margin: 0; font: inherit; }
.gv-muted { color: var(--text-3); font-size: var(--text-sm); }
.gv-hint { margin: 0; font-size: var(--text-xs); color: var(--text-3); }
.gv-mono { font-family: var(--font-mono); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }

.gv-layer {
  display: grid; grid-template-columns: auto 10px minmax(0, 1fr) auto; align-items: center; gap: 8px;
  min-height: 30px; padding: 3px 8px; border-radius: 6px; cursor: pointer; font-size: var(--text-sm); color: var(--text-1);
}
@media (hover: hover) { .gv-layer:hover { background: var(--surface-hover); } }
.gv-layer input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent-fill); }
.gv-layer__swatch { width: 10px; height: 10px; border-radius: 3px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
.gv-layer__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gv-layer__count { font-size: var(--text-xs); color: var(--text-3); font-variant-numeric: tabular-nums; }

.gv-kv { width: 100%; border-collapse: collapse; font-size: var(--text-sm); table-layout: fixed; }
.gv-kv th { width: 38%; padding: 4px 8px 4px 0; text-align: left; font-weight: 400; color: var(--text-3); vertical-align: top; }
.gv-kv td { padding: 4px 0; color: var(--text-1); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.gv-info .ifcv-pset { margin-top: 8px; }
.gv-info .ifcv-pset > summary { cursor: pointer; font-size: var(--text-xs); font-weight: 600; color: var(--text-2); padding: 4px 0; }

.gv-measures { display: flex; flex-direction: column; gap: 6px; }
.gv-measure {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; padding: 6px 6px 6px 10px; border-radius: 8px;
  border: 1px solid var(--border-subtle); background: var(--surface-1);
}
.gv-measure.is-ref { border-color: var(--accent-border); background: var(--accent-subtle-bg); }
.gv-measure__idx { font-size: var(--text-xs); font-weight: 600; color: var(--text-3); min-width: 22px; }
.gv-measure__val { flex: 1; min-width: 60px; font-size: var(--text-sm); color: var(--text-1); }
.gv-measure__ref { font-size: var(--text-2xs); }
.gv-measure__scale { --_h: 28px; }
.gv-calib {
  display: flex; align-items: center; gap: 8px; justify-content: space-between; padding: 6px 6px 6px 10px; border-radius: 8px;
  background: var(--accent-subtle-bg); color: var(--accent-text); font-size: var(--text-sm);
}
.gv-calib__text { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* Point cloud measurement rows / metadata in the inspector */
.gv .pcv-row { width: 100%; border: 1px solid var(--border-subtle); border-radius: 8px; background: var(--surface-1); color: var(--text-1); padding: 6px 10px; }
@media (hover: hover) { .gv .pcv-row:hover { background: var(--surface-hover); } }
/* The legacy viewers.css hovers of these rows would otherwise still stick after a tap. */
@media (hover: none) {
  .gv .dxfv-layer-row:hover { background: transparent; }
  .gv .dbv-table-row:not(.is-active):hover { background: transparent; }
  .gv .pcv-row:hover { background: var(--surface-1); }
}
.gv .pcv-list { display: flex; flex-direction: column; gap: 6px; }
.gv .pcv-meta { display: grid; gap: 4px; }
.gv .pcv-meta-row { display: grid; grid-template-columns: 40% minmax(0, 1fr); gap: 8px; font-size: var(--text-sm); }
.gv .pcv-meta-row span { color: var(--text-3); }
.gv .pcv-meta-row strong { font-weight: 400; color: var(--text-1); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

/* ───────── status bar ───────── */
.gv-status { gap: var(--space-3); }
.gv-crs {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border-radius: 6px;
  border: 1px solid var(--border-subtle); background: var(--surface-1); color: var(--text-2); font-size: var(--text-xs); max-width: 320px;
}
.gv-crs[hidden] { display: none; }
@media (hover: hover) { .gv-crs:hover { color: var(--text-1); background: var(--surface-hover); } }
.gv-crs__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gv-coords { font-family: var(--font-mono); font-size: var(--text-2xs); white-space: pre; overflow: hidden; text-overflow: ellipsis; }
.gv-status__hint { color: var(--text-3); }
.gv-status__end { margin-left: auto; }

/* ───────── popovers / dialogs ───────── */
.gv-options { display: flex; flex-direction: column; gap: 10px; padding: 12px; }
.gv-options__row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.gv-options .fw-field { gap: 4px; }
.gv-toggle { font-size: var(--text-sm); }
.gv-toggle input[disabled] + span { opacity: .5; }
.gv-dialog__lede { margin: 0 0 var(--space-3); color: var(--text-2); font-size: var(--text-sm); }
.gv-calib-form { display: flex; flex-direction: column; gap: var(--space-3); }
.gv-calib-form__row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: var(--text-sm); }
.gv-calib-form__pair { display: grid; grid-template-columns: minmax(0, 1fr) 120px; gap: var(--space-3); }

/* Tablet: the kit's 112 px list is too narrow for layer names. */
@media (min-width: 768px) and (max-width: 1279px) { .gv .fw-workbench { --list-w: 180px; } }

/* ───────── mobile: full-bleed frame, bottom bar, non-modal sheets ───────── */
.gv-bottombar { display: none; }
/* Not scoped to .gv: the Display popover moves its content under <body>. */
.gv-show-mobile-only { display: none !important; }
@media (max-width: 767px) { .gv-show-mobile-only { display: inline-flex !important; } }
@media (max-width: 767px) {
  .gv .gv-frame.fw-workbench {
    grid-template-rows: var(--framebar-h) minmax(0, 1fr) auto;
    margin-inline: calc(-1 * var(--gutter)); border-radius: 0; border-inline: 0; border-bottom: 0;
  }
  .gv .gv-hide-mobile { display: none !important; }
  .gv-bar { padding: 0 6px; gap: 4px; }
  .gv-bar__sep { display: none; }
  /* The chip may take what the bar leaves free (it shrinks with ellipsis), not a fixed 120 px ("lo…"). */
  .gv-file { max-width: min(48vw, 200px); }
  .gv .fw-bottombar.gv-bottombar { display: grid; }
  /* Live counts stay visible on phones for the 3D viewers (point count, clipped, triangles). */
  .gv:is([data-gv="pointcloud"], [data-gv="ifc"], [data-gv="stl"]) .gv-frame.fw-workbench { grid-template-rows: var(--framebar-h) minmax(0, 1fr) auto auto; }
  .gv:is([data-gv="pointcloud"], [data-gv="ifc"], [data-gv="stl"]) .fw-statusbar.gv-status { display: flex; min-height: 26px; }
  /* viewers.css (≤600 px) still hides the legacy .ifcv-status readout; in the frame it is the live count line. */
  .gv[data-gv="ifc"] .fw-statusbar .ifcv-status { display: inline-flex; }
  .gv #ifcv-wasm-banner { display: none; }
  .gv .gv-panel.is-sheet {
    display: flex !important; position: absolute; left: 0; right: 0; z-index: var(--z-sheet);
    bottom: var(--gv-sheet-bottom, calc(var(--bottombar-h) + env(safe-area-inset-bottom)));
    max-height: min(46dvh, var(--gv-sheet-max, 46dvh)); min-height: 120px;
    border: 1px solid var(--border-subtle); border-bottom: 0; border-radius: 16px 16px 0 0;
    background: var(--bg); box-shadow: 0 -12px 32px -12px rgba(0, 0, 0, .35);
  }
  .gv .gv-panel.is-sheet .gv-panel__close { display: inline-grid; }
  /* Half a stage is little room: tighter sections so the first rows show without scrolling. */
  .gv .gv-panel.is-sheet .gv-panel__head { padding: 4px 6px 0 16px; }
  .gv .gv-panel.is-sheet .fw-insp-section { padding: 8px 16px 12px; gap: var(--space-2); }
  .gv .gv-panel.is-sheet .gv-panel__body:has(.gv-section:not(.is-empty)) .gv-section.is-empty { display: none; }
  .gv-zoom { bottom: var(--space-2); right: var(--space-2); }
  .gv-opacity { left: var(--space-2); bottom: var(--space-2); }
  .gv-opacity input[type="range"] { width: 90px; }
  .gv-calib-form__pair { grid-template-columns: 1fr; }
}
@media (pointer: coarse) {
  .gv-layer { min-height: 44px; }
  .gv-layer input { width: 20px; height: 20px; }
  .gv-measure__scale { --_h: 44px; }
}

/* Neutralise the legacy panel boxes (viewers.css) inside the frame. */
.gv .dxfv-layer-list { display: flex; flex-direction: column; gap: 1px; max-height: none; overflow: visible; border: 0; padding: 0; border-radius: 0; }
.gv .dxfv-layer-row { margin: 0; font-size: var(--text-sm); }
.gv .dxfv-info, .gv .ifcv-info { padding: 0; background: none; border: 0; border-radius: 0; font-size: var(--text-sm); }
.gv .dxfv-info-table th, .gv .ifcv-info-table th { font-weight: 400; color: var(--text-3); font-size: var(--text-sm); text-transform: none; letter-spacing: normal; }
.gv .dxfv-info-table, .gv .ifcv-info-table { font-size: var(--text-sm); }
.gv .dxfv-measure-row, .gv .ifcv-measure-row { font-size: var(--text-sm); }
.gv .dxfv-calib-banner { margin: 0; border: 0; font-size: var(--text-sm); }
.gv .dxfv-measure-idx, .gv .ifcv-measure-idx { width: auto; }

/* ───────── point cloud specifics ───────── */
.gv .pcv-canvas-wrap { position: absolute; inset: 0; height: auto; min-height: 0; }
.gv .pcv-canvas { width: 100%; height: 100%; display: block; }
.gv .pcv-hud { backdrop-filter: none; background: color-mix(in srgb, var(--surface-1) 88%, transparent); color: var(--text-3); border-color: var(--border-subtle); }
.gv .pcv-pano { position: absolute; inset: 0; }
.gv .pcv-pano-bar { margin-top: 0; }
.gv .pcv-active-tool { font-size: var(--text-2xs); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-3); }
.gv .pcv-file { color: var(--text-2); max-width: 32ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }
.gv .pcv-status { font-family: var(--font-mono); font-size: var(--text-2xs); color: var(--text-2); }
.gv-zoom:has(> :only-child) { padding: 3px; }
.gv-display { display: flex; flex-direction: column; gap: 12px; padding: 12px; }
.gv-display__size input { width: 100%; accent-color: var(--accent-fill); }
.gv-display__colour { display: flex; gap: 8px; align-items: center; }
.gv-display__colour .fw-select { flex: 1; }
.gv-display__colour input[type="color"] { width: 36px; height: 32px; padding: 2px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface-1); }
.gv-display__colour input[type="color"]:disabled { opacity: .4; }
.gv-display .fw-btn { justify-content: flex-start; }
.gv .gv-parking { display: none !important; }
.gv #pcv-pano-measure { display: none; }
@media (max-width: 767px) {
  .gv .pcv-active-tool, .gv .pcv-file { display: none; }
}
.gv .ifcv-info-table th { text-transform: none; letter-spacing: normal; }
.gv .ifcv-info-table td, .gv .ifcv-info-table th { border: 0; }
.gv .gv-tools { display: flex; align-items: center; gap: 2px; }
.gv .gv-range { width: 100%; accent-color: var(--accent-fill); }
.gv .gv-color { width: 40px; height: 30px; padding: 2px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface-1); }
.gv .gv-frame.fw-workbench:fullscreen { height: 100% !important; margin: 0; border: 0; border-radius: 0; }

/* Touch targets ≥ 44 px on coarse pointers (the kit's .fw-zoom rule pins 28 px). */
@media (pointer: coarse) {
  .gv .fw-zoom .fw-iconbtn { --_s: 44px; }
  .gv .gv-file, .dv-officebar .gv-file { height: 44px; }
  /* Icon-only tools and Export in the frame bars (geo + document viewers) were 30–32 px wide. */
  .gv-bar .fw-seg__opt, .gv-bar .gv-btn { min-width: 44px; justify-content: center; }
}
/* 320 px with 44 px tools: the file chip drops its thumbnail so a few letters of the name still show. */
@media (max-width: 359px) { .gv-bar .gv-file .fw-filechip__thumb { display: none; } }
/* Narrow phones: the map opacity control sits above the zoom HUD instead of under it. */
@media (max-width: 479px) {
  .gv-opacity { bottom: calc(var(--space-2) + 60px); }
}
