/* Shared UI components for CesiumJS voxel demos.
   Copy this file (and components.js) into a new demo folder to reuse.

   Override tokens in your page's <style> block to retheme:
     :root { --ui-accent: #c06a4a; }
*/

/* ---------------------------------------------------------------------------
   Design tokens
   --------------------------------------------------------------------------- */
:root {
  /* Backgrounds */
  --ui-bg-panel:   rgba(30, 30, 30, 0.82);
  --ui-bg-tooltip: rgba(20, 20, 20, 0.92);

  /* Border radius */
  --ui-radius: 3px;

  /* Text hierarchy */
  --ui-text:           #eee;
  --ui-text-secondary: #ccc;
  --ui-text-muted:     #aaa;
  --ui-text-dim:       #888;

  /* Slider */
  --ui-accent: hsl(111, 15%, 43%);
  --ui-track:  #444;
  --ui-thumb:  #ddd;
}

/* ---------------------------------------------------------------------------
   Panel base — used by legend and controls
   --------------------------------------------------------------------------- */
.legend-panel,
#controls {
  position: absolute;
  background: var(--ui-bg-panel);
  color: var(--ui-text);
  border-radius: var(--ui-radius);
  padding: 10px 14px;
  font-size: 11px;
}

h3 {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ui-text-secondary);
}

/* ---------------------------------------------------------------------------
   Legend
   --------------------------------------------------------------------------- */
.legend-panel {
  top: 12px;
  right: 12px;
  max-height: 280px;
  min-width: 210px;
  max-width: 300px;
  pointer-events: none;
}

.legend-period {
  margin: 6px 0 4px;
  font-size: 10px;
  color: var(--ui-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.legend-item {
  display: flex;
  align-items: center;
  width: 100%;
  margin-bottom: 4px;
  gap: 8px;
  pointer-events: auto;
}

.legend-item--hidden {
  opacity: 0.35;
}

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  flex-shrink: 0;
  border: none;
  padding: 0;
  cursor: pointer;
  transition: outline 0.1s;
}

.legend-swatch:hover {
  outline: 2px solid oklch(100% 0.00011 271.152 / 0.8);
}

.legend-number {
  text-align: right;
  margin-left: auto;
  font-size: 10px;
  color: var(--ui-text-muted);
}

/* ---------------------------------------------------------------------------
   Controls panel
   --------------------------------------------------------------------------- */
#controls {
  top: 340px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 12px;
  max-width: 320px;
}

#controls label {
  color: var(--ui-text-secondary);
  white-space: nowrap;
}

/* ---------------------------------------------------------------------------
   Tooltip
   --------------------------------------------------------------------------- */
#tooltip {
  position: absolute;
  pointer-events: none;
  display: none;
  background: var(--ui-bg-tooltip);
  color: var(--ui-text);
  padding: 8px 12px;
  border-radius: var(--ui-radius);
  font-size: 12px;
  border-left: 3px solid transparent;
  max-width: 240px;
  line-height: 1.5;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* ---------------------------------------------------------------------------
   Clipping controls
   --------------------------------------------------------------------------- */
.clipping-controls {
  display: grid;
  row-gap: 4px;
}

#reset-clipping {
  background-color: var(--ui-accent);
  font-size: 12px;
  color: white;
  border-radius: 4px;
  border: none;
  padding-block: 4px;
  margin-block: 4px 8px;
  cursor: pointer;
}

/* ---------------------------------------------------------------------------
   Range slider (multi-thumb)
   --------------------------------------------------------------------------- */
.clip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 176px;
}

.clip-axis-label {
  font-size: 10px;
  color: var(--ui-text-muted);
  text-transform: uppercase;
  width: 10px;
  flex-shrink: 0;
  text-align: center;
}

.clip-range-slider {
  flex: 1;
  position: relative;
  height: 20px;
}

.range-track {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  left: 0;
  right: 0;
  height: 4px;
  background: var(--ui-track);
  border-radius: 2px;
}

.range-track-zone {
  position: absolute;
  top: -8px;
  bottom: -8px;
  left: 0;
  right: 0;
  cursor: pointer;
}

.range-select {
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: var(--range-min, 0%);
  right: calc(100% - var(--range-max, 100%));
  background: var(--ui-accent);
  border-radius: 2px;
  cursor: grab;
  overflow: visible;
}

/* https://ishadeed.com/article/target-size/#extend-target-size-with-pseudo-elements */
.range-select:after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  transform: scale(1.5);
}

.range-select:active {
  cursor: grabbing;
}

.thumb {
  position: absolute;
  top: 50%;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ui-thumb);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  cursor: ew-resize;
  z-index: 1;
}

.thumb-min {
  left: 0;
  transform: translate(-50%, -50%);
}

.thumb-max {
  right: 0;
  transform: translate(50%, -50%);
}

.clip-range-output {
  font-size: 10px;
  color: var(--ui-text-dim);
  white-space: nowrap;
  min-width: 44px;
  text-align: right;
}

/* ---------------------------------------------------------------------------
   Layer toggle + fence diagram (inside controls panel)
   --------------------------------------------------------------------------- */
.layer-toggle {
  display: flex;
  gap: 4px;
}

.layer-btn,
#fence-toggle,
.fence-tag {
  background: var(--ui-track);
  color: var(--ui-text);
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
}

.layer-btn.active,
#fence-toggle.active,
.fence-tag.active {
  background: var(--ui-accent);
  border-color: color-mix(in srgb, var(--ui-accent) 60%, white);
  color: #fff;
}

.layer-btn {
  flex: 1;
  padding: 5px;
  text-align: center;
}

#fence-toggle {
  display: block;
  width: 100%;
  padding: 5px;
}

#fence-options {
  display: none;
}

#fence-options.visible {
  display: block;
}

.fence-section-label {
  font-size: 10px;
  color: var(--ui-text-muted);
  margin: 6px 0 3px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.fence-lines {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 4px;
}

.fence-tag {
  padding: 2px 6px;
  white-space: nowrap;
}

.fence-width-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.fence-width-row label {
  font-size: 11px;
  color: var(--ui-text-muted);
  flex-shrink: 0;
}

.fence-width-row input[type=range] {
  flex: 1;
  accent-color: var(--ui-accent);
}

#fence-width-val {
  font-size: 11px;
  width: 32px;
  text-align: right;
  color: var(--ui-text-secondary);
}

/* ---------------------------------------------------------------------------
   Labeled slider (basemap opacity, vert. exag.)
   --------------------------------------------------------------------------- */
.labeled-slider {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.labeled-slider input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--ui-accent);
  outline: none;
  cursor: pointer;
}

.labeled-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ui-thumb);
  box-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

.labeled-slider input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: none;
  background: var(--ui-thumb);
  box-shadow: 0 1px 4px rgba(0,0,0,0.6);
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.slider-value {
  font-size: 10px;
  color: var(--ui-text-secondary);
  min-width: 28px;
  text-align: right;
}
