:root {
  --bg-color: #050811;
  --panel-bg: rgba(9, 16, 29, 0.72);
  --panel-border: rgba(0, 210, 255, 0.18);
  --panel-border-focus: rgba(0, 210, 255, 0.5);
  --text-main: #d3e5f0;
  --text-dim: #8ba5b8;
  --accent-cyan: #00d2ff;
  --accent-blue: #0088ff;
  --accent-green: #39e38d;
  --accent-orange: #ff9d00;
  --accent-red: #ff3c6b;
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-color);
  font-family: var(--font-sans);
  color: var(--text-main);
  user-select: none;
}

#app {
  position: absolute;
  inset: 0;
  z-index: 1;
}

#app canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Paneles flotantes (Glassmorphism) */
.panel {
  position: fixed;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 16px 20px;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  z-index: 10;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.panel:hover {
  border-color: rgba(0, 210, 255, 0.35);
  box-shadow: 0 8px 32px 0 rgba(0, 210, 255, 0.05);
}

.panel h1 {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--accent-cyan);
  letter-spacing: 1px;
  text-transform: uppercase;
}

.panel h2 {
  font-size: 11px;
  font-weight: 600;
  margin: 18px 0 8px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  border-top: 1px solid rgba(0, 210, 255, 0.12);
  padding-top: 12px;
}

.panel h2:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 10px;
}

/* Panel izquierdo */
#left {
  top: 16px;
  left: 16px;
  width: 300px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 210, 255, 0.3) transparent;
}

#left::-webkit-scrollbar {
  width: 6px;
}
#left::-webkit-scrollbar-thumb {
  background: rgba(0, 210, 255, 0.3);
  border-radius: 3px;
}

.network-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 10.5px;
  font-family: var(--font-mono);
  background: rgba(0, 210, 255, 0.12);
  color: var(--accent-cyan);
  border: 1px solid rgba(0, 210, 255, 0.25);
  margin-bottom: 12px;
  word-break: break-all;
}

/* Zona de drag and drop */
.drop-zone {
  border: 2px dashed var(--panel-border);
  border-radius: 8px;
  padding: 14px 10px;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.2);
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.drop-zone.dragover {
  border-color: var(--accent-cyan);
  background: rgba(0, 210, 255, 0.08);
  color: var(--text-main);
}

.btn-file {
  display: inline-block;
  padding: 5px 12px;
  background: rgba(0, 210, 255, 0.15);
  border: 1px solid rgba(0, 210, 255, 0.3);
  border-radius: 6px;
  color: var(--accent-cyan);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  transition: all 0.15s ease;
}

.btn-file:hover {
  background: rgba(0, 210, 255, 0.28);
  border-color: var(--accent-cyan);
}

.btn-file input[type="file"] {
  display: none;
}

/* Filas de checkboxes */
label.row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 0;
  font-size: 12.5px;
  transition: color 0.15s ease;
}

label.row:hover {
  color: var(--accent-cyan);
}

label.row input[type="checkbox"] {
  accent-color: var(--accent-cyan);
  cursor: pointer;
}

.sw {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 4px;
}
.sw.terrain { background: #3c5166; }
.sw.water { background: var(--accent-cyan); }
.sw.tank { background: var(--accent-blue); }
.sw.valve { background: var(--accent-orange); }
.sw.pump { background: var(--accent-green); }
.sw.label-sw { background: #d0e0ee; }
.sw.flow-sw { background: #4fd0ff; }

/* Sliders */
.slider {
  margin: 12px 0;
}

.slider .lab {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-dim);
}

.slider .lab b {
  color: var(--text-main);
  font-family: var(--font-mono);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent-cyan);
  margin-top: 6px;
  background: rgba(0, 210, 255, 0.1);
  height: 4px;
  border-radius: 2px;
  cursor: pointer;
}

/* Botones */
.btn {
  display: inline-block;
  width: 100%;
  padding: 8px 12px;
  cursor: pointer;
  background: rgba(0, 210, 255, 0.08);
  border: 1px solid var(--panel-border);
  color: var(--text-main);
  border-radius: 8px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  transition: all 0.15s ease;
  outline: none;
}

.btn:hover {
  background: rgba(0, 210, 255, 0.18);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.btn.active {
  background: var(--accent-cyan);
  border-color: var(--accent-cyan);
  color: #03060b;
}

.btn.alt {
  background: rgba(255, 255, 255, 0.03);
  margin-top: 6px;
}

.btn.alt:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--text-dim);
  color: var(--text-main);
}

.camera-btn-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 6px;
}

/* Barra superior */
#topBar {
  top: 16px;
  left: 332px;
  right: 16px;
  height: 52px;
  padding: 8px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.search-container {
  position: relative;
  display: flex;
  gap: 8px;
  flex-grow: 1;
  max-width: 450px;
}

#searchSuggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  background: rgba(8, 14, 24, 0.97);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: none;
  z-index: 30;
}

#searchSuggestions.visible {
  display: block;
}

.suggestion {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.suggestion:last-child {
  border-bottom: none;
}

.suggestion:hover,
.suggestion.active {
  background: rgba(0, 210, 255, 0.14);
}

.suggestion .s-id {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggestion .s-type {
  flex-shrink: 0;
  font-size: 9.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 1px 8px;
  border-radius: 10px;
  color: #cfe;
  background: rgba(255, 255, 255, 0.08);
}

.s-type.s-valve { color: #ffce80; background: rgba(255, 165, 0, 0.16); }
.s-type.s-pump { color: #7df0b6; background: rgba(57, 227, 141, 0.16); }
.s-type.s-tank,
.s-type.s-reservoir { color: #80d8ff; background: rgba(0, 136, 255, 0.18); }
.s-type.s-pipe { color: #9fdcff; background: rgba(0, 168, 255, 0.14); }
.s-type.s-junction { color: #bfe7ff; background: rgba(0, 210, 255, 0.12); }

.search-container input {
  flex-grow: 1;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 6px 12px;
  color: var(--text-main);
  font-family: inherit;
  font-size: 12px;
  outline: none;
}

.search-container input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 8px rgba(0, 210, 255, 0.25);
}

.search-container button {
  background: rgba(0, 210, 255, 0.15);
  border: 1px solid rgba(0, 210, 255, 0.3);
  color: var(--accent-cyan);
  padding: 0 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11.5px;
  font-weight: 600;
  transition: all 0.15s ease;
}

.search-container button:hover {
  background: rgba(0, 210, 255, 0.28);
  border-color: var(--accent-cyan);
}

.stats-row {
  display: flex;
  gap: 20px;
  font-size: 12.5px;
}

.stat .label {
  color: var(--text-dim);
}

.stat span:last-child {
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--accent-cyan);
}

/* Panel de información (derecho) */
#info {
  top: 84px;
  right: 16px;
  width: 320px;
  max-height: calc(100vh - 210px);
  overflow-y: auto;
}

.info-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(0, 210, 255, 0.15);
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.info-title {
  font-weight: 600;
  color: var(--accent-cyan);
  font-size: 13.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.close-info {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.close-info:hover {
  color: var(--accent-red);
}

.info-content {
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  color: var(--text-main);
}

.info-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  color: #000;
  margin-bottom: 8px;
}
.info-badge.potable { background: var(--accent-cyan); }
.info-badge.tank { background: var(--accent-blue); color: #fff; }
.info-badge.valve { background: var(--accent-orange); }
.info-badge.pump { background: var(--accent-green); }

/* Formulario de Edición */
.edit-form {
  border-top: 1px dashed rgba(0, 210, 255, 0.2);
  margin-top: 14px;
  padding-top: 14px;
}

.edit-form h3 {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  margin: 0 0 10px;
  color: var(--text-dim);
}

.form-group {
  margin-bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 11px;
  color: var(--text-dim);
}

.form-group input, .form-group select {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  padding: 5px 8px;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 11.5px;
  outline: none;
}

.form-group input:focus, .form-group select:focus {
  border-color: var(--accent-cyan);
}

/* Leyenda */
#legend {
  bottom: 16px;
  right: 16px;
  font-size: 11.5px;
  width: 260px;
}

.legrow {
  display: flex;
  align-items: center;
  padding: 3px 0;
}

/* Ayuda */
#help {
  bottom: 16px;
  left: 16px;
  right: 292px;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.5;
}

/* Punto de mira FPS */
#cross {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  z-index: 9;
  pointer-events: none;
  display: none;
}

#cross::before, #cross::after {
  content: "";
  position: absolute;
  background: var(--accent-cyan);
  opacity: 0.7;
}

#cross::before {
  left: 6px;
  top: 0;
  width: 2px;
  height: 14px;
}

#cross::after {
  top: 6px;
  left: 0;
  height: 2px;
  width: 14px;
}

/* Pantalla de carga */
#load {
  position: fixed;
  inset: 0;
  background: var(--bg-color);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 15px;
  transition: opacity 0.5s ease;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(0, 210, 255, 0.15);
  border-top-color: var(--accent-cyan);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.load-text {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--accent-cyan);
  text-transform: uppercase;
}

.load-sub {
  font-size: 11.5px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Ocultar elementos */
.hidden {
  display: none !important;
}
