/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body, #map {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 14px;
  color: #e0e0e0;
  background: #0a0f18;
}

/* === MapLibre overrides === */
.maplibregl-ctrl-attrib {
  font-size: 10px !important;
  background: rgba(10, 15, 24, 0.7) !important;
  color: #888 !important;
}
.maplibregl-ctrl-attrib a { color: #6af !important; }

/* === Top Bar === */
#topbar {
  position: absolute;
  top: 12px; left: 12px; right: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(20, 26, 38, 0.94);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 10px;
  z-index: 10;
  pointer-events: auto;
}

.ctrl-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctrl-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #8899aa;
}

#topbar button,
#topbar select {
  background: rgba(255,255,255,0.07);
  color: #d0d8e0;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
#topbar button:hover,
#topbar select:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.22);
}
#topbar select { min-width: 110px; }
#topbar select option { background: #1a2233; color: #d0d8e0; }

#btn-projection {
  font-size: 15px;
  padding: 4px 8px;
  min-width: 44px;
}

/* Toggle switches */
.toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  font-size: 12px;
  color: #99aabb;
  user-select: none;
}
.toggle input[type="checkbox"] {
  width: 15px; height: 15px;
  accent-color: #4da6ff;
  cursor: pointer;
}
.toggle:has(input:checked) span { color: #d0d8e0; }

#loading-indicator {
  margin-left: auto;
  font-size: 12px;
  color: #6af;
}
#loading-indicator.hidden { display: none; }

/* === Sidebar === */
#sidebar {
  position: absolute;
  top: 90px;
  right: 12px;
  width: 240px;
  padding: 14px;
  background: rgba(20, 26, 38, 0.94);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 10px;
  z-index: 10;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#entity-empty {
  font-size: 12px;
  color: #778899;
  text-align: center;
  padding: 8px 0;
}

#entity-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#entity-name {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  word-break: break-word;
}

#entity-area {
  font-size: 12px;
  color: #8fb8d8;
}

#entity-info label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: #99aabb;
}

#entity-info input[type="color"] {
  width: 32px; height: 28px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  padding: 1px;
}
#entity-info input[type="range"] {
  width: 100px;
  accent-color: #4da6ff;
  cursor: pointer;
}

.btn-danger {
  background: rgba(255, 80, 50, 0.2) !important;
  color: #f66 !important;
  border: 1px solid rgba(255, 80, 50, 0.35) !important;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-danger:hover {
  background: rgba(255, 80, 50, 0.35) !important;
}

.sidebar-hint {
  font-size: 11px;
  color: #556;
  text-align: center;
  line-height: 1.3;
  padding-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* === RTL (Arabic) === */
html[dir="rtl"] #sidebar {
  right: auto;
  left: 12px;
}
html[dir="rtl"] #topbar {
  direction: rtl;
}
html[dir="rtl"] #loading-indicator {
  margin-left: 0;
  margin-right: auto;
}
html[dir="rtl"] .ctrl-group {
  direction: rtl;
}

/* === Responsive === */
@media (max-width: 768px) {
  #topbar {
    top: 0; left: 0; right: 0;
    border-radius: 0;
    padding: 6px 8px;
    gap: 4px;
  }
  #topbar select { min-width: 90px; font-size: 12px; padding: 4px 6px; }
  #topbar button { font-size: 12px; padding: 4px 8px; }
  .toggles { display: none; } /* collapse toggles on mobile */

  #sidebar {
    top: auto; bottom: 0;
    right: 0; left: 0;
    width: 100%;
    border-radius: 12px 12px 0 0;
    padding: 10px 14px;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    justify-content: center;
  }
  #entity-empty { flex: 1 1 100%; }
  #entity-info {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
  }
  #entity-name { font-size: 13px; flex: 1 1 100%; }
  .sidebar-hint { display: none; }
}

@media (max-width: 480px) {
  #topbar { font-size: 11px; gap: 2px; padding: 4px 6px; }
  #topbar select { font-size: 11px; min-width: 75px; }
}
