/* demo page — cesium viewer */

body:has(.demo) {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
body:has(.demo) main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.demo {
  display: grid;
  grid-template-columns: 340px 1fr;
  border-top: 1px solid var(--line);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.demo__panel {
  border-right: 1px solid var(--line);
  padding: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow-y: auto;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--line-soft) transparent;
}

.demo__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.demo__row--head { gap: 10px; }
.demo__tag {
  font-family: var(--f-mono);
  font-size: 12px;
  color: var(--ink);
}
.demo__sub {
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--muted);
}

.demo__field {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.demo__label {
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--ink);
  display: flex;
  align-items: baseline;
  gap: 4px;
}
.demo__label .demo__value { margin-left: auto; }
.demo__value { color: var(--ink); }
.demo__num {
  color: var(--muted);
  font-weight: 400;
  letter-spacing: 0.04em;
}

.demo__input,
.demo__btn,
.demo__btn-inline {
  font-family: var(--f-mono);
  font-size: 12px;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 6px 8px;
  border-radius: 0;
  outline: none;
  width: 100%;
}
.demo__input::placeholder { color: var(--muted); }
.demo__input:focus { border-color: var(--ink); }
.demo__input[type="number"] { appearance: textfield; }

.demo__search {
  display: grid;
  grid-template-columns: 1fr 40px;
  gap: 0;
}
.demo__search .demo__input { border-right: none; }

.demo__btn-inline {
  width: 34px;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.demo__btn-inline:hover { background: var(--ink); color: var(--bg); }
.demo__btn-inline--ghost { color: var(--muted); width: auto; padding: 6px 10px; }

.demo__results {
  display: none;
  flex-direction: column;
  border: 1px solid var(--line-soft);
  max-height: 160px;
  overflow-y: auto;
  margin-top: 4px;
}
.demo__results[data-open="true"] { display: flex; }
.demo__result {
  font-family: var(--f-mono);
  font-size: 12px;
  color: var(--ink-soft);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  background: transparent;
  text-align: left;
  width: 100%;
  border-left: none;
  border-right: none;
  border-top: none;
}
.demo__result:last-child { border-bottom: none; }
.demo__result:hover { background: var(--ink); color: var(--bg); }

.demo__coords {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}
.demo__coords .demo__input:first-child { border-right: none; }

.demo__range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 1px;
  background: var(--line);
  outline: none;
  padding: 0;
  margin: 6px 0;
}
.demo__range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  background: var(--ink);
  cursor: pointer;
  border: none;
  border-radius: 0;
}
.demo__range::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: var(--ink);
  cursor: pointer;
  border: none;
  border-radius: 0;
}

.demo__btn {
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
  text-align: center;
}
.demo__btn:hover { background: var(--ink); color: var(--bg); }
.demo__btn--ghost { color: var(--ink-soft); }
.demo__btn--ghost[data-active="true"] { background: var(--ink); color: var(--bg); }

.demo__edit {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0;
}
.demo__edit .demo__btn { border-right: none; }

.demo__hint { display: none; }

.demo__lock {
  margin-top: auto;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.demo__quota {
  margin: 0;
  font-family: var(--f-mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.demo__quota--exhausted { color: #FF6B6B; }
.demo__lock-cta {
  display: block;
  align-self: stretch;
  text-align: center;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line-soft);
  padding: 11px 14px;
  font-family: var(--f-mono);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.demo__lock-cta:hover {
  color: var(--ink);
  border-color: var(--ink);
}
.demo__panel[data-locked="true"] .demo__lock-cta {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
.demo__panel[data-locked="true"] .demo__lock-cta:hover {
  background: var(--bg);
  color: var(--ink);
}

/* viewer */
.demo__viewer {
  position: relative;
  background: #000;
  min-height: 480px;
}
.demo__cesium {
  position: absolute;
  inset: 0;
  background: #000;
}

.demo__cesium .cesium-viewer-bottom,
.demo__cesium .cesium-viewer-toolbar,
.demo__cesium .cesium-viewer-animationContainer,
.demo__cesium .cesium-viewer-timelineContainer,
.demo__cesium .cesium-viewer-fullscreenContainer,
.demo__cesium .cesium-viewer-vrContainer,
.demo__cesium .cesium-credit-lightbox-overlay { display: none !important; }
.demo__cesium .cesium-widget-credits {
  font-family: var(--f-mono) !important;
  font-size: 10px !important;
  color: var(--muted) !important;
  background: transparent !important;
  padding: 4px 8px !important;
}
.demo__cesium canvas { outline: none; }

/* per-parcel hover annotation (cadastre layer) — fixed = pinned to the cursor,
   in viewport coords, so it tracks the mouse over any cell viewer */
.demo__parcel-tip {
  position: fixed;
  z-index: 30;
  pointer-events: none;
  max-width: 220px;
  padding: 7px 9px;
  background: rgba(0,0,0,0.85);
  border: 1px solid var(--line-soft);
  border-left: 2px solid #ffd24a;
  font-family: var(--f-mono);
  font-size: 11px;
  line-height: 1.45;
  color: var(--ink-soft);
}
.demo__parcel-tip[hidden] { display: none; }
.demo__parcel-tip b { color: var(--ink); font-weight: 500; }
.demo__parcel-idu { color: var(--muted); font-size: 10px; word-break: break-all; }

/* 2×2 static layer-snapshot grid (one cell per layer) */
.demo__grid {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: none;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
  background: var(--line-soft);
}
.demo__grid[data-active="true"] { display: grid; }
.demo__cell {
  position: relative;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: #000;
  font: inherit;
  color: inherit;
}
/* each cell hosts its own interactive Cesium viewer */
.demo__cell-viewer {
  position: absolute;
  inset: 0;
  background: #000;
  cursor: grab;
}
.demo__cell-viewer:active { cursor: grabbing; }
.demo__cell-viewer .cesium-viewer,
.demo__cell-viewer .cesium-widget,
.demo__cell-viewer .cesium-widget canvas { width: 100%; height: 100%; }
.demo__cell-viewer .cesium-viewer-bottom,
.demo__cell-viewer .cesium-viewer-toolbar,
.demo__cell-viewer .cesium-viewer-animationContainer,
.demo__cell-viewer .cesium-viewer-timelineContainer,
.demo__cell-viewer .cesium-widget-credits,
.demo__cell-viewer .cesium-credit-lightbox-overlay { display: none !important; }
.demo__cell-tag {
  position: absolute;
  left: 10px;
  top: 10px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 7px;
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: rgba(0,0,0,0.6);
  border: 1px solid var(--line-soft);
  padding: 4px 9px;
}
.demo__cell-n {
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--line-soft);
  padding: 0 3px;
}
.demo__cell-status {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  background: #0b0b0b;
}
/* indeterminate loading BAR — a highlight sweeps along a thin track */
.demo__cell-status::before {
  content: "";
  width: 96px;
  height: 3px;
  border-radius: 2px;
  background-color: rgba(255,255,255,0.12);
  background-image: linear-gradient(90deg, transparent 0%, var(--ink) 50%, transparent 100%);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  animation: demo-bar 1.1s ease-in-out infinite;
}
@keyframes demo-bar {
  0%   { background-position: -45% 0; }
  100% { background-position: 145% 0; }
}
/* once the cell viewer is up, hide the loading overlay */
.demo__cell[data-state="live"] .demo__cell-status,
.demo__cell[data-state="ready"] .demo__cell-status { display: none; }
.demo__cell[data-state="empty"] .demo__cell-status::before {
  animation: none;
  background-image: none;
  opacity: 0.4;
}
/* a small "drag to orbit" hint on hover */
.demo__cell::after {
  content: "drag ⟳";
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  pointer-events: none;
  font-family: var(--f-mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--ink);
  background: rgba(0,0,0,0.6);
  border: 1px solid var(--line-soft);
  padding: 3px 7px;
  opacity: 0;
  transition: opacity .15s ease;
}
.demo__cell[data-state="live"]:hover::after { opacity: 1; }
.demo__grid-back {
  position: absolute;
  left: 14px;
  top: 14px;
  z-index: 8;
  font-family: var(--f-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: rgba(0,0,0,0.7);
  border: 1px solid var(--line-soft);
  padding: 6px 11px;
  cursor: pointer;
  transition: background .12s ease;
}
.demo__grid-back:hover { background: rgba(255,255,255,0.08); }
.demo__grid-back[hidden] { display: none; }

/* stacked-layers legend (mirrors the 3D mille-feuille) */
.demo__layers {
  position: absolute;
  left: 14px;
  top: 14px;
  z-index: 6;
  display: none;
  min-width: 184px;
  background: rgba(0,0,0,0.7);
  border: 1px solid var(--line-soft);
  font-family: var(--f-mono);
}
.demo__layers[data-active="true"] { display: block; }
.demo__layers-head {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line-soft);
}
.demo__layers ul { list-style: none; margin: 0; padding: 4px 0; }
.demo__layers li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.demo__layers li:hover { color: var(--ink-soft); background: rgba(255,255,255,0.05); }
.demo__layers li[data-active="true"] {
  color: var(--ink);
  background: rgba(255,255,255,0.10);
}
.demo__layers-n {
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--line-soft);
  padding: 0 3px;
}
.demo__layers li[data-active="true"] .demo__layers-n {
  color: var(--ink);
  border-color: var(--ink);
}

.demo__hud {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  padding: 8px var(--gutter);
  background: rgba(0,0,0,0.7);
  border-top: 1px solid var(--line-soft);
  font-family: var(--f-mono);
  font-size: 12px;
  color: var(--ink-soft);
  gap: 0;
  pointer-events: none;
  z-index: 5;
}

/* embedded steps panel */
.demo__field--logs { gap: 5px; }
.demo__steps {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--line-soft);
  background: rgba(255,255,255,0.02);
}
.demo__step {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  grid-template-rows: auto 2px;
  gap: 2px 8px;
  padding: 6px 10px 0 10px;
  position: relative;
  border-bottom: 1px solid var(--line-soft);
  transition: background .2s ease;
}
.demo__step:last-child { border-bottom: none; }
.demo__step-marker {
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--muted);
  align-self: center;
  text-align: center;
  border: 1px solid var(--line-soft);
  padding: 1px 0;
  width: 22px;
  transition: color .2s ease, border-color .2s ease, background .2s ease;
}
.demo__step-body {
  display: flex;
  flex-direction: column;
  gap: 0;
  align-self: center;
}
.demo__step-title {
  font-family: var(--f-mono);
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0;
  transition: color .2s ease;
  line-height: 1.2;
}
.demo__step-sub {
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--faint);
  transition: color .2s ease;
  line-height: 1.2;
}
.demo__step-meta {
  align-self: center;
  font-family: var(--f-mono);
  font-size: 10px;
  color: var(--muted);
  min-width: 0;
  text-align: right;
}
.demo__step-bar {
  grid-column: 1 / -1;
  height: 2px;
  background: transparent;
  margin: 5px -10px 0;
  position: relative;
}
.demo__step-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--ink);
  transition: width 0s linear;
}

/* state colors */
.demo__step[data-status="running"] .demo__step-marker {
  color: var(--ink);
  border-color: var(--ink);
  animation: stepPulse 0.9s infinite;
}
.demo__step[data-status="running"] .demo__step-title { color: var(--ink); }
.demo__step[data-status="running"] .demo__step-sub { color: var(--ink-soft); }
.demo__step[data-status="running"] .demo__step-meta { color: var(--ink); }

.demo__step[data-status="done"] .demo__step-marker {
  color: var(--bg);
  border-color: var(--ink);
  background: var(--ink);
}
.demo__step[data-status="done"] .demo__step-title { color: var(--ink-soft); }
.demo__step[data-status="done"] .demo__step-meta { color: var(--muted); }
.demo__step[data-status="done"] .demo__step-bar-fill { background: var(--ink); }

@keyframes stepPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* primary action */
.demo__btn--primary {
  background: var(--ink);
  color: var(--bg);
  border: 1px solid var(--ink);
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 10px 14px;
  font-size: 12px;
}
.demo__btn--primary:hover { background: var(--bg); color: var(--ink); }
.demo__btn--primary:disabled { opacity: 0.4; cursor: not-allowed; background: var(--ink); color: var(--bg); }
.demo__btn--primary[data-mode="reset"] {
  background: transparent;
  color: var(--ink);
}
.demo__btn--primary[data-mode="reset"]:hover { background: var(--ink); color: var(--bg); }

.demo__btn--primary .applyBtn__reset { display: none; }
.demo__btn--primary[data-mode="reset"] .applyBtn__apply { display: none; }
.demo__btn--primary[data-mode="reset"] .applyBtn__reset { display: inline; }

/* locked inputs */
.demo__panel[data-locked="true"] .demo__input,
.demo__panel[data-locked="true"] .demo__range,
.demo__panel[data-locked="true"] .demo__btn-inline,
.demo__panel[data-locked="true"] .demo__btn--ghost,
.demo__panel[data-locked="true"] .demo__search {
  opacity: 0.35;
  pointer-events: none;
}

/* edit field — hidden until extracted */
.demo__field--edit { display: none; }
.demo__panel[data-locked="true"] .demo__field--edit { display: flex; }
.demo__panel[data-locked="true"] .demo__field--edit .demo__btn--ghost,
.demo__panel[data-locked="true"] .demo__field--edit .demo__btn-inline {
  opacity: 1;
  pointer-events: auto;
}

/* floating editor panel */
.demo__editor {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 20;
  width: 260px;
  background: rgba(0,0,0,0.92);
  border: 1px solid var(--ink);
  display: none;
  flex-direction: column;
  font-family: var(--f-mono);
}
.demo__editor[data-active="true"] { display: flex; }
.demo__editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.demo__editor-title {
  font-size: 11px;
  color: var(--ink);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.demo__editor-close {
  font-family: var(--f-mono);
  font-size: 18px;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color .12s ease;
}
.demo__editor-close:hover { color: var(--ink); }
.demo__editor-hint {
  margin: 10px 12px 8px;
  font-size: 11px;
  color: var(--ink-soft);
  line-height: 1.45;
}
.demo__editor-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 12px;
  color: #FF6B6B;
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
}
.demo__editor-dot {
  width: 8px;
  height: 8px;
  background: #FF4040;
  display: inline-block;
}
.demo__editor-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.demo__editor-btn {
  font-family: var(--f-mono);
  font-size: 11px;
  padding: 11px 8px;
  border: none;
  cursor: pointer;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  transition: background .12s ease, color .12s ease, opacity .12s ease;
}
.demo__editor-btn--ghost {
  background: transparent;
  color: var(--ink-soft);
  border-right: 1px solid var(--line-soft);
}
.demo__editor-btn--ghost:hover { background: var(--ink); color: var(--bg); }
.demo__editor-btn--primary {
  background: var(--ink);
  color: var(--bg);
  font-weight: 500;
}
.demo__editor-btn--primary:hover { background: var(--bg); color: var(--ink); }
.demo__editor-btn--primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.demo__hud-item { padding: 0 14px; }
.demo__hud-item:first-child { padding-left: 0; }
.demo__hud-spacer { width: 1px; height: 12px; background: var(--line-soft); }

/* responsive */
@media (max-width: 880px) {
  .demo {
    grid-template-columns: 1fr;
    min-height: auto;
  }
  .demo__panel {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .demo__viewer {
    height: 70vh;
    min-height: 420px;
  }
}
